Skip to content

Commit

Permalink
tools/tcpconnect: Support IPv6 DNS
Browse files Browse the repository at this point in the history
Add IPv6 DNS support for tcpconnect.
Fixes iovisor#3933.

Signed-off-by: Hengqi Chen <[email protected]>
  • Loading branch information
chenhengqi authored and yonghong-song committed Apr 27, 2022
1 parent 7231ddb commit 1e510db
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions tools/tcpconnect.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,31 @@
return 0;
}
#include <uapi/linux/udp.h>
int trace_udpv6_recvmsg(struct pt_regs *ctx)
{
struct sk_buff *skb = (struct sk_buff *)PT_REGS_PARM2(ctx);
struct udphdr *hdr = (void*)skb->head + skb->transport_header;
struct dns_data_t *event;
int zero = 0;
void *data;
/* hex(53) = 0x0035, htons(0x0035) = 0x3500 */
if (hdr->source != 0x3500)
return 0;
/* skip UDP header */
data = skb->data + 8;
event = dns_data.lookup(&zero);
if (!event)
return 0;
bpf_probe_read(event->pkt, sizeof(event->pkt), data);
dns_events.perf_submit(ctx, event, sizeof(*event));
return 0;
}
"""

if args.count and args.dns:
Expand Down Expand Up @@ -510,6 +535,7 @@ def save_dns(cpu, data, size):
if args.dns:
b.attach_kprobe(event="udp_recvmsg", fn_name="trace_udp_recvmsg")
b.attach_kretprobe(event="udp_recvmsg", fn_name="trace_udp_ret_recvmsg")
b.attach_kprobe(event="udpv6_queue_rcv_one_skb", fn_name="trace_udpv6_recvmsg")

print("Tracing connect ... Hit Ctrl-C to end")
if args.count:
Expand Down

0 comments on commit 1e510db

Please sign in to comment.