diff options
| author | Philippe Guibert <philippe.guibert@6wind.com> | 2019-02-11 15:46:48 +0100 |
|---|---|---|
| committer | Philippe Guibert <philippe.guibert@6wind.com> | 2019-06-12 08:37:54 +0200 |
| commit | f11e98eca3c4b4e3c91c826329018e848bcb9fc6 (patch) | |
| tree | ace27e5cf229093071ea7f0c00029920b4d8c46e /lib | |
| parent | e9c199a6c12ad8359d1792462545595d4679d20b (diff) | |
*: 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.
Also, it fixes 2 lookup calls in zebra and sharpd, where the vrf_id was
ignored until now.
Signed-off-by: Philippe Guibert <philippe.guibert@6wind.com>
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/if.c | 21 | ||||
| -rw-r--r-- | lib/if.h | 2 | ||||
| -rw-r--r-- | lib/zclient.c | 9 |
3 files changed, 17 insertions, 15 deletions
@@ -264,16 +264,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 @@ -293,7 +293,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; } @@ -425,7 +425,7 @@ struct interface *if_get_by_name(const char *name, struct vrf *vrf) switch (vrf_get_backend()) { case VRF_BACKEND_UNKNOWN: 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); @@ -635,7 +635,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... */ @@ -1128,6 +1128,7 @@ DEFPY_NOSH (interface, vrf_id_t vrf_id; struct interface *ifp; int ret; + struct vrf *vrf; if (!vrfname) vrfname = VRF_DEFAULT_NAME; @@ -1142,8 +1143,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. @@ -1161,9 +1160,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, @@ -1180,7 +1179,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); } @@ -494,7 +494,7 @@ size_t if_lookup_by_hwaddr(const uint8_t *hw_addr, size_t addrsz, /* 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/zclient.c b/lib/zclient.c index c5d4e0daff..da8dc4e906 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1490,7 +1490,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", @@ -1550,7 +1551,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, @@ -1846,7 +1848,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", |
