All of lore.kernel.org
 help / color / mirror / Atom feed
From: Anthony Liguori <anthony@codemonkey.ws>
To: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH] New scriptarg=... -net parameter allows passing of an argument
Date: Thu, 12 Jun 2008 13:39:03 -0500	[thread overview]
Message-ID: <48516D47.6080005@codemonkey.ws> (raw)
In-Reply-To: <18513.23567.23400.891876@mariner.uk.xensource.com>

Ian Jackson wrote:
> 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.
>   

env args should get passed down to the script although I can see an 
argument for being able to specify this in -net.  My only suggestion 
would be to use an env arg instead of "$2" as it will make it easier to 
extend in the future.

Regards,

Anthony Liguori

> With this patch it is possible to specify
>   -net=...,scriptarg=<extra-info>
> which gets passed as a $2 to the qemu-ifup script.
>
> Signed-off-by: Ian Jackson <ian.jackson@eu.citrix.com>
>
> ---
>  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);
>              }
>          }
>      }
>   

  reply	other threads:[~2008-06-12 18:39 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-12 17:25 [Qemu-devel] [PATCH] New scriptarg=... -net parameter allows passing of an argument Ian Jackson
2008-06-12 18:39 ` Anthony Liguori [this message]
2008-06-12 21:26   ` Avi Kivity
2008-06-12 21:50     ` Anthony Liguori
2008-06-12 22:04       ` Avi Kivity
2008-06-13  9:20       ` Ian Jackson
2008-06-13 11:10         ` [Qemu-devel] [PATCH] Pass all parameters to -net tap, ... as env vars to if script Ian Jackson

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=48516D47.6080005@codemonkey.ws \
    --to=anthony@codemonkey.ws \
    --cc=qemu-devel@nongnu.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.