diff options
| author | Alexei Starovoitov <ast@plumgrid.com> | 2014-12-01 18:06:36 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-12-06 00:47:32 -0500 |
| commit | 03f4723ed7a52bd31da26eefe2cdde563ea0f468 (patch) | |
| tree | 4a3f1b2427c8bf1f2e86f4f1e842a32c5602b621 /samples/bpf/Makefile | |
| parent | 89aa075832b0da4402acebd698d0411dcc82d03e (diff) | |
samples: bpf: example of stateful socket filtering
this socket filter example does:
- creates arraymap in kernel with key 4 bytes and value 8 bytes
- loads eBPF program which assumes that packet is IPv4 and loads one byte of
IP->proto from the packet and uses it as a key in a map
r0 = skb->data[ETH_HLEN + offsetof(struct iphdr, protocol)];
*(u32*)(fp - 4) = r0;
value = bpf_map_lookup_elem(map_fd, fp - 4);
if (value)
(*(u64*)value) += 1;
- attaches this program to raw socket
- every second user space reads map[IPPROTO_TCP], map[IPPROTO_UDP], map[IPPROTO_ICMP]
to see how many packets of given protocol were seen on loopback interface
Usage:
$sudo samples/bpf/sock_example
TCP 0 UDP 0 ICMP 0 packets
TCP 187600 UDP 0 ICMP 4 packets
TCP 376504 UDP 0 ICMP 8 packets
TCP 563116 UDP 0 ICMP 12 packets
TCP 753144 UDP 0 ICMP 16 packets
Signed-off-by: Alexei Starovoitov <ast@plumgrid.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'samples/bpf/Makefile')
| -rw-r--r-- | samples/bpf/Makefile | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/samples/bpf/Makefile b/samples/bpf/Makefile index 0718d9ce4619..f46d3492d032 100644 --- a/samples/bpf/Makefile +++ b/samples/bpf/Makefile | |||
| @@ -3,9 +3,11 @@ obj- := dummy.o | |||
| 3 | 3 | ||
| 4 | # List of programs to build | 4 | # List of programs to build |
| 5 | hostprogs-y := test_verifier test_maps | 5 | hostprogs-y := test_verifier test_maps |
| 6 | hostprogs-y += sock_example | ||
| 6 | 7 | ||
| 7 | test_verifier-objs := test_verifier.o libbpf.o | 8 | test_verifier-objs := test_verifier.o libbpf.o |
| 8 | test_maps-objs := test_maps.o libbpf.o | 9 | test_maps-objs := test_maps.o libbpf.o |
| 10 | sock_example-objs := sock_example.o libbpf.o | ||
| 9 | 11 | ||
| 10 | # Tell kbuild to always build the programs | 12 | # Tell kbuild to always build the programs |
| 11 | always := $(hostprogs-y) | 13 | always := $(hostprogs-y) |
