[iproute2,v2,2/3] ip vrf: use hook to change VRF in the child
diff mbox series

Message ID 20190611161031.12898-3-mcroce@redhat.com
State Superseded
Delegated to: David Ahern
Headers show
Series
  • refactor the cmd_exec()
Related show

Commit Message

Matteo Croce June 11, 2019, 4:10 p.m. UTC
On vrf exec, reset the VRF associations in the child process, via the
new hook added to cmd_exec(). In this way, the parent doesn't have to
reset the VRF associations before spawning other processes.

Signed-off-by: Matteo Croce <mcroce@redhat.com>
---
 ip/ipnetns.c |  5 -----
 ip/ipvrf.c   | 12 ++++++++----
 2 files changed, 8 insertions(+), 9 deletions(-)

Patch
diff mbox series

diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 58655676..1fff284e 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -400,11 +400,6 @@  static int do_switch(void *arg)
 {
 	char *netns = arg;
 
-	/* we just changed namespaces. clear any vrf association
-	 * with prior namespace before exec'ing command
-	 */
-	vrf_reset();
-
 	return netns_switch(netns);
 }
 
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index 2b019c6c..43366f6e 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -442,6 +442,13 @@  out:
 	return rc;
 }
 
+static int do_switch(void *arg)
+{
+	char *vrf = arg;
+
+	return vrf_switch(vrf);
+}
+
 static int ipvrf_exec(int argc, char **argv)
 {
 	if (argc < 1) {
@@ -453,10 +460,7 @@  static int ipvrf_exec(int argc, char **argv)
 		return -1;
 	}
 
-	if (vrf_switch(argv[0]))
-		return -1;
-
-	return -cmd_exec(argv[1], argv + 1, !!batch_mode, NULL, NULL);
+	return -cmd_exec(argv[1], argv + 1, !!batch_mode, do_switch, argv[0]);
 }
 
 /* reset VRF association of current process to default VRF;