diff mbox series

slirp: Implement RFC2132 TFTP server name

Message ID 20180824135312.1606-1-famz@redhat.com (mailing list archive)
State New, archived
Headers show
Series slirp: Implement RFC2132 TFTP server name | expand

Commit Message

Fam Zheng Aug. 24, 2018, 1:53 p.m. UTC
This new usernet option can be used to add data for option 66 (tftp
server name) in the BOOTP reply, which is useful in PXE based automatic
OS install such as OpenBSD.

Signed-off-by: Fam Zheng <famz@redhat.com>
---
 net/slirp.c      | 7 +++++--
 qapi/net.json    | 5 ++++-
 slirp/bootp.c    | 8 ++++++++
 slirp/bootp.h    | 1 +
 slirp/libslirp.h | 3 ++-
 slirp/slirp.c    | 6 +++++-
 slirp/slirp.h    | 2 ++
 7 files changed, 27 insertions(+), 5 deletions(-)

Comments

Eric Blake Aug. 24, 2018, 4:21 p.m. UTC | #1
On 08/24/2018 08:53 AM, Fam Zheng wrote:
> This new usernet option can be used to add data for option 66 (tftp
> server name) in the BOOTP reply, which is useful in PXE based automatic
> OS install such as OpenBSD.
> 
> Signed-off-by: Fam Zheng <famz@redhat.com>
> ---

> +++ b/qapi/net.json
> @@ -174,6 +174,8 @@
>   #
>   # @guestfwd: forward guest TCP connections
>   #
> +# @tftp-server-name: (optional) RFC2132 "TFTP server name" string (Since 3.1)

The doc generator automatically marks up optional members these days, so 
you can drop '(optional)' from this line.
Samuel Thibault Aug. 25, 2018, 4:53 p.m. UTC | #2
Hello,

Fam Zheng, le ven. 24 août 2018 21:53:12 +0800, a ecrit:
>                            const char *vnameserver, const char *vnameserver6,
>                            const char *smb_export, const char *vsmbserver,
>                            const char **dnssearch, const char *vdomainname,
> +                          const char *tftp_server_name,

I'd say rather put it between the vhostname and tftp_export parameters.

> @@ -321,6 +322,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
>      slirp->vdhcp_startaddr = vdhcp_start;
>      slirp->vnameserver_addr = vnameserver;
>      slirp->vnameserver_addr6 = vnameserver6;
> +    if (tftp_server_name) {
> +        slirp->tftp_server_name = g_strdup(tftp_server_name);
> +    }

I'd say do not bother testing for tftp_server_name != NULL, just always
use g_strdup, as is done for other values.

Samuel
Fam Zheng Aug. 27, 2018, 2:20 a.m. UTC | #3
On Sat, 08/25 18:53, Samuel Thibault wrote:
> Hello,
> 
> Fam Zheng, le ven. 24 août 2018 21:53:12 +0800, a ecrit:
> >                            const char *vnameserver, const char *vnameserver6,
> >                            const char *smb_export, const char *vsmbserver,
> >                            const char **dnssearch, const char *vdomainname,
> > +                          const char *tftp_server_name,
> 
> I'd say rather put it between the vhostname and tftp_export parameters.
> 
> > @@ -321,6 +322,9 @@ Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
> >      slirp->vdhcp_startaddr = vdhcp_start;
> >      slirp->vnameserver_addr = vnameserver;
> >      slirp->vnameserver_addr6 = vnameserver6;
> > +    if (tftp_server_name) {
> > +        slirp->tftp_server_name = g_strdup(tftp_server_name);
> > +    }
> 
> I'd say do not bother testing for tftp_server_name != NULL, just always
> use g_strdup, as is done for other values.

Both sound good. I'll send v2.

Fam
Fam Zheng Aug. 27, 2018, 2:20 a.m. UTC | #4
On Fri, 08/24 11:21, Eric Blake wrote:
> On 08/24/2018 08:53 AM, Fam Zheng wrote:
> > This new usernet option can be used to add data for option 66 (tftp
> > server name) in the BOOTP reply, which is useful in PXE based automatic
> > OS install such as OpenBSD.
> > 
> > Signed-off-by: Fam Zheng <famz@redhat.com>
> > ---
> 
> > +++ b/qapi/net.json
> > @@ -174,6 +174,8 @@
> >   #
> >   # @guestfwd: forward guest TCP connections
> >   #
> > +# @tftp-server-name: (optional) RFC2132 "TFTP server name" string (Since 3.1)
> 
> The doc generator automatically marks up optional members these days, so you
> can drop '(optional)' from this line.

OK, will drop in v2. Thanks!

Fam
diff mbox series

Patch

diff --git a/net/slirp.c b/net/slirp.c
index 1e14318b4d..b0c68a3665 100644
--- a/net/slirp.c
+++ b/net/slirp.c
@@ -158,6 +158,7 @@  static int net_slirp_init(NetClientState *peer, const char *model,
                           const char *vnameserver, const char *vnameserver6,
                           const char *smb_export, const char *vsmbserver,
                           const char **dnssearch, const char *vdomainname,
+                          const char *tftp_server_name,
                           Error **errp)
 {
     /* default settings according to historic slirp */
@@ -377,7 +378,8 @@  static int net_slirp_init(NetClientState *peer, const char *model,
     s->slirp = slirp_init(restricted, ipv4, net, mask, host,
                           ipv6, ip6_prefix, vprefix6_len, ip6_host,
                           vhostname, tftp_export, bootfile, dhcp,
-                          dns, ip6_dns, dnssearch, vdomainname, s);
+                          dns, ip6_dns, dnssearch, vdomainname,
+                          tftp_server_name, s);
     QTAILQ_INSERT_TAIL(&slirp_stacks, s, entry);
 
     for (config = slirp_configs; config; config = config->next) {
@@ -966,7 +968,8 @@  int net_init_slirp(const Netdev *netdev, const char *name,
                          user->ipv6_host, user->hostname, user->tftp,
                          user->bootfile, user->dhcpstart,
                          user->dns, user->ipv6_dns, user->smb,
-                         user->smbserver, dnssearch, user->domainname, errp);
+                         user->smbserver, dnssearch, user->domainname,
+                         user->tftp_server_name, errp);
 
     while (slirp_configs) {
         config = slirp_configs;
diff --git a/qapi/net.json b/qapi/net.json
index c86f351161..b3cd42f610 100644
--- a/qapi/net.json
+++ b/qapi/net.json
@@ -174,6 +174,8 @@ 
 #
 # @guestfwd: forward guest TCP connections
 #
+# @tftp-server-name: (optional) RFC2132 "TFTP server name" string (Since 3.1)
+#
 # Since: 1.2
 ##
 { 'struct': 'NetdevUserOptions',
@@ -198,7 +200,8 @@ 
     '*smb':       'str',
     '*smbserver': 'str',
     '*hostfwd':   ['String'],
-    '*guestfwd':  ['String'] } }
+    '*guestfwd':  ['String'],
+    '*tftp-server-name': 'str' } }
 
 ##
 # @NetdevTapOptions:
diff --git a/slirp/bootp.c b/slirp/bootp.c
index 9e7b53ba94..ed2cf3b96e 100644
--- a/slirp/bootp.c
+++ b/slirp/bootp.c
@@ -306,6 +306,14 @@  static void bootp_reply(Slirp *slirp, const struct bootp_t *bp)
             q += val;
         }
 
+        if (slirp->tftp_server_name) {
+            val = strlen(slirp->tftp_server_name);
+            *q++ = RFC2132_TFTP_SERVER_NAME;
+            *q++ = val;
+            memcpy(q, slirp->tftp_server_name, val);
+            q += val;
+        }
+
         if (slirp->vdnssearch) {
             size_t spaceleft = sizeof(rbp->bp_vend) - (q - rbp->bp_vend);
             val = slirp->vdnssearch_len;
diff --git a/slirp/bootp.h b/slirp/bootp.h
index 394525733e..4043489835 100644
--- a/slirp/bootp.h
+++ b/slirp/bootp.h
@@ -70,6 +70,7 @@ 
 #define RFC2132_MAX_SIZE	57
 #define RFC2132_RENEWAL_TIME    58
 #define RFC2132_REBIND_TIME     59
+#define RFC2132_TFTP_SERVER_NAME 66
 
 #define DHCPDISCOVER		1
 #define DHCPOFFER		2
diff --git a/slirp/libslirp.h b/slirp/libslirp.h
index 740408a96e..8bd2ad044b 100644
--- a/slirp/libslirp.h
+++ b/slirp/libslirp.h
@@ -16,7 +16,8 @@  Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   const char *tftp_path, const char *bootfile,
                   struct in_addr vdhcp_start, struct in_addr vnameserver,
                   struct in6_addr vnameserver6, const char **vdnssearch,
-                  const char *vdomainname, void *opaque);
+                  const char *vdomainname, const char *tftp_server_name,
+                  void *opaque);
 void slirp_cleanup(Slirp *slirp);
 
 void slirp_pollfds_fill(GArray *pollfds, uint32_t *timeout);
diff --git a/slirp/slirp.c b/slirp/slirp.c
index 5c3bd6163f..f62189c650 100644
--- a/slirp/slirp.c
+++ b/slirp/slirp.c
@@ -286,7 +286,8 @@  Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
                   const char *tftp_path, const char *bootfile,
                   struct in_addr vdhcp_start, struct in_addr vnameserver,
                   struct in6_addr vnameserver6, const char **vdnssearch,
-                  const char *vdomainname, void *opaque)
+                  const char *vdomainname, const char *tftp_server_name,
+                  void *opaque)
 {
     Slirp *slirp = g_malloc0(sizeof(Slirp));
 
@@ -321,6 +322,9 @@  Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
     slirp->vdhcp_startaddr = vdhcp_start;
     slirp->vnameserver_addr = vnameserver;
     slirp->vnameserver_addr6 = vnameserver6;
+    if (tftp_server_name) {
+        slirp->tftp_server_name = g_strdup(tftp_server_name);
+    }
 
     if (vdnssearch) {
         translate_dnssearch(slirp, vdnssearch);
diff --git a/slirp/slirp.h b/slirp/slirp.h
index 10b410898a..5ad982ee25 100644
--- a/slirp/slirp.h
+++ b/slirp/slirp.h
@@ -219,6 +219,8 @@  struct Slirp {
     GRand *grand;
     QEMUTimer *ra_timer;
 
+    char *tftp_server_name;
+
     void *opaque;
 };