Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Fix missing return code for dns response #329

Merged
merged 2 commits into from
May 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions pkg/plugin/common/common_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ package common
import (
"errors"
"os"
"strings"
"syscall"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/perf"
"github.com/google/gopacket/layers"
"github.com/microsoft/retina/pkg/log"
"go.uber.org/zap"
"golang.org/x/sys/unix"
Expand Down Expand Up @@ -41,18 +41,21 @@ func ProtocolToFlow(protocol string) int {
}

// Refer: https://www.iana.org/assignments/dns-parameters/dns-parameters.xhtml#dns-parameters-6
// Inspektor gadget uses Gopacket pkg for DNS response codes.
// Ref: https://github.com/google/gopacket/blob/32ee38206866f44a74a6033ec26aeeb474506804/layers/dns.go#L129
func RCodeToFlow(rCode string) uint32 {
if strings.EqualFold(rCode, "NoError") {
switch rCode {
case layers.DNSResponseCodeNoErr.String():
return 0
} else if strings.EqualFold(rCode, "FormErr") {
case layers.DNSResponseCodeFormErr.String():
return 1
} else if strings.EqualFold(rCode, "ServFail") {
case layers.DNSResponseCodeServFail.String():
return 2
} else if strings.EqualFold(rCode, "NXDomain") {
case layers.DNSResponseCodeNXDomain.String():
return 3
} else if strings.EqualFold(rCode, "NotImp") {
case layers.DNSResponseCodeNotImp.String():
return 4
} else if strings.EqualFold(rCode, "Refused") {
case layers.DNSResponseCodeRefused.String():
return 5
}
return 24
Expand Down
4 changes: 2 additions & 2 deletions pkg/plugin/dns/dns_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func TestRequestEventHandler(t *testing.T) {

event := &types.Event{
Qr: "Q",
Rcode: "NOERROR",
Rcode: "No Error",
QType: "A",
DNSName: "test.com",
Addresses: []string{},
Expand Down Expand Up @@ -175,7 +175,7 @@ func TestResponseEventHandler(t *testing.T) {

event := &types.Event{
Qr: "R",
Rcode: "NOERROR",
Rcode: "No Error",
QType: "A",
DNSName: "test.com",
Addresses: []string{"1.1.1.1", "2.2.2.2"},
Expand Down
Loading