]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: Refactor connected_down_ipv[4|6]
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Aug 2017 17:47:26 +0000 (13:47 -0400)
committerDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 31 Aug 2017 17:47:26 +0000 (13:47 -0400)
The connected_down_ipv[4|6] functions are basically identical.
Refactor into one common interface.

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

index 191e3144e61a96a50965b94d703c3dc0e02ef75e..df5a0506742effd206d6b9c0fbae9087aa48a655 100644 (file)
@@ -54,10 +54,7 @@ static void connected_withdraw(struct connected *ifc)
                if (ifc->address->family == AF_INET)
                        if_subnet_delete(ifc->ifp, ifc);
 
-               if (ifc->address->family == AF_INET)
-                       connected_down_ipv4(ifc->ifp, ifc);
-               else
-                       connected_down_ipv6(ifc->ifp, ifc);
+               connected_down(ifc->ifp, ifc);
 
                UNSET_FLAG(ifc->conf, ZEBRA_IFC_REAL);
        }
@@ -358,8 +355,9 @@ void connected_add_ipv4(struct interface *ifp, int flags, struct in_addr *addr,
        connected_update(ifp, ifc);
 }
 
-void connected_down_ipv4(struct interface *ifp, struct connected *ifc)
+void connected_down(struct interface *ifp, struct connected *ifc)
 {
+       afi_t afi;
        struct prefix p;
        struct nexthop nh = {
                .type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex,
@@ -368,37 +366,60 @@ void connected_down_ipv4(struct interface *ifp, struct connected *ifc)
        if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
                return;
 
-       PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc));
+       PREFIX_COPY(&p, CONNECTED_PREFIX(ifc));
 
        /* Apply mask to the network. */
        apply_mask(&p);
 
-       /* In case of connected address is 0.0.0.0/0 we treat it tunnel
-          address. */
-       if (prefix_ipv4_any((struct prefix_ipv4 *)&p))
-               return;
+       afi = family2afi(p.family);
+
+       switch (afi) {
+       case AFI_IP:
+               /*
+                * In case of connected address is 0.0.0.0/0 we treat it tunnel
+                *  address.
+                */
+               if (prefix_ipv4_any((struct prefix_ipv4 *)&p))
+                       return;
+               break;
+       case AFI_IP6:
+               if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6))
+                       return;
+               break;
+       default:
+               zlog_info("Unknown AFI: %s", afi2str(afi));
+               break;
+       }
 
-       /* Same logic as for connected_up(): push the changes into the
-        * head. */
-       rib_delete(AFI_IP, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
+       /*
+        * Same logic as for connected_up(): push the changes into the
+        * head.
+        */
+       rib_delete(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
                   &p, NULL, &nh, 0, 0);
 
-       rib_delete(AFI_IP, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
+       rib_delete(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
                   0, &p, NULL, &nh, 0, 0);
 
-       if (IS_ZEBRA_DEBUG_RIB_DETAILED)
-               zlog_debug(
-                       "%u: IF %s IPv4 address down, scheduling RIB processing",
-                       ifp->vrf_id, ifp->name);
+       if (IS_ZEBRA_DEBUG_RIB_DETAILED) {
+               char buf[PREFIX_STRLEN];
+
+               zlog_debug("%u: IF %s IP %s address down, scheduling RIB processing",
+                          ifp->vrf_id, ifp->name,
+                          prefix2str(&p, buf, sizeof(buf)));
+       }
 
        rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
 
        /* Schedule LSP forwarding entries for processing, if appropriate. */
        if (ifp->vrf_id == VRF_DEFAULT) {
-               if (IS_ZEBRA_DEBUG_MPLS)
-                       zlog_debug(
-                               "%u: IF %s IPv4 address add/up, scheduling MPLS processing",
-                               ifp->vrf_id, ifp->name);
+               if (IS_ZEBRA_DEBUG_MPLS) {
+                       char buf[PREFIX_STRLEN];
+
+                       zlog_debug("%u: IF %s IP %s address add/up, scheduling MPLS processing",
+                                  ifp->vrf_id, ifp->name,
+                                  prefix2str(&p, buf, sizeof(buf)));
+               }
                mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id));
        }
 }
@@ -491,43 +512,6 @@ void connected_add_ipv6(struct interface *ifp, int flags, struct in6_addr *addr,
        connected_update(ifp, ifc);
 }
 
-void connected_down_ipv6(struct interface *ifp, struct connected *ifc)
-{
-       struct prefix p;
-       struct nexthop nh = {
-               .type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex,
-       };
-
-       if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
-               return;
-
-       PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc));
-
-       apply_mask(&p);
-
-       if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6))
-               return;
-
-       rib_delete(AFI_IP6, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0,
-                  0, &p, NULL, &nh, 0, 0);
-
-       if (IS_ZEBRA_DEBUG_RIB_DETAILED)
-               zlog_debug(
-                       "%u: IF %s IPv6 address down, scheduling RIB processing",
-                       ifp->vrf_id, ifp->name);
-
-       rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE);
-
-       /* Schedule LSP forwarding entries for processing, if appropriate. */
-       if (ifp->vrf_id == VRF_DEFAULT) {
-               if (IS_ZEBRA_DEBUG_MPLS)
-                       zlog_debug(
-                               "%u: IF %s IPv4 address add/up, scheduling MPLS processing",
-                               ifp->vrf_id, ifp->name);
-               mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id));
-       }
-}
-
 void connected_delete_ipv6(struct interface *ifp, struct in6_addr *address,
                           u_char prefixlen)
 {
index 28b8104e8bf954261a4a4b70128ea6cc1d7fbffd..d10a092984e1557f49b7b147ec5f5258972ba277 100644 (file)
@@ -39,7 +39,7 @@ extern void connected_delete_ipv4(struct interface *ifp, int flags,
 extern void connected_delete_ipv4_unnumbered(struct connected *ifc);
 
 extern void connected_up(struct interface *ifp, struct connected *ifc);
-extern void connected_down_ipv4(struct interface *, struct connected *);
+extern void connected_down(struct interface *ifp, struct connected *ifc);
 
 extern void connected_add_ipv6(struct interface *ifp, int flags,
                               struct in6_addr *address, u_char prefixlen,
@@ -47,8 +47,6 @@ extern void connected_add_ipv6(struct interface *ifp, int flags,
 extern void connected_delete_ipv6(struct interface *ifp,
                                  struct in6_addr *address, u_char prefixlen);
 
-extern void connected_down_ipv6(struct interface *ifp, struct connected *);
-
 extern int connected_is_unnumbered(struct interface *);
 
 #endif /*_ZEBRA_CONNECTED_H */
index 354e9177ae33a7b553827ef177b24482dcdc688f..5d022591594262a104355d540104253eb73315fc 100644 (file)
@@ -544,17 +544,11 @@ static void if_uninstall_connected(struct interface *ifp)
        struct listnode *node;
        struct listnode *next;
        struct connected *ifc;
-       struct prefix *p;
 
        if (ifp->connected) {
                for (ALL_LIST_ELEMENTS(ifp->connected, node, next, ifc)) {
-                       p = ifc->address;
                        zebra_interface_address_delete_update(ifp, ifc);
-
-                       if (p->family == AF_INET)
-                               connected_down_ipv4(ifp, ifc);
-                       else if (p->family == AF_INET6)
-                               connected_down_ipv6(ifp, ifc);
+                       connected_down(ifp, ifc);
                }
        }
 }
@@ -603,7 +597,7 @@ static void if_delete_connected(struct interface *ifp)
                                        next = anode->next;
 
                                        ifc = listgetdata(anode);
-                                       connected_down_ipv4(ifp, ifc);
+                                       connected_down(ifp, ifc);
 
                                        /* XXX: We have to send notifications
                                         * here explicitly, because we destroy
@@ -637,7 +631,7 @@ static void if_delete_connected(struct interface *ifp)
                                rn->info = NULL;
                                route_unlock_node(rn);
                        } else if (cp.family == AF_INET6) {
-                               connected_down_ipv6(ifp, ifc);
+                               connected_down(ifp, ifc);
 
                                zebra_interface_address_delete_update(ifp, ifc);