hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/samples/bpf/xdp_router_ipv4_kern.c
....@@ -12,7 +12,7 @@
1212 #include <linux/if_vlan.h>
1313 #include <linux/ip.h>
1414 #include <linux/ipv6.h>
15
-#include "bpf_helpers.h"
15
+#include <bpf/bpf_helpers.h>
1616 #include <linux/slab.h>
1717 #include <net/ip_fib.h>
1818
....@@ -42,44 +42,44 @@
4242 };
4343
4444 /* Map for trie implementation*/
45
-struct bpf_map_def SEC("maps") lpm_map = {
46
- .type = BPF_MAP_TYPE_LPM_TRIE,
47
- .key_size = 8,
48
- .value_size = sizeof(struct trie_value),
49
- .max_entries = 50,
50
- .map_flags = BPF_F_NO_PREALLOC,
51
-};
45
+struct {
46
+ __uint(type, BPF_MAP_TYPE_LPM_TRIE);
47
+ __uint(key_size, 8);
48
+ __uint(value_size, sizeof(struct trie_value));
49
+ __uint(max_entries, 50);
50
+ __uint(map_flags, BPF_F_NO_PREALLOC);
51
+} lpm_map SEC(".maps");
5252
5353 /* Map for counter*/
54
-struct bpf_map_def SEC("maps") rxcnt = {
55
- .type = BPF_MAP_TYPE_PERCPU_ARRAY,
56
- .key_size = sizeof(u32),
57
- .value_size = sizeof(u64),
58
- .max_entries = 256,
59
-};
54
+struct {
55
+ __uint(type, BPF_MAP_TYPE_PERCPU_ARRAY);
56
+ __type(key, u32);
57
+ __type(value, u64);
58
+ __uint(max_entries, 256);
59
+} rxcnt SEC(".maps");
6060
6161 /* Map for ARP table*/
62
-struct bpf_map_def SEC("maps") arp_table = {
63
- .type = BPF_MAP_TYPE_HASH,
64
- .key_size = sizeof(__be32),
65
- .value_size = sizeof(__be64),
66
- .max_entries = 50,
67
-};
62
+struct {
63
+ __uint(type, BPF_MAP_TYPE_HASH);
64
+ __type(key, __be32);
65
+ __type(value, __be64);
66
+ __uint(max_entries, 50);
67
+} arp_table SEC(".maps");
6868
6969 /* Map to keep the exact match entries in the route table*/
70
-struct bpf_map_def SEC("maps") exact_match = {
71
- .type = BPF_MAP_TYPE_HASH,
72
- .key_size = sizeof(__be32),
73
- .value_size = sizeof(struct direct_map),
74
- .max_entries = 50,
75
-};
70
+struct {
71
+ __uint(type, BPF_MAP_TYPE_HASH);
72
+ __type(key, __be32);
73
+ __type(value, struct direct_map);
74
+ __uint(max_entries, 50);
75
+} exact_match SEC(".maps");
7676
77
-struct bpf_map_def SEC("maps") tx_port = {
78
- .type = BPF_MAP_TYPE_DEVMAP,
79
- .key_size = sizeof(int),
80
- .value_size = sizeof(int),
81
- .max_entries = 100,
82
-};
77
+struct {
78
+ __uint(type, BPF_MAP_TYPE_DEVMAP);
79
+ __uint(key_size, sizeof(int));
80
+ __uint(value_size, sizeof(int));
81
+ __uint(max_entries, 100);
82
+} tx_port SEC(".maps");
8383
8484 /* Function to set source and destination mac of the packet */
8585 static inline void set_src_dst_mac(void *data, void *src, void *dst)