Skip to content

Commit 207bf12

Browse files
authored
Merge pull request #134 from OpenCloudOS/dev
bpf: fix L3 protocol not filter exception
2 parents 7698521 + a0b5bda commit 207bf12

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

shared/bpf/skb_parse.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,16 @@ static __always_inline int probe_parse_skb(struct sk_buff *skb, struct sock *sk,
662662
l3_proto = bpf_ntohs(_(eth->h_proto));
663663
}
664664

665-
if (filter_enabled(args, l4_proto) && !args->l3_proto &&
666-
l3_proto != ETH_P_IP && l3_proto != ETH_P_IPV6)
667-
return -1;
665+
if (args) {
666+
if (args->l3_proto) {
667+
if (args->l3_proto != l3_proto)
668+
return -1;
669+
} else if (args->l4_proto) {
670+
/* Only IPv4 and IPv6 support L4 protocol filter */
671+
if (l3_proto != ETH_P_IP && l3_proto != ETH_P_IPV6)
672+
return -1;
673+
}
674+
}
668675

669676
pkt->proto_l3 = l3_proto;
670677
pr_debug_skb("l3=%d", l3_proto);
@@ -676,7 +683,7 @@ static __always_inline int probe_parse_skb(struct sk_buff *skb, struct sock *sk,
676683
case ETH_P_ARP:
677684
return probe_parse_arp(l3, pkt, args);
678685
default:
679-
return filter_enabled(args, l4_proto) ? -1 : 0;
686+
return 0;
680687
}
681688
}
682689

src/nettrace.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ static void do_parse_args(int argc, char *argv[])
350350
default:
351351
break;
352352
}
353+
354+
/* set L3 protocol if addr is offered */
353355
FILL_ADDR(saddr, pkt_args)
354356
FILL_ADDR(daddr, pkt_args)
355357
FILL_ADDR(addr, pkt_args)

0 commit comments

Comments
 (0)