github.com/datadog/cilium@v1.6.12/bpf/lib/conntrack_map.h (about) 1 /* 2 * Copyright (C) 2016-2019 Authors of Cilium 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 */ 18 #ifndef __LIB_CONNTRACK_MAP_H_ 19 #define __LIB_CONNTRACK_MAP_H_ 20 21 #include "common.h" 22 #include "config.h" 23 24 #if defined CT_MAP_TCP4 && defined CT_MAP_TCP6 25 #ifdef HAVE_LRU_MAP_TYPE 26 #define CT_MAP_TYPE BPF_MAP_TYPE_LRU_HASH 27 #else 28 #define CT_MAP_TYPE BPF_MAP_TYPE_HASH 29 #endif 30 31 #ifdef ENABLE_IPV6 32 struct bpf_elf_map __section_maps CT_MAP_TCP6 = { 33 .type = CT_MAP_TYPE, 34 .size_key = sizeof(struct ipv6_ct_tuple), 35 .size_value = sizeof(struct ct_entry), 36 .pinning = PIN_GLOBAL_NS, 37 .max_elem = CT_MAP_SIZE_TCP, 38 #ifndef HAVE_LRU_MAP_TYPE 39 .flags = CONDITIONAL_PREALLOC, 40 #endif 41 }; 42 43 struct bpf_elf_map __section_maps CT_MAP_ANY6 = { 44 .type = CT_MAP_TYPE, 45 .size_key = sizeof(struct ipv6_ct_tuple), 46 .size_value = sizeof(struct ct_entry), 47 .pinning = PIN_GLOBAL_NS, 48 .max_elem = CT_MAP_SIZE_ANY, 49 #ifndef HAVE_LRU_MAP_TYPE 50 .flags = CONDITIONAL_PREALLOC, 51 #endif 52 }; 53 54 static inline struct bpf_elf_map * 55 get_ct_map6(struct ipv6_ct_tuple *tuple) 56 { 57 if (tuple->nexthdr == IPPROTO_TCP) { 58 return &CT_MAP_TCP6; 59 } 60 return &CT_MAP_ANY6; 61 } 62 #endif 63 64 #ifdef ENABLE_IPV4 65 struct bpf_elf_map __section_maps CT_MAP_TCP4 = { 66 .type = CT_MAP_TYPE, 67 .size_key = sizeof(struct ipv4_ct_tuple), 68 .size_value = sizeof(struct ct_entry), 69 .pinning = PIN_GLOBAL_NS, 70 .max_elem = CT_MAP_SIZE_TCP, 71 #ifndef HAVE_LRU_MAP_TYPE 72 .flags = CONDITIONAL_PREALLOC, 73 #endif 74 }; 75 76 struct bpf_elf_map __section_maps CT_MAP_ANY4 = { 77 .type = CT_MAP_TYPE, 78 .size_key = sizeof(struct ipv4_ct_tuple), 79 .size_value = sizeof(struct ct_entry), 80 .pinning = PIN_GLOBAL_NS, 81 .max_elem = CT_MAP_SIZE_ANY, 82 #ifndef HAVE_LRU_MAP_TYPE 83 .flags = CONDITIONAL_PREALLOC, 84 #endif 85 }; 86 87 static inline struct bpf_elf_map * 88 get_ct_map4(struct ipv4_ct_tuple *tuple) 89 { 90 if (tuple->nexthdr == IPPROTO_TCP) { 91 return &CT_MAP_TCP4; 92 } 93 return &CT_MAP_ANY4; 94 } 95 #endif 96 #endif 97 #endif /* __LIB_CONNTRACK_MAP_H_ */