hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/samples/bpf/sockex3_kern.c
....@@ -5,7 +5,6 @@
55 * License as published by the Free Software Foundation.
66 */
77 #include <uapi/linux/bpf.h>
8
-#include "bpf_helpers.h"
98 #include <uapi/linux/in.h>
109 #include <uapi/linux/if.h>
1110 #include <uapi/linux/if_ether.h>
....@@ -13,28 +12,32 @@
1312 #include <uapi/linux/ipv6.h>
1413 #include <uapi/linux/if_tunnel.h>
1514 #include <uapi/linux/mpls.h>
15
+#include <bpf/bpf_helpers.h>
16
+#include "bpf_legacy.h"
1617 #define IP_MF 0x2000
1718 #define IP_OFFSET 0x1FFF
1819
1920 #define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F
2021
21
-struct bpf_map_def SEC("maps") jmp_table = {
22
- .type = BPF_MAP_TYPE_PROG_ARRAY,
23
- .key_size = sizeof(u32),
24
- .value_size = sizeof(u32),
25
- .max_entries = 8,
26
-};
22
+struct {
23
+ __uint(type, BPF_MAP_TYPE_PROG_ARRAY);
24
+ __uint(key_size, sizeof(u32));
25
+ __uint(value_size, sizeof(u32));
26
+ __uint(max_entries, 8);
27
+} jmp_table SEC(".maps");
2728
2829 #define PARSE_VLAN 1
2930 #define PARSE_MPLS 2
3031 #define PARSE_IP 3
3132 #define PARSE_IPV6 4
3233
33
-/* protocol dispatch routine.
34
- * It tail-calls next BPF program depending on eth proto
35
- * Note, we could have used:
36
- * bpf_tail_call(skb, &jmp_table, proto);
37
- * but it would need large prog_array
34
+/* Protocol dispatch routine. It tail-calls next BPF program depending
35
+ * on eth proto. Note, we could have used ...
36
+ *
37
+ * bpf_tail_call(skb, &jmp_table, proto);
38
+ *
39
+ * ... but it would need large prog_array and cannot be optimised given
40
+ * the map key is not static.
3841 */
3942 static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto)
4043 {
....@@ -91,12 +94,12 @@
9194 struct flow_key_record flow;
9295 };
9396
94
-struct bpf_map_def SEC("maps") percpu_map = {
95
- .type = BPF_MAP_TYPE_ARRAY,
96
- .key_size = sizeof(__u32),
97
- .value_size = sizeof(struct globals),
98
- .max_entries = 32,
99
-};
97
+struct {
98
+ __uint(type, BPF_MAP_TYPE_ARRAY);
99
+ __type(key, __u32);
100
+ __type(value, struct globals);
101
+ __uint(max_entries, 32);
102
+} percpu_map SEC(".maps");
100103
101104 /* user poor man's per_cpu until native support is ready */
102105 static struct globals *this_cpu_globals(void)
....@@ -112,12 +115,12 @@
112115 __u64 bytes;
113116 };
114117
115
-struct bpf_map_def SEC("maps") hash_map = {
116
- .type = BPF_MAP_TYPE_HASH,
117
- .key_size = sizeof(struct flow_key_record),
118
- .value_size = sizeof(struct pair),
119
- .max_entries = 1024,
120
-};
118
+struct {
119
+ __uint(type, BPF_MAP_TYPE_HASH);
120
+ __type(key, struct flow_key_record);
121
+ __type(value, struct pair);
122
+ __uint(max_entries, 1024);
123
+} hash_map SEC(".maps");
121124
122125 static void update_stats(struct __sk_buff *skb, struct globals *g)
123126 {