Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1K6qYU-0006X8-Qw for qemu-devel@nongnu.org; Thu, 12 Jun 2008 13:25:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1K6qYS-0006Sn-8k for qemu-devel@nongnu.org; Thu, 12 Jun 2008 13:25:46 -0400 Received: from [199.232.76.173] (port=43907 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1K6qYR-0006Se-OK for qemu-devel@nongnu.org; Thu, 12 Jun 2008 13:25:43 -0400 Received: from smtp02.citrix.com ([66.165.176.63]:41071) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1K6qYR-0000Dd-9O for qemu-devel@nongnu.org; Thu, 12 Jun 2008 13:25:43 -0400 Received: from mariner.uk.xensource.com ([10.80.2.22]) by smtp01.ad.xensource.com (8.13.1/8.13.1) with ESMTP id m5CHPep4008377 for ; Thu, 12 Jun 2008 10:25:41 -0700 Received: from iwj by mariner.uk.xensource.com with local (Exim 4.63) (envelope-from ) id 1K6qYJ-0005qu-0x for qemu-devel@nongnu.org; Thu, 12 Jun 2008 18:25:35 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Message-ID: <18513.23567.23400.891876@mariner.uk.xensource.com> Date: Thu, 12 Jun 2008 18:25:35 +0100 From: Ian Jackson Subject: [Qemu-devel] [PATCH] New scriptarg=... -net parameter allows passing of an argument Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Previously, network scripts would have to do all of their work based only on the script name and interface name. If the script's behaviour is supposed to be different for different network interfaces this might involve constructing a special script for each interface with the associated need to delete it etc. With this patch it is possible to specify -net=...,scriptarg= which gets passed as a $2 to the qemu-ifup script. Signed-off-by: Ian Jackson --- vl.c | 27 +++++++++++++++++++-------- 1 files changed, 19 insertions(+), 8 deletions(-) diff --git a/vl.c b/vl.c index 229b536..28f6fe0 100644 --- a/vl.c +++ b/vl.c @@ -3963,6 +3963,7 @@ typedef struct TAPState { VLANClientState *vc; int fd; char down_script[1024]; + char script_arg[1024]; } TAPState; static void tap_receive(void *opaque, const uint8_t *buf, int size) @@ -4198,10 +4199,11 @@ static int tap_open(char *ifname, int ifname_size) } #endif -static int launch_script(const char *setup_script, const char *ifname, int fd) +static int launch_script(const char *setup_script, const char *ifname, + const char *script_arg, int fd) { int pid, status; - char *args[3]; + char *args[4]; char **parg; /* try to launch network script */ @@ -4219,6 +4221,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) parg = args; *parg++ = (char *)setup_script; *parg++ = (char *)ifname; + if (script_arg && script_arg[0]) + *parg++ = (char *)script_arg; *parg++ = NULL; execv(setup_script, args); _exit(1); @@ -4235,7 +4239,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd) } static int net_tap_init(VLANState *vlan, const char *ifname1, - const char *setup_script, const char *down_script) + const char *setup_script, const char *down_script, + const char *script_arg) { TAPState *s; int fd; @@ -4252,7 +4257,7 @@ static int net_tap_init(VLANState *vlan, const char *ifname1, if (!setup_script || !strcmp(setup_script, "no")) setup_script = ""; if (setup_script[0] != '\0') { - if (launch_script(setup_script, ifname, fd)) + if (launch_script(setup_script, ifname, script_arg, fd)) return -1; } s = net_tap_fd_init(vlan, fd); @@ -4262,6 +4267,8 @@ static int net_tap_init(VLANState *vlan, const char *ifname1, "tap: ifname=%s setup_script=%s", ifname, setup_script); if (down_script && strcmp(down_script, "no")) snprintf(s->down_script, sizeof(s->down_script), "%s", down_script); + if (script_arg && script_arg[0]) + snprintf(s->script_arg, sizeof(s->script_arg), "%s", script_arg); return 0; } @@ -4854,7 +4861,7 @@ static int net_client_init(const char *str) #else if (!strcmp(device, "tap")) { char ifname[64]; - char setup_script[1024], down_script[1024]; + char setup_script[1024], down_script[1024], script_arg[1024]; int fd; vlan->nb_host_devs++; if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { @@ -4873,7 +4880,10 @@ static int net_client_init(const char *str) if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) { pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT); } - ret = net_tap_init(vlan, ifname, setup_script, down_script); + if (get_param_value(script_arg, sizeof(script_arg), "scriptarg", p) == 0) { + pstrcpy(script_arg, sizeof(script_arg), ""); + } + ret = net_tap_init(vlan, ifname, setup_script, down_script, script_arg); } } else #endif @@ -7191,11 +7201,12 @@ static void help(int exitcode) "-net tap[,vlan=n],ifname=name\n" " connect the host TAP network interface to VLAN 'n'\n" #else - "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n" + "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile][,scriptarg=extraargument]\n" " connect the host TAP network interface to VLAN 'n' and use the\n" " network scripts 'file' (default=%s)\n" " and 'dfile' (default=%s);\n" " use '[down]script=no' to disable script execution;\n" + " use 'scriptarg=...' to pass an additional (nonempty) argument;\n" " use 'fd=h' to connect to an already opened TAP interface\n" #endif "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n" @@ -8638,7 +8649,7 @@ int main(int argc, char **argv) if (sscanf(vc->info_str, "tap: ifname=%63s ", ifname) == 1 && s->down_script[0]) - launch_script(s->down_script, ifname, s->fd); + launch_script(s->down_script, ifname, s->script_arg, s->fd); } } } -- 1.4.4.4