Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

selftests: openvswitch: add a simple test for tunnel metadata

This test ensures that upon receiving decapsulated packets from a
tunnel interface in openvswitch, the tunnel metadata fields are
properly populated. This partially covers interoperability of the
kernel tunnel ports and openvswitch tunnels (LWT) and parsing and
formatting of the tunnel metadata fields of the openvswitch netlink
uAPI. Doing so, this test also ensures that fields and flags are
properly extracted during decapsulation by the tunnel core code,
serving as a regression test for the previously fixed issue with the
DF bit not being extracted from the outer IP header.

The ovs-dpctl.py script already supports all that is necessary for
the tunnel ports for this test, so we only need to adjust the
ovs_add_if() function to pass the '-t' port type argument in order
to be able to create tunnel ports in the openvswitch datapath.

Reviewed-by: Aaron Conole <aconole@redhat.com>
Signed-off-by: Ilya Maximets <i.maximets@ovn.org>
Link: https://patch.msgid.link/20250909165440.229890-3-i.maximets@ovn.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Ilya Maximets and committed by
Jakub Kicinski
6cafb93c a9888628

+81 -7
+81 -7
tools/testing/selftests/net/openvswitch/openvswitch.sh
··· 25 25 nat_related_v4 ip4-nat-related: ICMP related matches work with SNAT 26 26 netlink_checks ovsnl: validate netlink attrs and settings 27 27 upcall_interfaces ovs: test the upcall interfaces 28 + tunnel_metadata ovs: test extraction of tunnel metadata 28 29 drop_reason drop: test drop reasons are emitted 29 30 psample psample: Sampling packets with psample" 30 31 ··· 114 113 } 115 114 116 115 ovs_add_if () { 117 - info "Adding IF to DP: br:$2 if:$3" 118 - if [ "$4" != "-u" ]; then 119 - ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if "$2" "$3" \ 120 - || return 1 116 + info "Adding IF to DP: br:$3 if:$4 ($2)" 117 + if [ "$5" != "-u" ]; then 118 + ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if \ 119 + -t "$2" "$3" "$4" || return 1 121 120 else 122 121 python3 $ovs_base/ovs-dpctl.py add-if \ 123 - -u "$2" "$3" >$ovs_dir/$3.out 2>$ovs_dir/$3.err & 122 + -u -t "$2" "$3" "$4" >$ovs_dir/$4.out 2>$ovs_dir/$4.err & 124 123 pid=$! 125 124 on_exit "ovs_sbx $1 kill -TERM $pid 2>/dev/null" 126 125 fi ··· 167 166 fi 168 167 169 168 if [ "$7" != "-u" ]; then 170 - ovs_add_if "$1" "$2" "$4" || return 1 169 + ovs_add_if "$1" "netdev" "$2" "$4" || return 1 171 170 else 172 - ovs_add_if "$1" "$2" "$4" -u || return 1 171 + ovs_add_if "$1" "netdev" "$2" "$4" -u || return 1 173 172 fi 174 173 175 174 if [ $TRACING -eq 1 ]; then ··· 754 753 >$ovs_dir/arping.stdout 2>$ovs_dir/arping.stderr 755 754 756 755 grep -E "MISS upcall\[0/yes\]: .*arp\(sip=172.31.110.1,tip=172.31.110.20,op=1,sha=" $ovs_dir/left0.out >/dev/null 2>&1 || return 1 756 + return 0 757 + } 758 + 759 + ovs_add_kernel_tunnel() { 760 + local sbxname=$1; shift 761 + local ns=$1; shift 762 + local tnl_type=$1; shift 763 + local name=$1; shift 764 + local addr=$1; shift 765 + 766 + info "setting up kernel ${tnl_type} tunnel ${name}" 767 + ovs_sbx "${sbxname}" ip -netns ${ns} link add dev ${name} type ${tnl_type} $* || return 1 768 + on_exit "ovs_sbx ${sbxname} ip -netns ${ns} link del ${name} >/dev/null 2>&1" 769 + ovs_sbx "${sbxname}" ip -netns ${ns} addr add dev ${name} ${addr} || return 1 770 + ovs_sbx "${sbxname}" ip -netns ${ns} link set dev ${name} mtu 1450 up || return 1 771 + } 772 + 773 + test_tunnel_metadata() { 774 + which arping >/dev/null 2>&1 || return $ksft_skip 775 + 776 + sbxname="test_tunnel_metadata" 777 + sbx_add "${sbxname}" || return 1 778 + 779 + info "setting up new DP" 780 + ovs_add_dp "${sbxname}" tdp0 -V 2:1 || return 1 781 + 782 + ovs_add_netns_and_veths "${sbxname}" tdp0 tns left0 l0 \ 783 + 172.31.110.1/24 || return 1 784 + 785 + info "removing veth interface from openvswitch and setting IP" 786 + ovs_del_if "${sbxname}" tdp0 left0 || return 1 787 + ovs_sbx "${sbxname}" ip addr add 172.31.110.2/24 dev left0 || return 1 788 + ovs_sbx "${sbxname}" ip link set left0 up || return 1 789 + 790 + info "setting up tunnel port in openvswitch" 791 + ovs_add_if "${sbxname}" "vxlan" tdp0 ovs-vxlan0 -u || return 1 792 + on_exit "ovs_sbx ${sbxname} ip link del ovs-vxlan0" 793 + ovs_wait ip link show ovs-vxlan0 &>/dev/null || return 1 794 + ovs_sbx "${sbxname}" ip link set ovs-vxlan0 up || return 1 795 + 796 + configs=$(echo ' 797 + 1 172.31.221.1/24 1155332 32 set udpcsum flags\(df\|csum\) 798 + 2 172.31.222.1/24 1234567 45 set noudpcsum flags\(df\) 799 + 3 172.31.223.1/24 1020304 23 unset udpcsum flags\(csum\) 800 + 4 172.31.224.1/24 1357986 15 unset noudpcsum' | sed '/^$/d') 801 + 802 + while read -r i addr id ttl df csum flags; do 803 + ovs_add_kernel_tunnel "${sbxname}" tns vxlan vxlan${i} ${addr} \ 804 + remote 172.31.110.2 id ${id} dstport 4789 \ 805 + ttl ${ttl} df ${df} ${csum} || return 1 806 + done <<< "${configs}" 807 + 808 + ovs_wait grep -q 'listening on upcall packet handler' \ 809 + ${ovs_dir}/ovs-vxlan0.out || return 1 810 + 811 + info "sending arping" 812 + for i in 1 2 3 4; do 813 + ovs_sbx "${sbxname}" ip netns exec tns \ 814 + arping -I vxlan${i} 172.31.22${i}.2 -c 1 \ 815 + >${ovs_dir}/arping.stdout 2>${ovs_dir}/arping.stderr 816 + done 817 + 818 + info "checking that received decapsulated packets carry correct metadata" 819 + while read -r i addr id ttl df csum flags; do 820 + arp_hdr="arp\\(sip=172.31.22${i}.1,tip=172.31.22${i}.2,op=1,sha=" 821 + addrs="src=172.31.110.1,dst=172.31.110.2" 822 + ports="tp_src=[0-9]*,tp_dst=4789" 823 + tnl_md="tunnel\\(tun_id=${id},${addrs},ttl=${ttl},${ports},${flags}\\)" 824 + 825 + ovs_sbx "${sbxname}" grep -qE "MISS upcall.*${tnl_md}.*${arp_hdr}" \ 826 + ${ovs_dir}/ovs-vxlan0.out || return 1 827 + done <<< "${configs}" 828 + 757 829 return 0 758 830 } 759 831