summaryrefslogtreecommitdiff
path: root/staticd/static_nht.c
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2018-08-28 22:45:06 -0400
committerPhilippe Guibert <philippe.guibert@6wind.com>2018-08-31 11:29:27 +0200
commitf591b309f2c938de48e826c9e669fe88110dd9ed (patch)
tree9e59b33649210fb9d80cf4047eb3a6f77da9699f /staticd/static_nht.c
parent88d52a3f22963e6caa31cc0a7e0e9540b30713c2 (diff)
staticd: Fix mixup in vrf translations
When we store the nexthop for ref-counting, keep track of the nexthop vrf_id as well. This will allow us to track the nexthop per vrf! Additionally when we get the callback from zebra about a nexthop update, iterate over all static routes to see if the nexthop we are getting a callback is one we are concerned about. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'staticd/static_nht.c')
-rw-r--r--staticd/static_nht.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/staticd/static_nht.c b/staticd/static_nht.c
index c6e4587b6a..44f7fb79da 100644
--- a/staticd/static_nht.c
+++ b/staticd/static_nht.c
@@ -29,8 +29,8 @@
#include "static_zebra.h"
#include "static_nht.h"
-void static_nht_update(struct prefix *p, uint32_t nh_num,
- afi_t afi, vrf_id_t vrf_id)
+void static_nht_update(struct prefix *p, uint32_t nh_num, afi_t afi,
+ vrf_id_t nh_vrf_id)
{
struct route_table *stable;
struct static_route *si;
@@ -40,41 +40,47 @@ void static_nht_update(struct prefix *p, uint32_t nh_num,
bool orig;
bool reinstall;
- vrf = vrf_lookup_by_id(vrf_id);
+ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) {
+ svrf = vrf->info;
+ if (!svrf)
+ continue;
- if (!vrf || !vrf->info)
- return;
+ stable = static_vrf_static_table(afi, SAFI_UNICAST, svrf);
+ if (!stable)
+ continue;
- svrf = vrf->info;
- stable = static_vrf_static_table(afi, SAFI_UNICAST, svrf);
- if (!stable)
- return;
+ for (rn = route_top(stable); rn; rn = route_next(rn)) {
+ reinstall = false;
+ for (si = rn->info; si; si = si->next) {
+ if (si->nh_vrf_id != nh_vrf_id)
+ continue;
- for (rn = route_top(stable); rn; rn = route_next(rn)) {
- reinstall = false;
- for (si = rn->info; si; si = si->next) {
- 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 (si->type != STATIC_IPV4_GATEWAY
+ && si->type != STATIC_IPV4_GATEWAY_IFNAME
+ && si->type != STATIC_IPV6_GATEWAY
+ && si->type != STATIC_IPV6_GATEWAY_IFNAME)
+ continue;
- orig = si->nh_valid;
- if (p->family == AF_INET &&
- p->u.prefix4.s_addr == si->addr.ipv4.s_addr)
- si->nh_valid = !!nh_num;
+ orig = si->nh_valid;
+ 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;
+ if (p->family == AF_INET6
+ && memcmp(&p->u.prefix6, &si->addr.ipv6, 16)
+ == 0)
+ si->nh_valid = !!nh_num;
- if (orig != si->nh_valid)
- reinstall = true;
+ if (orig != si->nh_valid)
+ reinstall = true;
- if (reinstall) {
- static_zebra_route_add(rn, si, vrf_id,
- SAFI_UNICAST, true);
- reinstall = false;
+ if (reinstall) {
+ static_zebra_route_add(
+ rn, si, vrf->vrf_id,
+ SAFI_UNICAST, true);
+ reinstall = false;
+ }
}
}
}