]> git.proxmox.com Git - mirror_frr.git/blobdiff - staticd/static_zebra.c
*: Convert from ->interface_up to the interface callback
[mirror_frr.git] / staticd / static_zebra.c
index 13c04259d733728f272d5d3c77a89f2083e1909b..4ba244208625b02323d8f41855407f9a9240f9bf 100644 (file)
@@ -49,28 +49,11 @@ bool debug;
 struct zclient *zclient;
 static struct hash *static_nht_hash;
 
-static struct interface *zebra_interface_if_lookup(struct stream *s)
-{
-       char ifname_tmp[INTERFACE_NAMSIZ];
-
-       /* Read interface name. */
-       stream_get(ifname_tmp, s, INTERFACE_NAMSIZ);
-
-       /* And look it up. */
-       return if_lookup_by_name(ifname_tmp, VRF_DEFAULT);
-}
-
 /* Inteface addition message from zebra. */
-static int interface_add(ZAPI_CALLBACK_ARGS)
+static int static_ifp_create(struct interface *ifp)
 {
-       struct interface *ifp;
-
-       ifp = zebra_interface_add_read(zclient->ibuf, vrf_id);
-
-       if (!ifp)
-               return 0;
-
        static_ifindex_update(ifp, true);
+
        return 0;
 }
 
@@ -113,31 +96,30 @@ static int interface_address_delete(ZAPI_CALLBACK_ARGS)
        return 0;
 }
 
-static int interface_state_up(ZAPI_CALLBACK_ARGS)
+static int static_ifp_up(struct interface *ifp)
 {
-       struct interface *ifp;
-
-       ifp = zebra_interface_if_lookup(zclient->ibuf);
+       if (if_is_vrf(ifp)) {
+               struct static_vrf *svrf = static_vrf_lookup_by_id(ifp->vrf_id);
 
-       if (ifp) {
-               if (if_is_vrf(ifp)) {
-                       struct static_vrf *svrf =
-                                       static_vrf_lookup_by_id(vrf_id);
-
-                       static_fixup_vrf_ids(svrf);
-                       static_config_install_delayed_routes(svrf);
-               }
-
-               /* Install any static reliant on this interface coming up */
-               static_install_intf_nh(ifp);
+               static_fixup_vrf_ids(svrf);
+               static_config_install_delayed_routes(svrf);
        }
 
+       /* Install any static reliant on this interface coming up */
+       static_install_intf_nh(ifp);
+       static_ifindex_update(ifp, true);
+
        return 0;
 }
 
 static int interface_state_down(ZAPI_CALLBACK_ARGS)
 {
-       zebra_interface_state_read(zclient->ibuf, vrf_id);
+       struct interface *ifp;
+
+       ifp = zebra_interface_state_read(zclient->ibuf, vrf_id);
+
+       if (ifp)
+               static_ifindex_update(ifp, false);
 
        return 0;
 }
@@ -194,6 +176,25 @@ struct static_nht_data {
        uint8_t nh_num;
 };
 
+/* API to check whether the configured nexthop address is
+ * one of its local connected address or not.
+ */
+static bool
+static_nexthop_is_local(vrf_id_t vrfid, struct prefix *addr, int family)
+{
+       if (family == AF_INET) {
+               if (if_lookup_exact_address(&addr->u.prefix4,
+                                       AF_INET,
+                                       vrfid))
+                       return true;
+       } else if (family == AF_INET6) {
+               if (if_lookup_exact_address(&addr->u.prefix6,
+                                       AF_INET6,
+                                       vrfid))
+                       return true;
+       }
+       return false;
+}
 static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS)
 {
        struct static_nht_data *nhtd, lookup;
@@ -208,6 +209,12 @@ static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS)
        if (nhr.prefix.family == AF_INET6)
                afi = AFI_IP6;
 
+       if (nhr.type == ZEBRA_ROUTE_CONNECT) {
+               if (static_nexthop_is_local(vrf_id, &nhr.prefix,
+                                       nhr.prefix.family))
+                       nhr.nexthop_num = 0;
+       }
+
        memset(&lookup, 0, sizeof(lookup));
        lookup.nh = &nhr.prefix;
        lookup.nh_vrf_id = vrf_id;
@@ -473,18 +480,30 @@ extern void static_zebra_route_add(struct route_node *rn,
                           ZEBRA_ROUTE_ADD : ZEBRA_ROUTE_DELETE,
                           zclient, &api);
 }
+
+static int static_ifp_down(struct interface *ifp)
+{
+       return 0;
+}
+
+static int static_ifp_destroy(struct interface *ifp)
+{
+       return 0;
+}
+
 void static_zebra_init(void)
 {
        struct zclient_options opt = { .receive_notify = true };
 
+       if_zapi_callbacks(static_ifp_create, static_ifp_up,
+                         static_ifp_down, static_ifp_destroy);
+
        zclient = zclient_new(master, &opt);
 
        zclient_init(zclient, ZEBRA_ROUTE_STATIC, 0, &static_privs);
        zclient->zebra_capabilities = static_zebra_capabilities;
        zclient->zebra_connected = zebra_connected;
-       zclient->interface_add = interface_add;
        zclient->interface_delete = interface_delete;
-       zclient->interface_up = interface_state_up;
        zclient->interface_down = interface_state_down;
        zclient->interface_address_add = interface_address_add;
        zclient->interface_address_delete = interface_address_delete;