File tree Expand file tree Collapse file tree 1 file changed +16
-19
lines changed
Expand file tree Collapse file tree 1 file changed +16
-19
lines changed Original file line number Diff line number Diff line change 1- #include "vmlinux.h"
2- #include <bpf/bpf_helpers.h>
31#include <linux/bpf.h>
42#include <linux/if_ether.h>
53#include <linux/ip.h>
4+ #include <bpf/bpf_helpers.h>
65
76struct fake_iphdr {
8- unsigned short useless ;
9- unsigned short tot_len ;
10- unsigned short id ;
11- unsigned short frag_off ;
12- unsigned char ttl ;
13- unsigned char protocol ;
14- unsigned short check ;
15- unsigned int saddr ;
16- unsigned int daddr ;
7+ unsigned short useless ;
8+ unsigned short tot_len ;
9+ unsigned short id ;
10+ unsigned short frag_off ;
11+ unsigned char ttl ;
12+ unsigned char protocol ;
13+ unsigned short check ;
14+ unsigned int saddr ;
15+ unsigned int daddr ;
1716};
1817
1918SEC ("xdp" )
2019int xdp_prog (struct xdp_md * ctx ) {
2120 unsigned long data = ctx -> data ;
2221 unsigned long data_end = ctx -> data_end ;
2322
24- if (data + sizeof (struct ethhdr ) + sizeof (struct fake_iphdr ) <= data_end ) {
25- struct fake_iphdr * iph = (void * )data + sizeof (struct ethhdr );
26-
27- bpf_printk ("%d" , iph -> saddr );
28-
29- return XDP_PASS ;
30- } else {
23+ if (data + sizeof (struct ethhdr ) + sizeof (struct fake_iphdr ) > data_end ) {
3124 return XDP_ABORTED ;
3225 }
33- struct task_struct * a = btf_bpf_get_current_task_btf ();
26+ struct fake_iphdr * iph = (void * )data + sizeof (struct ethhdr );
27+
28+ bpf_printk ("%d" , iph -> saddr );
29+
30+ return XDP_PASS ;
3431}
3532
3633char _license [] SEC ("license" ) = "GPL" ;
You can’t perform that action at this time.
0 commit comments