| .. | .. |
|---|
| 5 | 5 | * License as published by the Free Software Foundation. |
|---|
| 6 | 6 | */ |
|---|
| 7 | 7 | #include <uapi/linux/bpf.h> |
|---|
| 8 | | -#include "bpf_helpers.h" |
|---|
| 9 | 8 | #include <uapi/linux/in.h> |
|---|
| 10 | 9 | #include <uapi/linux/if.h> |
|---|
| 11 | 10 | #include <uapi/linux/if_ether.h> |
|---|
| .. | .. |
|---|
| 13 | 12 | #include <uapi/linux/ipv6.h> |
|---|
| 14 | 13 | #include <uapi/linux/if_tunnel.h> |
|---|
| 15 | 14 | #include <uapi/linux/mpls.h> |
|---|
| 15 | +#include <bpf/bpf_helpers.h> |
|---|
| 16 | +#include "bpf_legacy.h" |
|---|
| 16 | 17 | #define IP_MF 0x2000 |
|---|
| 17 | 18 | #define IP_OFFSET 0x1FFF |
|---|
| 18 | 19 | |
|---|
| 19 | 20 | #define PROG(F) SEC("socket/"__stringify(F)) int bpf_func_##F |
|---|
| 20 | 21 | |
|---|
| 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"); |
|---|
| 27 | 28 | |
|---|
| 28 | 29 | #define PARSE_VLAN 1 |
|---|
| 29 | 30 | #define PARSE_MPLS 2 |
|---|
| 30 | 31 | #define PARSE_IP 3 |
|---|
| 31 | 32 | #define PARSE_IPV6 4 |
|---|
| 32 | 33 | |
|---|
| 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. |
|---|
| 38 | 41 | */ |
|---|
| 39 | 42 | static inline void parse_eth_proto(struct __sk_buff *skb, u32 proto) |
|---|
| 40 | 43 | { |
|---|
| .. | .. |
|---|
| 91 | 94 | struct flow_key_record flow; |
|---|
| 92 | 95 | }; |
|---|
| 93 | 96 | |
|---|
| 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"); |
|---|
| 100 | 103 | |
|---|
| 101 | 104 | /* user poor man's per_cpu until native support is ready */ |
|---|
| 102 | 105 | static struct globals *this_cpu_globals(void) |
|---|
| .. | .. |
|---|
| 112 | 115 | __u64 bytes; |
|---|
| 113 | 116 | }; |
|---|
| 114 | 117 | |
|---|
| 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"); |
|---|
| 121 | 124 | |
|---|
| 122 | 125 | static void update_stats(struct __sk_buff *skb, struct globals *g) |
|---|
| 123 | 126 | { |
|---|