github.phpd.cn/cilium/cilium@v1.6.12/test/bpf/elf-demo.c (about) 1 // SPDX-License-Identifier: GPL-2.0 2 // Copyright (c) 2018-2019 Authors of Cilium 3 #include <linux/bpf.h> 4 #include <string.h> 5 6 #define LB_RR_MAX_SEQ 7 #include "lib/utils.h" 8 #include "lib/common.h" 9 #include "lib/eth.h" 10 11 DEFINE_U32(FOO, 0xF0F0F0F0); 12 DEFINE_U32(BAR, 0xCECECECE); 13 DEFINE_IPV6(GLOBAL_IPV6, 0x1, 0, 0x1, 0, 0, 0x1, 0, 0x1, 0x1, 0, 0x1, 0, 0, 0x1, 0, 0x1); 14 DEFINE_MAC(LOCAL_MAC, 0, 0x1, 0, 0, 0, 0x1); 15 16 #define CALLS_MAP_ID 1 17 #undef CALLS_MAP 18 #define CALLS_MAP test_cilium_calls_4278124286 // 0xFEFEFEFE 19 20 struct bpf_elf_map __section_maps CALLS_MAP = { 21 .type = BPF_MAP_TYPE_PROG_ARRAY, 22 .id = CALLS_MAP_ID, 23 .size_key = sizeof(__u32), 24 .size_value = sizeof(__u32), 25 .pinning = PIN_GLOBAL_NS, 26 .max_elem = CALLS_MAP_ID, 27 }; 28 29 __section_tail(CALLS_MAP_ID, 0) int tail_lxc_prog(struct __sk_buff *skb) { 30 return TC_ACT_OK; 31 } 32 33 int __main(struct __sk_buff *skb) 34 { 35 union v6addr v6 = {}; 36 union macaddr mac = fetch_mac(LOCAL_MAC); 37 38 skb->mark = fetch_u32(FOO); 39 skb->cb[0] = fetch_u32(BAR); 40 41 BPF_V6(v6, GLOBAL_IPV6); 42 skb->cb[1] = v6.p1; 43 skb->cb[2] = v6.p2; 44 skb->cb[3] = v6.p3; 45 skb->cb[4] = v6.p4; 46 47 skb->priority = mac.p1; 48 skb->tc_classid = mac.p2; 49 50 tail_call(skb, &CALLS_MAP, CALLS_MAP_ID); 51 return TC_ACT_OK; 52 } 53 54 char __license[] __section("license") = "";