selftests/bpf: Don't assign outer source IP to host
authorPaul Chaignon <paul@isovalent.com>
Mon, 25 Jul 2022 14:32:53 +0000 (16:32 +0200)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 26 Jul 2022 10:43:48 +0000 (12:43 +0200)
commit1115169f47ae45eeb04c616c404492bc8268daa0
tree626feefb8f1c328ec7114d388f9c8bba0cfa184a
parentb8fff748521c7178b9a7d32b5a34a81cec8396f3
selftests/bpf: Don't assign outer source IP to host

The previous commit fixed a bug in the bpf_skb_set_tunnel_key helper to
avoid dropping packets whose outer source IP address isn't assigned to a
host interface. This commit changes the corresponding selftest to not
assign the outer source IP address to an interface.

Not assigning the source IP to an interface causes two issues in the
existing test:

1. The ARP requests will fail for that IP address so we need to add the
   ARP entry manually.
2. The encapsulated ICMP echo reply traffic will not reach the VXLAN
   device. It will be dropped by the stack before, because the
   outer destination IP is unknown.

To solve 2., we have two choices. Either we perform decapsulation
ourselves in a BPF program attached at veth1 (the base device for the
VXLAN device), or we switch the outer destination address when we
receive the packet at veth1, such that the stack properly demultiplexes
it to the VXLAN device afterward.

This commit implements the second approach, where we switch the outer
destination address from the unassigned IP address to the assigned one,
only for VXLAN traffic ingressing veth1.

Then, at the vxlan device, the BPF program that checks the output of
bpf_skb_get_tunnel_key needs to be updated as the expected local IP
address is now the unassigned one.

Signed-off-by: Paul Chaignon <paul@isovalent.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Link: https://lore.kernel.org/bpf/4addde76eaf3477a58975bef15ed2788c44e5f55.1658759380.git.paul@isovalent.com
tools/testing/selftests/bpf/prog_tests/test_tunnel.c
tools/testing/selftests/bpf/progs/test_tunnel_kern.c