samples: bpf: trivial eBPF program in C
authorAlexei Starovoitov <ast@plumgrid.com>
Mon, 1 Dec 2014 23:06:38 +0000 (15:06 -0800)
committerDavid S. Miller <davem@davemloft.net>
Sat, 6 Dec 2014 05:47:33 +0000 (21:47 -0800)
commita80857822b0c2ed608c93504bd3687b78f20c619
tree8fb218a13a13a16d5083c7b831398f967137f152
parent249b812d8005ec38e351ee763ceb85d56b155064
samples: bpf: trivial eBPF program in C

this example does the same task as previous socket example
in assembler, but this one does it in C.

eBPF program in kernel does:
    /* assume that packet is IPv4, load one byte of IP->proto */
    int index = load_byte(skb, ETH_HLEN + offsetof(struct iphdr, protocol));
    long *value;

    value = bpf_map_lookup_elem(&my_map, &index);
    if (value)
        __sync_fetch_and_add(value, 1);

Corresponding user space reads map[tcp], map[udp], map[icmp]
and prints protocol stats every second

Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
samples/bpf/Makefile
samples/bpf/libbpf.h
samples/bpf/sockex1_kern.c [new file with mode: 0644]
samples/bpf/sockex1_user.c [new file with mode: 0644]