github.com/cilium/cilium@v1.16.2/bpf/tests/lib/endpoint.h (about) 1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */ 2 /* Copyright Authors of Cilium */ 3 4 static __always_inline void 5 endpoint_v4_add_entry(__be32 addr, __u32 ifindex, __u16 lxc_id, __u32 flags, __u32 sec_id, 6 const __u8 *ep_mac_addr, const __u8 *node_mac_addr) 7 { 8 struct endpoint_key key = { 9 .ip4 = addr, 10 .family = ENDPOINT_KEY_IPV4, 11 }; 12 struct endpoint_info value = { 13 .ifindex = ifindex, 14 .lxc_id = lxc_id, 15 .flags = flags, 16 .sec_id = sec_id, 17 }; 18 19 if (ep_mac_addr) 20 memcpy(&value.mac, ep_mac_addr, ETH_ALEN); 21 if (node_mac_addr) 22 memcpy(&value.node_mac, node_mac_addr, ETH_ALEN); 23 24 map_update_elem(&ENDPOINTS_MAP, &key, &value, BPF_ANY); 25 } 26 27 static __always_inline void 28 endpoint_v4_del_entry(__be32 addr) 29 { 30 struct endpoint_key key = { 31 .ip4 = addr, 32 .family = ENDPOINT_KEY_IPV4, 33 }; 34 35 map_delete_elem(&ENDPOINTS_MAP, &key); 36 } 37 38 static __always_inline void 39 endpoint_v6_add_entry(const union v6addr *addr, __u32 ifindex, __u16 lxc_id, 40 __u32 flags, __u32 sec_id, 41 const __u8 *ep_mac_addr, const __u8 *node_mac_addr) 42 { 43 struct endpoint_key key = { 44 .family = ENDPOINT_KEY_IPV6, 45 }; 46 47 struct endpoint_info value = { 48 .ifindex = ifindex, 49 .lxc_id = lxc_id, 50 .flags = flags, 51 .sec_id = sec_id, 52 }; 53 54 memcpy(&key.ip6, addr, sizeof(*addr)); 55 56 if (ep_mac_addr) 57 memcpy(&value.mac, ep_mac_addr, ETH_ALEN); 58 if (node_mac_addr) 59 memcpy(&value.node_mac, node_mac_addr, ETH_ALEN); 60 61 map_update_elem(&ENDPOINTS_MAP, &key, &value, BPF_ANY); 62 }