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;
}
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;
}
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;
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;
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;