.. | .. |
---|
18 | 18 | #include <linux/if_vlan.h> |
---|
19 | 19 | #include <linux/ip.h> |
---|
20 | 20 | #include <linux/icmp.h> |
---|
21 | | -#include "bpf_helpers.h" |
---|
| 21 | +#include <bpf/bpf_helpers.h> |
---|
22 | 22 | |
---|
23 | 23 | #define DEFAULT_TTL 64 |
---|
24 | 24 | #define MAX_PCKT_SIZE 600 |
---|
25 | 25 | #define ICMP_TOOBIG_SIZE 98 |
---|
26 | 26 | #define ICMP_TOOBIG_PAYLOAD_SIZE 92 |
---|
27 | 27 | |
---|
28 | | -struct bpf_map_def SEC("maps") icmpcnt = { |
---|
29 | | - .type = BPF_MAP_TYPE_ARRAY, |
---|
30 | | - .key_size = sizeof(__u32), |
---|
31 | | - .value_size = sizeof(__u64), |
---|
32 | | - .max_entries = 1, |
---|
33 | | -}; |
---|
| 28 | +/* volatile to prevent compiler optimizations */ |
---|
| 29 | +static volatile __u32 max_pcktsz = MAX_PCKT_SIZE; |
---|
| 30 | + |
---|
| 31 | +struct { |
---|
| 32 | + __uint(type, BPF_MAP_TYPE_ARRAY); |
---|
| 33 | + __type(key, __u32); |
---|
| 34 | + __type(value, __u64); |
---|
| 35 | + __uint(max_entries, 1); |
---|
| 36 | +} icmpcnt SEC(".maps"); |
---|
34 | 37 | |
---|
35 | 38 | static __always_inline void count_icmp(void) |
---|
36 | 39 | { |
---|
.. | .. |
---|
92 | 95 | orig_iph = data + off; |
---|
93 | 96 | icmp_hdr->type = ICMP_DEST_UNREACH; |
---|
94 | 97 | icmp_hdr->code = ICMP_FRAG_NEEDED; |
---|
95 | | - icmp_hdr->un.frag.mtu = htons(MAX_PCKT_SIZE-sizeof(struct ethhdr)); |
---|
| 98 | + icmp_hdr->un.frag.mtu = htons(max_pcktsz - sizeof(struct ethhdr)); |
---|
96 | 99 | icmp_hdr->checksum = 0; |
---|
97 | 100 | ipv4_csum(icmp_hdr, ICMP_TOOBIG_PAYLOAD_SIZE, &csum); |
---|
98 | 101 | icmp_hdr->checksum = csum; |
---|
.. | .. |
---|
121 | 124 | int pckt_size = data_end - data; |
---|
122 | 125 | int offset; |
---|
123 | 126 | |
---|
124 | | - if (pckt_size > MAX_PCKT_SIZE) { |
---|
| 127 | + if (pckt_size > max(max_pcktsz, ICMP_TOOBIG_SIZE)) { |
---|
125 | 128 | offset = pckt_size - ICMP_TOOBIG_SIZE; |
---|
126 | 129 | if (bpf_xdp_adjust_tail(xdp, 0 - offset)) |
---|
127 | 130 | return XDP_PASS; |
---|