]> git.proxmox.com Git - mirror_iproute2.git/blame - examples/bpf/bpf_cyclic.c
examples, bpf: further improve examples
[mirror_iproute2.git] / examples / bpf / bpf_cyclic.c
CommitLineData
41d6e33f 1#include "../../include/bpf_api.h"
0b7e3fc8
DB
2
3/* Cyclic dependency example to test the kernel's runtime upper
41d6e33f
DB
4 * bound on loops. Also demonstrates on how to use direct-actions,
5 * loaded as: tc filter add [...] bpf da obj [...]
0b7e3fc8 6 */
41d6e33f
DB
7#define JMP_MAP_ID 0xabccba
8
9BPF_PROG_ARRAY(jmp_tc, JMP_MAP_ID, PIN_OBJECT_NS, 1);
0b7e3fc8 10
41d6e33f
DB
11__section_tail(JMP_MAP_ID, 0)
12int cls_loop(struct __sk_buff *skb)
0b7e3fc8
DB
13{
14 char fmt[] = "cb: %u\n";
15
41d6e33f
DB
16 trace_printk(fmt, sizeof(fmt), skb->cb[0]++);
17 tail_call(skb, &jmp_tc, 0);
18
19 skb->tc_classid = TC_H_MAKE(1, 42);
20 return TC_ACT_OK;
0b7e3fc8
DB
21}
22
41d6e33f
DB
23__section_cls_entry
24int cls_entry(struct __sk_buff *skb)
0b7e3fc8 25{
41d6e33f
DB
26 tail_call(skb, &jmp_tc, 0);
27 return TC_ACT_SHOT;
0b7e3fc8
DB
28}
29
41d6e33f 30BPF_LICENSE("GPL");