summaryrefslogtreecommitdiff
path: root/lib/if.c
diff options
context:
space:
mode:
authorPhilippe Guibert <philippe.guibert@6wind.com>2019-02-11 15:46:48 +0100
committerPhilippe Guibert <philippe.guibert@6wind.com>2019-06-12 08:37:54 +0200
commitf11e98eca3c4b4e3c91c826329018e848bcb9fc6 (patch)
treeace27e5cf229093071ea7f0c00029920b4d8c46e /lib/if.c
parente9c199a6c12ad8359d1792462545595d4679d20b (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/if.c')
-rw-r--r--lib/if.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/lib/if.c b/lib/if.c
index 22f83bb675..1a51e3ee8d 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -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);
}