Skip to content

Commit

Permalink
samples/bpf: xdp_redirect_cpu handle parsing of double VLAN tagged pa…
Browse files Browse the repository at this point in the history
…ckets

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 <[email protected]>
Reported-by: Marek Majkowski <[email protected]>
Signed-off-by: Jesper Dangaard Brouer <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
  • Loading branch information
netoptimizer authored and borkmann committed Jul 13, 2018
1 parent ee15f7c commit d23b27c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion samples/bpf/xdp_redirect_cpu_kern.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,16 @@ bool parse_eth(struct ethhdr *eth, void *data_end,
return false;
eth_type = vlan_hdr->h_vlan_encapsulated_proto;
}
/* TODO: Handle double VLAN tagged packet */
/* Handle double VLAN tagged packet */
if (eth_type == htons(ETH_P_8021Q) || eth_type == htons(ETH_P_8021AD)) {
struct vlan_hdr *vlan_hdr;

vlan_hdr = (void *)eth + offset;
offset += sizeof(*vlan_hdr);
if ((void *)eth + offset > data_end)
return false;
eth_type = vlan_hdr->h_vlan_encapsulated_proto;
}

*eth_proto = ntohs(eth_type);
*l3_offset = offset;
Expand Down

0 comments on commit d23b27c

Please sign in to comment.