qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH] [slirp] add nextserver support in slirp's dhcp-


From: Stefan Hajnoczi
Subject: Re: [Qemu-devel] [PATCH] [slirp] add nextserver support in slirp's dhcp-server
Date: Mon, 24 Jun 2013 11:37:32 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

On Fri, Jun 21, 2013 at 03:20:09PM +0200, Bas van Sisseren wrote:
> The slirp dhcp-server normally returns its own address as tftp
> nextserver for netbooting. This patch makes that address
> configurable, so it is possible to use an external tftp boot-
> environment.
> 
> Signed-off-by: Bas van Sisseren <address@hidden>
> ---
>  net/slirp.c      | 10 ++++++++--
>  qapi-schema.json |  3 +++
>  qemu-options.hx  |  5 ++++-
>  slirp/bootp.c    |  6 +++++-
>  slirp/libslirp.h |  1 +
>  slirp/slirp.c    |  2 ++
>  slirp/slirp.h    |  1 +
>  7 files changed, 24 insertions(+), 4 deletions(-)

CCing Jan Kiszka, the slirp/ maintainer.

> diff --git a/net/slirp.c b/net/slirp.c
> index 124e953..f3e239c 100644
> --- a/net/slirp.c
> +++ b/net/slirp.c
> @@ -136,6 +136,7 @@ static int net_slirp_init(NetClientState *peer, const 
> char *model,
>                            const char *vnetwork, const char *vhost,
>                            const char *vhostname, const char *tftp_export,
>                            const char *bootfile, const char *vdhcp_start,
> +                          const char *vnextserver,
>                            const char *vnameserver, const char *smb_export,
>                            const char *vsmbserver, const char **dnssearch)
>  {
> @@ -145,6 +146,7 @@ static int net_slirp_init(NetClientState *peer, const 
> char *model,
>      struct in_addr host = { .s_addr = htonl(0x0a000202) }; /* 10.0.2.2 */
>      struct in_addr dhcp = { .s_addr = htonl(0x0a00020f) }; /* 10.0.2.15 */
>      struct in_addr dns  = { .s_addr = htonl(0x0a000203) }; /* 10.0.2.3 */
> +    struct in_addr nxtsrv = { .s_addr = 0 };
>  #ifndef _WIN32
>      struct in_addr smbsrv = { .s_addr = 0 };
>  #endif
> @@ -228,6 +230,10 @@ static int net_slirp_init(NetClientState *peer, const 
> char *model,
>          return -1;
>      }
>  
> +    if (vnextserver && !inet_aton(vnextserver, &nxtsrv)) {
> +        return -1;
> +    }
> +
>  #ifndef _WIN32
>      if (vsmbserver && !inet_aton(vsmbserver, &smbsrv)) {
>          return -1;
> @@ -243,7 +249,7 @@ static int net_slirp_init(NetClientState *peer, const 
> char *model,
>      s = DO_UPCAST(SlirpState, nc, nc);
>  
>      s->slirp = slirp_init(restricted, net, mask, host, vhostname,
> -                          tftp_export, bootfile, dhcp, dns, dnssearch, s);
> +                          tftp_export, bootfile, dhcp, nxtsrv, dns, 
> dnssearch, s);
>      QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
>  
>      for (config = slirp_configs; config; config = config->next) {
> @@ -751,7 +757,7 @@ int net_init_slirp(const NetClientOptions *opts, const 
> char *name,
>  
>      ret = net_slirp_init(peer, "user", name, user->q_restrict, vnet,
>                           user->host, user->hostname, user->tftp,
> -                         user->bootfile, user->dhcpstart, user->dns, 
> user->smb,
> +                         user->bootfile, user->dhcpstart, user->nextserver, 
> user->dns, user->smb,
>                           user->smbserver, dnssearch);
>  
>      while (slirp_configs) {
> diff --git a/qapi-schema.json b/qapi-schema.json
> index a80ee40..a8e2c3d 100644
> --- a/qapi-schema.json
> +++ b/qapi-schema.json
> @@ -2537,6 +2537,8 @@
>  # @dhcpstart: #optional the first of the 16 IPs the built-in DHCP server can
>  #             assign
>  #
> +# @nextserver: #optional IP address of BOOTP server
> +#
>  # @dns: #optional guest-visible address of the virtual nameserver
>  #
>  # @dnssearch: #optional list of DNS suffixes to search, passed as DHCP option
> @@ -2563,6 +2565,7 @@
>      '*tftp':      'str',
>      '*bootfile':  'str',
>      '*dhcpstart': 'str',
> +    '*nextserver': 'str',
>      '*dns':       'str',
>      '*dnssearch': ['String'],
>      '*smb':       'str',
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 8355f9b..8afe42a 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -1350,7 +1350,7 @@ DEF("net", HAS_ARG, QEMU_OPTION_net,
>  #ifdef CONFIG_SLIRP
>      "-net 
> user[,vlan=n][,name=str][,net=addr[/mask]][,host=addr][,restrict=on|off]\n"
>      "         
> [,hostname=host][,dhcpstart=addr][,dns=addr][,dnssearch=domain][,tftp=dir]\n"
> -    "         [,bootfile=f][,hostfwd=rule][,guestfwd=rule]"
> +    "         [,bootfile=f][,nextserver=addr][,hostfwd=rule][,guestfwd=rule]"
>  #ifndef _WIN32
>                                               "[,smb=dir[,smbserver=addr]]\n"
>  #endif
> @@ -1498,6 +1498,9 @@ When using the user mode network stack, broadcast 
> @var{file} as the BOOTP
>  filename. In conjunction with @option{tftp}, this can be used to network boot
>  a guest from a local directory.
>  
> address@hidden address@hidden
> +Specify the IP address of the TFTP server.
> +
>  Example (using pxelinux):
>  @example
>  qemu-system-i386 -hda linux.img -boot n -net 
> user,tftp=/path/to/tftp/files,bootfile=/pxelinux.0
> diff --git a/slirp/bootp.c b/slirp/bootp.c
> index b7db9fa..d2e89d6 100644
> --- a/slirp/bootp.c
> +++ b/slirp/bootp.c
> @@ -227,7 +227,11 @@ static void bootp_reply(Slirp *slirp, const struct 
> bootp_t *bp)
>      memcpy(rbp->bp_hwaddr, bp->bp_hwaddr, ETH_ALEN);
>  
>      rbp->bp_yiaddr = daddr.sin_addr; /* Client IP address */
> -    rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */
> +    if (slirp->vnext_server.s_addr == 0) {
> +        rbp->bp_siaddr = saddr.sin_addr; /* Server IP address */
> +    } else {
> +        rbp->bp_siaddr = slirp->vnext_server; /* Next-Server address */
> +    }
>  
>      q = rbp->bp_vend;
>      memcpy(q, rfc1533_cookie, 4);
> diff --git a/slirp/libslirp.h b/slirp/libslirp.h
> index ceabff8..c3d800b 100644
> --- a/slirp/libslirp.h
> +++ b/slirp/libslirp.h
> @@ -12,6 +12,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
>                    struct in_addr vnetmask, struct in_addr vhost,
>                    const char *vhostname, const char *tftp_path,
>                    const char *bootfile, struct in_addr vdhcp_start,
> +                  struct in_addr vnext_server,
>                    struct in_addr vnameserver, const char **vdnssearch,
>                    void *opaque);
>  void slirp_cleanup(Slirp *slirp);
> diff --git a/slirp/slirp.c b/slirp/slirp.c
> index 80b28ea..35f2afd 100644
> --- a/slirp/slirp.c
> +++ b/slirp/slirp.c
> @@ -200,6 +200,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
>                    struct in_addr vnetmask, struct in_addr vhost,
>                    const char *vhostname, const char *tftp_path,
>                    const char *bootfile, struct in_addr vdhcp_start,
> +                  struct in_addr vnext_server,
>                    struct in_addr vnameserver, const char **vdnssearch,
>                    void *opaque)
>  {
> @@ -225,6 +226,7 @@ Slirp *slirp_init(int restricted, struct in_addr vnetwork,
>      slirp->tftp_prefix = g_strdup(tftp_path);
>      slirp->bootp_filename = g_strdup(bootfile);
>      slirp->vdhcp_startaddr = vdhcp_start;
> +    slirp->vnext_server = vnext_server;
>      slirp->vnameserver_addr = vnameserver;
>  
>      if (vdnssearch) {
> diff --git a/slirp/slirp.h b/slirp/slirp.h
> index fe0e65d..a28a8d1 100644
> --- a/slirp/slirp.h
> +++ b/slirp/slirp.h
> @@ -209,6 +209,7 @@ struct Slirp {
>      struct in_addr vnetwork_mask;
>      struct in_addr vhost_addr;
>      struct in_addr vdhcp_startaddr;
> +    struct in_addr vnext_server;
>      struct in_addr vnameserver_addr;
>  
>      struct in_addr client_ipaddr;
> -- 
> 1.8.3.1
> 
> 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]