summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorRuss White <russ@riw.us>2018-09-11 17:33:27 +0200
committerGitHub <noreply@github.com>2018-09-11 17:33:27 +0200
commit88f47ef36536a040b30652bc22c253e7c5bc1c2e (patch)
tree272285fef5319101109e4148f7784155bebe5fdc /lib
parentMerge branch 'pr2983' (diff)
parentzebra/lib: code cleaning (diff)
downloadfrr-88f47ef36536a040b30652bc22c253e7c5bc1c2e.tar.xz
frr-88f47ef36536a040b30652bc22c253e7c5bc1c2e.zip
Merge pull request #2944 from thbtcllt/master
fix zebra crash when a vrf interface changes with netns implementation for vrf
Diffstat (limited to 'lib')
-rw-r--r--lib/if.c64
-rw-r--r--lib/vrf.c10
2 files changed, 44 insertions, 30 deletions
diff --git a/lib/if.c b/lib/if.c
index a03c9da6f..2f2073c0a 100644
--- a/lib/if.c
+++ b/lib/if.c
@@ -371,37 +371,47 @@ struct interface *if_lookup_prefix(struct prefix *prefix, vrf_id_t vrf_id)
one. */
struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id, int vty)
{
- struct interface *ifp;
+ struct interface *ifp = NULL;
- ifp = if_lookup_by_name(name, vrf_id);
- if (ifp)
- return ifp;
- /* Not Found on same VRF. If the interface command
- * was entered in vty without a VRF (passed as VRF_DEFAULT),
- * accept the ifp we found. If a vrf was entered and there is
- * a mismatch, reject it if from vty.
- */
- ifp = if_lookup_by_name_all_vrf(name);
- if (!ifp)
+ if (vrf_is_mapped_on_netns(vrf_lookup_by_id(vrf_id))) {
+ ifp = if_lookup_by_name(name, vrf_id);
+ if (ifp)
+ return ifp;
+ if (vty) {
+ /* If the interface command was entered in vty without a
+ * VRF (passed as VRF_DEFAULT), search an interface with
+ * this name in all VRs
+ */
+ if (vrf_id == VRF_DEFAULT)
+ return if_lookup_by_name_all_vrf(name);
+ return NULL;
+ }
return if_create(name, vrf_id);
- if (vty) {
- if (vrf_id == VRF_DEFAULT)
+ }
+ /* vrf is based on vrf-lite */
+ ifp = if_lookup_by_name_all_vrf(name);
+ if (ifp) {
+ if (ifp->vrf_id == vrf_id)
return ifp;
- return NULL;
+ /* Found a match on a different VRF. If the interface command
+ * was entered in vty without a VRF (passed as VRF_DEFAULT),
+ * accept the ifp we found. If a vrf was entered and there is a
+ * mismatch, reject it if from vty. If it came from the kernel
+ * or by way of zclient, believe it and update the ifp
+ * accordingly.
+ */
+ if (vty) {
+ if (vrf_id == VRF_DEFAULT)
+ return ifp;
+ return NULL;
+ }
+ /* 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_id);
+ return ifp;
}
- /* if vrf backend uses NETNS, then
- * this should not be considered as an update
- * then create the new interface
- */
- if (ifp->vrf_id != vrf_id && vrf_is_mapped_on_netns(
- vrf_lookup_by_id(vrf_id)))
- return if_create(name, vrf_id);
- /* 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_id);
- return ifp;
+ return if_create(name, vrf_id);
}
void if_set_index(struct interface *ifp, ifindex_t ifindex)
diff --git a/lib/vrf.c b/lib/vrf.c
index 1fb1b786c..3ab830c55 100644
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -493,9 +493,15 @@ void vrf_init(int (*create)(struct vrf *), int (*enable)(struct vrf *),
"vrf_init: failed to create the default VRF!");
exit(1);
}
- if (vrf_is_backend_netns())
+ if (vrf_is_backend_netns()) {
+ struct ns *ns;
+
strlcpy(default_vrf->data.l.netns_name,
VRF_DEFAULT_NAME, NS_NAMSIZ);
+ ns = ns_lookup(ns_get_default_id());
+ ns->vrf_ctxt = default_vrf;
+ default_vrf->ns_ctxt = ns;
+ }
/* Enable the default VRF. */
if (!vrf_enable(default_vrf)) {
@@ -711,8 +717,6 @@ int vrf_is_mapped_on_netns(struct vrf *vrf)
{
if (!vrf || vrf->data.l.netns_name[0] == '\0')
return 0;
- if (vrf->vrf_id == VRF_DEFAULT)
- return 0;
return 1;
}