summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2017-08-29 18:23:08 -0400
committerDonald Sharp <sharpd@cumulusnetworks.com>2017-08-31 13:47:03 -0400
commitae87977c35c5e63ac2640de06ed2783759f2dfdd (patch)
tree9c483db4fec3777095ae5523d812bc45548c0e74
parent72a1b201d3acc71a5cb4c7a06ed91ef30e21ee11 (diff)
zebra: Refactor connected_up_ipv[4|6]
The connected_up_ipv[4|6] functions were almost identical. Combine the forces for the goodness of mankind Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
-rw-r--r--zebra/connected.c104
-rw-r--r--zebra/connected.h3
-rw-r--r--zebra/interface.c7
3 files changed, 45 insertions, 69 deletions
diff --git a/zebra/connected.c b/zebra/connected.c
index 7176ce70bd..191e3144e6 100644
--- a/zebra/connected.c
+++ b/zebra/connected.c
@@ -92,10 +92,7 @@ static void connected_announce(struct interface *ifp, struct connected *ifc)
zebra_interface_address_add_update(ifp, ifc);
if (if_is_operative(ifp)) {
- if (ifc->address->family == AF_INET)
- connected_up_ipv4(ifp, ifc);
- else
- connected_up_ipv6(ifp, ifc);
+ connected_up(ifp, ifc);
}
}
@@ -204,8 +201,9 @@ static void connected_update(struct interface *ifp, struct connected *ifc)
}
/* Called from if_up(). */
-void connected_up_ipv4(struct interface *ifp, struct connected *ifc)
+void connected_up(struct interface *ifp, struct connected *ifc)
{
+ afi_t afi;
struct prefix p;
struct nexthop nh = {
.type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex,
@@ -214,34 +212,59 @@ void connected_up_ipv4(struct interface *ifp, struct connected *ifc)
if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
return;
- PREFIX_COPY_IPV4((struct prefix_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))
+ 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:
+#ifndef LINUX
+ /* XXX: It is already done by rib_bogus_ipv6 within rib_add */
+ if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6))
+ return;
+#endif
+ break;
+ default:
+ zlog_warn("Received unknown AFI: %s", afi2str(afi));
return;
+ break;
+ }
- rib_add(AFI_IP, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
+ rib_add(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
&p, NULL, &nh, RT_TABLE_MAIN, ifp->metric, 0, 0);
- rib_add(AFI_IP, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
+ rib_add(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
&p, NULL, &nh, RT_TABLE_MAIN, ifp->metric, 0, 0);
- if (IS_ZEBRA_DEBUG_RIB_DETAILED)
- zlog_debug(
- "%u: IF %s IPv4 address add/up, scheduling RIB processing",
- ifp->vrf_id, ifp->name);
+ if (IS_ZEBRA_DEBUG_RIB_DETAILED) {
+ char buf[PREFIX_STRLEN];
+
+ zlog_debug("%u: IF %s address %s add/up, 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));
}
}
@@ -355,7 +378,7 @@ void connected_down_ipv4(struct interface *ifp, struct connected *ifc)
if (prefix_ipv4_any((struct prefix_ipv4 *)&p))
return;
- /* Same logic as for connected_up_ipv4(): push the changes into the
+ /* 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,
&p, NULL, &nh, 0, 0);
@@ -426,47 +449,6 @@ void connected_delete_ipv4(struct interface *ifp, int flags,
}
}
-void connected_up_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((struct prefix_ipv6 *)&p, CONNECTED_PREFIX(ifc));
-
- /* Apply mask to the network. */
- apply_mask(&p);
-
-#ifndef LINUX
- /* XXX: It is already done by rib_bogus_ipv6 within rib_add */
- if (IN6_IS_ADDR_UNSPECIFIED(&p.u.prefix6))
- return;
-#endif
-
- rib_add(AFI_IP6, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0,
- &p, NULL, &nh, RT_TABLE_MAIN, ifp->metric, 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));
- }
-}
-
/* Add connected IPv6 route to the interface. */
void connected_add_ipv6(struct interface *ifp, int flags, struct in6_addr *addr,
u_char prefixlen, const char *label)
diff --git a/zebra/connected.h b/zebra/connected.h
index c6da36956d..28b8104e8b 100644
--- a/zebra/connected.h
+++ b/zebra/connected.h
@@ -38,7 +38,7 @@ extern void connected_delete_ipv4(struct interface *ifp, int flags,
extern void connected_delete_ipv4_unnumbered(struct connected *ifc);
-extern void connected_up_ipv4(struct interface *, struct connected *);
+extern void connected_up(struct interface *ifp, struct connected *ifc);
extern void connected_down_ipv4(struct interface *, struct connected *);
extern void connected_add_ipv6(struct interface *ifp, int flags,
@@ -47,7 +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_up_ipv6(struct interface *, struct connected *);
extern void connected_down_ipv6(struct interface *ifp, struct connected *);
extern int connected_is_unnumbered(struct interface *);
diff --git a/zebra/interface.c b/zebra/interface.c
index 5668590fdc..354e9177ae 100644
--- a/zebra/interface.c
+++ b/zebra/interface.c
@@ -527,18 +527,13 @@ static void if_install_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)) {
if (CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL))
zebra_interface_address_add_update(ifp, ifc);
- p = ifc->address;
- if (p->family == AF_INET)
- connected_up_ipv4(ifp, ifc);
- else if (p->family == AF_INET6)
- connected_up_ipv6(ifp, ifc);
+ connected_up(ifp, ifc);
}
}
}