]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Allow one connected route per network mask on a interface 8514/head
authorDonald Sharp <sharpd@nvidia.com>
Mon, 19 Apr 2021 23:23:45 +0000 (19:23 -0400)
committerDonald Sharp <sharpd@nvidia.com>
Mon, 3 May 2021 13:17:22 +0000 (09:17 -0400)
Currently FRR reads the kernel for interface state and FRR
creates a connected route per address on an interface.  If
you are in a situation where you have multiple addresses
on an interface just create 1 connected route for them:

sharpd@eva:/tmp/topotests$ vtysh -c "show int dummy302"
Interface dummy302 is up, line protocol is up
  Link ups:       0    last: (never)
  Link downs:     0    last: (never)
  vrf: default
  index 3279 metric 0 mtu 1500 speed 0
  flags: <UP,BROADCAST,RUNNING,NOARP>
  Type: Ethernet
  HWaddr: aa:4a:ed:95:9f:18
  inet 10.4.1.1/24
  inet 10.4.1.2/24 secondary
  inet 10.4.1.3/24 secondary
  inet 10.4.1.4/24 secondary
  inet 10.4.1.5/24 secondary
  inet6 fe80::a84a:edff:fe95:9f18/64
  Interface Type Other
  Interface Slave Type None
  protodown: off

sharpd@eva:/tmp/topotests$ vtysh -c "show ip route connected"
Codes: K - kernel route, C - connected, S - static, R - RIP,
       O - OSPF, I - IS-IS, B - BGP, E - EIGRP, N - NHRP,
       T - Table, v - VNC, V - VNC-Direct, A - Babel, D - SHARP,
       F - PBR, f - OpenFabric,
       > - selected route, * - FIB route, q - queued, r - rejected, b - backup
       t - trapped, o - offload failure

C>* 10.4.1.0/24 is directly connected, dummy302, 00:10:03
C>* 192.168.161.0/24 is directly connected, enp39s0, 00:10:03

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
zebra/connected.c

index 6f405ca1bbbe533a1cca57e5bbaf11c51c9e5687..1e03f8b639b8a08ef8a10ec7f179857e7f366fbf 100644 (file)
@@ -208,6 +208,9 @@ void connected_up(struct interface *ifp, struct connected *ifc)
        struct zebra_vrf *zvrf;
        uint32_t metric;
        uint32_t flags = 0;
+       uint32_t count = 0;
+       struct listnode *cnode;
+       struct connected *c;
 
        zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
        if (!zvrf) {
@@ -263,6 +266,27 @@ void connected_up(struct interface *ifp, struct connected *ifc)
        if (zrouter.asic_offloaded)
                flags |= ZEBRA_FLAG_OFFLOADED;
 
+       /*
+        * It's possible to add the same network and mask
+        * to an interface over and over.  This would
+        * result in an equivalent number of connected
+        * routes.  Just add one connected route in
+        * for all the addresses on an interface that
+        * resolve to the same network and mask
+        */
+       for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+               struct prefix cp;
+
+               PREFIX_COPY(&cp, CONNECTED_PREFIX(c));
+               apply_mask(&cp);
+
+               if (prefix_same(&cp, &p))
+                       count++;
+
+               if (count >= 2)
+                       return;
+       }
+
        rib_add(afi, SAFI_UNICAST, zvrf->vrf->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
                flags, &p, NULL, &nh, 0, zvrf->table_id, metric, 0, 0, 0);
 
@@ -358,6 +382,9 @@ void connected_down(struct interface *ifp, struct connected *ifc)
                .vrf_id = ifp->vrf_id,
        };
        struct zebra_vrf *zvrf;
+       uint32_t count = 0;
+       struct listnode *cnode;
+       struct connected *c;
 
        zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id);
        if (!zvrf) {
@@ -396,6 +423,26 @@ void connected_down(struct interface *ifp, struct connected *ifc)
                break;
        }
 
+       /*
+        * It's possible to have X number of addresses
+        * on a interface that all resolve to the same
+        * network and mask.  Find them and just
+        * allow the deletion when are removing the last
+        * one.
+        */
+       for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, c)) {
+               struct prefix cp;
+
+               PREFIX_COPY(&cp, CONNECTED_PREFIX(c));
+               apply_mask(&cp);
+
+               if (prefix_same(&p, &cp))
+                       count++;
+
+               if (count >= 2)
+                       return;
+       }
+
        /*
         * Same logic as for connected_up(): push the changes into the
         * head.