From badcb3fd5710a511e35ac3afd724ef68c77614b7 Mon Sep 17 00:00:00 2001 From: "Alexander V. Chernikov" Date: Wed, 29 Mar 2023 20:28:24 +0000 Subject: [PATCH] routing: fix panic when adding an interface route to the p2p interface without and inet/inet6 addresses attached. MFC after: 3 days --- sys/net/if.c | 2 +- tests/sys/net/routing/test_routing_l3.py | 39 ++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/sys/net/if.c b/sys/net/if.c index ff942bceb090..4b3b7d5b121b 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -2056,7 +2056,7 @@ ifaof_ifpforaddr(const struct sockaddr *addr, struct ifnet *ifp) continue; } if (ifp->if_flags & IFF_POINTOPOINT) { - if (sa_equal(addr, ifa->ifa_dstaddr)) + if (ifa->ifa_dstaddr && sa_equal(addr, ifa->ifa_dstaddr)) goto done; } else { cp = addr->sa_data; diff --git a/tests/sys/net/routing/test_routing_l3.py b/tests/sys/net/routing/test_routing_l3.py index 74017ae0459c..3a3822293424 100755 --- a/tests/sys/net/routing/test_routing_l3.py +++ b/tests/sys/net/routing/test_routing_l3.py @@ -1,7 +1,13 @@ import ipaddress +import socket import pytest +from atf_python.sys.net.rtsock import RtConst +from atf_python.sys.net.rtsock import Rtsock +from atf_python.sys.net.rtsock import RtsockRtMessage +from atf_python.sys.net.rtsock import SaHelper from atf_python.sys.net.tools import ToolsHelper +from atf_python.sys.net.vnet import SingleVnetTestTemplate from atf_python.sys.net.vnet import VnetTestTemplate @@ -79,3 +85,36 @@ def test_change_prefix_route_same_iface(self, family): nhops = ToolsHelper.get_nhops(family) nh = [nh for nh in nhops if nh["index"] == nhop_kidx][0] assert nh["ifa"] == str(second_addr.ip) + + +class TestRouteCornerCase1(SingleVnetTestTemplate): + @pytest.mark.parametrize("family", ["inet", "inet6"]) + @pytest.mark.require_user("root") + def test_add_direct_route_p2p_wo_ifa(self, family): + + tun_ifname = ToolsHelper.get_output("/sbin/ifconfig tun create").rstrip() + tun_ifindex = socket.if_nametoindex(tun_ifname) + assert tun_ifindex > 0 + rtsock = Rtsock() + + if family == "inet": + prefix = "172.16.0.0/12" + else: + prefix = "2a02:6b8::/64" + IFT_ETHER = 0x06 + gw_link = SaHelper.link_sa(ifindex=tun_ifindex, iftype=IFT_ETHER) + + msg = rtsock.new_rtm_add(prefix, gw_link) + msg.add_link_attr(RtConst.RTA_IFP, tun_ifindex) + rtsock.write_message(msg) + + data = rtsock.read_data(msg.rtm_seq) + msg_in = RtsockRtMessage.from_bytes(data) + msg_in.print_in_message() + + desired_sa = { + RtConst.RTA_DST: msg.get_sa(RtConst.RTA_DST), + RtConst.RTA_NETMASK: msg.get_sa(RtConst.RTA_NETMASK), + } + + msg_in.verify(msg.rtm_type, desired_sa)