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)
struct static_route *cp;
struct static_route *update = NULL;
struct route_table *stable = svrf->stable[afi][safi];
+ struct interface *ifp;
if (!stable)
return -1;
si->tag = tag;
si->vrf_id = svrf->vrf->vrf_id;
si->nh_vrf_id = nh_svrf->vrf->vrf_id;
- strcpy(si->nh_vrfname, nh_svrf->vrf->name);
+ strlcpy(si->nh_vrfname, nh_svrf->vrf->name, sizeof(si->nh_vrfname));
si->table_id = table_id;
si->onlink = onlink;
si->next = cp;
/* check whether interface exists in system & install if it does */
- if (!ifname)
- static_install_route(rn, si, safi);
- else {
- struct interface *ifp;
+ switch (si->type) {
+ case STATIC_IPV4_GATEWAY:
+ case STATIC_IPV6_GATEWAY:
+ static_zebra_nht_register(rn, si, true);
+ break;
+ case STATIC_IPV4_GATEWAY_IFNAME:
+ case STATIC_IPV6_GATEWAY_IFNAME:
+ ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
+ if (ifp && ifp->ifindex != IFINDEX_INTERNAL)
+ si->ifindex = ifp->ifindex;
+ else
+ zlog_warn("Static Route using %s interface not installed because the interface does not exist in specified vrf",
+ ifname);
+ static_zebra_nht_register(rn, si, true);
+ break;
+ case STATIC_BLACKHOLE:
+ static_install_route(rn, si, safi);
+ break;
+ case STATIC_IFNAME:
ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id);
if (ifp && ifp->ifindex != IFINDEX_INTERNAL) {
si->ifindex = ifp->ifindex;
} else
zlog_warn("Static Route using %s interface not installed because the interface does not exist in specified vrf",
ifname);
+
+ break;
}
return 1;
return 0;
}
- static_zebra_nht_register(si, false);
+ static_zebra_nht_register(rn, si, false);
/* Unlink static route from linked list. */
if (si->prev)
continue;
si->nh_vrf_id = svrf->vrf->vrf_id;
+ si->nh_registered = false;
if (si->ifindex) {
ifp = if_lookup_by_name(si->ifname,
si->nh_vrf_id);
}
}
+/*
+ * This function enables static routes when an interface it relies
+ * on in a different vrf is coming up.
+ *
+ * stable -> The stable we are looking at.
+ * ifp -> interface coming up
+ * afi -> the afi in question
+ * safi -> the safi in question
+ */
+static void static_fixup_intf_nh(struct route_table *stable,
+ struct interface *ifp,
+ afi_t afi, safi_t safi)
+{
+ struct route_node *rn;
+ struct static_route *si;
+
+ for (rn = route_top(stable); rn; rn = route_next(rn)) {
+ for (si = rn->info; si; si = si->next) {
+ if (si->nh_vrf_id != ifp->vrf_id)
+ continue;
+
+ if (si->ifindex != ifp->ifindex)
+ continue;
+
+ static_install_route(rn, si, safi);
+ }
+ }
+}
+
+/*
+ * This function enables static routes that rely on an interface in
+ * a different vrf when that interface comes up.
+ */
+void static_install_intf_nh(struct interface *ifp)
+{
+ struct route_table *stable;
+ struct vrf *vrf;
+ afi_t afi;
+ safi_t safi;
+
+ RB_FOREACH(vrf, vrf_name_head, &vrfs_by_name) {
+ struct static_vrf *svrf = vrf->info;
+
+ /* Not needed if same vrf since happens naturally */
+ if (vrf->vrf_id == ifp->vrf_id)
+ continue;
+
+ /* Install any static routes configured for this interface. */
+ for (afi = AFI_IP; afi < AFI_MAX; afi++) {
+ for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
+ stable = svrf->stable[afi][safi];
+ if (!stable)
+ continue;
+
+ static_fixup_intf_nh(stable, ifp, afi, safi);
+ }
+ }
+ }
+}
+
/* called from if_{add,delete}_update, i.e. when ifindex becomes [in]valid */
void static_ifindex_update(struct interface *ifp, bool up)
{