Blame examples/bpf/legacy/bpf_cyclic.c

Packit Bot 867fae
#include "../../../include/bpf_api.h"
Packit Bot 867fae
Packit Bot 867fae
/* Cyclic dependency example to test the kernel's runtime upper
Packit Bot 867fae
 * bound on loops. Also demonstrates on how to use direct-actions,
Packit Bot 867fae
 * loaded as: tc filter add [...] bpf da obj [...]
Packit Bot 867fae
 */
Packit Bot 867fae
#define JMP_MAP_ID	0xabccba
Packit Bot 867fae
Packit Bot 867fae
struct bpf_elf_map __section_maps jmp_tc = {
Packit Bot 867fae
	.type		= BPF_MAP_TYPE_PROG_ARRAY,
Packit Bot 867fae
	.id		= JMP_MAP_ID,
Packit Bot 867fae
	.size_key	= sizeof(uint32_t),
Packit Bot 867fae
	.size_value	= sizeof(uint32_t),
Packit Bot 867fae
	.pinning	= PIN_OBJECT_NS,
Packit Bot 867fae
	.max_elem	= 1,
Packit Bot 867fae
};
Packit Bot 867fae
Packit Bot 867fae
__section_tail(JMP_MAP_ID, 0)
Packit Bot 867fae
int cls_loop(struct __sk_buff *skb)
Packit Bot 867fae
{
Packit Bot 867fae
	printt("cb: %u\n", skb->cb[0]++);
Packit Bot 867fae
	tail_call(skb, &jmp_tc, 0);
Packit Bot 867fae
Packit Bot 867fae
	skb->tc_classid = TC_H_MAKE(1, 42);
Packit Bot 867fae
	return TC_ACT_OK;
Packit Bot 867fae
}
Packit Bot 867fae
Packit Bot 867fae
__section_cls_entry
Packit Bot 867fae
int cls_entry(struct __sk_buff *skb)
Packit Bot 867fae
{
Packit Bot 867fae
	tail_call(skb, &jmp_tc, 0);
Packit Bot 867fae
	return TC_ACT_SHOT;
Packit Bot 867fae
}
Packit Bot 867fae
Packit Bot 867fae
BPF_LICENSE("GPL");