blob: 11d1c061dc17d81ccdd1a5043a73d9738159e5fb [file] [log] [blame]
Daniel Borkmann41d6e332015-12-02 00:25:36 +01001#include "../../include/bpf_api.h"
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +01002
3/* Cyclic dependency example to test the kernel's runtime upper
Daniel Borkmann41d6e332015-12-02 00:25:36 +01004 * bound on loops. Also demonstrates on how to use direct-actions,
5 * loaded as: tc filter add [...] bpf da obj [...]
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +01006 */
Daniel Borkmann41d6e332015-12-02 00:25:36 +01007#define JMP_MAP_ID 0xabccba
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +01008
Daniel Borkmann4dd3f502016-04-09 00:32:05 +02009struct bpf_elf_map __section_maps jmp_tc = {
10 .type = BPF_MAP_TYPE_PROG_ARRAY,
11 .id = JMP_MAP_ID,
12 .size_key = sizeof(uint32_t),
13 .size_value = sizeof(uint32_t),
14 .pinning = PIN_OBJECT_NS,
15 .max_elem = 1,
16};
Daniel Borkmann41d6e332015-12-02 00:25:36 +010017
18__section_tail(JMP_MAP_ID, 0)
19int cls_loop(struct __sk_buff *skb)
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +010020{
Daniel Borkmann92a36992016-02-07 02:11:50 +010021 printt("cb: %u\n", skb->cb[0]++);
Daniel Borkmann41d6e332015-12-02 00:25:36 +010022 tail_call(skb, &jmp_tc, 0);
23
24 skb->tc_classid = TC_H_MAKE(1, 42);
25 return TC_ACT_OK;
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +010026}
27
Daniel Borkmann41d6e332015-12-02 00:25:36 +010028__section_cls_entry
29int cls_entry(struct __sk_buff *skb)
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +010030{
Daniel Borkmann41d6e332015-12-02 00:25:36 +010031 tail_call(skb, &jmp_tc, 0);
32 return TC_ACT_SHOT;
Daniel Borkmann0b7e3fc2015-11-26 15:38:46 +010033}
34
Daniel Borkmann41d6e332015-12-02 00:25:36 +010035BPF_LICENSE("GPL");