From 9c4adddcf8ca4fa880f5928f9f4f094a598730ec Mon Sep 17 00:00:00 2001 From: mzz2017 <2017@duck.com> Date: Sun, 16 Jul 2023 23:18:59 +0800 Subject: [PATCH] fix(ebpf): udp problem caused by #221 by accident --- control/kern/tproxy.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/control/kern/tproxy.c b/control/kern/tproxy.c index 98598acf3..a2988bf68 100644 --- a/control/kern/tproxy.c +++ b/control/kern/tproxy.c @@ -368,6 +368,7 @@ get_tuples(const struct __sk_buff *skb, struct tuples *tuples, const struct tcphdr *tcph, const struct udphdr *udph, __u8 l4proto) { __builtin_memset(tuples, 0, sizeof(*tuples)); tuples->l4proto = l4proto; + if (skb->protocol == bpf_htons(ETH_P_IP)) { tuples->sip.u6_addr32[2] = bpf_htonl(0x0000ffff); tuples->sip.u6_addr32[3] = iph->saddr; @@ -684,15 +685,12 @@ parse_transport(const struct __sk_buff *skb, __u32 eth_h_len, } break; case IPPROTO_UDP: { if ((ret = - bpf_skb_load_bytes(skb, offset, tcph, sizeof(struct tcphdr)))) { - // Not a complete tcphdr. + bpf_skb_load_bytes(skb, offset, udph, sizeof(struct udphdr)))) { + // Not a complete udphdr. return -EFAULT; } } break; default: - /// EXPECTED: Maybe ICMP, MPLS, etc. - // bpf_printk("IP but not supported packet: protocol is %u", - // iph->protocol); return 1; } *ihl = iph->ihl; @@ -710,7 +708,10 @@ parse_transport(const struct __sk_buff *skb, __u32 eth_h_len, return handle_ipv6_extensions(skb, offset, ipv6h->nexthdr, icmp6h, tcph, udph, ihl, l4proto); } else { - bpf_printk("unknown link proto: %u", bpf_ntohl(skb->protocol)); + /// EXPECTED: Maybe ICMP, MPLS, etc. + // bpf_printk("IP but not supported packet: protocol is %u", + // iph->protocol); + // bpf_printk("unknown link proto: %u", bpf_ntohl(skb->protocol)); return 1; } }