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

Add support for snooping DNS over TCP #1887

Merged
merged 2 commits into from
Sep 23, 2016
Merged
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
28 changes: 27 additions & 1 deletion probe/endpoint/dns_snooper_linux_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,38 @@ func (s *DNSSnooper) Stop() {
}
}

// Gopacket doesn't provide direct support for DNS over TCP, see https://github.com/google/gopacket/issues/236
// TODO: deal with TCP fragmentation and out-of-order segments

This comment was marked as abuse.

This comment was marked as abuse.

type tcpWithDNSSupport struct {
tcp layers.TCP
}

func (m *tcpWithDNSSupport) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
return m.tcp.DecodeFromBytes(data, df)
}
func (m *tcpWithDNSSupport) CanDecode() gopacket.LayerClass { return m.tcp.CanDecode() }
func (m *tcpWithDNSSupport) NextLayerType() gopacket.LayerType {
if m.tcp.SrcPort == 53 || m.tcp.DstPort == 53 {
return layers.LayerTypeDNS
}
return m.tcp.NextLayerType()
}
func (m *tcpWithDNSSupport) LayerPayload() []byte {
payload := m.tcp.LayerPayload()
// Omit the DNS length field, only included
// in TCP, in order to reuse the DNS UDP parser
if len(payload) > 1 && (m.tcp.SrcPort == 53 || m.tcp.DstPort == 53) {
payload = payload[2:]
}
return payload
}

func (s *DNSSnooper) run() {
var (
decodedLayers []gopacket.LayerType
dns layers.DNS
udp layers.UDP
tcp layers.TCP
tcp tcpWithDNSSupport
ip4 layers.IPv4
ip6 layers.IPv6
eth layers.Ethernet
Expand Down