]> git.proxmox.com Git - mirror_frr.git/commitdiff
Merge pull request #12700 from taspelund/martian_tip_improvement
authorDonatas Abraitis <donatas@opensourcerouting.org>
Mon, 30 Jan 2023 08:52:44 +0000 (10:52 +0200)
committerGitHub <noreply@github.com>
Mon, 30 Jan 2023 08:52:44 +0000 (10:52 +0200)
BGP Martian Tunnel-IP Improvements

12 files changed:
babeld/babel_interface.c
babeld/babeld.c
tests/topotests/babel_topo1/r1/babeld.conf [new file with mode: 0644]
tests/topotests/babel_topo1/r1/show_ip_route.json_ref [new file with mode: 0644]
tests/topotests/babel_topo1/r1/zebra.conf [new file with mode: 0644]
tests/topotests/babel_topo1/r2/babeld.conf [new file with mode: 0644]
tests/topotests/babel_topo1/r2/show_ip_route.json_ref [new file with mode: 0644]
tests/topotests/babel_topo1/r2/zebra.conf [new file with mode: 0644]
tests/topotests/babel_topo1/r3/babeld.conf [new file with mode: 0644]
tests/topotests/babel_topo1/r3/show_ip_route.json_ref [new file with mode: 0644]
tests/topotests/babel_topo1/r3/zebra.conf [new file with mode: 0644]
tests/topotests/babel_topo1/test_babel_topo1.py [new file with mode: 0644]

index cc5089801739d0b8a36d1e5833285f61aa52556a..4ca875206f3bf3d69b02481c3c6ef08a1dde089c 100644 (file)
@@ -632,15 +632,15 @@ interface_recalculate(struct interface *ifp)
 
     rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
                     (char*)&mreq, sizeof(mreq));
-    if(rc < 0) {
-        flog_err_sys(EC_LIB_SOCKET,
-                 "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
-                  ifp->name, safe_strerror(errno));
-        /* This is probably due to a missing link-local address,
-         so down this interface, and wait until the main loop
-         tries to up it again. */
-        interface_reset(ifp);
-        return -1;
+    if (rc < 0 && errno != EADDRINUSE) {
+           flog_err_sys(EC_LIB_SOCKET,
+                        "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
+                        ifp->name, safe_strerror(errno));
+           /* This is probably due to a missing link-local address,
+            so down this interface, and wait until the main loop
+            tries to up it again. */
+           interface_reset(ifp);
+           return -1;
     }
 
     set_timeout(&babel_ifp->hello_timeout, babel_ifp->hello_interval);
index 34e1a4318bd36aa6071608c261ce29af6b00a216..972d52819b879e43a4d1b8509a0657cfcc3a512e 100644 (file)
@@ -165,7 +165,7 @@ babel_create_routing_process (void)
     }
 
     /* Threads. */
-    thread_add_read(master, &babel_read_protocol, NULL, protocol_socket, &babel_routing_process->t_read);
+    thread_add_read(master, babel_read_protocol, NULL, protocol_socket, &babel_routing_process->t_read);
     /* wait a little: zebra will announce interfaces, addresses, routes... */
     thread_add_timer_msec(master, babel_init_routing_process, NULL, 200L, &babel_routing_process->t_update);
 
diff --git a/tests/topotests/babel_topo1/r1/babeld.conf b/tests/topotests/babel_topo1/r1/babeld.conf
new file mode 100644 (file)
index 0000000..372d2ed
--- /dev/null
@@ -0,0 +1,21 @@
+log file eigrpd.log
+
+interface r1-eth0
+  babel hello-interval 1000
+  babel wired
+  babel update-interval 50
+!
+interface r1-eth1
+  babel hello-interval 1000
+  babel wired
+  babel update-interval 50
+!
+router babel
+ network r1-eth0
+ network r1-eth1
+ redistribute ipv4 connected
+ redistribute ipv6 connected
+!
+line vty
+!
+
diff --git a/tests/topotests/babel_topo1/r1/show_ip_route.json_ref b/tests/topotests/babel_topo1/r1/show_ip_route.json_ref
new file mode 100644 (file)
index 0000000..0d52b67
--- /dev/null
@@ -0,0 +1,80 @@
+{
+  "192.168.1.0/24":[
+    {
+      "prefix":"192.168.1.0/24",
+      "protocol":"connected",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "directlyConnected":true,
+          "interfaceName":"r1-eth0",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "192.168.2.0/24":[
+    {
+      "prefix":"192.168.2.0/24",
+      "prefixLen":24,
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.1.2",
+          "afi":"ipv4",
+          "interfaceName":"r1-eth1"
+        }
+      ]
+    }
+  ],
+  "192.168.3.0/24":[
+    {
+      "prefix":"192.168.3.0/24",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.1.2",
+          "afi":"ipv4",
+          "interfaceName":"r1-eth1",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "193.1.1.0/26":[
+    {
+      "prefix":"193.1.1.0/26",
+      "protocol":"connected",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "directlyConnected":true,
+          "interfaceName":"r1-eth1",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "193.1.2.0/24":[
+    {
+      "prefix":"193.1.2.0/24",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.1.2",
+          "afi":"ipv4",
+          "interfaceName":"r1-eth1",
+          "active":true
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/babel_topo1/r1/zebra.conf b/tests/topotests/babel_topo1/r1/zebra.conf
new file mode 100644 (file)
index 0000000..5eda3e2
--- /dev/null
@@ -0,0 +1,22 @@
+log file zebra.log
+! debug zebra rib detail
+!
+hostname r1
+!
+interface r1-eth0
+ ip address 192.168.1.1/24
+ ipv6 address 192:168:1::1/64
+!
+interface r1-eth1
+ description to sw2 - babel interface
+ ip address 193.1.1.1/26
+ ipv6 address 193:1:1::1/64
+ no link-detect
+!
+ip forwarding
+ipv6 forwarding
+!
+!
+line vty
+!
+
diff --git a/tests/topotests/babel_topo1/r2/babeld.conf b/tests/topotests/babel_topo1/r2/babeld.conf
new file mode 100644 (file)
index 0000000..8a36dda
--- /dev/null
@@ -0,0 +1,18 @@
+log file eigrpd.log
+!
+interface r2-eth0
+  babel hello-interval 1000
+  babel wired
+  babel update-interval 50
+!
+interface r2-eth1
+  babel hello-interval 1000
+  babel wired
+  babel update-interval 50
+!
+router babel
+ network r2-eth0
+ network r2-eth1
+ redistribute ipv4 connected
+ redistribute ipv6 connected
+!
diff --git a/tests/topotests/babel_topo1/r2/show_ip_route.json_ref b/tests/topotests/babel_topo1/r2/show_ip_route.json_ref
new file mode 100644 (file)
index 0000000..ff3f6ab
--- /dev/null
@@ -0,0 +1,80 @@
+{
+  "192.168.1.0/24":[
+    {
+      "prefix":"192.168.1.0/24",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.1.1",
+          "afi":"ipv4",
+          "interfaceName":"r2-eth0",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "192.168.2.0/24":[
+    {
+      "prefix":"192.168.2.0/24",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.2.2",
+          "afi":"ipv4",
+          "interfaceName":"r2-eth1",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "192.168.3.0/24":[
+    {
+      "prefix":"192.168.3.0/24",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.2.2",
+          "afi":"ipv4",
+          "interfaceName":"r2-eth1",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "193.1.1.0/26":[
+    {
+      "prefix":"193.1.1.0/26",
+      "protocol":"connected",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "directlyConnected":true,
+          "interfaceName":"r2-eth0",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "193.1.2.0/24":[
+    {
+      "prefix":"193.1.2.0/24",
+      "protocol":"connected",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "directlyConnected":true,
+          "interfaceName":"r2-eth1",
+          "active":true
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/babel_topo1/r2/zebra.conf b/tests/topotests/babel_topo1/r2/zebra.conf
new file mode 100644 (file)
index 0000000..301a8b2
--- /dev/null
@@ -0,0 +1,23 @@
+log file zebra.log
+!
+hostname r2
+!
+interface r2-eth0
+ description to sw2 - babel interface
+ ip address 193.1.1.2/26
+ ipv6 address 193:1:1::2/64
+ no link-detect
+!
+interface r2-eth1
+ description to sw3 - babel interface
+ ip address 193.1.2.1/24
+ ipv6 address 193:1:2::1/64
+ no link-detect
+!
+ip forwarding
+ipv6 forwarding
+!
+!
+line vty
+!
+
diff --git a/tests/topotests/babel_topo1/r3/babeld.conf b/tests/topotests/babel_topo1/r3/babeld.conf
new file mode 100644 (file)
index 0000000..1e9dc26
--- /dev/null
@@ -0,0 +1,18 @@
+log file eigrpd.log
+!
+interface r3-eth0
+  babel hello-interval 1000
+  babel wired
+  babel update-interval 50
+!
+interface r3-eth1
+  babel hello-interval 1000
+  babel wired
+  babel update-interval 50
+!
+router  babel
+ network r3-eth0
+ network r3-eth1
+ redistribute ipv4 connected
+ redistribute ipv4 static
+ redistirbute ipv6 connected
diff --git a/tests/topotests/babel_topo1/r3/show_ip_route.json_ref b/tests/topotests/babel_topo1/r3/show_ip_route.json_ref
new file mode 100644 (file)
index 0000000..7fe66fa
--- /dev/null
@@ -0,0 +1,81 @@
+{
+  "192.168.1.0/24":[
+    {
+      "prefix":"192.168.1.0/24",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.2.1",
+          "afi":"ipv4",
+          "interfaceName":"r3-eth1",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "192.168.2.0/24":[
+    {
+      "prefix":"192.168.2.0/24",
+      "protocol":"static",
+      "selected":true,
+      "distance":1,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"192.168.3.10",
+          "afi":"ipv4",
+          "interfaceName":"r3-eth0",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "192.168.3.0/24":[
+    {
+      "prefix":"192.168.3.0/24",
+      "protocol":"connected",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "directlyConnected":true,
+          "interfaceName":"r3-eth0",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "193.1.1.0/26":[
+    {
+      "prefix":"193.1.1.0/26",
+      "protocol":"babel",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "ip":"193.1.2.1",
+          "afi":"ipv4",
+          "interfaceName":"r3-eth1",
+          "active":true
+        }
+      ]
+    }
+  ],
+  "193.1.2.0/24":[
+    {
+      "prefix":"193.1.2.0/24",
+      "protocol":"connected",
+      "selected":true,
+      "nexthops":[
+        {
+          "fib":true,
+          "directlyConnected":true,
+          "interfaceName":"r3-eth1",
+          "active":true
+        }
+      ]
+    }
+  ]
+}
diff --git a/tests/topotests/babel_topo1/r3/zebra.conf b/tests/topotests/babel_topo1/r3/zebra.conf
new file mode 100644 (file)
index 0000000..34e8c62
--- /dev/null
@@ -0,0 +1,25 @@
+log file zebra.log
+!
+hostname r3
+!
+interface r3-eth0
+ description to sw4 - Stub interface
+ ip address 192.168.3.1/24
+ ipv6 address 192:168:3::1/64
+ no link-detect
+!
+interface r3-eth1
+ description to sw3 - RIPv2 interface
+ ip address 193.1.2.2/24
+ ipv6 address 193:1:2::2/64
+ no link-detect
+!
+ip route 192.168.2.0/24 192.168.3.10
+ipv6 route 192:168:2::0/64 192:168:3::10
+!
+ip forwarding
+ipv6 forwarding
+!
+!
+line vty
+!
diff --git a/tests/topotests/babel_topo1/test_babel_topo1.py b/tests/topotests/babel_topo1/test_babel_topo1.py
new file mode 100644 (file)
index 0000000..12f8104
--- /dev/null
@@ -0,0 +1,171 @@
+#!/usr/bin/env python
+
+#
+# test_babel_topo1.py
+#
+# Copyright (c) 2017 by
+# Cumulus Networks, Inc.
+# Donald Sharp
+#
+# Permission to use, copy, modify, and/or distribute this software
+# for any purpose with or without fee is hereby granted, provided
+# that the above copyright notice and this permission notice appear
+# in all copies.
+#
+# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES
+# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR
+# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY
+# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
+# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
+# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
+# OF THIS SOFTWARE.
+#
+
+"""
+test_babel_topo1.py: Testing BABEL
+
+"""
+
+import os
+import re
+import sys
+import pytest
+import json
+
+pytestmark = [pytest.mark.babeld]
+
+# Save the Current Working Directory to find configuration files.
+CWD = os.path.dirname(os.path.realpath(__file__))
+sys.path.append(os.path.join(CWD, "../"))
+
+# pylint: disable=C0413
+# Import topogen and topotest helpers
+from lib import topotest
+from lib.topogen import Topogen, TopoRouter, get_topogen
+from lib.topolog import logger
+
+# Required to instantiate the topology builder class.
+
+#####################################################
+##
+##   Network Topology Definition
+##
+#####################################################
+
+
+def build_topo(tgen):
+    for routern in range(1, 4):
+        tgen.add_router("r{}".format(routern))
+
+    # On main router
+    # First switch is for a dummy interface (for local network)
+    switch = tgen.add_switch("sw1")
+    switch.add_link(tgen.gears["r1"])
+
+    # Switches for BABEL
+    # switch 2 switch is for connection to BABEL router
+    switch = tgen.add_switch("sw2")
+    switch.add_link(tgen.gears["r1"])
+    switch.add_link(tgen.gears["r2"])
+
+    # switch 4 is stub on remote BABEL router
+    switch = tgen.add_switch("sw4")
+    switch.add_link(tgen.gears["r3"])
+
+    # switch 3 is between BABEL routers
+    switch = tgen.add_switch("sw3")
+    switch.add_link(tgen.gears["r2"])
+    switch.add_link(tgen.gears["r3"])
+
+
+#####################################################
+##
+##   Tests starting
+##
+#####################################################
+
+
+def setup_module(module):
+    "Setup topology"
+    tgen = Topogen(build_topo, module.__name__)
+    tgen.start_topology()
+
+    # This is a sample of configuration loading.
+    router_list = tgen.routers()
+    for rname, router in router_list.items():
+        router.load_config(
+            TopoRouter.RD_ZEBRA, os.path.join(CWD, "{}/zebra.conf".format(rname))
+        )
+        router.load_config(
+            TopoRouter.RD_BABEL, os.path.join(CWD, "{}/babeld.conf".format(rname))
+        )
+
+    tgen.start_router()
+
+
+def teardown_module(_mod):
+    "Teardown the pytest environment"
+    tgen = get_topogen()
+
+    # This function tears down the whole topology.
+    tgen.stop_topology()
+
+
+def test_converge_protocols():
+    "Wait for protocol convergence"
+
+    tgen = get_topogen()
+    # Don't run this test if we have any failure.
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    topotest.sleep(10, "Waiting for BABEL convergence")
+
+
+def test_zebra_ipv4_routingTable():
+    "Test 'show ip route'"
+
+    tgen = get_topogen()
+    # Don't run this test if we have any failure.
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    failures = 0
+    router_list = tgen.routers().values()
+    for router in router_list:
+        output = router.vtysh_cmd("show ip route json", isjson=True)
+        refTableFile = "{}/{}/show_ip_route.json_ref".format(CWD, router.name)
+        expected = json.loads(open(refTableFile).read())
+
+        assertmsg = "Zebra IPv4 Routing Table verification failed for router {}".format(
+            router.name
+        )
+        assert topotest.json_cmp(output, expected) is None, assertmsg
+
+def test_shutdown_check_stderr():
+    if os.environ.get("TOPOTESTS_CHECK_STDERR") is None:
+        pytest.skip("Skipping test for Stderr output and memory leaks")
+
+    tgen = get_topogen()
+    # Don't run this test if we have any failure.
+    if tgen.routers_have_failure():
+        pytest.skip(tgen.errors)
+
+    logger.info("Verifying unexpected STDERR output from daemons")
+
+    router_list = tgen.routers().values()
+    for router in router_list:
+        router.stop()
+
+        log = tgen.net[router.name].getStdErr("babeld")
+        if log:
+            logger.error("BABELd StdErr Log:" + log)
+        log = tgen.net[router.name].getStdErr("zebra")
+        if log:
+            logger.error("Zebra StdErr Log:" + log)
+
+
+if __name__ == "__main__":
+    args = ["-s"] + sys.argv[1:]
+    sys.exit(pytest.main(args))