mirror of
https://github.com/varun-r-mallya/Python-BPF.git
synced 2025-12-31 21:06:25 +00:00
fix the c form of the xdp program
This commit is contained in:
@ -1,19 +1,18 @@
|
|||||||
#include "vmlinux.h"
|
|
||||||
#include <bpf/bpf_helpers.h>
|
|
||||||
#include <linux/bpf.h>
|
#include <linux/bpf.h>
|
||||||
#include <linux/if_ether.h>
|
#include <linux/if_ether.h>
|
||||||
#include <linux/ip.h>
|
#include <linux/ip.h>
|
||||||
|
#include <bpf/bpf_helpers.h>
|
||||||
|
|
||||||
struct fake_iphdr {
|
struct fake_iphdr {
|
||||||
unsigned short useless;
|
unsigned short useless;
|
||||||
unsigned short tot_len;
|
unsigned short tot_len;
|
||||||
unsigned short id;
|
unsigned short id;
|
||||||
unsigned short frag_off;
|
unsigned short frag_off;
|
||||||
unsigned char ttl;
|
unsigned char ttl;
|
||||||
unsigned char protocol;
|
unsigned char protocol;
|
||||||
unsigned short check;
|
unsigned short check;
|
||||||
unsigned int saddr;
|
unsigned int saddr;
|
||||||
unsigned int daddr;
|
unsigned int daddr;
|
||||||
};
|
};
|
||||||
|
|
||||||
SEC("xdp")
|
SEC("xdp")
|
||||||
@ -21,16 +20,14 @@ int xdp_prog(struct xdp_md *ctx) {
|
|||||||
unsigned long data = ctx->data;
|
unsigned long data = ctx->data;
|
||||||
unsigned long data_end = ctx->data_end;
|
unsigned long data_end = ctx->data_end;
|
||||||
|
|
||||||
if (data + sizeof(struct ethhdr) + sizeof(struct fake_iphdr) <= data_end) {
|
if (data + sizeof(struct ethhdr) + sizeof(struct fake_iphdr) > data_end) {
|
||||||
struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr);
|
|
||||||
|
|
||||||
bpf_printk("%d", iph->saddr);
|
|
||||||
|
|
||||||
return XDP_PASS;
|
|
||||||
} else {
|
|
||||||
return XDP_ABORTED;
|
return XDP_ABORTED;
|
||||||
}
|
}
|
||||||
struct task_struct * a = btf_bpf_get_current_task_btf();
|
struct fake_iphdr *iph = (void *)data + sizeof(struct ethhdr);
|
||||||
|
|
||||||
|
bpf_printk("%d", iph->saddr);
|
||||||
|
|
||||||
|
return XDP_PASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
char _license[] SEC("license") = "GPL";
|
char _license[] SEC("license") = "GPL";
|
||||||
|
|||||||
Reference in New Issue
Block a user