git: 1db64f89363c - main - netlink: Add tests when adding an interface route

From: R. Christian McDonald <rcm_at_FreeBSD.org>
Date: Tue, 28 Nov 2023 21:53:25 UTC
The branch main has been updated by rcm:

URL: https://cgit.FreeBSD.org/src/commit/?id=1db64f89363c97858961c4df0b7d02f3223723cf

commit 1db64f89363c97858961c4df0b7d02f3223723cf
Author:     Jose Luis Duran <jlduran@gmail.com>
AuthorDate: 2023-11-28 19:58:03 +0000
Commit:     R. Christian McDonald <rcm@FreeBSD.org>
CommitDate: 2023-11-28 21:53:00 +0000

    netlink: Add tests when adding an interface route
    
    Add tests for adding a route using an interface only (without an IP
    address).
    
    Reviewed by:    rcm
    Approved by:    kp (mentor)
    MFC after:      1 week
    Differential Revision:  https://reviews.freebsd.org/D41436
---
 tests/sys/netlink/test_rtnl_route.py | 41 ++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)

diff --git a/tests/sys/netlink/test_rtnl_route.py b/tests/sys/netlink/test_rtnl_route.py
index e6bbe7656eb4..20f2c3ce3ee2 100644
--- a/tests/sys/netlink/test_rtnl_route.py
+++ b/tests/sys/netlink/test_rtnl_route.py
@@ -3,6 +3,7 @@ import socket
 
 import pytest
 from atf_python.sys.net.tools import ToolsHelper
+from atf_python.sys.net.vnet import IfaceFactory
 from atf_python.sys.net.vnet import SingleVnetTestTemplate
 from atf_python.sys.netlink.attrs import NlAttrIp
 from atf_python.sys.netlink.attrs import NlAttrU32
@@ -45,6 +46,46 @@ class TestRtNlRoute(NetlinkTestTemplate, SingleVnetTestTemplate):
         ToolsHelper.print_net_debug()
         ToolsHelper.print_output("netstat -6onW")
 
+    @pytest.mark.timeout(5)
+    def test_add_route6_ll_if_gw(self):
+        tun_ifname = IfaceFactory().create_iface("", "tun")[0].name
+        tun_ifindex = socket.if_nametoindex(tun_ifname)
+
+        msg = NetlinkRtMessage(self.helper, NlRtMsgType.RTM_NEWROUTE)
+        msg.set_request()
+        msg.add_nlflags([NlmNewFlags.NLM_F_CREATE])
+        msg.base_hdr.rtm_family = socket.AF_INET6
+        msg.base_hdr.rtm_dst_len = 64
+        msg.add_nla(NlAttrIp(RtattrType.RTA_DST, "2001:db8:2::"))
+        msg.add_nla(NlAttrU32(RtattrType.RTA_OIF, tun_ifindex))
+
+        rx_msg = self.get_reply(msg)
+        assert rx_msg.is_type(NlMsgType.NLMSG_ERROR)
+        assert rx_msg.error_code == 0
+
+        ToolsHelper.print_net_debug()
+        ToolsHelper.print_output("netstat -6onW")
+
+    @pytest.mark.timeout(5)
+    def test_add_route4_ll_if_gw(self):
+        tun_ifname = IfaceFactory().create_iface("", "tun")[0].name
+        tun_ifindex = socket.if_nametoindex(tun_ifname)
+
+        msg = NetlinkRtMessage(self.helper, NlRtMsgType.RTM_NEWROUTE)
+        msg.set_request()
+        msg.add_nlflags([NlmNewFlags.NLM_F_CREATE])
+        msg.base_hdr.rtm_family = socket.AF_INET
+        msg.base_hdr.rtm_dst_len = 32
+        msg.add_nla(NlAttrIp(RtattrType.RTA_DST, "192.0.2.1"))
+        msg.add_nla(NlAttrU32(RtattrType.RTA_OIF, tun_ifindex))
+
+        rx_msg = self.get_reply(msg)
+        assert rx_msg.is_type(NlMsgType.NLMSG_ERROR)
+        assert rx_msg.error_code == 0
+
+        ToolsHelper.print_net_debug()
+        ToolsHelper.print_output("netstat -4onW")
+
     @pytest.mark.timeout(20)
     def test_buffer_override(self):
         msg_flags = (