Skip to content

Commit

Permalink
bpf,test: Initialize per-cluster CT/SNAT for test
Browse files Browse the repository at this point in the history
Initialize per-cluster CT/SNAT map when BPF_TEST macro is defined.

Signed-off-by: Yutaro Hayakawa <yutaro.hayakawa@isovalent.com>
  • Loading branch information
YutaroHayakawa committed Mar 22, 2023
1 parent c1f2237 commit b5996c2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 18 deletions.
46 changes: 34 additions & 12 deletions bpf/lib/conntrack_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,33 +123,55 @@ struct {
} CT_MAP_ANY4 __section_maps_btf;

#ifdef ENABLE_CLUSTER_AWARE_ADDRESSING
struct per_cluster_ct_map4_inner_map {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, struct ipv4_ct_tuple);
__type(value, struct ct_entry);
__uint(max_entries, CT_MAP_SIZE_TCP);
#ifndef BPF_TEST
};
#else
} per_cluster_ct_tcp4_1 __section_maps_btf,
per_cluster_ct_tcp4_2 __section_maps_btf,
per_cluster_ct_any4_1 __section_maps_btf,
per_cluster_ct_any4_2 __section_maps_btf;
#endif

struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__type(key, __u32);
__type(value, __u32);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(max_entries, 256); /* Keep this sync with ClusterIDMax */
__array(values, struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, struct ipv4_ct_tuple);
__type(value, struct ct_entry);
__uint(max_entries, CT_MAP_SIZE_TCP);
});
__array(values, struct per_cluster_ct_map4_inner_map);
#ifndef BPF_TEST
} PER_CLUSTER_CT_TCP4 __section_maps_btf;
#else
} PER_CLUSTER_CT_TCP4 __section_maps_btf = {
.values = {
[1] = &per_cluster_ct_tcp4_1,
[2] = &per_cluster_ct_tcp4_2,
},
};
#endif

struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__type(key, __u32);
__type(value, __u32);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(max_entries, 256); /* Keep this sync with ClusterIDMax */
__array(values, struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, struct ipv4_ct_tuple);
__type(value, struct ct_entry);
__uint(max_entries, CT_MAP_SIZE_ANY);
});
__array(values, struct per_cluster_ct_map4_inner_map);
#ifndef BPF_TEST
} PER_CLUSTER_CT_ANY4 __section_maps_btf;
#else
} PER_CLUSTER_CT_ANY4 __section_maps_btf = {
.values = {
[1] = &per_cluster_ct_any4_1,
[2] = &per_cluster_ct_any4_2,
},
};
#endif
#endif

static __always_inline void *
Expand Down
28 changes: 22 additions & 6 deletions bpf/lib/nat.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,35 @@ struct {
} SNAT_MAPPING_IPV4 __section_maps_btf;

#ifdef ENABLE_CLUSTER_AWARE_ADDRESSING
struct per_cluster_snat_mapping_ipv4_inner_map {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, struct ipv4_ct_tuple);
__type(value, struct ipv4_nat_entry);
__uint(max_entries, SNAT_MAPPING_IPV4_SIZE);
#ifndef BPF_TEST
};
#else
} per_cluster_snat_mapping_ipv4_1 __section_maps_btf,
per_cluster_snat_mapping_ipv4_2 __section_maps_btf;
#endif

struct {
__uint(type, BPF_MAP_TYPE_ARRAY_OF_MAPS);
__type(key, __u32);
__type(value, __u32);
__uint(pinning, LIBBPF_PIN_BY_NAME);
__uint(max_entries, 256);
__array(values, struct {
__uint(type, BPF_MAP_TYPE_LRU_HASH);
__type(key, struct ipv4_ct_tuple);
__type(value, struct ipv4_nat_entry);
__uint(max_entries, SNAT_MAPPING_IPV4_SIZE);
});
__array(values, struct per_cluster_snat_mapping_ipv4_inner_map);
#ifndef BPF_TEST
} PER_CLUSTER_SNAT_MAPPING_IPV4 __section_maps_btf;
#else
} PER_CLUSTER_SNAT_MAPPING_IPV4 __section_maps_btf = {
.values = {
[1] = &per_cluster_snat_mapping_ipv4_1,
[2] = &per_cluster_snat_mapping_ipv4_2,
},
};
#endif
#endif

#ifdef ENABLE_IP_MASQ_AGENT
Expand Down

0 comments on commit b5996c2

Please sign in to comment.