Skip to content

Commit 2e5fb2f

Browse files
committed
Merge branch 'net-dst_metadata-fix-df-flag-extraction-on-tunnel-rx'
Ilya Maximets says: ==================== net: dst_metadata: fix DF flag extraction on tunnel rx Two patches here, first fixes the issue where tunnel core doesn't actually extract DF bit from the outer IP header, even though both OVS and TC flower allow matching on it. More details in the commit message. The second is a selftest for openvswitch that reproduces the issue, but also just adds some basic coverage for the tunnel metadata extraction and related openvswitch uAPI. ==================== Link: https://patch.msgid.link/20250909165440.229890-1-i.maximets@ovn.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2 parents 56c0a2a + 6cafb93 commit 2e5fb2f

2 files changed

Lines changed: 90 additions & 9 deletions

File tree

include/net/dst_metadata.h

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#define __NET_DST_METADATA_H 1
44

55
#include <linux/skbuff.h>
6+
#include <net/ip.h>
67
#include <net/ip_tunnels.h>
78
#include <net/macsec.h>
89
#include <net/dst.h>
@@ -220,9 +221,15 @@ static inline struct metadata_dst *ip_tun_rx_dst(struct sk_buff *skb,
220221
int md_size)
221222
{
222223
const struct iphdr *iph = ip_hdr(skb);
224+
struct metadata_dst *tun_dst;
225+
226+
tun_dst = __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl,
227+
0, flags, tunnel_id, md_size);
223228

224-
return __ip_tun_set_dst(iph->saddr, iph->daddr, iph->tos, iph->ttl,
225-
0, flags, tunnel_id, md_size);
229+
if (tun_dst && (iph->frag_off & htons(IP_DF)))
230+
__set_bit(IP_TUNNEL_DONT_FRAGMENT_BIT,
231+
tun_dst->u.tun_info.key.tun_flags);
232+
return tun_dst;
226233
}
227234

228235
static inline struct metadata_dst *__ipv6_tun_set_dst(const struct in6_addr *saddr,

tools/testing/selftests/net/openvswitch/openvswitch.sh

Lines changed: 81 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ tests="
2525
nat_related_v4 ip4-nat-related: ICMP related matches work with SNAT
2626
netlink_checks ovsnl: validate netlink attrs and settings
2727
upcall_interfaces ovs: test the upcall interfaces
28+
tunnel_metadata ovs: test extraction of tunnel metadata
2829
drop_reason drop: test drop reasons are emitted
2930
psample psample: Sampling packets with psample"
3031

@@ -113,13 +114,13 @@ ovs_add_dp () {
113114
}
114115

115116
ovs_add_if () {
116-
info "Adding IF to DP: br:$2 if:$3"
117-
if [ "$4" != "-u" ]; then
118-
ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if "$2" "$3" \
119-
|| return 1
117+
info "Adding IF to DP: br:$3 if:$4 ($2)"
118+
if [ "$5" != "-u" ]; then
119+
ovs_sbx "$1" python3 $ovs_base/ovs-dpctl.py add-if \
120+
-t "$2" "$3" "$4" || return 1
120121
else
121122
python3 $ovs_base/ovs-dpctl.py add-if \
122-
-u "$2" "$3" >$ovs_dir/$3.out 2>$ovs_dir/$3.err &
123+
-u -t "$2" "$3" "$4" >$ovs_dir/$4.out 2>$ovs_dir/$4.err &
123124
pid=$!
124125
on_exit "ovs_sbx $1 kill -TERM $pid 2>/dev/null"
125126
fi
@@ -166,9 +167,9 @@ ovs_add_netns_and_veths () {
166167
fi
167168

168169
if [ "$7" != "-u" ]; then
169-
ovs_add_if "$1" "$2" "$4" || return 1
170+
ovs_add_if "$1" "netdev" "$2" "$4" || return 1
170171
else
171-
ovs_add_if "$1" "$2" "$4" -u || return 1
172+
ovs_add_if "$1" "netdev" "$2" "$4" -u || return 1
172173
fi
173174

174175
if [ $TRACING -eq 1 ]; then
@@ -756,6 +757,79 @@ test_upcall_interfaces() {
756757
return 0
757758
}
758759

760+
ovs_add_kernel_tunnel() {
761+
local sbxname=$1; shift
762+
local ns=$1; shift
763+
local tnl_type=$1; shift
764+
local name=$1; shift
765+
local addr=$1; shift
766+
767+
info "setting up kernel ${tnl_type} tunnel ${name}"
768+
ovs_sbx "${sbxname}" ip -netns ${ns} link add dev ${name} type ${tnl_type} $* || return 1
769+
on_exit "ovs_sbx ${sbxname} ip -netns ${ns} link del ${name} >/dev/null 2>&1"
770+
ovs_sbx "${sbxname}" ip -netns ${ns} addr add dev ${name} ${addr} || return 1
771+
ovs_sbx "${sbxname}" ip -netns ${ns} link set dev ${name} mtu 1450 up || return 1
772+
}
773+
774+
test_tunnel_metadata() {
775+
which arping >/dev/null 2>&1 || return $ksft_skip
776+
777+
sbxname="test_tunnel_metadata"
778+
sbx_add "${sbxname}" || return 1
779+
780+
info "setting up new DP"
781+
ovs_add_dp "${sbxname}" tdp0 -V 2:1 || return 1
782+
783+
ovs_add_netns_and_veths "${sbxname}" tdp0 tns left0 l0 \
784+
172.31.110.1/24 || return 1
785+
786+
info "removing veth interface from openvswitch and setting IP"
787+
ovs_del_if "${sbxname}" tdp0 left0 || return 1
788+
ovs_sbx "${sbxname}" ip addr add 172.31.110.2/24 dev left0 || return 1
789+
ovs_sbx "${sbxname}" ip link set left0 up || return 1
790+
791+
info "setting up tunnel port in openvswitch"
792+
ovs_add_if "${sbxname}" "vxlan" tdp0 ovs-vxlan0 -u || return 1
793+
on_exit "ovs_sbx ${sbxname} ip link del ovs-vxlan0"
794+
ovs_wait ip link show ovs-vxlan0 &>/dev/null || return 1
795+
ovs_sbx "${sbxname}" ip link set ovs-vxlan0 up || return 1
796+
797+
configs=$(echo '
798+
1 172.31.221.1/24 1155332 32 set udpcsum flags\(df\|csum\)
799+
2 172.31.222.1/24 1234567 45 set noudpcsum flags\(df\)
800+
3 172.31.223.1/24 1020304 23 unset udpcsum flags\(csum\)
801+
4 172.31.224.1/24 1357986 15 unset noudpcsum' | sed '/^$/d')
802+
803+
while read -r i addr id ttl df csum flags; do
804+
ovs_add_kernel_tunnel "${sbxname}" tns vxlan vxlan${i} ${addr} \
805+
remote 172.31.110.2 id ${id} dstport 4789 \
806+
ttl ${ttl} df ${df} ${csum} || return 1
807+
done <<< "${configs}"
808+
809+
ovs_wait grep -q 'listening on upcall packet handler' \
810+
${ovs_dir}/ovs-vxlan0.out || return 1
811+
812+
info "sending arping"
813+
for i in 1 2 3 4; do
814+
ovs_sbx "${sbxname}" ip netns exec tns \
815+
arping -I vxlan${i} 172.31.22${i}.2 -c 1 \
816+
>${ovs_dir}/arping.stdout 2>${ovs_dir}/arping.stderr
817+
done
818+
819+
info "checking that received decapsulated packets carry correct metadata"
820+
while read -r i addr id ttl df csum flags; do
821+
arp_hdr="arp\\(sip=172.31.22${i}.1,tip=172.31.22${i}.2,op=1,sha="
822+
addrs="src=172.31.110.1,dst=172.31.110.2"
823+
ports="tp_src=[0-9]*,tp_dst=4789"
824+
tnl_md="tunnel\\(tun_id=${id},${addrs},ttl=${ttl},${ports},${flags}\\)"
825+
826+
ovs_sbx "${sbxname}" grep -qE "MISS upcall.*${tnl_md}.*${arp_hdr}" \
827+
${ovs_dir}/ovs-vxlan0.out || return 1
828+
done <<< "${configs}"
829+
830+
return 0
831+
}
832+
759833
run_test() {
760834
(
761835
tname="$1"

0 commit comments

Comments
 (0)