]> git.puffer.fish Git - mirror/frr.git/commitdiff
zebra: intf address handler is platform-neutral 9052/head
authorMark Stapp <mjs.ietf@gmail.com>
Wed, 8 Sep 2021 19:58:04 +0000 (15:58 -0400)
committerMark Stapp <mjs.ietf@gmail.com>
Tue, 14 Sep 2021 15:07:30 +0000 (11:07 -0400)
Move the handler for incoming interface address events
to a neutral source file - it's not netlink-specific and
shouldn't have been in a netlink file.

Signed-off-by: Mark Stapp <mjs.ietf@gmail.com>
zebra/if_netlink.c
zebra/if_netlink.h
zebra/interface.c

index d554b02c690011ed6ac507cc4d2b4422c3aaeebd..8c528913e9f88e1b64544c58381d91552a31f681 100644 (file)
@@ -1662,114 +1662,6 @@ int netlink_interface_addr_dplane(struct nlmsghdr *h, ns_id_t ns_id,
        return 0;
 }
 
-/*
- * Handle an interface addr event based on info in a dplane context object.
- * This runs in the main pthread, using the info in the context object to
- * modify an interface.
- */
-int netlink_interface_addr_ctx(struct zebra_dplane_ctx *ctx)
-{
-       int ret = -1;
-       struct interface *ifp;
-       uint8_t flags = 0;
-       const char *label = NULL;
-       ns_id_t ns_id;
-       struct zebra_ns *zns;
-       uint32_t metric = METRIC_MAX;
-       ifindex_t ifindex;
-       const struct prefix *addr, *dest = NULL;
-       enum dplane_op_e op;
-
-       op = dplane_ctx_get_op(ctx);
-       ns_id = dplane_ctx_get_ns_id(ctx);
-
-       zns = zebra_ns_lookup(ns_id);
-       if (zns == NULL) {
-               /* No ns - deleted maybe? */
-               if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug("%s: can't find zns id %u", __func__, ns_id);
-               goto done;
-       }
-
-       ifindex = dplane_ctx_get_ifindex(ctx);
-
-       ifp = if_lookup_by_index_per_ns(zns, ifindex);
-       if (ifp == NULL) {
-               if (IS_ZEBRA_DEBUG_KERNEL)
-                       zlog_debug("%s: can't find ifp at nsid %u index %d",
-                                  __func__, ns_id, ifindex);
-               goto done;
-       }
-
-       addr = dplane_ctx_get_intf_addr(ctx);
-
-       if (IS_ZEBRA_DEBUG_KERNEL)
-               zlog_debug("%s: %s: ifindex %u, addr %pFX", __func__,
-                          dplane_op2str(op), ifindex, addr);
-
-       /* Is there a peer or broadcast address? */
-       dest = dplane_ctx_get_intf_dest(ctx);
-       if (dest->prefixlen == 0)
-               dest = NULL;
-
-       if (dplane_ctx_intf_is_connected(ctx))
-               SET_FLAG(flags, ZEBRA_IFA_PEER);
-
-       /* Flags. */
-       if (dplane_ctx_intf_is_secondary(ctx))
-               SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
-
-       /* Label? */
-       if (dplane_ctx_intf_has_label(ctx))
-               label = dplane_ctx_get_intf_label(ctx);
-
-       if (label && strcmp(ifp->name, label) == 0)
-               label = NULL;
-
-       metric = dplane_ctx_get_intf_metric(ctx);
-
-       /* Register interface address to the interface. */
-       if (addr->family == AF_INET) {
-               if (op == DPLANE_OP_INTF_ADDR_ADD)
-                       connected_add_ipv4(
-                               ifp, flags, &addr->u.prefix4, addr->prefixlen,
-                               dest ? &dest->u.prefix4 : NULL, label, metric);
-               else if (CHECK_FLAG(flags, ZEBRA_IFA_PEER)) {
-                       /* Delete with a peer address */
-                       connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
-                                             addr->prefixlen,
-                                             &dest->u.prefix4);
-               } else
-                       connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
-                                             addr->prefixlen, NULL);
-       }
-
-       if (addr->family == AF_INET6) {
-               if (op == DPLANE_OP_INTF_ADDR_ADD) {
-                       connected_add_ipv6(ifp, flags, &addr->u.prefix6,
-                                          dest ? &dest->u.prefix6 : NULL,
-                                          addr->prefixlen, label, metric);
-               } else
-                       connected_delete_ipv6(ifp, &addr->u.prefix6, NULL,
-                                             addr->prefixlen);
-       }
-
-       /*
-        * Linux kernel does not send route delete on interface down/addr del
-        * so we have to re-process routes it owns (i.e. kernel routes)
-        */
-       if (op != DPLANE_OP_INTF_ADDR_ADD)
-               rib_update(RIB_UPDATE_KERNEL);
-
-       ret = 0;
-
-done:
-       /* We're responsible for the ctx object */
-       dplane_ctx_fini(&ctx);
-
-       return ret;
-}
-
 int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup)
 {
        int len;
index 1ca2c755fea18f43b62467f05eb1ed8b6929a7e1..a1ce7af8c7807ddb52ea2a732b8a8a819744209e 100644 (file)
@@ -37,9 +37,6 @@ extern int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id,
 int netlink_interface_addr_dplane(struct nlmsghdr *h, ns_id_t ns_id,
                                  int startup);
 
-/* Handle an interface addr change event. */
-int netlink_interface_addr_ctx(struct zebra_dplane_ctx *ctx);
-
 extern int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup);
 extern int interface_lookup_netlink(struct zebra_ns *zns);
 
index ec1f16f671606dbeae55a1da6b4aa51a6854538c..a68d00d55ce035c04d5812110d9c0a0a99e0179e 100644 (file)
@@ -1205,14 +1205,107 @@ void zebra_if_set_protodown(struct interface *ifp, bool down)
 #endif
 }
 
-/* Handler for incoming intf address change events */
+/*
+ * Handle an interface addr event based on info in a dplane context object.
+ * This runs in the main pthread, using the info in the context object to
+ * modify an interface.
+ */
 void zebra_if_addr_update_ctx(struct zebra_dplane_ctx *ctx)
 {
-#ifdef HAVE_NETLINK
-       netlink_interface_addr_ctx(ctx);
-#else
+       struct interface *ifp;
+       uint8_t flags = 0;
+       const char *label = NULL;
+       ns_id_t ns_id;
+       struct zebra_ns *zns;
+       uint32_t metric = METRIC_MAX;
+       ifindex_t ifindex;
+       const struct prefix *addr, *dest = NULL;
+       enum dplane_op_e op;
+
+       op = dplane_ctx_get_op(ctx);
+       ns_id = dplane_ctx_get_ns_id(ctx);
+
+       zns = zebra_ns_lookup(ns_id);
+       if (zns == NULL) {
+               /* No ns - deleted maybe? */
+               if (IS_ZEBRA_DEBUG_KERNEL)
+                       zlog_debug("%s: can't find zns id %u", __func__, ns_id);
+               goto done;
+       }
+
+       ifindex = dplane_ctx_get_ifindex(ctx);
+
+       ifp = if_lookup_by_index_per_ns(zns, ifindex);
+       if (ifp == NULL) {
+               if (IS_ZEBRA_DEBUG_KERNEL)
+                       zlog_debug("%s: can't find ifp at nsid %u index %d",
+                                  __func__, ns_id, ifindex);
+               goto done;
+       }
+
+       addr = dplane_ctx_get_intf_addr(ctx);
+
+       if (IS_ZEBRA_DEBUG_KERNEL)
+               zlog_debug("%s: %s: ifindex %u, addr %pFX", __func__,
+                          dplane_op2str(op), ifindex, addr);
+
+       /* Is there a peer or broadcast address? */
+       dest = dplane_ctx_get_intf_dest(ctx);
+       if (dest->prefixlen == 0)
+               dest = NULL;
+
+       if (dplane_ctx_intf_is_connected(ctx))
+               SET_FLAG(flags, ZEBRA_IFA_PEER);
+
+       /* Flags. */
+       if (dplane_ctx_intf_is_secondary(ctx))
+               SET_FLAG(flags, ZEBRA_IFA_SECONDARY);
+
+       /* Label? */
+       if (dplane_ctx_intf_has_label(ctx))
+               label = dplane_ctx_get_intf_label(ctx);
+
+       if (label && strcmp(ifp->name, label) == 0)
+               label = NULL;
+
+       metric = dplane_ctx_get_intf_metric(ctx);
+
+       /* Register interface address to the interface. */
+       if (addr->family == AF_INET) {
+               if (op == DPLANE_OP_INTF_ADDR_ADD)
+                       connected_add_ipv4(
+                               ifp, flags, &addr->u.prefix4, addr->prefixlen,
+                               dest ? &dest->u.prefix4 : NULL, label, metric);
+               else if (CHECK_FLAG(flags, ZEBRA_IFA_PEER)) {
+                       /* Delete with a peer address */
+                       connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
+                                             addr->prefixlen,
+                                             &dest->u.prefix4);
+               } else
+                       connected_delete_ipv4(ifp, flags, &addr->u.prefix4,
+                                             addr->prefixlen, NULL);
+       }
+
+       if (addr->family == AF_INET6) {
+               if (op == DPLANE_OP_INTF_ADDR_ADD) {
+                       connected_add_ipv6(ifp, flags, &addr->u.prefix6,
+                                          dest ? &dest->u.prefix6 : NULL,
+                                          addr->prefixlen, label, metric);
+               } else
+                       connected_delete_ipv6(ifp, &addr->u.prefix6, NULL,
+                                             addr->prefixlen);
+       }
+
+       /*
+        * Linux kernel does not send route delete on interface down/addr del
+        * so we have to re-process routes it owns (i.e. kernel routes)
+        */
+       if (op != DPLANE_OP_INTF_ADDR_ADD)
+               rib_update(RIB_UPDATE_KERNEL);
+
+done:
+       /* We're responsible for the ctx object */
        dplane_ctx_fini(&ctx);
-#endif /* HAVE_NETLINK */
 }
 
 /* Dump if address information to vty. */