samples: bpf: Add max_pckt_size option at xdp_adjust_tail
Currently, at xdp_adjust_tail_kern.c, MAX_PCKT_SIZE is limited to 600. To make this size flexible, static global variable 'max_pcktsz' is added. By updating new packet size from the user space, xdp_adjust_tail_kern.o will use this value as a new max packet size. This static global variable can be accesible from .data section with bpf_object__find_map* from user space, since it is considered as internal map (accessible with .bss/.data/.rodata suffix). If no '-P <MAX_PCKT_SIZE>' option is used, the size of maximum packet will be 600 as a default. For clarity, change the helper to fetch map from 'bpf_map__next' to 'bpf_object__find_map_fd_by_name'. Also, changed the way to test prog_fd, map_fd from '!= 0' to '< 0', since fd could be 0 when stdin is closed. Signed-off-by: Daniel T. Lee <danieltimlee@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Acked-by: Andrii Nakryiko <andriin@fb.com> Link: https://lore.kernel.org/bpf/20191007172117.3916-1-danieltimlee@gmail.com
This commit is contained in:

committed by
Alexei Starovoitov

parent
72ccd9200f
commit
8fdf5b780a
@@ -25,6 +25,9 @@
|
||||
#define ICMP_TOOBIG_SIZE 98
|
||||
#define ICMP_TOOBIG_PAYLOAD_SIZE 92
|
||||
|
||||
/* volatile to prevent compiler optimizations */
|
||||
static volatile __u32 max_pcktsz = MAX_PCKT_SIZE;
|
||||
|
||||
struct bpf_map_def SEC("maps") icmpcnt = {
|
||||
.type = BPF_MAP_TYPE_ARRAY,
|
||||
.key_size = sizeof(__u32),
|
||||
@@ -92,7 +95,7 @@ static __always_inline int send_icmp4_too_big(struct xdp_md *xdp)
|
||||
orig_iph = data + off;
|
||||
icmp_hdr->type = ICMP_DEST_UNREACH;
|
||||
icmp_hdr->code = ICMP_FRAG_NEEDED;
|
||||
icmp_hdr->un.frag.mtu = htons(MAX_PCKT_SIZE-sizeof(struct ethhdr));
|
||||
icmp_hdr->un.frag.mtu = htons(max_pcktsz - sizeof(struct ethhdr));
|
||||
icmp_hdr->checksum = 0;
|
||||
ipv4_csum(icmp_hdr, ICMP_TOOBIG_PAYLOAD_SIZE, &csum);
|
||||
icmp_hdr->checksum = csum;
|
||||
@@ -121,7 +124,7 @@ static __always_inline int handle_ipv4(struct xdp_md *xdp)
|
||||
int pckt_size = data_end - data;
|
||||
int offset;
|
||||
|
||||
if (pckt_size > MAX_PCKT_SIZE) {
|
||||
if (pckt_size > max(max_pcktsz, ICMP_TOOBIG_SIZE)) {
|
||||
offset = pckt_size - ICMP_TOOBIG_SIZE;
|
||||
if (bpf_xdp_adjust_tail(xdp, 0 - offset))
|
||||
return XDP_PASS;
|
||||
|
Reference in New Issue
Block a user