dropbox / dropbox/goebpf

creating elf file

Open
#8 13 comments 0 reactions 0 assignees View on GitHub
help wanted question
Dominant language
Go
Stars
1.2k
Forks
82
PR merge metrics
No merged PRs in 30d

Description

I am trying to create my own elf file using examples suggested in the examples. .c file as below

```
#include "bpf_helpers.h"

struct iphdr {
__u8 ihl : 4;
__u8 version : 4;
__u8 tos;
__u16 tot_len;
__u16 id;
__u16 frag_off;
__u8 ttl;
__u8 protocol;
__u16 check;
__u32 saddr;
__u32 daddr;
};

struct Key {
__u32 src_ip; //source ip
__u32 dst_ip; //destination ip
__u16 src_port; //source port
__u16 dst_port; //destination port
};

struct Leaf {
__u64 timestamp; //timestamp in ns
};

// eBPF map to store IP proto counters (tcp, udp, etc)
BPF_MAP_DEF(sessions) = {
.map_type = BPF_MAP_TYPE_HASH,
.key_size = 96,
.value_size = 64,
.max_entries = 255,
};
BPF_MAP_ADD(sessions);

SEC("socket_filter")
int ip_filter(struct __sk_buff *skb) {
struct Key key = {};
struct Leaf zero = {0};

struct iphdr *ip = (struct iphdr *)skb_network_header(skb);

```
1) Getting following warning. Basically how to get iphdr from sk_buff ?
```
clang -I../../.. -O2 -target bpf -c ebpf_prog/xdp.c -o ebpf_prog/xdp.elf -static
ebpf_prog/xdp.c:59:38: warning: implicit declaration of function 'skb_network_header' is invalid in C99
[-Wimplicit-function-declaration]
struct iphdr *ip = (struct iphdr *)skb_network_header(skb);
^
ebpf_prog/xdp.c:59:22: warning: cast to 'struct iphdr *' from smaller integer type 'int' [-Wint-to-pointer-cast]
struct iphdr *ip = (struct iphdr *)skb_network_header(skb);

```
2) When i run the program using go, get following issue ?
`LoadElf() failed: loadPrograms() failed: Invalid BPF instruction (at 0): &{133 0 1 0 4294967295}`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.