-net user options for setting subnet and hostname
PATCH 1/1 -net user options for setting subnet and hostname
Currently the user-level networking (slirp) code in qemu uses subnet 10.0.2.0/24. Changing this hardcoded value, which can be desirable if that subnet is already used for other purposes, requires recompiling qemu.
The attached patch makes the subnet configurable on the command line via a new "subnet" option to "-net user". The subnet must be specified as "X.X.X.X/24".
This change also affected the handling of "-redir", since qemu uses X.X.X.15 as the target address if the user does not specify one. Since qemu parses command-line options immediately but defers acting on "-net" options, net_slirp_redir() wouldn't know what subnet to use. It seems that "-redir", "-smb" and "-tftp", which are all slirp-specific, logically belong under "-net user" anyway, so I converted them into "-net user" options. Doing so cleans up the code quite a bit, as slirp gets initialized only by net_client_init().
Finally, the patch includes the "hostname" option to "-net user", which I posted in a previous patch.
Comments and suggestions would be welcome.
--Ed
slirp/bootp.c +14 -4
@@ -27,8 +27,6 @@#define NB_ADDR 16 -#define START_ADDR 15 -#define LEASE_TIME (24 * 3600) typedef struct {
@@ -47,6 +45,8 @@ #define dprintf(fmt, args...)#endif +const char *dhcp_hostname; +static BOOTPClient *get_new_addr (struct in_addr *paddr) {BOOTPClient *bc;
@@ -60,7 +60,7 @@ found: bc = &bootp_clients[i]; bc->allocated =1 ; - paddr->s_addr =htonl (ntohl (special_addr.s_addr) | (i +START_ADDR )); + paddr->s_addr =htonl (ntohl (special_addr.s_addr) | (i +DHCP_START_ADDR ));return bc; }
@@ -77,7 +77,7 @@ found: bc = &bootp_clients[i]; bc->allocated =1 ; - paddr->s_addr =htonl (ntohl (special_addr.s_addr) | (i +START_ADDR )); + paddr->s_addr =htonl (ntohl (special_addr.s_addr) | (i +DHCP_START_ADDR ));return bc; }
@@ -228,6 +228,16 @@ val =htonl (LEASE_TIME );memcpy (q, &val,4 ); q +=4 ; + +if (dhcp_hostname && *dhcp_hostname) { + val =strlen (dhcp_hostname); +if (val >32 ) + val =32 ; + *q++ =RFC1533_HOSTNAME ; + *q++ = val; +memcpy (q, dhcp_hostname, val); + q += val; + } } *q++ =RFC1533_END ;
slirp/ctl.h +0 -3
@@ -2,6 +2,3 @@#define CTL_EXEC 1#define CTL_ALIAS 2#define CTL_DNS 3 - -#define CTL_SPECIAL "10.0.2.0" -#define CTL_LOCAL "10.0.2.15"
slirp/libslirp.h +1 -3
@@ -13,7 +13,7 @@extern "C" {#endif -void slirp_init (void ); +void slirp_init (struct in_addr subnet,char *dhcp_host,char *tftp_pfx);void slirp_select_fill (int *pnfds,fd_set *readfds,fd_set *writefds,fd_set *xfds);
@@ -31,8 +31,6 @@int slirp_add_exec (int do_pty,const char *args,int addr_low_byte,int guest_port); -extern const char *tftp_prefix; - #ifdef __cplusplus }#endif
slirp/slirp.c +9 -2
@@ -123,7 +123,7 @@ }#endif -void slirp_init (void ) +void slirp_init (struct in_addr subnet,char *dhcp_host,char *tftp_pfx) {// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
@@ -151,8 +151,13 @@exit (1 ); } -inet_aton (CTL_SPECIAL , &special_addr); + special_addr = subnet;getouraddr (); + +if (dhcp_host) + dhcp_hostname = dhcp_host; +if (tftp_pfx) + tftp_prefix = tftp_pfx; }#define CONN_CANFSEND (so) (((so)->so_state & (SS_FCANTSENDMORE|SS_ISFCONNECTED)) == SS_ISFCONNECTED)
@@ -639,6 +644,8 @@int slirp_redir (int is_udp,int host_port,struct in_addr guest_addr,int guest_port) { +if (!guest_addr.s_addr) + guest_addr.s_addr =htonl (ntohl (special_addr.s_addr) |DHCP_START_ADDR );if (is_udp) {if (!udp_listen (htons (host_port), guest_addr.s_addr,htons (guest_port),0 ))
slirp/slirp.h +5 -0
@@ -336,4 +336,9 @@#define errno (WSAGetLastError())#endif +extern const char *dhcp_hostname; +extern const char *tftp_prefix; + +#define DHCP_START_ADDR 15 +#endif
vl.c +58 -54
182 lines not on this page · raw message