summaryrefslogtreecommitdiffstats
path: root/samples
diff options
context:
space:
mode:
authorJesper Dangaard Brouer <brouer@redhat.com>2018-07-13 10:35:14 -0400
committerDaniel Borkmann <daniel@iogearbox.net>2018-07-13 18:52:54 -0400
commitd23b27c02f03438ac1867b4b6a484b92f536bd28 (patch)
tree8c88b6174e3852757e525fbff8991e911892ddcf /samples
parentee15f7cdf0fcd605d521a55fca375fd87a965776 (diff)
samples/bpf: xdp_redirect_cpu handle parsing of double VLAN tagged packets
People noticed that the code match on IEEE 802.1ad (ETH_P_8021AD) ethertype, and this implies Q-in-Q or double tagged VLANs. Thus, we better parse the next VLAN header too. It is even marked as a TODO. This is relevant for real world use-cases, as XDP cpumap redirect can be used when the NIC RSS hashing is broken. E.g. the ixgbe driver HW cannot handle double tagged VLAN packets, and places everything into a single RX queue. Using cpumap redirect, users can redistribute traffic across CPUs to solve this, which is faster than the network stacks RPS solution. It is left as an exerise how to distribute the packets across CPUs. It would be convenient to use the RX hash, but that is not _yet_ exposed to XDP programs. For now, users can code their own hash, as I've demonstrated in the Suricata code (where Q-in-Q is handled correctly). Reported-by: Florian Maury <florian.maury-cv@x-cli.eu> Reported-by: Marek Majkowski <marek@cloudflare.com> Signed-off-by: Jesper Dangaard Brouer <brouer@redhat.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Diffstat (limited to 'samples')
-rw-r--r--samples/bpf/xdp_redirect_cpu_kern.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/samples/bpf/xdp_redirect_cpu_kern.c b/samples/bpf/xdp_redirect_cpu_kern.c
index 303e9e7161f3..8cb703671b04 100644
--- a/samples/bpf/xdp_redirect_cpu_kern.c
+++ b/samples/bpf/xdp_redirect_cpu_kern.c
@@ -134,7 +134,16 @@ bool parse_eth(struct ethhdr *eth, void *data_end,
134 return false; 134 return false;
135 eth_type = vlan_hdr->h_vlan_encapsulated_proto; 135 eth_type = vlan_hdr->h_vlan_encapsulated_proto;
136 } 136 }
137 /* TODO: Handle double VLAN tagged packet */ 137 /* Handle double VLAN tagged packet */
138 if (eth_type == htons(ETH_P_8021Q) || eth_type == htons(ETH_P_8021AD)) {
139 struct vlan_hdr *vlan_hdr;
140
141 vlan_hdr = (void *)eth + offset;
142 offset += sizeof(*vlan_hdr);
143 if ((void *)eth + offset > data_end)
144 return false;
145 eth_type = vlan_hdr->h_vlan_encapsulated_proto;
146 }
138 147
139 *eth_proto = ntohs(eth_type); 148 *eth_proto = ntohs(eth_type);
140 *l3_offset = offset; 149 *l3_offset = offset;