From 718074ec2c14938a7ff29de8d1306cb856c670a1 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 11 Feb 2019 15:03:19 +0100 Subject: [PATCH 1/7] lib, bgpd, ospfd, pimd, zebra: change if_update_to_new_vrf() api vrf_id parameter is replaced with struct vrf * parameter. It is needed to create vrf structure before entering in the fuction. an error is generated in case the vrf parameter is missing. Signed-off-by: Philippe Guibert --- bgpd/bgp_zebra.c | 2 +- lib/if.c | 18 ++++++++++++------ lib/if.h | 2 +- ospfd/ospf_zebra.c | 2 +- pimd/pim_zebra.c | 2 +- zebra/if_netlink.c | 2 +- zebra/interface.c | 3 ++- 7 files changed, 19 insertions(+), 12 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 3f18d69a2d6a..f1534ca505c1 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -517,7 +517,7 @@ static int bgp_interface_vrf_update(int command, struct zclient *zclient, } } - if_update_to_new_vrf(ifp, new_vrf_id); + if_update_to_new_vrf(ifp, vrf_get(new_vrf_id, NULL)); bgp = bgp_lookup_by_vrf_id(new_vrf_id); if (!bgp) diff --git a/lib/if.c b/lib/if.c index 6b0019403c2f..b6af83b51482 100644 --- a/lib/if.c +++ b/lib/if.c @@ -160,11 +160,18 @@ struct interface *if_create(const char *name, struct vrf *vrf) return ifp; } -/* Create new interface structure. */ -void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id) +/* Create new interface structure. + * vrf must be created outside of this routing + */ +void if_update_to_new_vrf(struct interface *ifp, struct vrf *vrf) { - struct vrf *old_vrf, *vrf; + struct vrf *old_vrf; + if (!vrf) { + flog_err(EC_LIB_INTERFACE, "interface %s. Unknown VRF", + ifp->name); + return; + } /* remove interface from old master vrf list */ old_vrf = vrf_lookup_by_id(ifp->vrf_id); if (old_vrf) { @@ -173,8 +180,7 @@ void if_update_to_new_vrf(struct interface *ifp, vrf_id_t vrf_id) IFINDEX_RB_REMOVE(old_vrf, ifp); } - ifp->vrf_id = vrf_id; - vrf = vrf_get(ifp->vrf_id, NULL); + ifp->vrf_id = vrf->vrf_id; IFNAME_RB_INSERT(vrf, ifp); if (ifp->ifindex != IFINDEX_INTERNAL) @@ -409,7 +415,7 @@ struct interface *if_get_by_name(const char *name, struct vrf *vrf) /* If it came from the kernel or by way of zclient, * believe it and update the ifp accordingly. */ - if_update_to_new_vrf(ifp, vrf->vrf_id); + if_update_to_new_vrf(ifp, vrf); return ifp; } return if_create(name, vrf); diff --git a/lib/if.h b/lib/if.h index 822b7d1aea7e..af65db9e62c6 100644 --- a/lib/if.h +++ b/lib/if.h @@ -471,7 +471,7 @@ extern int if_cmp_name_func(const char *p1, const char *p2); * This is useful for vrf route-leaking. So more than anything * else think before you use VRF_UNKNOWN */ -extern void if_update_to_new_vrf(struct interface *, vrf_id_t vrf_id); +extern void if_update_to_new_vrf(struct interface *, struct vrf *vrf); extern struct interface *if_create(const char *name, struct vrf *vrf); extern struct interface *if_lookup_by_index(ifindex_t, vrf_id_t vrf_id); extern struct interface *if_lookup_exact_address(void *matchaddr, int family, diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index ea2c492e183e..fb5e8447946e 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -374,7 +374,7 @@ static int ospf_interface_vrf_update(int command, struct zclient *zclient, ospf_vrf_id_to_name(new_vrf_id), new_vrf_id); /*if_update(ifp, ifp->name, strlen(ifp->name), new_vrf_id);*/ - if_update_to_new_vrf(ifp, new_vrf_id); + if_update_to_new_vrf(ifp, vrf_get(new_vrf_id, NULL)); return 0; } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index 11ca6e8a1080..cef78bad8d2f 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -283,7 +283,7 @@ static int pim_zebra_interface_vrf_update(int command, struct zclient *zclient, __PRETTY_FUNCTION__, ifp->name, vrf_id, new_vrf_id); - if_update_to_new_vrf(ifp, new_vrf_id); + if_update_to_new_vrf(ifp, vrf_get(new_vrf_id, NULL)); return 0; } diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 1bed2bea7b67..0a65c3c519c0 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -1242,7 +1242,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) } else { /* pre-configured interface, learnt now */ if (ifp->vrf_id != vrf_id) - if_update_to_new_vrf(ifp, vrf_id); + if_update_to_new_vrf(ifp, vrf); } /* Update interface information. */ diff --git a/zebra/interface.c b/zebra/interface.c index c88aadc68378..1ffe8af6ac50 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -759,6 +759,7 @@ void if_delete_update(struct interface *ifp) void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id) { vrf_id_t old_vrf_id; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); old_vrf_id = ifp->vrf_id; @@ -776,7 +777,7 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id) zebra_interface_vrf_update_del(ifp, vrf_id); /* update VRF */ - if_update_to_new_vrf(ifp, vrf_id); + if_update_to_new_vrf(ifp, vrf); /* Send out notification on interface VRF change. */ /* This is to issue an ADD, if needed. */ From 44f0a3e89e20e2a01d495f86fea6c43d34a9ded9 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 11 Feb 2019 15:46:48 +0100 Subject: [PATCH 2/7] *: change if_lookup_by_name() api with vrf the vrf_id parameter is replaced by struct vrf * parameter. this impacts most of the daemons that look for an interface based on the name and the vrf identifier. Signed-off-by: Philippe Guibert --- babeld/babel_interface.c | 10 ++++++---- babeld/babeld.c | 2 +- bfdd/bfd.c | 2 +- bfdd/bfd_packet.c | 4 ++-- bgpd/bgp_network.c | 6 ++++-- bgpd/bgp_zebra.c | 12 +++++++----- bgpd/bgpd.c | 3 ++- eigrpd/eigrp_filter.c | 3 ++- eigrpd/eigrp_routemap.c | 2 +- eigrpd/eigrp_zebra.c | 3 ++- isisd/isis_northbound.c | 4 ++-- isisd/isis_te.c | 2 +- lib/if.c | 21 ++++++++++----------- lib/if.h | 2 +- lib/vrf.h | 2 +- lib/zclient.c | 9 ++++++--- nhrpd/nhrp_interface.c | 3 ++- ospf6d/ospf6_asbr.c | 3 ++- ospf6d/ospf6_interface.c | 11 +++++++---- ospf6d/ospf6_top.c | 3 ++- ospfd/ospf_te.c | 2 +- ospfd/ospf_vty.c | 18 ++++++++++++------ ospfd/ospf_zebra.c | 3 ++- pimd/pim_cmd.c | 12 ++++++++---- pimd/pim_iface.c | 6 ++++-- pimd/pim_msdp_socket.c | 6 ++++-- pimd/pim_zebra.c | 2 +- ripd/rip_routemap.c | 3 ++- ripd/ripd.c | 6 ++++-- ripngd/ripng_routemap.c | 3 ++- ripngd/ripngd.c | 6 ++++-- sharpd/sharp_zebra.c | 3 ++- staticd/static_routes.c | 9 ++++++--- staticd/static_zebra.c | 3 ++- zebra/if_ioctl.c | 3 ++- zebra/interface.c | 5 +++-- zebra/zapi_msg.c | 6 ++---- 37 files changed, 123 insertions(+), 80 deletions(-) diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c index 79242f5b85c5..fd48417fdb91 100644 --- a/babeld/babel_interface.c +++ b/babeld/babel_interface.c @@ -243,7 +243,7 @@ babel_enable_if_add (const char *ifname) vector_set (babel_enable_if, strdup (ifname)); - ifp = if_lookup_by_name(ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(ifname, vrf_lookup_by_id(VRF_DEFAULT)); if (ifp != NULL) interface_recalculate(ifp); @@ -266,7 +266,7 @@ babel_enable_if_delete (const char *ifname) free (str); vector_unset (babel_enable_if, babel_enable_if_index); - ifp = if_lookup_by_name(ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(ifname, vrf_lookup_by_id(VRF_DEFAULT)); if (ifp != NULL) interface_reset(ifp); @@ -909,7 +909,8 @@ DEFUN (show_babel_interface, show_babel_interface_sub (vty, ifp); return CMD_SUCCESS; } - if ((ifp = if_lookup_by_name (argv[3]->arg, VRF_DEFAULT)) == NULL) + if ((ifp = if_lookup_by_name (argv[3]->arg, + vrf_lookup_by_id(VRF_DEFAULT))) == NULL) { vty_out (vty, "No such interface name\n"); return CMD_WARNING; @@ -951,7 +952,8 @@ DEFUN (show_babel_neighbour, } return CMD_SUCCESS; } - if ((ifp = if_lookup_by_name (argv[3]->arg, VRF_DEFAULT)) == NULL) + if ((ifp = if_lookup_by_name (argv[3]->arg, + vrf_lookup_by_id(VRF_DEFAULT))) == NULL) { vty_out (vty, "No such interface name\n"); return CMD_WARNING; diff --git a/babeld/babeld.c b/babeld/babeld.c index 39451b435a44..298903f50fff 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -555,7 +555,7 @@ babel_distribute_update (struct distribute_ctx *ctx, struct distribute *dist) if (! dist->ifname) return; - ifp = if_lookup_by_name (dist->ifname, VRF_DEFAULT); + ifp = if_lookup_by_name (dist->ifname, vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; diff --git a/bfdd/bfd.c b/bfdd/bfd.c index df263a91c97a..cc532e835e78 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -563,7 +563,7 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc) * our limits). */ if (bpc->bpc_has_localif) { - ifp = if_lookup_by_name(bpc->bpc_localif, VRF_DEFAULT); + ifp = if_lookup_by_name(bpc->bpc_localif, vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { log_error( "session-new: specified interface doesn't exists."); diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index 9cfd7e866f84..09e0fbb2629a 100644 --- a/bfdd/bfd_packet.c +++ b/bfdd/bfd_packet.c @@ -633,7 +633,7 @@ int bfd_recv_cb(struct thread *t) * packet came in. */ if (bfd->ifp == NULL) - bfd->ifp = if_lookup_by_name(port, VRF_DEFAULT); + bfd->ifp = if_lookup_by_name(port, vrf_lookup_by_id(VRF_DEFAULT)); /* Log remote discriminator changes. */ if ((bfd->discrs.remote_discr != 0) @@ -1100,7 +1100,7 @@ int bp_peer_socketv6(struct bfd_peer_cfg *bpc) #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ sin6 = bpc->bpc_local.sa_sin6; if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) { - ifp = if_lookup_by_name(bpc->bpc_localif, VRF_DEFAULT); + ifp = if_lookup_by_name(bpc->bpc_localif, vrf_lookup_by_id(VRF_DEFAULT)); sin6.sin6_scope_id = (ifp != NULL) ? ifp->ifindex : IFINDEX_INTERNAL; } diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 4153da5a6441..7d135f7e6ad9 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -252,7 +252,8 @@ static int bgp_get_instance_for_inc_conn(int sock, struct bgp **bgp_inst) if (bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) continue; - ifp = if_lookup_by_name(name, bgp->vrf_id); + ifp = if_lookup_by_name(name, + vrf_lookup_by_id(bgp->vrf_id)); if (ifp) { *bgp_inst = bgp; return 0; @@ -512,7 +513,8 @@ static int bgp_update_source(struct peer *peer) /* Source is specified with interface name. */ if (peer->update_if) { - ifp = if_lookup_by_name(peer->update_if, peer->bgp->vrf_id); + ifp = if_lookup_by_name(peer->update_if, + vrf_lookup_by_id(peer->bgp->vrf_id)); if (!ifp) return -1; diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index f1534ca505c1..7673d40d5e67 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -802,7 +802,7 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote, nexthop->v4 = local->sin.sin_addr; if (peer->update_if) ifp = if_lookup_by_name(peer->update_if, - peer->bgp->vrf_id); + vrf_lookup_by_id(peer->bgp->vrf_id)); else ifp = if_lookup_by_ipv4_exact(&local->sin.sin_addr, peer->bgp->vrf_id); @@ -813,10 +813,10 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote, ifp = if_lookup_by_name(peer->conf_if ? peer->conf_if : peer->ifname, - peer->bgp->vrf_id); + vrf_lookup_by_id(peer->bgp->vrf_id)); } else if (peer->update_if) ifp = if_lookup_by_name(peer->update_if, - peer->bgp->vrf_id); + vrf_lookup_by_id(peer->bgp->vrf_id)); else ifp = if_lookup_by_ipv6_exact(&local->sin6.sin6_addr, local->sin6.sin6_scope_id, @@ -2863,7 +2863,8 @@ static void bgp_encode_pbr_interface_list(struct bgp *bgp, struct stream *s) head = &(bgp_pbr_cfg->ifaces_by_name_ipv4); RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) { - ifp = if_lookup_by_name(pbr_if->name, bgp->vrf_id); + ifp = if_lookup_by_name(pbr_if->name, + vrf_lookup_by_id(bgp->vrf_id)); if (ifp) stream_putl(s, ifp->ifindex); } @@ -2881,7 +2882,8 @@ static int bgp_pbr_get_ifnumber(struct bgp *bgp) head = &(bgp_pbr_cfg->ifaces_by_name_ipv4); RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) { - if (if_lookup_by_name(pbr_if->name, bgp->vrf_id)) + if (if_lookup_by_name(pbr_if->name, + vrf_lookup_by_id(bgp->vrf_id))) cnt++; } return cnt; diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index aceb990534c1..888a44b238fc 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1435,7 +1435,8 @@ void bgp_peer_conf_if_to_su_update(struct peer *peer) hash_release(peer->bgp->peerhash, peer); prev_family = peer->su.sa.sa_family; - if ((ifp = if_lookup_by_name(peer->conf_if, peer->bgp->vrf_id))) { + if ((ifp = if_lookup_by_name(peer->conf_if, + vrf_lookup_by_id(peer->bgp->vrf_id)))) { peer->ifp = ifp; /* If BGP unnumbered is not "v6only", we first see if we can * derive the diff --git a/eigrpd/eigrp_filter.c b/eigrpd/eigrp_filter.c index 93eed9452ccb..7727fd96c8ab 100644 --- a/eigrpd/eigrp_filter.c +++ b/eigrpd/eigrp_filter.c @@ -174,7 +174,8 @@ void eigrp_distribute_update(struct distribute_ctx *ctx, return; } - ifp = if_lookup_by_name(dist->ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(dist->ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; diff --git a/eigrpd/eigrp_routemap.c b/eigrpd/eigrp_routemap.c index ee8d5f758270..85f524ff248d 100644 --- a/eigrpd/eigrp_routemap.c +++ b/eigrpd/eigrp_routemap.c @@ -62,7 +62,7 @@ void eigrp_if_rmap_update(struct if_rmap *if_rmap) struct route_map *rmap; struct eigrp *e; - ifp = if_lookup_by_name(if_rmap->ifname); + ifp = if_lookup_by_name(if_rmap->ifname, vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; diff --git a/eigrpd/eigrp_zebra.c b/eigrpd/eigrp_zebra.c index 09d876afaa2c..347f1bbf5bc2 100644 --- a/eigrpd/eigrp_zebra.c +++ b/eigrpd/eigrp_zebra.c @@ -350,7 +350,8 @@ static struct interface *zebra_interface_if_lookup(struct stream *s) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* And look it up. */ - return if_lookup_by_name(ifname_tmp, VRF_DEFAULT); + return if_lookup_by_name(ifname_tmp, + vrf_lookup_by_id(VRF_DEFAULT)); } void eigrp_zebra_route_add(struct prefix *p, struct list *successors, diff --git a/isisd/isis_northbound.c b/isisd/isis_northbound.c index 9c2bb1728ed1..df91541e7426 100644 --- a/isisd/isis_northbound.c +++ b/isisd/isis_northbound.c @@ -1604,7 +1604,7 @@ static int lib_interface_isis_area_tag_modify(enum nb_event event, vrfname = yang_dnode_get_string(dnode->parent->parent, "./vrf"); vrf = vrf_lookup_by_name(vrfname); assert(vrf); - ifp = if_lookup_by_name(ifname, vrf->vrf_id); + ifp = if_lookup_by_name(ifname, vrf); if (!ifp) return NB_OK; circuit = circuit_lookup_by_ifp(ifp, isis->init_circ_list); @@ -1642,7 +1642,7 @@ static int lib_interface_isis_circuit_type_modify(enum nb_event event, vrfname = yang_dnode_get_string(dnode->parent->parent, "./vrf"); vrf = vrf_lookup_by_name(vrfname); assert(vrf); - ifp = if_lookup_by_name(ifname, vrf->vrf_id); + ifp = if_lookup_by_name(ifname, vrf); if (!ifp) break; circuit = circuit_lookup_by_ifp(ifp, isis->init_circ_list); diff --git a/isisd/isis_te.c b/isisd/isis_te.c index 23a1f10a18ad..5103e50092a2 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -1199,7 +1199,7 @@ DEFUN (show_isis_mpls_te_interface, /* Interface name is specified. */ else { if ((ifp = if_lookup_by_name(argv[idx_interface]->arg, - VRF_DEFAULT)) + vrf_lookup_by_id(VRF_DEFAULT))) == NULL) vty_out(vty, "No such interface name\n"); else diff --git a/lib/if.c b/lib/if.c index b6af83b51482..2d0f5a6e7e1c 100644 --- a/lib/if.c +++ b/lib/if.c @@ -271,16 +271,16 @@ const char *ifindex2ifname(ifindex_t ifindex, vrf_id_t vrf_id) ifindex_t ifname2ifindex(const char *name, vrf_id_t vrf_id) { struct interface *ifp; + struct vrf *vrf = vrf_lookup_by_id(vrf_id); - return ((ifp = if_lookup_by_name(name, vrf_id)) != NULL) + return ((ifp = if_lookup_by_name(name, vrf)) != NULL) ? ifp->ifindex : IFINDEX_INTERNAL; } /* Interface existance check by interface name. */ -struct interface *if_lookup_by_name(const char *name, vrf_id_t vrf_id) +struct interface *if_lookup_by_name(const char *name, struct vrf *vrf) { - struct vrf *vrf = vrf_lookup_by_id(vrf_id); struct interface if_tmp; if (!vrf || !name @@ -300,7 +300,7 @@ struct interface *if_lookup_by_name_all_vrf(const char *name) return NULL; RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) { - ifp = if_lookup_by_name(name, vrf->vrf_id); + ifp = if_lookup_by_name(name, vrf); if (ifp) return ifp; } @@ -403,7 +403,7 @@ struct interface *if_get_by_name(const char *name, struct vrf *vrf) switch (vrf_get_backend()) { case VRF_BACKEND_NETNS: - ifp = if_lookup_by_name(name, vrf->vrf_id); + ifp = if_lookup_by_name(name, vrf); if (ifp) return ifp; return if_create(name, vrf); @@ -613,7 +613,7 @@ static struct interface *if_sunwzebra_get(const char *name, struct vrf *vrf) struct interface *ifp; char *cp; - if ((ifp = if_lookup_by_name(name, vrf->vrf_id)) != NULL) + if ((ifp = if_lookup_by_name(name, vrf)) != NULL) return ifp; /* hunt the primary interface name... */ @@ -1094,6 +1094,7 @@ DEFPY_NOSH (interface, vrf_id_t vrf_id; struct interface *ifp; int ret; + struct vrf *vrf; if (!vrfname) vrfname = VRF_DEFAULT_NAME; @@ -1108,8 +1109,6 @@ DEFPY_NOSH (interface, VRF_GET_ID(vrf_id, vrfname, false); ifp = if_lookup_by_name_all_vrf(ifname); if (ifp && ifp->vrf_id != vrf_id) { - struct vrf *vrf; - /* * Special case 1: a VRF name was specified, but the found * interface is associated to different VRF. Reject the command. @@ -1127,9 +1126,9 @@ DEFPY_NOSH (interface, */ vrf = vrf_lookup_by_id(ifp->vrf_id); assert(vrf); - vrf_id = ifp->vrf_id; vrfname = vrf->name; - } + } else + vrf = vrf_lookup_by_id(vrf_id); snprintf(xpath_list, sizeof(xpath_list), "/frr-interface:lib/interface[name='%s'][vrf='%s']", ifname, @@ -1146,7 +1145,7 @@ DEFPY_NOSH (interface, * all interface-level commands are converted to the new * northbound model. */ - ifp = if_lookup_by_name(ifname, vrf_id); + ifp = if_lookup_by_name(ifname, vrf); if (ifp) VTY_PUSH_CONTEXT(INTERFACE_NODE, ifp); } diff --git a/lib/if.h b/lib/if.h index af65db9e62c6..23140e24e179 100644 --- a/lib/if.h +++ b/lib/if.h @@ -484,7 +484,7 @@ extern struct interface *if_lookup_prefix(struct prefix *prefix, /* These 3 functions are to be used when the ifname argument is terminated by a '\0' character: */ extern struct interface *if_lookup_by_name_all_vrf(const char *ifname); -extern struct interface *if_lookup_by_name(const char *ifname, vrf_id_t vrf_id); +extern struct interface *if_lookup_by_name(const char *ifname, struct vrf *vrf); extern struct interface *if_get_by_name(const char *ifname, struct vrf *vrf); extern void if_set_index(struct interface *ifp, ifindex_t ifindex); diff --git a/lib/vrf.h b/lib/vrf.h index e80796f48096..eba262a38fe2 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -109,7 +109,7 @@ extern struct vrf *vrf_get(vrf_id_t, const char *); extern const char *vrf_id_to_name(vrf_id_t vrf_id); extern vrf_id_t vrf_name_to_id(const char *); -#define VRF_GET_ID(V, NAME, USE_JSON) \ +#define VRF_GET_ID(V, NAME, USE_JSON) \ do { \ struct vrf *_vrf; \ if (!(_vrf = vrf_lookup_by_name(NAME))) { \ diff --git a/lib/zclient.c b/lib/zclient.c index ff6cf9e9e9b8..d076f1622ea5 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1464,7 +1464,8 @@ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* Lookup this by interface index. */ - ifp = if_lookup_by_name(ifname_tmp, vrf_id); + ifp = if_lookup_by_name(ifname_tmp, + vrf_lookup_by_id(vrf_id)); if (ifp == NULL) { flog_err(EC_LIB_ZAPI_ENCODE, "INTERFACE_STATE: Cannot find IF %s in VRF %d", @@ -1524,7 +1525,8 @@ struct interface *zebra_interface_link_params_read(struct stream *s, ifindex = stream_getl(s); - struct interface *ifp = if_lookup_by_index(ifindex, vrf_id); + struct interface *ifp = if_lookup_by_index(ifindex, + vrf_id); if (ifp == NULL) { flog_err(EC_LIB_ZAPI_ENCODE, @@ -1819,7 +1821,8 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s, stream_get(ifname, s, INTERFACE_NAMSIZ); /* Lookup interface. */ - ifp = if_lookup_by_name(ifname, vrf_id); + ifp = if_lookup_by_name(ifname, + vrf_lookup_by_id(vrf_id)); if (ifp == NULL) { flog_err(EC_LIB_ZAPI_ENCODE, "INTERFACE_VRF_UPDATE: Cannot find IF %s in VRF %d", diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index ccca100db579..52f887850141 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -126,7 +126,8 @@ static void nhrp_interface_update_nbma(struct interface *ifp) sockunion_family(&nbma) = AF_UNSPEC; if (nifp->source) - nbmaifp = if_lookup_by_name(nifp->source, VRF_DEFAULT); + nbmaifp = if_lookup_by_name(nifp->source, + vrf_lookup_by_id(VRF_DEFAULT)); switch (ifp->ll_type) { case ZEBRA_LLT_IPGRE: { diff --git a/ospf6d/ospf6_asbr.c b/ospf6d/ospf6_asbr.c index 3153c29aa18a..b1085ebc8a16 100644 --- a/ospf6d/ospf6_asbr.c +++ b/ospf6d/ospf6_asbr.c @@ -1404,7 +1404,8 @@ ospf6_routemap_rule_match_interface(void *rule, const struct prefix *prefix, if (type == RMAP_OSPF6) { ei = ((struct ospf6_route *)object)->route_option; - ifp = if_lookup_by_name((char *)rule, VRF_DEFAULT); + ifp = if_lookup_by_name((char *)rule, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp != NULL && ei->ifindex == ifp->ifindex) return RMAP_MATCH; diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index dd08144daaf3..742aadbad4df 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -994,7 +994,8 @@ DEFUN (show_ipv6_ospf6_interface, struct interface *ifp; if (argc == 5) { - ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { vty_out(vty, "No such Interface: %s\n", argv[idx_ifname]->arg); @@ -1079,7 +1080,8 @@ DEFUN (show_ipv6_ospf6_interface_traffic, if (argv_find(argv, argc, "IFNAME", &idx_ifname)) { intf_name = argv[idx_ifname]->arg; - ifp = if_lookup_by_name(intf_name, VRF_DEFAULT); + ifp = if_lookup_by_name(intf_name, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { vty_out(vty, "No such Interface: %s\n", intf_name); return CMD_WARNING; @@ -1123,7 +1125,8 @@ DEFUN (show_ipv6_ospf6_interface_ifname_prefix, struct interface *ifp; struct ospf6_interface *oi; - ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { vty_out(vty, "No such Interface: %s\n", argv[idx_ifname]->arg); return CMD_WARNING; @@ -2024,7 +2027,7 @@ DEFUN (clear_ipv6_ospf6_interface, } else /* Interface name is specified. */ { if ((ifp = if_lookup_by_name(argv[idx_ifname]->arg, - VRF_DEFAULT)) + vrf_lookup_by_id(VRF_DEFAULT))) == NULL) { vty_out(vty, "No such Interface: %s\n", argv[idx_ifname]->arg); diff --git a/ospf6d/ospf6_top.c b/ospf6d/ospf6_top.c index 5cd657259b3f..bbc9247b0762 100644 --- a/ospf6d/ospf6_top.c +++ b/ospf6d/ospf6_top.c @@ -715,7 +715,8 @@ DEFUN (no_ospf6_interface_area, struct interface *ifp; uint32_t area_id; - ifp = if_lookup_by_name(argv[idx_ifname]->arg, VRF_DEFAULT); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { vty_out(vty, "No such interface %s\n", argv[idx_ifname]->arg); return CMD_SUCCESS; diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index bd8cbee11ab2..a2b4dbde2fc8 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -2568,7 +2568,7 @@ DEFUN (show_ip_ospf_mpls_te_link, if (idx_interface) { ifp = if_lookup_by_name( argv[idx_interface]->arg, - ospf->vrf_id); + vrf_lookup_by_id(ospf->vrf_id)); if (ifp == NULL) { vty_out(vty, "No such interface name in vrf %s\n", vrf->name); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 097b706a91e1..4e490458ace9 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -3742,7 +3742,8 @@ static int show_ip_ospf_interface_common(struct vty *vty, struct ospf *ospf, json_interface); } else { /* Interface name is specified. */ - ifp = if_lookup_by_name(intf_name, ospf->vrf_id); + ifp = if_lookup_by_name(intf_name, + vrf_lookup_by_id(ospf->vrf_id)); if (ifp == NULL) { if (use_json) json_object_boolean_true_add(json_vrf, @@ -3882,7 +3883,8 @@ static int show_ip_ospf_interface_traffic_common( } } else { /* Interface name is specified. */ - ifp = if_lookup_by_name(intf_name, ospf->vrf_id); + ifp = if_lookup_by_name(intf_name, + vrf_lookup_by_id(ospf->vrf_id)); if (ifp != NULL) { struct route_node *rn; struct ospf_interface *oi; @@ -4692,7 +4694,8 @@ static int show_ip_ospf_neighbor_int_common(struct vty *vty, struct ospf *ospf, ospf_show_vrf_name(ospf, vty, json, use_vrf); - ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); + ifp = if_lookup_by_name(argv[arg_base]->arg, + vrf_lookup_by_id(ospf->vrf_id)); if (!ifp) { if (use_json) json_object_boolean_true_add(json, "noSuchIface"); @@ -4760,7 +4763,8 @@ DEFUN (show_ip_ospf_neighbor_int, argv_find(argv, argc, "IFNAME", &idx_ifname); - ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + vrf_lookup_by_id(vrf_id)); if (!ifp) return ret; @@ -5577,7 +5581,8 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, vty_out(vty, "\nOSPF Instance: %d\n\n", ospf->instance); } - ifp = if_lookup_by_name(argv[arg_base]->arg, ospf->vrf_id); + ifp = if_lookup_by_name(argv[arg_base]->arg, + vrf_lookup_by_id(ospf->vrf_id)); if (!ifp) { if (!use_json) vty_out(vty, "No such interface.\n"); @@ -10687,7 +10692,8 @@ DEFUN (clear_ip_ospf_interface, } } else { /* Interface name is specified. */ - ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + vrf_lookup_by_id(vrf_id)); if (ifp == NULL) vty_out(vty, "No such interface name\n"); else diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index fb5e8447946e..d9bc980a95e2 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -178,7 +178,8 @@ static struct interface *zebra_interface_if_lookup(struct stream *s, stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* And look it up. */ - return if_lookup_by_name(ifname_tmp, vrf_id); + return if_lookup_by_name(ifname_tmp, + vrf_lookup_by_id(vrf_id)); } static int ospf_interface_state_up(int command, struct zclient *zclient, diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index d2d2445a1553..6f9fcfc86bdd 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -6630,7 +6630,8 @@ DEFUN (interface_ip_mroute, pim = pim_ifp->pim; oifname = argv[idx_interface]->arg; - oif = if_lookup_by_name(oifname, pim->vrf_id); + oif = if_lookup_by_name(oifname, + vrf_lookup_by_id(pim->vrf_id)); if (!oif) { vty_out(vty, "No such interface name %s\n", oifname); return CMD_WARNING; @@ -6681,7 +6682,8 @@ DEFUN (interface_ip_mroute_source, pim = pim_ifp->pim; oifname = argv[idx_interface]->arg; - oif = if_lookup_by_name(oifname, pim->vrf_id); + oif = if_lookup_by_name(oifname, + vrf_lookup_by_id(pim->vrf_id)); if (!oif) { vty_out(vty, "No such interface name %s\n", oifname); return CMD_WARNING; @@ -6736,7 +6738,8 @@ DEFUN (interface_no_ip_mroute, pim = pim_ifp->pim; oifname = argv[idx_interface]->arg; - oif = if_lookup_by_name(oifname, pim->vrf_id); + oif = if_lookup_by_name(oifname, + vrf_lookup_by_id(pim->vrf_id)); if (!oif) { vty_out(vty, "No such interface name %s\n", oifname); return CMD_WARNING; @@ -6788,7 +6791,8 @@ DEFUN (interface_no_ip_mroute_source, pim = pim_ifp->pim; oifname = argv[idx_interface]->arg; - oif = if_lookup_by_name(oifname, pim->vrf_id); + oif = if_lookup_by_name(oifname, + vrf_lookup_by_id(pim->vrf_id)); if (!oif) { vty_out(vty, "No such interface name %s\n", oifname); return CMD_WARNING; diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 6b962132404b..a79a10e0973c 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -889,9 +889,11 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) struct interface *lo_ifp; // DBS - Come back and check here if (ifp->vrf_id == VRF_DEFAULT) - lo_ifp = if_lookup_by_name("lo", vrf->vrf_id); + lo_ifp = if_lookup_by_name("lo", + vrf_lookup_by_id(vrf->vrf_id)); else - lo_ifp = if_lookup_by_name(vrf->name, vrf->vrf_id); + lo_ifp = if_lookup_by_name(vrf->name, + vrf_lookup_by_id(vrf->vrf_id)); if (lo_ifp) return pim_find_primary_addr(lo_ifp); diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index b1f7cfd2c66b..243280a9df7a 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -158,7 +158,8 @@ int pim_msdp_sock_listen(struct pim_instance *pim) if (pim->vrf_id != VRF_DEFAULT) { struct interface *ifp = - if_lookup_by_name(pim->vrf->name, pim->vrf_id); + if_lookup_by_name(pim->vrf->name, + vrf_lookup_by_id(pim->vrf_id)); if (!ifp) { flog_err(EC_LIB_INTERFACE, "%s: Unable to lookup vrf interface: %s", @@ -239,7 +240,8 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) if (mp->pim->vrf_id != VRF_DEFAULT) { struct interface *ifp = - if_lookup_by_name(mp->pim->vrf->name, mp->pim->vrf_id); + if_lookup_by_name(mp->pim->vrf->name, + vrf_lookup_by_id(mp->pim->vrf_id)); if (!ifp) { flog_err(EC_LIB_INTERFACE, "%s: Unable to lookup vrf interface: %s", diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index cef78bad8d2f..d827e23dbf95 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -206,7 +206,7 @@ static int pim_zebra_if_state_up(int command, struct zclient *zclient, if ((table_id == vrf->data.l.table_id) && (ifp->vrf_id != vrf->vrf_id)) { struct interface *master = if_lookup_by_name( - vrf->name, vrf->vrf_id); + vrf->name, vrf); if (!master) { zlog_debug( diff --git a/ripd/rip_routemap.c b/ripd/rip_routemap.c index 3216b8f89fda..3f8b9cb76bad 100644 --- a/ripd/rip_routemap.c +++ b/ripd/rip_routemap.c @@ -106,7 +106,8 @@ static route_map_result_t route_match_interface(void *rule, if (type == RMAP_RIP) { ifname = rule; - ifp = if_lookup_by_name(ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (!ifp) return RMAP_NOMATCH; diff --git a/ripd/ripd.c b/ripd/ripd.c index 38b4aed5bceb..4af76a3b7a3c 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -3248,7 +3248,8 @@ static void rip_distribute_update(struct distribute_ctx *ctx, if (!dist->ifname) return; - ifp = if_lookup_by_name(dist->ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(dist->ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; @@ -3399,7 +3400,8 @@ static void rip_if_rmap_update(struct if_rmap *if_rmap) struct rip_interface *ri; struct route_map *rmap; - ifp = if_lookup_by_name(if_rmap->ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(if_rmap->ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; diff --git a/ripngd/ripng_routemap.c b/ripngd/ripng_routemap.c index 0604e272cdfd..874d815167c8 100644 --- a/ripngd/ripng_routemap.c +++ b/ripngd/ripng_routemap.c @@ -97,7 +97,8 @@ static route_map_result_t route_match_interface(void *rule, if (type == RMAP_RIPNG) { ifname = rule; - ifp = if_lookup_by_name(ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (!ifp) return RMAP_NOMATCH; diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 70655beff1e1..1c2abf3da2dd 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -2327,7 +2327,8 @@ static void ripng_distribute_update(struct distribute_ctx *ctx, if (!dist->ifname) return; - ifp = if_lookup_by_name(dist->ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(dist->ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; @@ -2482,7 +2483,8 @@ static void ripng_if_rmap_update(struct if_rmap *if_rmap) struct ripng_interface *ri; struct route_map *rmap; - ifp = if_lookup_by_name(if_rmap->ifname, VRF_DEFAULT); + ifp = if_lookup_by_name(if_rmap->ifname, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) return; diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 30e616a05775..089e63fc0022 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -54,7 +54,8 @@ static struct interface *zebra_interface_if_lookup(struct stream *s) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* And look it up. */ - return if_lookup_by_name(ifname_tmp, VRF_DEFAULT); + return if_lookup_by_name(ifname_tmp, + vrf_lookup_by_id(VRF_DEFAULT)); } /* Inteface addition message from zebra. */ diff --git a/staticd/static_routes.c b/staticd/static_routes.c index a5f0f74b003e..babccdd4f1d8 100644 --- a/staticd/static_routes.c +++ b/staticd/static_routes.c @@ -187,7 +187,8 @@ int static_add_route(afi_t afi, safi_t safi, uint8_t type, struct prefix *p, else { struct interface *ifp; - ifp = if_lookup_by_name(ifname, nh_svrf->vrf->vrf_id); + ifp = if_lookup_by_name(ifname, + vrf_lookup_by_id(nh_svrf->vrf->vrf_id)); if (ifp && ifp->ifindex != IFINDEX_INTERNAL) { si->ifindex = ifp->ifindex; static_install_route(rn, si, safi); @@ -331,7 +332,8 @@ static void static_fixup_vrf(struct static_vrf *svrf, si->nh_vrf_id = svrf->vrf->vrf_id; if (si->ifindex) { ifp = if_lookup_by_name(si->ifname, - si->nh_vrf_id); + vrf_lookup_by_id( + si->nh_vrf_id)); if (ifp) si->ifindex = ifp->ifindex; else @@ -366,7 +368,8 @@ static void static_enable_vrf(struct static_vrf *svrf, si->vrf_id = vrf->vrf_id; if (si->ifindex) { ifp = if_lookup_by_name(si->ifname, - si->nh_vrf_id); + vrf_lookup_by_id( + si->nh_vrf_id)); if (ifp) si->ifindex = ifp->ifindex; else diff --git a/staticd/static_zebra.c b/staticd/static_zebra.c index 3f3117752439..c152d18f3b3e 100644 --- a/staticd/static_zebra.c +++ b/staticd/static_zebra.c @@ -55,7 +55,8 @@ static struct interface *zebra_interface_if_lookup(struct stream *s) stream_get(ifname_tmp, s, INTERFACE_NAMSIZ); /* And look it up. */ - return if_lookup_by_name(ifname_tmp, VRF_DEFAULT); + return if_lookup_by_name(ifname_tmp, + vrf_lookup_by_id(VRF_DEFAULT)); } /* Inteface addition message from zebra. */ diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 6c841fff71fa..274096aab659 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -196,7 +196,8 @@ static int if_getaddrs(void) continue; } - ifp = if_lookup_by_name(ifap->ifa_name, VRF_DEFAULT); + ifp = if_lookup_by_name(ifap->ifa_name, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { flog_err(EC_LIB_INTERFACE, "if_getaddrs(): Can't lookup interface %s\n", diff --git a/zebra/interface.c b/zebra/interface.c index 1ffe8af6ac50..1718b0e6306f 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -1632,7 +1632,8 @@ DEFUN (show_interface_name_vrf, VRF_GET_ID(vrf_id, argv[idx_name]->arg, false); /* Specified interface print. */ - ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf_id); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, + vrf_lookup_by_id(vrf_id)); if (ifp == NULL) { vty_out(vty, "%% Can't find interface %s\n", argv[idx_ifname]->arg); @@ -1662,7 +1663,7 @@ DEFUN (show_interface_name_vrf_all, /* All interface print. */ RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { /* Specified interface print. */ - ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf->vrf_id); + ifp = if_lookup_by_name(argv[idx_ifname]->arg, vrf); if (ifp) { if_dump_vty(vty, ifp); found++; diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 9b91289decb2..d862627b5f75 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2177,10 +2177,8 @@ static void zread_vrf_label(ZAPI_HANDLER_ARGS) STREAM_GETC(s, ltype); - if (zvrf->vrf->vrf_id != VRF_DEFAULT) - ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf->vrf_id); - else - ifp = if_lookup_by_name("lo", VRF_DEFAULT); + ifp = if_lookup_by_name(zvrf->vrf->name, + vrf_lookup_by_id(zvrf->vrf->vrf_id)); if (!ifp) { zlog_debug("Unable to find specified Interface for %s", From 54f7d837d8ffb712793b1c6289f95b61216cb0ea Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 11 Feb 2019 16:05:39 +0100 Subject: [PATCH 3/7] lib: create vrf upon interface cmd access change of behaviour: upon accessing interface cmd node, the vrf and the interface is being created. this is a change of behaviour in regards to how frr behaved before; but if we look finer, we can see that the changes are not so big: - first, the vrf will be created, only for unknown instances. that means that if the user does not type the vrf parameter, then the special case 2 will be handled as before - second, only when unknown vrf instances are present, that is to say at startup when zebra is not synced with the daemon, then the interface is created. that means that here too, the special case 2 will not be affected. A special macro has been created instead of VRF_GET_ID, that is called VRF_GET_INSTANCE, that is supposed to be used whenever needed. Signed-off-by: Philippe Guibert --- lib/if.c | 21 ++++++++++++++------- lib/vrf.h | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/lib/if.c b/lib/if.c index 2d0f5a6e7e1c..eebaa414614b 100644 --- a/lib/if.c +++ b/lib/if.c @@ -1091,7 +1091,6 @@ DEFPY_NOSH (interface, VRF_CMD_HELP_STR) { char xpath_list[XPATH_MAXLEN]; - vrf_id_t vrf_id; struct interface *ifp; int ret; struct vrf *vrf; @@ -1106,14 +1105,23 @@ DEFPY_NOSH (interface, * interface is found, then a new one should be created on the default * VRF. */ - VRF_GET_ID(vrf_id, vrfname, false); - ifp = if_lookup_by_name_all_vrf(ifname); - if (ifp && ifp->vrf_id != vrf_id) { + VRF_GET_INSTANCE(vrf, vrfname, false); + /* + * within vrf context, vrf_id may be unknown + * this happens on daemons relying on zebra + * on this specific case, interface creation may + * be forced + */ + if (vrf && vrf->vrf_id == VRF_UNKNOWN) + ifp = if_get_by_name(ifname, vrf); + else + ifp = if_lookup_by_name_all_vrf(ifname); + if (ifp && ifp->vrf_id != vrf->vrf_id) { /* * Special case 1: a VRF name was specified, but the found * interface is associated to different VRF. Reject the command. */ - if (vrf_id != VRF_DEFAULT) { + if (vrf->vrf_id != VRF_DEFAULT) { vty_out(vty, "%% interface %s not in %s vrf\n", ifname, vrfname); return CMD_WARNING_CONFIG_FAILED; @@ -1127,8 +1135,7 @@ DEFPY_NOSH (interface, vrf = vrf_lookup_by_id(ifp->vrf_id); assert(vrf); vrfname = vrf->name; - } else - vrf = vrf_lookup_by_id(vrf_id); + } snprintf(xpath_list, sizeof(xpath_list), "/frr-interface:lib/interface[name='%s'][vrf='%s']", ifname, diff --git a/lib/vrf.h b/lib/vrf.h index eba262a38fe2..a26cc37f0903 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -109,6 +109,23 @@ extern struct vrf *vrf_get(vrf_id_t, const char *); extern const char *vrf_id_to_name(vrf_id_t vrf_id); extern vrf_id_t vrf_name_to_id(const char *); +/* vrf context is searched and created + */ +#define VRF_GET_INSTANCE(V, NAME, USE_JSON) \ + do { \ + struct vrf *_vrf; \ + \ + _vrf = vrf_get(VRF_UNKNOWN, NAME); \ + if (_vrf->vrf_id == VRF_UNKNOWN) { \ + if (USE_JSON) { \ + vty_out(vty, "{}\n"); \ + } else { \ + vty_out(vty, "%% VRF %s not active\n", NAME); \ + } \ + } \ + (V) = _vrf; \ + } while (0) + #define VRF_GET_ID(V, NAME, USE_JSON) \ do { \ struct vrf *_vrf; \ From 7da8f57c0e11417323589d6d4d22b2f577117bbf Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Wed, 6 Feb 2019 18:02:19 +0100 Subject: [PATCH 4/7] lib: new interface zebra hook looks for interface with vrf as it is not possible to receive hooks of interface creation before vrf creation and enable, then the vrf should be retrieved. Consequently, it is possible to look in the list of interfaces for pre configured interfaces. Signed-off-by: Philippe Guibert --- lib/zclient.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/zclient.c b/lib/zclient.c index d076f1622ea5..319880c43014 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1443,6 +1443,10 @@ struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id) /* Lookup/create interface by name. */ ifp = if_get_by_name(ifname_tmp, vrf); + /* update vrf_id of interface */ + if (ifp->vrf_id == VRF_UNKNOWN && + vrf->vrf_id != VRF_UNKNOWN) + ifp->vrf_id = vrf_id; zebra_interface_if_set_value(s, ifp); return ifp; From fa5efab6029c449799efb7bd502aa176e6bf4828 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 11 Feb 2019 17:42:50 +0100 Subject: [PATCH 5/7] *: change interface structure, from vrf_id to vrf field vrf_id is replaced by the pointer of the struct vrf *. For that all other code referencing to (interface)->vrf_id is replaced. some new generic functions are created in vrf: vrf_to_id, vrf_to_name, vrf_to_vrf_info an ospf function is also created:t ospf_lookup_by_vrf it is to be noted that now that interface has a vrf pointer, some more optimisations could be thought through all the rest of the code. as example, many structure store the vrf_id. those structures could get the exact vrf structure if inherited from an interface vrf context. Signed-off-by: Philippe Guibert --- bfdd/bfd.c | 3 ++- bfdd/bfd_packet.c | 3 ++- bgpd/bgp_zebra.c | 4 ++-- isisd/isis_cli.c | 3 +-- lib/if.c | 25 ++++++++++---------- lib/if.h | 30 +++++++++++++----------- lib/vrf.c | 15 ++++++++++++ lib/vrf.h | 3 +++ lib/zclient.c | 11 +++++---- ospfd/ospf_interface.c | 4 ++-- ospfd/ospf_vty.c | 14 +++++------ ospfd/ospf_zebra.c | 8 +++---- ospfd/ospfd.c | 9 ++++++-- ospfd/ospfd.h | 1 + pimd/pim_iface.c | 14 +++++------ pimd/pim_static.c | 2 +- pimd/pim_zebra.c | 2 +- staticd/static_routes.c | 4 ++-- zebra/connected.c | 51 +++++++++++++++++++++-------------------- zebra/if_ioctl.c | 3 ++- zebra/if_netlink.c | 16 ++++++------- zebra/interface.c | 42 +++++++++++++++++---------------- zebra/ioctl.c | 14 ++++++----- zebra/redistribute.c | 18 +++++++-------- zebra/router-id.c | 4 ++-- zebra/rt_netlink.c | 15 ++++++------ zebra/rtadv.c | 8 +++---- zebra/zapi_msg.c | 16 +++++++------ zebra/zebra_ptm.c | 2 +- zebra/zebra_vxlan.c | 43 +++++++++++++++++----------------- 30 files changed, 213 insertions(+), 174 deletions(-) diff --git a/bfdd/bfd.c b/bfdd/bfd.c index cc532e835e78..d4ac9fbb15c5 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -563,7 +563,8 @@ struct bfd_session *ptm_bfd_sess_new(struct bfd_peer_cfg *bpc) * our limits). */ if (bpc->bpc_has_localif) { - ifp = if_lookup_by_name(bpc->bpc_localif, vrf_lookup_by_id(VRF_DEFAULT)); + ifp = if_lookup_by_name(bpc->bpc_localif, + vrf_lookup_by_id(VRF_DEFAULT)); if (ifp == NULL) { log_error( "session-new: specified interface doesn't exists."); diff --git a/bfdd/bfd_packet.c b/bfdd/bfd_packet.c index 09e0fbb2629a..64fd9a2b217a 100644 --- a/bfdd/bfd_packet.c +++ b/bfdd/bfd_packet.c @@ -1100,7 +1100,8 @@ int bp_peer_socketv6(struct bfd_peer_cfg *bpc) #endif /* HAVE_STRUCT_SOCKADDR_SA_LEN */ sin6 = bpc->bpc_local.sa_sin6; if (IN6_IS_ADDR_LINKLOCAL(&sin6.sin6_addr)) { - ifp = if_lookup_by_name(bpc->bpc_localif, vrf_lookup_by_id(VRF_DEFAULT)); + ifp = if_lookup_by_name(bpc->bpc_localif, + vrf_lookup_by_id(VRF_DEFAULT)); sin6.sin6_scope_id = (ifp != NULL) ? ifp->ifindex : IFINDEX_INTERNAL; } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 7673d40d5e67..84906b06f8b1 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -813,10 +813,10 @@ bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote, ifp = if_lookup_by_name(peer->conf_if ? peer->conf_if : peer->ifname, - vrf_lookup_by_id(peer->bgp->vrf_id)); + vrf_lookup_by_id(peer->bgp->vrf_id)); } else if (peer->update_if) ifp = if_lookup_by_name(peer->update_if, - vrf_lookup_by_id(peer->bgp->vrf_id)); + vrf_lookup_by_id(peer->bgp->vrf_id)); else ifp = if_lookup_by_ipv6_exact(&local->sin6.sin6_addr, local->sin6.sin6_scope_id, diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c index c68f49f92dd8..bdedab232872 100644 --- a/isisd/isis_cli.c +++ b/isisd/isis_cli.c @@ -97,8 +97,7 @@ DEFPY(no_router_isis, no_router_isis_cmd, "no router isis WORD$tag", /* add callbacks to delete each of the circuits listed */ const char *vrf_name = - vrf_lookup_by_id(circuit->interface->vrf_id) - ->name; + circuit->interface->vrf->name; snprintf( temp_xpath, XPATH_MAXLEN, "/frr-interface:lib/interface[name='%s'][vrf='%s']/frr-isisd:isis", diff --git a/lib/if.c b/lib/if.c index eebaa414614b..061941c10ab0 100644 --- a/lib/if.c +++ b/lib/if.c @@ -144,7 +144,7 @@ struct interface *if_create(const char *name, struct vrf *vrf) assert(name); strlcpy(ifp->name, name, sizeof(ifp->name)); - ifp->vrf_id = vrf->vrf_id; + ifp->vrf = vrf; IFNAME_RB_INSERT(vrf, ifp); ifp->connected = list_new(); ifp->connected->del = (void (*)(void *))connected_free; @@ -173,14 +173,14 @@ void if_update_to_new_vrf(struct interface *ifp, struct vrf *vrf) return; } /* remove interface from old master vrf list */ - old_vrf = vrf_lookup_by_id(ifp->vrf_id); + old_vrf = ifp->vrf; if (old_vrf) { IFNAME_RB_REMOVE(old_vrf, ifp); if (ifp->ifindex != IFINDEX_INTERNAL) IFINDEX_RB_REMOVE(old_vrf, ifp); } - ifp->vrf_id = vrf->vrf_id; + ifp->vrf = vrf; IFNAME_RB_INSERT(vrf, ifp); if (ifp->ifindex != IFINDEX_INTERNAL) @@ -223,9 +223,8 @@ void if_delete_retain(struct interface *ifp) /* Delete and free interface structure. */ void if_delete(struct interface *ifp) { - struct vrf *vrf; + struct vrf *vrf = ifp->vrf; - vrf = vrf_lookup_by_id(ifp->vrf_id); assert(vrf); IFNAME_RB_REMOVE(vrf, ifp); @@ -410,7 +409,7 @@ struct interface *if_get_by_name(const char *name, struct vrf *vrf) case VRF_BACKEND_VRF_LITE: ifp = if_lookup_by_name_all_vrf(name); if (ifp) { - if (ifp->vrf_id == vrf->vrf_id) + if (ifp->vrf == vrf) return ifp; /* If it came from the kernel or by way of zclient, * believe it and update the ifp accordingly. @@ -428,7 +427,7 @@ void if_set_index(struct interface *ifp, ifindex_t ifindex) { struct vrf *vrf; - vrf = vrf_lookup_by_id(ifp->vrf_id); + vrf = ifp->vrf; assert(vrf); if (ifp->ifindex == ifindex) @@ -572,7 +571,8 @@ static void if_dump(const struct interface *ifp) zlog_info( "Interface %s vrf %u index %d metric %d mtu %d " "mtu6 %d %s", - ifp->name, ifp->vrf_id, ifp->ifindex, ifp->metric, + ifp->name, vrf_to_id(ifp->vrf), + ifp->ifindex, ifp->metric, ifp->mtu, ifp->mtu6, if_flag_dump(ifp->flags)); } @@ -755,7 +755,8 @@ connected_log(struct connected *connected, char *str) p = connected->address; snprintf(logbuf, BUFSIZ, "%s interface %s vrf %u %s %s/%d ", str, - ifp->name, ifp->vrf_id, prefix_family_str(p), + ifp->name, vrf_to_id(ifp->vrf), + prefix_family_str(p), inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), p->prefixlen); p = connected->destination; @@ -1116,7 +1117,7 @@ DEFPY_NOSH (interface, ifp = if_get_by_name(ifname, vrf); else ifp = if_lookup_by_name_all_vrf(ifname); - if (ifp && ifp->vrf_id != vrf->vrf_id) { + if (ifp && ifp->vrf != vrf) { /* * Special case 1: a VRF name was specified, but the found * interface is associated to different VRF. Reject the command. @@ -1132,7 +1133,7 @@ DEFPY_NOSH (interface, * interface is associated to a VRF other than the default one. * Update vrf_id and vrfname to account for that. */ - vrf = vrf_lookup_by_id(ifp->vrf_id); + vrf = vrf_lookup_by_id(ifp->vrf->vrf_id); assert(vrf); vrfname = vrf->name; } @@ -1294,7 +1295,7 @@ static int lib_interface_create(enum nb_event event, } if (vrf_get_backend() == VRF_BACKEND_VRF_LITE) { ifp = if_lookup_by_name_all_vrf(ifname); - if (ifp && ifp->vrf_id != vrf->vrf_id) { + if (ifp && ifp->vrf != vrf) { zlog_warn( "%s: interface %s already exists in another VRF", __func__, ifp->name); diff --git a/lib/if.h b/lib/if.h index 23140e24e179..d6395896bdc8 100644 --- a/lib/if.h +++ b/lib/if.h @@ -286,7 +286,7 @@ struct interface { #endif /* HAVE_NET_RT_IFLIST */ struct route_node *node; - vrf_id_t vrf_id; + struct vrf *vrf; QOBJ_FIELDS }; @@ -297,33 +297,37 @@ RB_HEAD(if_index_head, interface); RB_PROTOTYPE(if_index_head, interface, index_entry, if_cmp_func); DECLARE_QOBJ_TYPE(interface) -#define IFNAME_RB_INSERT(vrf, ifp) \ - if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp))) \ +#define IFNAME_RB_INSERT(_vrf, _ifp) \ + if (RB_INSERT(if_name_head, &(_vrf)->ifaces_by_name, (_ifp))) \ flog_err(EC_LIB_INTERFACE, \ "%s(%s): corruption detected -- interface with this " \ "name exists already in VRF %u!", \ - __func__, (ifp)->name, (ifp)->vrf_id); + __func__, (_ifp)->name, (_ifp)->vrf ? \ + (_ifp)->vrf->vrf_id : VRF_UNKNOWN); -#define IFNAME_RB_REMOVE(vrf, ifp) \ - if (RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)) == NULL) \ +#define IFNAME_RB_REMOVE(_vrf, _ifp) \ + if (RB_REMOVE(if_name_head, &(_vrf)->ifaces_by_name, (_ifp)) == NULL) \ flog_err(EC_LIB_INTERFACE, \ "%s(%s): corruption detected -- interface with this " \ "name doesn't exist in VRF %u!", \ - __func__, (ifp)->name, (ifp)->vrf_id); + __func__, (_ifp)->name, (_ifp)->vrf ? \ + (_ifp)->vrf->vrf_id : VRF_UNKNOWN); -#define IFINDEX_RB_INSERT(vrf, ifp) \ - if (RB_INSERT(if_index_head, &vrf->ifaces_by_index, (ifp))) \ +#define IFINDEX_RB_INSERT(_vrf, _ifp) \ + if (RB_INSERT(if_index_head, &(_vrf)->ifaces_by_index, (_ifp))) \ flog_err(EC_LIB_INTERFACE, \ "%s(%u): corruption detected -- interface with this " \ "ifindex exists already in VRF %u!", \ - __func__, (ifp)->ifindex, (ifp)->vrf_id); + __func__, (_ifp)->ifindex, (_ifp)->vrf ? \ + (_ifp)->vrf->vrf_id : VRF_UNKNOWN); -#define IFINDEX_RB_REMOVE(vrf, ifp) \ - if (RB_REMOVE(if_index_head, &vrf->ifaces_by_index, (ifp)) == NULL) \ +#define IFINDEX_RB_REMOVE(_vrf, _ifp) \ + if (RB_REMOVE(if_index_head, &(_vrf)->ifaces_by_index, (_ifp)) == NULL)\ flog_err(EC_LIB_INTERFACE, \ "%s(%u): corruption detected -- interface with this " \ "ifindex doesn't exist in VRF %u!", \ - __func__, (ifp)->ifindex, (ifp)->vrf_id); + __func__, (_ifp)->ifindex, (_ifp)->vrf ? \ + (_ifp)->vrf->vrf_id : VRF_UNKNOWN); #define FOR_ALL_INTERFACES(vrf, ifp) \ if (vrf) \ diff --git a/lib/vrf.c b/lib/vrf.c index f9f14822cba6..ba92331c2f46 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -1032,3 +1032,18 @@ vrf_id_t vrf_generate_id(void) return ++vrf_id_local; } + +vrf_id_t vrf_to_id(struct vrf *vrf) +{ + return vrf ? vrf->vrf_id : VRF_UNKNOWN; +} + +const char *vrf_to_name(struct vrf *vrf) +{ + return vrf ? vrf->name : "NIL"; +} + +void *vrf_to_vrf_info(struct vrf *vrf) +{ + return vrf ? vrf->info : NULL; +} diff --git a/lib/vrf.h b/lib/vrf.h index a26cc37f0903..cb00c1860c33 100644 --- a/lib/vrf.h +++ b/lib/vrf.h @@ -108,6 +108,9 @@ extern struct vrf *vrf_lookup_by_name(const char *); extern struct vrf *vrf_get(vrf_id_t, const char *); extern const char *vrf_id_to_name(vrf_id_t vrf_id); extern vrf_id_t vrf_name_to_id(const char *); +extern vrf_id_t vrf_to_id(struct vrf *vrf); +extern const char *vrf_to_name(struct vrf *vrf); +extern void *vrf_to_vrf_info(struct vrf *vrf); /* vrf context is searched and created */ diff --git a/lib/zclient.c b/lib/zclient.c index 319880c43014..ded5c7201b17 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1444,9 +1444,9 @@ struct interface *zebra_interface_add_read(struct stream *s, vrf_id_t vrf_id) ifp = if_get_by_name(ifname_tmp, vrf); /* update vrf_id of interface */ - if (ifp->vrf_id == VRF_UNKNOWN && + if (ifp->vrf->vrf_id == VRF_UNKNOWN && vrf->vrf_id != VRF_UNKNOWN) - ifp->vrf_id = vrf_id; + ifp->vrf = vrf; zebra_interface_if_set_value(s, ifp); return ifp; @@ -2812,11 +2812,12 @@ void zclient_interface_set_master(struct zclient *client, s = client->obuf; stream_reset(s); - zclient_create_header(s, ZEBRA_INTERFACE_SET_MASTER, master->vrf_id); + zclient_create_header(s, ZEBRA_INTERFACE_SET_MASTER, + vrf_to_id(master->vrf)); - stream_putl(s, master->vrf_id); + stream_putl(s, vrf_to_id(master->vrf)); stream_putl(s, master->ifindex); - stream_putl(s, slave->vrf_id); + stream_putl(s, vrf_to_id(slave->vrf)); stream_putl(s, slave->ifindex); stream_putw_at(s, 0, stream_get_endp(s)); diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index 4075f32092c2..6516129c5db1 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -349,8 +349,8 @@ void ospf_if_free(struct ospf_interface *oi) if (IS_DEBUG_OSPF_EVENT) zlog_debug("%s: ospf interface %s vrf %s id %u deleted", __PRETTY_FUNCTION__, oi->ifp->name, - ospf_vrf_id_to_name(oi->ifp->vrf_id), - oi->ifp->vrf_id); + vrf_to_name(oi->ifp->vrf), + vrf_to_id(oi->ifp->vrf)); ospf_delete_from_if(oi->ifp, oi); diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 4e490458ace9..343cfd6f4ceb 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -7282,7 +7282,7 @@ static int ospf_vty_dead_interval_set(struct vty *vty, const char *interval_str, if (nbr_str) { struct ospf *ospf = NULL; - ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); + ospf = ospf_lookup_by_vrf(ifp->vrf); if (ospf) { oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); if (oi) @@ -7399,7 +7399,7 @@ DEFUN (no_ip_ospf_dead_interval, if (argc == 1) { struct ospf *ospf = NULL; - ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); + ospf = ospf_lookup_by_vrf(ifp->vrf); if (ospf) { oi = ospf_if_lookup_by_local_addr(ospf, ifp, addr); if (oi) @@ -7998,8 +7998,8 @@ DEFUN (ip_ospf_area, argv_find(argv, argc, "area", &idx); areaid = argv[idx + 1]->arg; - if (ifp->vrf_id && !instance) - ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); + if (ifp->vrf && !instance) + ospf = ospf_lookup_by_vrf(ifp->vrf); else ospf = ospf_lookup_instance(instance); @@ -8096,8 +8096,8 @@ DEFUN (no_ip_ospf_area, if (argv_find(argv, argc, "(1-65535)", &idx)) instance = strtol(argv[idx]->arg, NULL, 10); - if (ifp->vrf_id && !instance) - ospf = ospf_lookup_by_vrf_id(ifp->vrf_id); + if (ifp->vrf && !instance) + ospf = ospf_lookup_by_vrf(ifp->vrf); else ospf = ospf_lookup_instance(instance); @@ -9723,7 +9723,7 @@ static int config_write_interface_one(struct vty *vty, struct vrf *vrf) continue; vty_frame(vty, "!\n"); - if (ifp->vrf_id == VRF_DEFAULT) + if (ifp->vrf && ifp->vrf->vrf_id == VRF_DEFAULT) vty_frame(vty, "interface %s\n", ifp->name); else vty_frame(vty, "interface %s vrf %s\n", ifp->name, diff --git a/ospfd/ospf_zebra.c b/ospfd/ospf_zebra.c index d9bc980a95e2..a9bd2058d5aa 100644 --- a/ospfd/ospf_zebra.c +++ b/ospfd/ospf_zebra.c @@ -112,8 +112,8 @@ static int ospf_interface_add(int command, struct zclient *zclient, if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) zlog_debug( "Zebra: interface add %s vrf %s[%u] index %d flags %llx metric %d mtu %d speed %u", - ifp->name, ospf_vrf_id_to_name(ifp->vrf_id), - ifp->vrf_id, ifp->ifindex, + ifp->name, vrf_to_name(ifp->vrf), + vrf_to_id(ifp->vrf), ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu, ifp->speed); @@ -155,8 +155,8 @@ static int ospf_interface_delete(int command, struct zclient *zclient, if (IS_DEBUG_OSPF(zebra, ZEBRA_INTERFACE)) zlog_debug( "Zebra: interface delete %s vrf %s[%u] index %d flags %llx metric %d mtu %d", - ifp->name, ospf_vrf_id_to_name(ifp->vrf_id), - ifp->vrf_id, ifp->ifindex, + ifp->name, vrf_to_name(ifp->vrf), + vrf_to_id(ifp->vrf), ifp->ifindex, (unsigned long long)ifp->flags, ifp->metric, ifp->mtu); hook_call(ospf_if_delete, ifp); diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index a18e2de72511..1b569e494731 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -448,6 +448,11 @@ struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id) vrf = vrf_lookup_by_id(vrf_id); if (!vrf) return NULL; + return ospf_lookup_by_vrf(vrf); +} + +struct ospf *ospf_lookup_by_vrf(struct vrf *vrf) +{ return (vrf->info) ? (struct ospf *)vrf->info : NULL; } @@ -1343,8 +1348,8 @@ void ospf_if_update(struct ospf *ospf, struct interface *ifp) if (IS_DEBUG_OSPF_EVENT) zlog_debug( - "%s: interface %s ifp->vrf_id %u ospf vrf %s vrf_id %u router_id %s", - __PRETTY_FUNCTION__, ifp->name, ifp->vrf_id, + "%s: interface %s ifp->vrf->vrf_id %u ospf vrf %s vrf_id %u router_id %s", + __PRETTY_FUNCTION__, ifp->name, vrf_to_id(ifp->vrf), ospf_vrf_id_to_name(ospf->vrf_id), ospf->vrf_id, inet_ntoa(ospf->router_id)); diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index cbea033b7357..a46febaecaf9 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -507,6 +507,7 @@ extern struct ospf *ospf_get_instance(unsigned short); extern struct ospf *ospf_lookup_by_inst_name(unsigned short instance, const char *name); extern struct ospf *ospf_lookup_by_vrf_id(vrf_id_t vrf_id); +extern struct ospf *ospf_lookup_by_vrf(struct vrf *vrf); extern void ospf_finish(struct ospf *); extern void ospf_router_id_update(struct ospf *ospf); extern int ospf_network_set(struct ospf *, struct prefix_ipv4 *, struct in_addr, diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index a79a10e0973c..69add89f6dc4 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -119,7 +119,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim, pim_ifp = XCALLOC(MTYPE_PIM_INTERFACE, sizeof(*pim_ifp)); pim_ifp->options = 0; - pim_ifp->pim = pim_get_pim_instance(ifp->vrf_id); + pim_ifp->pim = pim_get_pim_instance(vrf_to_id(ifp->vrf)); pim_ifp->mroute_vif_index = -1; pim_ifp->igmp_version = IGMP_DEFAULT_VERSION; @@ -775,7 +775,7 @@ void pim_if_addr_del_all(struct interface *ifp) struct connected *ifc; struct listnode *node; struct listnode *nextnode; - struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + struct vrf *vrf = ifp->vrf; struct pim_instance *pim; if (!vrf) @@ -847,7 +847,7 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) int v4_addrs = 0; int v6_addrs = 0; struct pim_interface *pim_ifp = ifp->info; - struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); + struct vrf *vrf = ifp->vrf; if (!vrf) return addr; @@ -888,12 +888,10 @@ struct in_addr pim_find_primary_addr(struct interface *ifp) if (!v4_addrs && v6_addrs && !if_is_loopback(ifp)) { struct interface *lo_ifp; // DBS - Come back and check here - if (ifp->vrf_id == VRF_DEFAULT) - lo_ifp = if_lookup_by_name("lo", - vrf_lookup_by_id(vrf->vrf_id)); + if (vrf_to_id(ifp->vrf) == VRF_DEFAULT) + lo_ifp = if_lookup_by_name("lo", vrf); else - lo_ifp = if_lookup_by_name(vrf->name, - vrf_lookup_by_id(vrf->vrf_id)); + lo_ifp = if_lookup_by_name(vrf->name, vrf); if (lo_ifp) return pim_find_primary_addr(lo_ifp); diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 442b22e06fc6..4ddf21951b00 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -92,7 +92,7 @@ int pim_static_add(struct pim_instance *pim, struct interface *iif, return -4; } #endif - if (iif->vrf_id != oif->vrf_id) { + if (iif->vrf != oif->vrf) { return -3; } diff --git a/pimd/pim_zebra.c b/pimd/pim_zebra.c index d827e23dbf95..44110a5d6d22 100644 --- a/pimd/pim_zebra.c +++ b/pimd/pim_zebra.c @@ -204,7 +204,7 @@ static int pim_zebra_if_state_up(int command, struct zclient *zclient, struct vrf *vrf; RB_FOREACH (vrf, vrf_name_head, &vrfs_by_name) { if ((table_id == vrf->data.l.table_id) - && (ifp->vrf_id != vrf->vrf_id)) { + && (ifp->vrf != vrf)) { struct interface *master = if_lookup_by_name( vrf->name, vrf); diff --git a/staticd/static_routes.c b/staticd/static_routes.c index babccdd4f1d8..d68990464768 100644 --- a/staticd/static_routes.c +++ b/staticd/static_routes.c @@ -518,7 +518,7 @@ static void static_fixup_intf_nh(struct route_table *stable, 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) + if (si->nh_vrf_id != vrf_to_id(ifp->vrf)) continue; if (si->ifindex != ifp->ifindex) @@ -544,7 +544,7 @@ void static_install_intf_nh(struct interface *ifp) struct static_vrf *svrf = vrf->info; /* Not needed if same vrf since happens naturally */ - if (vrf->vrf_id == ifp->vrf_id) + if (vrf == ifp->vrf) continue; /* Install any static routes configured for this interface. */ diff --git a/zebra/connected.c b/zebra/connected.c index c449855f6dfb..dddc3a9f782c 100644 --- a/zebra/connected.c +++ b/zebra/connected.c @@ -207,7 +207,7 @@ void connected_up(struct interface *ifp, struct connected *ifc) struct nexthop nh = { .type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex, - .vrf_id = ifp->vrf_id, + .vrf_id = vrf_to_id(ifp->vrf), }; uint32_t metric; @@ -246,33 +246,34 @@ void connected_up(struct interface *ifp, struct connected *ifc) metric = (ifc->metric < (uint32_t)METRIC_MAX) ? ifc->metric : ifp->metric; - rib_add(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, &p, - NULL, &nh, RT_TABLE_MAIN, metric, 0, 0, 0); + rib_add(afi, SAFI_UNICAST, vrf_to_id(ifp->vrf), ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, &nh, RT_TABLE_MAIN, metric, 0, 0, 0); - rib_add(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, &p, - NULL, &nh, RT_TABLE_MAIN, metric, 0, 0, 0); + rib_add(afi, SAFI_MULTICAST, vrf_to_id(ifp->vrf), ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, &nh, RT_TABLE_MAIN, metric, 0, 0, 0); if (IS_ZEBRA_DEBUG_RIB_DETAILED) { char buf[PREFIX_STRLEN]; zlog_debug( "%u: IF %s address %s add/up, scheduling RIB processing", - ifp->vrf_id, ifp->name, + vrf_to_id(ifp->vrf), ifp->name, prefix2str(&p, buf, sizeof(buf))); } - rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); + rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE); /* Schedule LSP forwarding entries for processing, if appropriate. */ - if (ifp->vrf_id == VRF_DEFAULT) { + if (vrf_to_id(ifp->vrf) == VRF_DEFAULT) { if (IS_ZEBRA_DEBUG_MPLS) { char buf[PREFIX_STRLEN]; zlog_debug( "%u: IF %s IP %s address add/up, scheduling MPLS processing", - ifp->vrf_id, ifp->name, + vrf_to_id(ifp->vrf), ifp->name, prefix2str(&p, buf, sizeof(buf))); } - mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); + mpls_mark_lsps_for_processing( + vrf_info_lookup(vrf_to_id(ifp->vrf))); } } @@ -375,7 +376,7 @@ void connected_down(struct interface *ifp, struct connected *ifc) struct nexthop nh = { .type = NEXTHOP_TYPE_IFINDEX, .ifindex = ifp->ifindex, - .vrf_id = ifp->vrf_id, + .vrf_id = vrf_to_id(ifp->vrf), }; if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) @@ -410,34 +411,34 @@ void connected_down(struct interface *ifp, struct connected *ifc) * Same logic as for connected_up(): push the changes into the * head. */ - rib_delete(afi, SAFI_UNICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, - &p, NULL, &nh, 0, 0, 0, false); + rib_delete(afi, SAFI_UNICAST, vrf_to_id(ifp->vrf), ZEBRA_ROUTE_CONNECT, + 0, 0, &p, NULL, &nh, 0, 0, 0, false); - rib_delete(afi, SAFI_MULTICAST, ifp->vrf_id, ZEBRA_ROUTE_CONNECT, 0, 0, - &p, NULL, &nh, 0, 0, 0, false); + rib_delete(afi, SAFI_MULTICAST, vrf_to_id(ifp->vrf), + ZEBRA_ROUTE_CONNECT, 0, 0, &p, NULL, &nh, 0, 0, 0, false); if (IS_ZEBRA_DEBUG_RIB_DETAILED) { char buf[PREFIX_STRLEN]; zlog_debug( "%u: IF %s IP %s address down, scheduling RIB processing", - ifp->vrf_id, ifp->name, + vrf_to_id(ifp->vrf), ifp->name, prefix2str(&p, buf, sizeof(buf))); } - rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); + rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE); /* Schedule LSP forwarding entries for processing, if appropriate. */ - if (ifp->vrf_id == VRF_DEFAULT) { + if (vrf_to_id(ifp->vrf) == VRF_DEFAULT) { if (IS_ZEBRA_DEBUG_MPLS) { char buf[PREFIX_STRLEN]; zlog_debug( "%u: IF %s IP %s address down, scheduling MPLS processing", - ifp->vrf_id, ifp->name, + vrf_to_id(ifp->vrf), ifp->name, prefix2str(&p, buf, sizeof(buf))); } - mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); + mpls_mark_lsps_for_processing(ifp->vrf->info); } } @@ -456,22 +457,22 @@ static void connected_delete_helper(struct connected *ifc, struct prefix *p) zlog_debug( "%u: IF %s IP %s address del, scheduling RIB processing", - ifp->vrf_id, ifp->name, + vrf_to_id(ifp->vrf), ifp->name, prefix2str(p, buf, sizeof(buf))); } - rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); + rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE); /* Schedule LSP forwarding entries for processing, if appropriate. */ - if (ifp->vrf_id == VRF_DEFAULT) { + if (vrf_to_id(ifp->vrf) == VRF_DEFAULT) { if (IS_ZEBRA_DEBUG_MPLS) { char buf[PREFIX_STRLEN]; zlog_debug( "%u: IF %s IP %s address delete, scheduling MPLS processing", - ifp->vrf_id, ifp->name, + vrf_to_id(ifp->vrf), ifp->name, prefix2str(p, buf, sizeof(buf))); } - mpls_mark_lsps_for_processing(vrf_info_lookup(ifp->vrf_id)); + mpls_mark_lsps_for_processing(ifp->vrf->info); } } diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 274096aab659..294508c083f4 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -152,7 +152,8 @@ static int if_get_hwaddr(struct interface *ifp) ifreq.ifr_addr.sa_family = AF_INET; /* Fetch Hardware address if available. */ - ret = vrf_if_ioctl(SIOCGIFHWADDR, (caddr_t)&ifreq, ifp->vrf_id); + ret = vrf_if_ioctl(SIOCGIFHWADDR, (caddr_t)&ifreq, + vrf_to_id(ifp->vrf)); if (ret < 0) ifp->hw_addr_len = 0; else { diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 0a65c3c519c0..c62d40358754 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -386,7 +386,7 @@ static int get_iflink_speed(struct interface *interface) /* use ioctl to get IP address of an interface */ frr_elevate_privs(&zserv_privs) { sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP, - interface->vrf_id, + vrf_to_id(interface->vrf), NULL); if (sd < 0) { if (IS_ZEBRA_DEBUG_KERNEL) @@ -395,7 +395,7 @@ static int get_iflink_speed(struct interface *interface) return 0; } /* Get the current link state for the interface */ - rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL, + rc = vrf_ioctl(vrf_to_id(interface->vrf), sd, SIOCETHTOOL, (char *)&ifdata); } if (rc < 0) { @@ -851,7 +851,7 @@ static int netlink_address(int cmd, int family, struct interface *ifp, struct zebra_ns *zns; if (vrf_is_backend_netns()) - zns = zebra_ns_lookup((ns_id_t)ifp->vrf_id); + zns = zebra_ns_lookup((ns_id_t)vrf_to_id(ifp->vrf)); else zns = zebra_ns_lookup(NS_DEFAULT); p = ifc->address; @@ -1241,7 +1241,7 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) ifp = if_get_by_name(name, vrf); } else { /* pre-configured interface, learnt now */ - if (ifp->vrf_id != vrf_id) + if (ifp->vrf != vrf) if_update_to_new_vrf(ifp, vrf); } @@ -1281,16 +1281,16 @@ int netlink_link_change(struct nlmsghdr *h, ns_id_t ns_id, int startup) bridge_ifindex); else if (IS_ZEBRA_IF_BOND_SLAVE(ifp)) zebra_l2if_update_bond_slave(ifp, bond_ifindex); - } else if (ifp->vrf_id != vrf_id) { + } else if (ifp->vrf != vrf) { /* VRF change for an interface. */ if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "RTM_NEWLINK vrf-change for %s(%u) " "vrf_id %u -> %u flags 0x%x", - name, ifp->ifindex, ifp->vrf_id, vrf_id, - ifi->ifi_flags); + name, ifp->ifindex, vrf_to_id(ifp->vrf), + vrf_id, ifi->ifi_flags); - if_handle_vrf_change(ifp, vrf_id); + if_handle_vrf_change(ifp, vrf->vrf_id); } else { bool was_bridge_slave, was_bond_slave; diff --git a/zebra/interface.c b/zebra/interface.c index 1718b0e6306f..82342ccbcfb1 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -521,7 +521,7 @@ void if_add_update(struct interface *ifp) { struct zebra_if *if_data; struct zebra_ns *zns; - struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); + struct zebra_vrf *zvrf = vrf_to_vrf_info(ifp->vrf); /* case interface populate before vrf enabled */ if (zvrf->zns) @@ -549,7 +549,8 @@ void if_add_update(struct interface *ifp) zlog_debug( "interface %s vrf %u index %d is shutdown. " "Won't wake it up.", - ifp->name, ifp->vrf_id, ifp->ifindex); + ifp->name, vrf_to_id(ifp->vrf), + ifp->ifindex); return; } @@ -558,12 +559,13 @@ void if_add_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( "interface %s vrf %u index %d becomes active.", - ifp->name, ifp->vrf_id, ifp->ifindex); + ifp->name, vrf_to_id(ifp->vrf), ifp->ifindex); } else { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("interface %s vrf %u index %d is added.", - ifp->name, ifp->vrf_id, ifp->ifindex); + ifp->name, vrf_to_id(ifp->vrf), + ifp->ifindex); } } @@ -705,7 +707,7 @@ void if_delete_update(struct interface *ifp) flog_err( EC_LIB_INTERFACE, "interface %s vrf %u index %d is still up while being deleted.", - ifp->name, ifp->vrf_id, ifp->ifindex); + ifp->name, vrf_to_id(ifp->vrf), ifp->ifindex); return; } @@ -717,7 +719,7 @@ void if_delete_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug("interface %s vrf %u index %d is now inactive.", - ifp->name, ifp->vrf_id, ifp->ifindex); + ifp->name, vrf_to_id(ifp->vrf), ifp->ifindex); /* Delete connected routes from the kernel. */ if_delete_connected(ifp); @@ -741,7 +743,7 @@ void if_delete_update(struct interface *ifp) * occur with this implementation whereas it is not possible with * vrf-lite). */ - if (ifp->vrf_id && !vrf_is_backend_netns()) + if (ifp->vrf && ifp->vrf->vrf_id && !vrf_is_backend_netns()) if_handle_vrf_change(ifp, VRF_DEFAULT); /* Reset some zebra interface params to default values. */ @@ -761,7 +763,7 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id) vrf_id_t old_vrf_id; struct vrf *vrf = vrf_lookup_by_id(vrf_id); - old_vrf_id = ifp->vrf_id; + old_vrf_id = vrf_to_id(ifp->vrf); /* Uninstall connected routes. */ if_uninstall_connected(ifp); @@ -792,9 +794,9 @@ void if_handle_vrf_change(struct interface *ifp, vrf_id_t vrf_id) */ if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug("%u: IF %s VRF change, scheduling RIB processing", - ifp->vrf_id, ifp->name); + vrf_to_id(ifp->vrf), ifp->name); rib_update(old_vrf_id, RIB_UPDATE_IF_CHANGE); - rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); + rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE); } static void ipv6_ll_address_to_mac(struct in6_addr *address, uint8_t *mac) @@ -812,7 +814,7 @@ void if_nbr_mac_to_ipv4ll_neigh_update(struct interface *ifp, struct in6_addr *address, int add) { - struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); + struct zebra_vrf *zvrf = vrf_to_vrf_info(ifp->vrf); struct zebra_if *zif = ifp->info; char buf[16] = "169.254.0.1"; struct in_addr ipv4_ll; @@ -908,7 +910,7 @@ void if_up(struct interface *ifp) { struct zebra_if *zif; struct interface *link_if; - struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); + struct zebra_vrf *zvrf = vrf_to_vrf_info(ifp->vrf); zif = ifp->info; zif->up_count++; @@ -939,8 +941,8 @@ void if_up(struct interface *ifp) if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug("%u: IF %s up, scheduling RIB processing", - ifp->vrf_id, ifp->name); - rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); + vrf_to_id(ifp->vrf), ifp->name); + rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE); /* Handle interface up for specific types for EVPN. Non-VxLAN interfaces * are checked to see if (remote) neighbor entries need to be installed @@ -965,7 +967,7 @@ void if_down(struct interface *ifp) { struct zebra_if *zif; struct interface *link_if; - struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); + struct zebra_vrf *zvrf = vrf_to_vrf_info(ifp->vrf); zif = ifp->info; zif->down_count++; @@ -997,8 +999,8 @@ void if_down(struct interface *ifp) if (IS_ZEBRA_DEBUG_RIB_DETAILED) zlog_debug("%u: IF %s down, scheduling RIB processing", - ifp->vrf_id, ifp->name); - rib_update(ifp->vrf_id, RIB_UPDATE_IF_CHANGE); + vrf_to_id(ifp->vrf), ifp->name); + rib_update(vrf_to_id(ifp->vrf), RIB_UPDATE_IF_CHANGE); if_nbr_ipv6ll_to_ipv4ll_neigh_del_all(ifp); @@ -1292,7 +1294,7 @@ static void if_dump_vty(struct vty *vty, struct interface *ifp) zebra_ptm_show_status(vty, ifp); - vrf = vrf_lookup_by_id(ifp->vrf_id); + vrf = ifp->vrf; vty_out(vty, " vrf: %s\n", vrf->name); if (ifp->desc) @@ -3096,9 +3098,9 @@ static int if_config_write(struct vty *vty) struct vrf *vrf; if_data = ifp->info; - vrf = vrf_lookup_by_id(ifp->vrf_id); + vrf = ifp->vrf; - if (ifp->vrf_id == VRF_DEFAULT) + if (vrf->vrf_id == VRF_DEFAULT) vty_frame(vty, "interface %s\n", ifp->name); else vty_frame(vty, "interface %s vrf %s\n", diff --git a/zebra/ioctl.c b/zebra/ioctl.c index ebe1edcaef0a..4f44c5986c65 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -141,7 +141,8 @@ void if_get_metric(struct interface *ifp) ifreq_set_name(&ifreq, ifp); - if (vrf_if_ioctl(SIOCGIFMETRIC, (caddr_t)&ifreq, ifp->vrf_id) < 0) + if (vrf_if_ioctl(SIOCGIFMETRIC, (caddr_t)&ifreq, + vrf_to_id(ifp->vrf)) < 0) return; ifp->metric = ifreq.ifr_metric; if (ifp->metric == 0) @@ -159,7 +160,8 @@ void if_get_mtu(struct interface *ifp) ifreq_set_name(&ifreq, ifp); #if defined(SIOCGIFMTU) - if (vrf_if_ioctl(SIOCGIFMTU, (caddr_t)&ifreq, ifp->vrf_id) < 0) { + if (vrf_if_ioctl(SIOCGIFMTU, (caddr_t)&ifreq, + vrf_to_id(ifp->vrf)) < 0) { zlog_info("Can't lookup mtu by ioctl(SIOCGIFMTU)"); ifp->mtu6 = ifp->mtu = -1; return; @@ -210,7 +212,7 @@ int if_set_prefix(struct interface *ifp, struct connected *ifc) } p = (struct prefix_ipv4 *)ifc->address; - rib_lookup_and_pushup(p, ifp->vrf_id); + rib_lookup_and_pushup(p, vrf_to_id(ifp->vrf)); memset(&addreq, 0, sizeof addreq); strncpy((char *)&addreq.ifra_name, ifp->name, sizeof addreq.ifra_name); @@ -395,7 +397,7 @@ void if_get_flags(struct interface *ifp) ifreq_set_name(&ifreq, ifp); - ret = vrf_if_ioctl(SIOCGIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id); + ret = vrf_if_ioctl(SIOCGIFFLAGS, (caddr_t)&ifreq, vrf_to_id(ifp->vrf)); if (ret < 0) { flog_err_sys(EC_LIB_SYSTEM_CALL, "vrf_if_ioctl(SIOCGIFFLAGS) failed: %s", @@ -445,7 +447,7 @@ int if_set_flags(struct interface *ifp, uint64_t flags) ifreq.ifr_flags = ifp->flags; ifreq.ifr_flags |= flags; - ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id); + ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, vrf_to_id(ifp->vrf)); if (ret < 0) { zlog_info("can't set interface flags"); @@ -466,7 +468,7 @@ int if_unset_flags(struct interface *ifp, uint64_t flags) ifreq.ifr_flags = ifp->flags; ifreq.ifr_flags &= ~flags; - ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id); + ret = vrf_if_ioctl(SIOCSIFFLAGS, (caddr_t)&ifreq, vrf_to_id(ifp->vrf)); if (ret < 0) { zlog_info("can't unset interface flags"); diff --git a/zebra/redistribute.c b/zebra/redistribute.c index f98a4c02c320..dd1ac3041e18 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -402,7 +402,7 @@ void zebra_interface_up_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("MESSAGE: ZEBRA_INTERFACE_UP %s(%u)", - ifp->name, ifp->vrf_id); + ifp->name, vrf_to_id(ifp->vrf)); if (ifp->ptm_status || !ifp->ptm_enable) { for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, @@ -422,7 +422,7 @@ void zebra_interface_down_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("MESSAGE: ZEBRA_INTERFACE_DOWN %s(%u)", - ifp->name, ifp->vrf_id); + ifp->name, vrf_to_id(ifp->vrf)); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { zsend_interface_update(ZEBRA_INTERFACE_DOWN, client, ifp); @@ -437,7 +437,7 @@ void zebra_interface_add_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADD %s(%u)", ifp->name, - ifp->vrf_id); + vrf_to_id(ifp->vrf)); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { client->ifadd_cnt++; @@ -453,7 +453,7 @@ void zebra_interface_delete_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("MESSAGE: ZEBRA_INTERFACE_DELETE %s(%u)", - ifp->name, ifp->vrf_id); + ifp->name, vrf_to_id(ifp->vrf)); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { client->ifdel_cnt++; @@ -475,7 +475,7 @@ void zebra_interface_address_add_update(struct interface *ifp, p = ifc->address; zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_ADD %s on %s(%u)", prefix2str(p, buf, sizeof(buf)), ifp->name, - ifp->vrf_id); + vrf_to_id(ifp->vrf)); } if (!CHECK_FLAG(ifc->conf, ZEBRA_IFC_REAL)) @@ -509,7 +509,7 @@ void zebra_interface_address_delete_update(struct interface *ifp, p = ifc->address; zlog_debug("MESSAGE: ZEBRA_INTERFACE_ADDRESS_DELETE %s on %s(%u)", prefix2str(p, buf, sizeof(buf)), - ifp->name, ifp->vrf_id); + ifp->name, vrf_to_id(ifp->vrf)); } zebra_vxlan_add_del_gw_macip(ifp, ifc->address, 0); @@ -535,7 +535,7 @@ void zebra_interface_vrf_update_del(struct interface *ifp, vrf_id_t new_vrf_id) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug( "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/DEL %s VRF Id %u -> %u", - ifp->name, ifp->vrf_id, new_vrf_id); + ifp->name, vrf_to_id(ifp->vrf), new_vrf_id); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { /* Need to delete if the client is not interested in the new @@ -558,7 +558,7 @@ void zebra_interface_vrf_update_add(struct interface *ifp, vrf_id_t old_vrf_id) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug( "MESSAGE: ZEBRA_INTERFACE_VRF_UPDATE/ADD %s VRF Id %u -> %u", - ifp->name, old_vrf_id, ifp->vrf_id); + ifp->name, old_vrf_id, vrf_to_id(ifp->vrf)); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) { /* Need to add if the client is interested in the new VRF. */ @@ -809,7 +809,7 @@ void zebra_interface_parameters_update(struct interface *ifp) if (IS_ZEBRA_DEBUG_EVENT) zlog_debug("MESSAGE: ZEBRA_INTERFACE_LINK_PARAMS %s(%u)", - ifp->name, ifp->vrf_id); + ifp->name, vrf_to_id(ifp->vrf)); for (ALL_LIST_ELEMENTS(zrouter.client_list, node, nnode, client)) zsend_interface_link_params(client, ifp); diff --git a/zebra/router-id.c b/zebra/router-id.c index 569ffbab411f..b5a8860c43da 100644 --- a/zebra/router-id.c +++ b/zebra/router-id.c @@ -122,7 +122,7 @@ void router_id_add_address(struct connected *ifc) struct prefix before; struct prefix after; struct zserv *client; - struct zebra_vrf *zvrf = vrf_info_get(ifc->ifp->vrf_id); + struct zebra_vrf *zvrf = vrf_info_get(vrf_to_id(ifc->ifp->vrf)); if (router_id_bad_address(ifc)) return; @@ -154,7 +154,7 @@ void router_id_del_address(struct connected *ifc) struct prefix before; struct listnode *node; struct zserv *client; - struct zebra_vrf *zvrf = vrf_info_get(ifc->ifp->vrf_id); + struct zebra_vrf *zvrf = vrf_info_get(vrf_to_id(ifc->ifp->vrf)); if (router_id_bad_address(ifc)) return; diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 3868412b20bb..42d2af89f3de 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -545,7 +545,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, zebra_ns_lookup(ns_id), index); if (ifp) - nh_vrf_id = ifp->vrf_id; + nh_vrf_id = vrf_to_id(ifp->vrf); } nh.vrf_id = nh_vrf_id; @@ -605,7 +605,7 @@ static int netlink_route_change_read_unicast(struct nlmsghdr *h, ns_id_t ns_id, zebra_ns_lookup(ns_id), index); if (ifp) - nh_vrf_id = ifp->vrf_id; + nh_vrf_id = vrf_to_id(ifp->vrf); else { flog_warn( EC_ZEBRA_UNKNOWN_INTERFACE, @@ -1891,7 +1891,7 @@ static int netlink_vxlan_flood_list_update(struct interface *ifp, char buf[256]; } req; uint8_t dst_mac[6] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0}; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); + struct zebra_vrf *zvrf = (struct zebra_vrf *)vrf_to_vrf_info(ifp->vrf); zns = zvrf->zns; memset(&req, 0, sizeof(req)); @@ -2267,7 +2267,7 @@ static int netlink_macfdb_update(struct interface *ifp, vlanid_t vid, int vid_present = 0; char vid_buf[20]; char dst_buf[30]; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); + struct zebra_vrf *zvrf = (struct zebra_vrf *)vrf_to_vrf_info(ifp->vrf); zns = zvrf->zns; zif = ifp->info; @@ -2601,7 +2601,8 @@ int netlink_neigh_read_specific_ip(struct ipaddr *ip, { int ret = 0; struct zebra_ns *zns; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(vlan_if->vrf_id); + struct zebra_vrf *zvrf = (struct zebra_vrf *)vrf_to_vrf_info( + vlan_if->vrf); char buf[INET6_ADDRSTRLEN]; struct zebra_dplane_info dp_info; @@ -2614,7 +2615,7 @@ int netlink_neigh_read_specific_ip(struct ipaddr *ip, __PRETTY_FUNCTION__, vlan_if->name, vlan_if->ifindex, ipaddr2str(ip, buf, sizeof(buf)), - vlan_if->vrf_id); + vrf_to_id(vlan_if->vrf)); ret = netlink_request_specific_neigh_in_vlan(zns, RTM_GETNEIGH, ip, vlan_if->ifindex); @@ -2679,7 +2680,7 @@ static int netlink_neigh_update2(struct interface *ifp, struct ipaddr *ip, struct zebra_ns *zns; char buf[INET6_ADDRSTRLEN]; char buf2[ETHER_ADDR_STRLEN]; - struct zebra_vrf *zvrf = zebra_vrf_lookup_by_id(ifp->vrf_id); + struct zebra_vrf *zvrf = (struct zebra_vrf *)vrf_to_vrf_info(ifp->vrf); zns = zvrf->zns; memset(&req, 0, sizeof(req)); diff --git a/zebra/rtadv.c b/zebra/rtadv.c index 86edc6fb5e9b..f1e8ca09f4f5 100644 --- a/zebra/rtadv.c +++ b/zebra/rtadv.c @@ -451,7 +451,7 @@ static int rtadv_timer(struct thread *thread) static void rtadv_process_solicit(struct interface *ifp) { - struct zebra_vrf *zvrf = vrf_info_lookup(ifp->vrf_id); + struct zebra_vrf *zvrf = (struct zebra_vrf *)vrf_to_vrf_info(ifp->vrf); struct zebra_ns *zns = zvrf->zns; assert(zns); @@ -803,7 +803,7 @@ static void ipv6_nd_suppress_ra_set(struct interface *ifp, struct zebra_ns *zns; zif = ifp->info; - zvrf = vrf_info_lookup(ifp->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(ifp->vrf); zns = zvrf->zns; if (status == RA_SUPPRESS) { @@ -877,11 +877,11 @@ static void zebra_interface_radv_set(ZAPI_HANDLER_ARGS, int enable) zebra_route_string(client->proto)); return; } - if (ifp->vrf_id != zvrf_id(zvrf)) { + if (ifp->vrf != zvrf->vrf) { zlog_debug( "%u: IF %u RA %s client %s - VRF mismatch, IF VRF %u", zvrf_id(zvrf), ifindex, enable ? "enable" : "disable", - zebra_route_string(client->proto), ifp->vrf_id); + zebra_route_string(client->proto), vrf_to_id(ifp->vrf)); return; } diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index d862627b5f75..cad4e3b1d821 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -162,7 +162,7 @@ int zsend_interface_add(struct zserv *client, struct interface *ifp) { struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, ZEBRA_INTERFACE_ADD, ifp->vrf_id); + zclient_create_header(s, ZEBRA_INTERFACE_ADD, vrf_to_id(ifp->vrf)); zserv_encode_interface(s, ifp); client->ifadd_cnt++; @@ -174,7 +174,7 @@ int zsend_interface_delete(struct zserv *client, struct interface *ifp) { struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id); + zclient_create_header(s, ZEBRA_INTERFACE_DELETE, vrf_to_id(ifp->vrf)); zserv_encode_interface(s, ifp); client->ifdel_cnt++; @@ -214,7 +214,8 @@ int zsend_interface_link_params(struct zserv *client, struct interface *ifp) return 0; } - zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf_id); + zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS, + vrf_to_id(ifp->vrf)); /* Add Interface Index */ stream_putl(s, ifp->ifindex); @@ -276,7 +277,7 @@ int zsend_interface_address(int cmd, struct zserv *client, struct prefix *p; struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, cmd, ifp->vrf_id); + zclient_create_header(s, cmd, vrf_to_id(ifp->vrf)); stream_putl(s, ifp->ifindex); /* Interface address flag. */ @@ -318,7 +319,7 @@ static int zsend_interface_nbr_address(int cmd, struct zserv *client, struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); struct prefix *p; - zclient_create_header(s, cmd, ifp->vrf_id); + zclient_create_header(s, cmd, vrf_to_id(ifp->vrf)); stream_putl(s, ifp->ifindex); /* Prefix information. */ @@ -426,7 +427,8 @@ int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp, { struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf_id); + zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, + vrf_to_id(ifp->vrf)); /* Fill in the name of the interface and its new VRF (id) */ stream_put(s, ifp->name, INTERFACE_NAMSIZ); @@ -501,7 +503,7 @@ int zsend_interface_update(int cmd, struct zserv *client, struct interface *ifp) { struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, cmd, ifp->vrf_id); + zclient_create_header(s, cmd, vrf_to_id(ifp->vrf)); zserv_encode_interface(s, ifp); if (cmd == ZEBRA_INTERFACE_UP) diff --git a/zebra/zebra_ptm.c b/zebra/zebra_ptm.c index 1e942d6433f9..7cdda5be76ad 100644 --- a/zebra/zebra_ptm.c +++ b/zebra/zebra_ptm.c @@ -521,7 +521,7 @@ static int zebra_ptm_handle_bfd_msg(void *arg, void *in_ctxt, } if (!strcmp(ZEBRA_PTM_INVALID_VRF, vrf_str) && ifp) { - vrf_id = ifp->vrf_id; + vrf_id = vrf_to_id(ifp->vrf); } else { vrf_id = vrf_name_to_id(vrf_str); } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 560cd89abd78..ccd28e8c7725 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -2316,7 +2316,7 @@ static void zvni_process_neigh_on_local_mac_change(zebra_vni_t *zvni, struct zebra_vrf *zvrf = NULL; char buf[ETHER_ADDR_STRLEN]; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug("Processing neighbors on local MAC %s %s, VNI %u", @@ -2575,7 +2575,7 @@ struct interface *zebra_get_vrr_intf_for_svi(struct interface *ifp) struct interface *tmp_if = NULL; struct zebra_if *zif = NULL; - zvrf = vrf_info_lookup(ifp->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(ifp->vrf); assert(zvrf); FOR_ALL_INTERFACES (zvrf->vrf, tmp_if) { @@ -2679,10 +2679,10 @@ static int zvni_advertise_subnet(zebra_vni_t *zvni, struct interface *ifp, apply_mask(&p); if (advertise) - ip_prefix_send_to_client(ifp->vrf_id, &p, + ip_prefix_send_to_client(vrf_to_id(ifp->vrf), &p, ZEBRA_IP_PREFIX_ROUTE_ADD); else - ip_prefix_send_to_client(ifp->vrf_id, &p, + ip_prefix_send_to_client(vrf_to_id(ifp->vrf), &p, ZEBRA_IP_PREFIX_ROUTE_DEL); } return 0; @@ -2801,7 +2801,7 @@ static int zvni_gw_macip_del(struct interface *ifp, zebra_vni_t *zvni, if (IS_ZEBRA_DEBUG_VXLAN) zlog_debug( "%u:SVI %s(%u) VNI %u, sending GW MAC %s IP %s del to BGP", - ifp->vrf_id, ifp->name, ifp->ifindex, zvni->vni, + vrf_to_id(ifp->vrf), ifp->name, ifp->ifindex, zvni->vni, prefix_mac2str(&(n->emac), buf1, sizeof(buf1)), ipaddr2str(ip, buf2, sizeof(buf2))); @@ -2988,7 +2988,7 @@ static int zvni_local_neigh_update(zebra_vni_t *zvni, } } - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (!zvrf) return -1; @@ -4016,8 +4016,9 @@ static void zvni_build_hash_table(void) vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); if (vlan_if) { - zvni->vrf_id = vlan_if->vrf_id; - zl3vni = zl3vni_from_vrf(vlan_if->vrf_id); + zvni->vrf_id = vrf_to_id(vlan_if->vrf); + zl3vni = zl3vni_from_vrf( + vrf_to_id(vlan_if->vrf)); if (zl3vni) listnode_add_sort(zl3vni->l2vnis, zvni); } @@ -5165,7 +5166,7 @@ static void process_remote_macip_add(vni_t vni, return; } - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (!zvrf) return; @@ -5493,7 +5494,7 @@ static void process_remote_macip_del(vni_t vni, if (!mac && !n) return; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); /* Ignore the delete if this mac is a gateway mac-ip */ if (CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL) @@ -7178,7 +7179,7 @@ int zebra_vxlan_handle_kernel_neigh_del(struct interface *ifp, return 0; } - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (!zvrf) { zlog_debug("%s: VNI %u vrf lookup failed.", __PRETTY_FUNCTION__, zvni->vni); @@ -7598,7 +7599,7 @@ int zebra_vxlan_local_mac_add_update(struct interface *ifp, return -1; } - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (!zvrf) return -1; @@ -8109,10 +8110,10 @@ int zebra_vxlan_svi_up(struct interface *ifp, struct interface *link_if) zlog_debug( "SVI %s(%u) VNI %u VRF %s is UP, installing neighbors", ifp->name, ifp->ifindex, zvni->vni, - vrf_id_to_name(ifp->vrf_id)); + vrf_to_name(ifp->vrf)); /* update the vrf information for l2-vni and inform bgp */ - zvni->vrf_id = ifp->vrf_id; + zvni->vrf_id = vrf_to_id(ifp->vrf); zvni_send_add_to_client(zvni); /* Install any remote neighbors for this VNI. */ @@ -8238,8 +8239,8 @@ int zebra_vxlan_if_up(struct interface *ifp) vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); if (vlan_if) { - zvni->vrf_id = vlan_if->vrf_id; - zl3vni = zl3vni_from_vrf(vlan_if->vrf_id); + zvni->vrf_id = vrf_to_id(vlan_if->vrf); + zl3vni = zl3vni_from_vrf(vrf_to_id(vlan_if->vrf)); if (zl3vni) listnode_add_sort(zl3vni->l2vnis, zvni); } @@ -8551,8 +8552,8 @@ int zebra_vxlan_if_add(struct interface *ifp) vlan_if = zvni_map_to_svi(vxl->access_vlan, zif->brslave_info.br_if); if (vlan_if) { - zvni->vrf_id = vlan_if->vrf_id; - zl3vni = zl3vni_from_vrf(vlan_if->vrf_id); + zvni->vrf_id = vrf_to_id(vlan_if->vrf); + zl3vni = zl3vni_from_vrf(vrf_to_id(vlan_if->vrf)); if (zl3vni) listnode_add_sort(zl3vni->l2vnis, zvni); } @@ -8561,7 +8562,7 @@ int zebra_vxlan_if_add(struct interface *ifp) zlog_debug( "Add L2-VNI %u VRF %s intf %s(%u) VLAN %u local IP %s master %u", vni, - vlan_if ? vrf_id_to_name(vlan_if->vrf_id) + vlan_if ? vrf_to_name(vlan_if->vrf) : VRF_DEFAULT_NAME, ifp->name, ifp->ifindex, vxl->access_vlan, inet_ntoa(vxl->vtep_ip), @@ -9170,7 +9171,7 @@ static int zebra_vxlan_dad_ip_auto_recovery_exp(struct thread *t) if (!zvni) return 0; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (!zvrf) return 0; @@ -9220,7 +9221,7 @@ static int zebra_vxlan_dad_mac_auto_recovery_exp(struct thread *t) if (!zvni) return 0; - zvrf = vrf_info_lookup(zvni->vxlan_if->vrf_id); + zvrf = (struct zebra_vrf *)vrf_to_vrf_info(zvni->vxlan_if->vrf); if (!zvrf) return 0; From fd1b57680c42fd4ed5c48e886de4e72404830c7c Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 11 Feb 2019 17:51:05 +0100 Subject: [PATCH 6/7] lib: interface creation based on unknown vrf is possible this is an additional behaviour with previous releases, against nb api. with vrf not yet initialised, it must become possible to create interfaces based on those vrfs. Signed-off-by: Philippe Guibert --- lib/if.c | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/if.c b/lib/if.c index 061941c10ab0..02359fae435d 100644 --- a/lib/if.c +++ b/lib/if.c @@ -1291,7 +1291,6 @@ static int lib_interface_create(enum nb_event event, if (vrf->vrf_id == VRF_UNKNOWN) { zlog_warn("%s: VRF %s is not active", __func__, vrf->name); - return NB_ERR_VALIDATION; } if (vrf_get_backend() == VRF_BACKEND_VRF_LITE) { ifp = if_lookup_by_name_all_vrf(ifname); From c627c5da58056f31e29d67d004a1e9299f07c32f Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Mon, 11 Feb 2019 21:47:23 +0100 Subject: [PATCH 7/7] zebra: create vrf upon netlink interface event create vrf upon netlink interface event. Signed-off-by: Philippe Guibert --- zebra/if_netlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index c62d40358754..e1f2568d745e 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -672,7 +672,7 @@ static int netlink_interface(struct nlmsghdr *h, ns_id_t ns_id, int startup) if (vrf_is_backend_netns()) vrf_id = (vrf_id_t)ns_id; - vrf = vrf_lookup_by_id(vrf_id); + vrf = vrf_get(vrf_id, NULL); /* If linking to another interface, note it. */ if (tb[IFLA_LINK])