netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matteo Croce <mcroce@redhat.com>
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>,
	David Ahern <dsahern@kernel.org>
Subject: [PATCH iproute2 v2 2/3] ip vrf: use hook to change VRF in the child
Date: Tue, 11 Jun 2019 18:10:30 +0200	[thread overview]
Message-ID: <20190611161031.12898-3-mcroce@redhat.com> (raw)
In-Reply-To: <20190611161031.12898-1-mcroce@redhat.com>

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(-)

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;
-- 
2.21.0


  parent reply	other threads:[~2019-06-11 16:11 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-11 16:10 [PATCH iproute2 v2 0/3] refactor the cmd_exec() Matteo Croce
2019-06-11 16:10 ` [PATCH iproute2 v2 1/3] netns: switch netns in the child when executing commands Matteo Croce
2019-06-11 16:10 ` Matteo Croce [this message]
2019-06-11 16:10 ` [PATCH iproute2 v2 3/3] netns: make netns_{save,restore} static Matteo Croce
2019-06-13 17:07 ` [PATCH iproute2 v2 0/3] refactor the cmd_exec() Andrea Claudi
2019-06-14 14:35 ` David Ahern
2019-06-15 14:06   ` Matteo Croce
2019-06-17 22:20     ` Matteo Croce
2019-06-17 22:24       ` David Ahern
2019-06-18 14:49 Matteo Croce
2019-06-18 14:49 ` [PATCH iproute2 v2 2/3] ip vrf: use hook to change VRF in the child Matteo Croce

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190611161031.12898-3-mcroce@redhat.com \
    --to=mcroce@redhat.com \
    --cc=dsahern@kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).