Skip to content

Commit

Permalink
packetloss: ignore non ip packet
Browse files Browse the repository at this point in the history
  • Loading branch information
jzwlqx committed Apr 7, 2024
1 parent 0390fe4 commit 464ceef
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions bpf/headers/inspector.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ static __always_inline int set_tuple(struct sk_buff *skb, struct tuple *tpl) {
l3_off = BPF_CORE_READ(skb, network_header);
l4_off = BPF_CORE_READ(skb, transport_header);

if (l3_off == 0){
return -1;
}

ip = (struct iphdr *)(skb_head + l3_off);
bpf_probe_read(&iphdr_first_byte, 1, ip);
ip_vsn = iphdr_first_byte >> 4;
Expand Down
5 changes: 4 additions & 1 deletion bpf/packetloss.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ int kfree_skb(struct kfree_skb_args *args) {
struct sk_buff *skb = (struct sk_buff *)args->skb;
struct insp_pl_event_t event = {0};

set_tuple(skb, &event.tuple);
if (set_tuple(skb, &event.tuple) < 0){
//invalid packet, skip
goto out;
}
event.location = (u64)args->location;

if (enable_packetloss_stack){
Expand Down
Binary file modified pkg/exporter/probe/tracepacketloss/bpf_bpfeb.o
Binary file not shown.
Binary file modified pkg/exporter/probe/tracepacketloss/bpf_bpfel.o
Binary file not shown.

0 comments on commit 464ceef

Please sign in to comment.