summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--staticd/static_nht.c76
-rw-r--r--staticd/static_nht.h16
-rw-r--r--staticd/static_routes.c4
-rw-r--r--staticd/static_zebra.c7
-rw-r--r--staticd/static_zebra.h3
5 files changed, 70 insertions, 36 deletions
diff --git a/staticd/static_nht.c b/staticd/static_nht.c
index 2aa0db59f1..8891ae3210 100644
--- a/staticd/static_nht.c
+++ b/staticd/static_nht.c
@@ -23,18 +23,47 @@
#include "table.h"
#include "vrf.h"
#include "nexthop.h"
+#include "srcdest_table.h"
#include "static_vrf.h"
#include "static_routes.h"
#include "static_zebra.h"
#include "static_nht.h"
-static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
- afi_t afi, safi_t safi, struct vrf *vrf,
- vrf_id_t nh_vrf_id)
+static void static_nht_update_rn(struct route_node *rn,
+ struct prefix *nhp, uint32_t nh_num,
+ vrf_id_t nh_vrf_id, struct vrf *vrf,
+ safi_t safi)
{
- struct route_table *stable;
struct static_route *si;
+
+ for (si = rn->info; si; si = si->next) {
+ if (si->nh_vrf_id != nh_vrf_id)
+ continue;
+
+ if (si->type != STATIC_IPV4_GATEWAY
+ && si->type != STATIC_IPV4_GATEWAY_IFNAME
+ && si->type != STATIC_IPV6_GATEWAY
+ && si->type != STATIC_IPV6_GATEWAY_IFNAME)
+ continue;
+
+ if (nhp->family == AF_INET
+ && nhp->u.prefix4.s_addr == si->addr.ipv4.s_addr)
+ si->nh_valid = !!nh_num;
+
+ if (nhp->family == AF_INET6
+ && memcmp(&nhp->u.prefix6, &si->addr.ipv6, 16) == 0)
+ si->nh_valid = !!nh_num;
+
+ static_zebra_route_add(rn, si, vrf->vrf_id, safi, true);
+ }
+}
+
+static void static_nht_update_safi(struct prefix *sp, struct prefix *nhp,
+ uint32_t nh_num, afi_t afi, safi_t safi,
+ struct vrf *vrf, vrf_id_t nh_vrf_id)
+{
+ struct route_table *stable;
struct static_vrf *svrf;
struct route_node *rn;
@@ -46,40 +75,31 @@ static void static_nht_update_safi(struct prefix *p, uint32_t nh_num,
if (!stable)
return;
- for (rn = route_top(stable); rn; rn = route_next(rn)) {
- for (si = rn->info; si; si = si->next) {
- if (si->nh_vrf_id != nh_vrf_id)
- continue;
-
- if (si->type != STATIC_IPV4_GATEWAY
- && si->type != STATIC_IPV4_GATEWAY_IFNAME
- && si->type != STATIC_IPV6_GATEWAY
- && si->type != STATIC_IPV6_GATEWAY_IFNAME)
- continue;
-
- if (p->family == AF_INET
- && p->u.prefix4.s_addr == si->addr.ipv4.s_addr)
- si->nh_valid = !!nh_num;
-
- if (p->family == AF_INET6
- && memcmp(&p->u.prefix6, &si->addr.ipv6, 16) == 0)
- si->nh_valid = !!nh_num;
-
- static_zebra_route_add(rn, si, vrf->vrf_id, safi, true);
+ if (sp) {
+ rn = srcdest_rnode_lookup(stable, sp, NULL);
+ if (rn) {
+ static_nht_update_rn(rn, nhp, nh_num, nh_vrf_id,
+ vrf, safi);
+ route_unlock_node(rn);
}
+ return;
}
+
+ for (rn = route_top(stable); rn; rn = route_next(rn))
+ static_nht_update_rn(rn, nhp, nh_num, nh_vrf_id, vrf, safi);
+
}
-void static_nht_update(struct prefix *p, uint32_t nh_num, afi_t afi,
- vrf_id_t nh_vrf_id)
+void static_nht_update(struct prefix *sp, struct prefix *nhp,
+ uint32_t nh_num, afi_t afi, vrf_id_t nh_vrf_id)
{
struct vrf *vrf;
RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
- static_nht_update_safi(p, nh_num, afi, SAFI_UNICAST,
+ static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_UNICAST,
vrf, nh_vrf_id);
- static_nht_update_safi(p, nh_num, afi, SAFI_MULTICAST,
+ static_nht_update_safi(sp, nhp, nh_num, afi, SAFI_MULTICAST,
vrf, nh_vrf_id);
}
}
diff --git a/staticd/static_nht.h b/staticd/static_nht.h
index f273c71bba..7b94616856 100644
--- a/staticd/static_nht.h
+++ b/staticd/static_nht.h
@@ -20,6 +20,18 @@
#ifndef __STATIC_NHT_H__
#define __STATIC_NHT_H__
-extern void static_nht_update(struct prefix *p, uint32_t nh_num,
- afi_t afi, vrf_id_t vrf_id);
+/*
+ * When we get notification that nexthop tracking has an answer for
+ * us call this function to find the nexthop we are tracking so it
+ * can be installed or removed.
+ *
+ * sp -> The route we are looking at. If NULL then look at all
+ * routes.
+ * nhp -> The nexthop that is being tracked.
+ * nh_num -> number of valid nexthops.
+ * afi -> The afi we are working in.
+ * vrf_id -> The vrf the nexthop is in.
+ */
+extern void static_nht_update(struct prefix *sp, struct prefix *nhp,
+ uint32_t nh_num, afi_t afi, vrf_id_t vrf_id);
#endif
diff --git a/staticd/static_routes.c b/staticd/static_routes.c
index 5f9ecad694..a6d4c1806a 100644
--- a/staticd/static_routes.c
+++ b/staticd/static_routes.c
@@ -39,7 +39,7 @@ static void static_install_route(struct route_node *rn,
struct static_route *si;
for (si = rn->info; si; si = si->next)
- static_zebra_nht_register(si, true);
+ static_zebra_nht_register(rn, si, true);
si = rn->info;
if (si)
@@ -242,7 +242,7 @@ int static_delete_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p,
return 0;
}
- static_zebra_nht_register(si, false);
+ static_zebra_nht_register(rn, si, false);
/* Unlink static route from linked list. */
if (si->prev)
diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c
index c6da00418b..65d8e6fb92 100644
--- a/staticd/static_zebra.c
+++ b/staticd/static_zebra.c
@@ -210,7 +210,7 @@ static int static_zebra_nexthop_update(ZAPI_CALLBACK_ARGS)
if (nhtd) {
nhtd->nh_num = nhr.nexthop_num;
- static_nht_update(&nhr.prefix, nhr.nexthop_num, afi,
+ static_nht_update(NULL, &nhr.prefix, nhr.nexthop_num, afi,
nhtd->nh_vrf_id);
} else
zlog_err("No nhtd?");
@@ -267,7 +267,8 @@ static void static_nht_hash_free(void *data)
XFREE(MTYPE_TMP, nhtd);
}
-void static_zebra_nht_register(struct static_route *si, bool reg)
+void static_zebra_nht_register(struct route_node *rn,
+ struct static_route *si, bool reg)
{
struct static_nht_data *nhtd, lookup;
uint32_t cmd;
@@ -316,7 +317,7 @@ void static_zebra_nht_register(struct static_route *si, bool reg)
nhtd->refcount++;
if (nhtd->refcount > 1) {
- static_nht_update(nhtd->nh, nhtd->nh_num,
+ static_nht_update(&rn->p, nhtd->nh, nhtd->nh_num,
afi, si->nh_vrf_id);
return;
}
diff --git a/staticd/static_zebra.h b/staticd/static_zebra.h
index a82eb162e1..15f5410b81 100644
--- a/staticd/static_zebra.h
+++ b/staticd/static_zebra.h
@@ -21,7 +21,8 @@
extern struct thread_master *master;
-extern void static_zebra_nht_register(struct static_route *si, bool reg);
+extern void static_zebra_nht_register(struct route_node *rn,
+ struct static_route *si, bool reg);
extern void static_zebra_route_add(struct route_node *rn,
struct static_route *si_changed,