Networking fixes and slirp enhancements
cover Networking fixes and slirp enhancements
This series starts with four networking-related fixes and then focuses on a grand refactoring of the slirp user space IP stack configuration.
The major contribution is that the virtual IP addresses used by slirp can now be (almost) freely configured. This enables sophisticated virtual network setups, specifically with guests that depends on specific addresses.
Find this series also at git://git.kiszka.org/qemu.git queues/net
Jan Kiszka (11):
net: Don't deliver to disabled interfaces in qemu_sendv_packet
net: Fix and improved ordered packet delivery
slirp: Avoid zombie processes after fork_exec
net: Real fix for check_params users
net: Improve parameter error reporting
slirp: Reorder initialization
Introduce get_next_param_value
slirp: Move smb, redir, tftp and bootp parameters and -net channel
slirp: Rework internal configuration
slirp: Rework external configuration interface
slirp: Bind support for host forwarding rules
hw/pci-hotplug.c | 7 +- net.c | 710 +++++++++++++++++++++++++++++++++++++++-------------- net.h | 5 +- qemu-options.hx | 226 ++++++++++-------- slirp/bootp.c | 30 +-- slirp/ctl.h | 7 - slirp/ip_icmp.c | 15 +- slirp/ip_input.c | 9 +- slirp/libslirp.h | 20 +- slirp/main.h | 12 +- slirp/misc.c | 9 +- slirp/misc.h | 4 +- slirp/slirp.c | 167 +++++++------ slirp/slirp.h | 1 - slirp/socket.c | 23 +- slirp/socket.h | 2 +- slirp/tcp_input.c | 16 +- slirp/tcp_subr.c | 133 +++------- slirp/tftp.c | 6 +- slirp/udp.c | 30 ++- slirp/udp.h | 2 +- sysemu.h | 5 +- vl.c | 77 ++++--- 23 files changed, 937 insertions(+), 579 deletions(-) delete mode 100644 slirp/ctl.h
--
Siemens AG, Corporate Technology, CT SE 2
Corporate Competence Center Embedded Linux
PATCH 1/11 net: Don't deliver to disabled interfaces in qemu_sendv_packet
---
net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
net.c +1 -1
@@ -494,7 +494,7 @@ ssize_t qemu_sendv_packet(VLANClientState *vc1, const struct iovec *iov,if (vc->link_down) len =calc_iov_length (iov, iovcnt); -if (vc->fd_readv) +else if (vc->fd_readv) len = vc->fd_readv (vc->opaque, iov, iovcnt);else if (vc->fd_read) len =vc_sendv_compat (vc, iov, iovcnt);
Re: [Qemu-devel] [PATCH 01/11] net: Don't deliver to disabled interfaces in qemu_sendv_packet
Quoted 11 lines · Jan Kiszka
Signed-off-by Jan Kiszka <[email protected]>---
net.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)net.c +0
-0
net.c ssize_t qemu_sendv_packet(VLANClientState *vc1, const struct iovec *iov, · line 498
Quoted 6 lines
net.c +1
-1@@ -494,7 +494,7 @@ ssize_t qemu_sendv_packet(VLANClientState *vc1, const struct iovec *iov,if (vc->link_down) len =calc_iov_length (iov, iovcnt); -if (vc->fd_readv) +else if (vc->fd_readv) len = vc->fd_readv (vc->opaque, iov, iovcnt);
Cheers,
Mark.
[Qemu-devel] "FLOSS bounty" ( FB )for running QEMU on SheevaPlug
I want to use QEMU on the SheevaPlug ( which is ARM based ).
http://www.marvell.com/products/embedded_processors/developer/kirkwood/sheevaplug.jsp
What size "FB" ($$$) will it take to get this done ? Everything I plan to do on the SheevaPlug will be FLOSS.
Best
Gus S. Calabrese
Re: [Qemu-devel] "FLOSS bounty" ( FB )for running QEMU on SheevaPlug
Quoted 5 lines · On Saturday 09 of May 2009 00:27:37 AGSCalabrese wrote:
I want to use QEMU on the SheevaPlug ( which is ARM based ).
http://www.marvell.com/products/embedded_processors/developer/kirkwood/shee
vaplug.jsp What size "FB" ($$$) will it take to get this done ? Everything I plan to do on the SheevaPlug will be FLOSS.
It does run linux so where's the problem ?
Quoted 3 lines
Best
Gus S. Calabrese
Re: [Qemu-devel] "FLOSS bounty" ( FB )for running QEMU on SheevaPlug
In reply to AGSCalabreseQuoted 5 lines · AGSCalabrese
I want to use QEMU on the SheevaPlug ( which is ARM based ).
http://www.marvell.com/products/embedded_processors/developer/kirkwood/shee
vaplug.jsp What size "FB" ($$$) will it take to get this done ? Everything I plan to do on the SheevaPlug will be FLOSS.
Should pretty much work already.
Paul
PATCH 2/11 net: Fix and improved ordered packet delivery
In reply to Jan KiszkaFix a race in qemu_send_packet when delivering deferred packets and add proper deferring also to qemu_sendv_packet.
---
net.c | 57 ++++++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 42 insertions(+), 15 deletions(-)
net.c +42 -15
@@ -438,8 +438,8 @@ void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size) vlan->delivering =1 ;qemu_deliver_packet (vc, buf, size);while ((packet = vlan->send_queue) !=NULL ) { -qemu_deliver_packet (packet->sender, packet->data, packet->size); vlan->send_queue = packet->next; +qemu_deliver_packet (packet->sender, packet->data, packet->size);qemu_free (packet); } vlan->delivering =0 ;
@@ -476,30 +476,57 @@ static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)return offset; } -ssize_t qemu_sendv_packet (VLANClientState *vc1,const struct iovec *iov, +ssize_t qemu_sendv_packet (VLANClientState *sender,const struct iovec *iov,int iovcnt) { -VLANState *vlan = vc1->vlan; +VLANState *vlan = sender->vlan;VLANClientState *vc; +VLANPacket *packet;ssize_t max_len =0 ; +int i; -if (vc1->link_down) +if (sender->link_down)return calc_iov_length (iov, iovcnt); -for (vc = vlan->first_client; vc !=NULL ; vc = vc->next) { -ssize_t len =0 ; +if (vlan->delivering) { + max_len =calc_iov_length (iov, iovcnt); -if (vc == vc1) -continue ; + packet =qemu_malloc (sizeof (VLANPacket) + max_len); + packet->next = vlan->send_queue; + packet->sender = sender; + packet->size =0 ; +for (i =0 ; i < iovcnt; i++) { +size_t len = iov[i].iov_len; + +memcpy (packet->data + packet->size, iov[i].iov_base, len); + packet->size += len; + } + vlan->send_queue = packet; + }else { + vlan->delivering =1 ; + +for (vc = vlan->first_client; vc !=NULL ; vc = vc->next) { +ssize_t len =0 ; -if (vc->link_down) - len =calc_iov_length (iov, iovcnt); -else if (vc->fd_readv) - len = vc->fd_readv (vc->opaque, iov, iovcnt); -else if (vc->fd_read) - len =vc_sendv_compat (vc, iov, iovcnt); +if (vc == sender) { +continue ; + } +if (vc->link_down) { + len =calc_iov_length (iov, iovcnt); + }else if (vc->fd_readv) { + len = vc->fd_readv (vc->opaque, iov, iovcnt); + }else if (vc->fd_read) { + len =vc_sendv_compat (vc, iov, iovcnt); + } + max_len =MAX (max_len, len); + } - max_len =MAX (max_len, len); +while ((packet = vlan->send_queue) !=NULL ) { + vlan->send_queue = packet->next; +qemu_deliver_packet (packet->sender, packet->data, packet->size); +qemu_free (packet); + } + vlan->delivering =0 ; }return max_len;
Re: [Qemu-devel] [PATCH 02/11] net: Fix and improved ordered packet delivery
Quoted 1 line · Jan Kiszka
Fix a race in
qemu_send_packetwhen delivering deferred packets and
Not really a race condition, but yeah - delivering a deferred packet can cause another packet to be queued.
Quoted 1 line
add proper deferring also to
qemu_sendv_packet.
Yep, we need this.
Quoted 1 line
Signed-off-by Jan Kiszka <[email protected]>
Cheers,
Mark.
PATCH 3/11 slirp: Avoid zombie processes after fork_exec
In reply to Jan KiszkaSlirp uses fork_exec for spawning service processes, and QEMU uses this for running smbd. As SIGCHLD is not handled, these processes become zombies on termination. Fix this by installing a proper signal handler, but also make sure we disable the signal while waiting on forked network setup/shutdown scripts.
---
net.c | 60 ++++++++++++++++++++++++++++++++++-------------------------- vl.c | 13 +++++++++++-- 2 files changed, 45 insertions(+), 28 deletions(-)
net.c +34 -26
@@ -1049,38 +1049,46 @@ static int tap_open(char *ifname, int ifname_size)static int launch_script (const char *setup_script,const char *ifname,int fd) { +sigset_t oldmask, mask;int pid, status;char *args[3 ];char **parg; -/* try to launch network script */ - pid =fork (); -if (pid >=0 ) { -if (pid ==0 ) { -int open_max =sysconf (_SC_OPEN_MAX), i; -for (i =0 ; i < open_max; i++) -if (i !=STDIN_FILENO && - i !=STDOUT_FILENO && - i !=STDERR_FILENO && - i != fd) -close (i); - - parg = args; - *parg++ = (char *)setup_script; - *parg++ = (char *)ifname; - *parg++ =NULL ; -execv (setup_script, args); -_exit (1 ); - } -while (waitpid (pid, &status,0 ) != pid); -if (!WIFEXITED (status) || -WEXITSTATUS (status) !=0 ) { -fprintf (stderr,"%s: could not launch network script\n" , - setup_script); -return -1 ; +sigemptyset (&mask); +sigaddset (&mask,SIGCHLD ); +sigprocmask (SIG_BLOCK , &mask, &oldmask); + +/* try to launch network script */ + pid =fork (); +if (pid ==0 ) { +int open_max =sysconf (_SC_OPEN_MAX), i; + +for (i =0 ; i < open_max; i++) { +if (i !=STDIN_FILENO && + i !=STDOUT_FILENO && + i !=STDERR_FILENO && + i != fd) { +close (i); } } -return 0 ; + parg = args; + *parg++ = (char *)setup_script; + *parg++ = (char *)ifname; + *parg++ =NULL ; +execv (setup_script, args); +_exit (1 ); + }else if (pid >0 ) { +while (waitpid (pid, &status,0 ) != pid) { +/* loop */ + } +sigprocmask (SIG_SETMASK , &oldmask,NULL ); + +if (WIFEXITED (status) &&WEXITSTATUS (status) ==0 ) { +return 0 ; + } + } +fprintf (stderr,"%s: could not launch network script\n" , setup_script); +return -1 ; } static int net_tap_init(VLANState *vlan, const char *model,
vl.c +11 -2
@@ -4780,7 +4780,12 @@ static void termsig_handler(int signal)qemu_system_shutdown_request (); } -static void termsig_setup (void ) +static void sigchld_handler (int signal) +{ +waitpid (-1 ,NULL ,WNOHANG ); +} + +static void sighandler_setup (void ) {struct sigaction act;
@@ -4789,6 +4794,10 @@ static void termsig_setup(void)sigaction (SIGINT , &act,NULL );sigaction (SIGHUP , &act,NULL );sigaction (SIGTERM , &act,NULL ); + + act.sa_handler = sigchld_handler; + act.sa_flags =SA_NOCLDSTOP ; + sigaction(SIGCHLD, &act, NULL); }#endif
@@ -5784,7 +5793,7 @@ int main(int argc, char **argv, char **envp)#ifndef _WIN32/* must be after terminal init, SDL library changes signal handlers */ -termsig_setup (); +sighandler_setup ();#endif /* Maintain compatibility with multiple stdio monitors */
PATCH 4/11 net: Real fix for check_params users
In reply to Jan KiszkaOK, last try: ea053add70 broke -net socket, ffad4116b9 tried to fix it but broke error reporting of invalid parameters. So this patch widely reverts ffad4116b9 again and intead fixes those callers of check_params that originally suffered from overwritten buffers by using separate ones.
---
net.c | 23 ++++++++++++----------- sysemu.h | 3 ++- vl.c | 39 ++++++++++++++------------------------- 3 files changed, 28 insertions(+), 37 deletions(-)
net.c +12 -11
@@ -1826,7 +1826,7 @@ int net_client_init(const char *device, const char *p)uint8_t *macaddr;int idx =nic_get_free_idx (); -if (check_params (nic_params, p) <0 ) { +if (check_params (buf,sizeof (buf), nic_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1877,7 +1877,7 @@ int net_client_init(const char *device, const char *p)static const char *const slirp_params[] = {"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,NULL }; -if (check_params (slirp_params, p) <0 ) { +if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1928,7 +1928,7 @@ int net_client_init(const char *device, const char *p) };char ifname[64 ]; -if (check_params (tap_params, p) <0 ) { +if (check_params (buf,sizeof (buf), tap_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1944,12 +1944,12 @@ int net_client_init(const char *device, const char *p)#elif defined (_AIX)#else if (!strcmp (device,"tap" )) { -char ifname[64 ]; +char ifname[64 ], chkbuf[64 ];char setup_script[1024 ], down_script[1024 ];int fd; vlan->nb_host_devs++;if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) { -if (check_params (fd_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1962,7 +1962,7 @@ int net_client_init(const char *device, const char *p)static const char *const tap_params[] = {"vlan" ,"name" ,"ifname" ,"script" ,"downscript" ,NULL }; -if (check_params (tap_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), tap_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1981,9 +1981,10 @@ int net_client_init(const char *device, const char *p) } else#endif if (!strcmp (device,"socket" )) { +char chkbuf[64 ];if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {int fd; -if (check_params (fd_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1996,7 +1997,7 @@ int net_client_init(const char *device, const char *p)static const char *const listen_params[] = {"vlan" ,"name" ,"listen" ,NULL }; -if (check_params (listen_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), listen_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2006,7 +2007,7 @@ int net_client_init(const char *device, const char *p)static const char *const connect_params[] = {"vlan" ,"name" ,"connect" ,NULL }; -if (check_params (connect_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), connect_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2016,7 +2017,7 @@ int net_client_init(const char *device, const char *p)static const char *const mcast_params[] = {"vlan" ,"name" ,"mcast" ,NULL }; -if (check_params (mcast_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), mcast_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2037,7 +2038,7 @@ int net_client_init(const char *device, const char *p)char vde_sock[1024 ], vde_group[512 ];int vde_port, vde_mode; -if (check_params (vde_params, p) <0 ) { +if (check_params (buf,sizeof (buf), vde_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
sysemu.h +2 -1
@@ -257,6 +257,7 @@ const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);const char *get_opt_value (char *buf,int buf_size,const char *p);int get_param_value (char *buf,int buf_size,const char *tag,const char *str); -int check_params (const char *const *params,const char *str); +int check_params (char *buf,int buf_size, +const char *const *params,const char *str);#endif
vl.c +14 -25
@@ -1869,45 +1869,34 @@ int get_param_value(char *buf, int buf_size,return 0 ; } -int check_params (const char *const *params,const char *str) +int check_params (char *buf,int buf_size, +const char *const *params,const char *str) { -int name_buf_size =1 ;const char *p; -char *name_buf; -int i, len; -int ret =0 ; - -for (i =0 ; params[i] !=NULL ; i++) { - len =strlen (params[i]) +1 ; -if (len > name_buf_size) { - name_buf_size = len; - } - } - name_buf =qemu_malloc (name_buf_size); +int i; p = str;while (*p !='\0' ) { - p =get_opt_name (name_buf, name_buf_size, p,'=' ); + p =get_opt_name (buf, buf_size, p,'=' );if (*p !='=' ) { - ret =-1 ; -break ; +return -1 ; } p++; -for (i =0 ; params[i] !=NULL ; i++) -if (!strcmp (params[i], name_buf)) +for (i =0 ; params[i] !=NULL ; i++) { +if (!strcmp (params[i], buf)) {break ; + } + }if (params[i] ==NULL ) { - ret =-1 ; -break ; +return -1 ; } p =get_opt_value (NULL ,0 , p); -if (*p !=',' ) +if (*p !=',' ) {break ; + } p++; } - -qemu_free (name_buf); -return ret; +return 0 ; }/***********************************************************/
@@ -2260,7 +2249,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)"cache" ,"format" ,"serial" ,"werror" , NULL }; -if (check_params (params, str) <0 ) { +if (check_params (buf,sizeof (buf), params, str) <0 ) {fprintf (stderr,"qemu: unknown parameter '%s' in '%s'\n" , buf, str);return -1 ;
Re: [Qemu-devel] [PATCH 04/11] net: Real fix for check_params users
Hi Jan,
Quoted 19 lines · Jan Kiszka
OK, last try:
ea053add70broke -net socket,ffad4116b9tried to fix it but broke error reporting of invalid parameters. So this patch widely revertsffad4116b9again and intead fixes those callers ofcheck_paramsthat originally suffered from overwritten buffers by using separate ones.Signed-off-by Jan Kiszka <[email protected]>---
net.c | 23 ++++++++++++----------- sysemu.h | 3 ++- vl.c | 39 ++++++++++++++------------------------- 3 files changed, 28 insertions(+), 37 deletions(-)net.c +0
-0
net.c int net_client_init(const char *device, const char *p) · line 1832
Quoted 8 lines
net.c +1
-1@@ -1826,7 +1826,7 @@ int net_client_init(const char *device, const char *p)uint8_t *macaddr;int idx =nic_get_free_idx (); -if (check_params (nic_params, p) <0 ) { +if (check_params (buf,sizeof (buf), nic_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
All callers used the scratch buffer to obtain the invalid parameter name for error messages. Now, e.g. I get:
$> qemu-system-x86_64 -drive foo=bar
qemu: unknown parameter '' in 'foo=bar'
Cheers,
Mark.
Re: [Qemu-devel] [PATCH 04/11] net: Real fix for check_params users
Quoted 34 lines · Mark McLoughlin
Hi Jan,
Quoted 19 lines · Jan Kiszka
OK, last try:
ea053add70broke -net socket,ffad4116b9tried to fix it but broke error reporting of invalid parameters. So this patch widely revertsffad4116b9again and intead fixes those callers ofcheck_paramsthat originally suffered from overwritten buffers by using separate ones.Signed-off-by Jan Kiszka <[email protected]>---
net.c | 23 ++++++++++++----------- sysemu.h | 3 ++- vl.c | 39 ++++++++++++++------------------------- 3 files changed, 28 insertions(+), 37 deletions(-)net.c +0
-0net.c int net_client_init(const char *device, const char *p) · line 1832
Quoted 8 lines
net.c +1
-1@@ -1826,7 +1826,7 @@ int net_client_init(const char *device, const char *p)uint8_t *macaddr;int idx =nic_get_free_idx (); -if (check_params (nic_params, p) <0 ) { +if (check_params (buf,sizeof (buf), nic_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;All callers used the scratch buffer to obtain the invalid parameter name for error messages. Now, e.g. I get:
Quoted 3 lines
$> qemu-system-x86_64 -drive foo=bar
qemu: unknown parameter '' in 'foo=bar'
Works for me with that patch applied. Are you sure you ran the right (==patched) instance of qemu-system-x86_64? :->
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 04/11] net: Real fix for check_params users
Quoted 35 lines · Jan Kiszka
Quoted 34 lines · Mark McLoughlin
Hi Jan,
Quoted 19 lines · Jan Kiszka
OK, last try:
ea053add70broke -net socket,ffad4116b9tried to fix it but broke error reporting of invalid parameters. So this patch widely revertsffad4116b9again and intead fixes those callers ofcheck_paramsthat originally suffered from overwritten buffers by using separate ones.Signed-off-by Jan Kiszka <[email protected]>---
net.c | 23 ++++++++++++----------- sysemu.h | 3 ++- vl.c | 39 ++++++++++++++------------------------- 3 files changed, 28 insertions(+), 37 deletions(-)net.c +0
-0net.c int net_client_init(const char *device, const char *p) · line 1832
Quoted 8 lines
net.c +1
-1@@ -1826,7 +1826,7 @@ int net_client_init(const char *device, const char *p)uint8_t *macaddr;int idx =nic_get_free_idx (); -if (check_params (nic_params, p) <0 ) { +if (check_params (buf,sizeof (buf), nic_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;All callers used the scratch buffer to obtain the invalid parameter name for error messages. Now, e.g. I get:
Quoted 6 lines
Quoted 3 lines
$> qemu-system-x86_64 -drive foo=bar
qemu: unknown parameter '' in 'foo=bar'Works for me with that patch applied. Are you sure you ran the right (==patched) instance of qemu-system-x86_64? :->
Apologies, I was confused - I thought this patch had already been applied and was causing the problem that it actually fixes :-)
Cheers,
Mark.
Re: [Qemu-devel] [PATCH 04/11] net: Real fix for check_params users
In reply to Jan KiszkaQuoted 7 lines · Jan Kiszka
OK, last try:
ea053add70broke -net socket,ffad4116b9tried to fix it but broke error reporting of invalid parameters. So this patch widely revertsffad4116b9again and intead fixes those callers ofcheck_paramsthat originally suffered from overwritten buffers by using separate ones.Signed-off-by Jan Kiszka <[email protected]>
Okay, I think we should revert Kevin's fix from master and replace it with this one.
Quoted 4 lines
net.c +0
-0@@ -1944,12 +1944,12 @@ int net_client_init(const char *device, const char *p)#elif defined (_AIX)#else if (!strcmp (device,"tap" )) {
net.c int net_client_init(const char *device, const char *p) · line 1954
Quoted 10 lines
net.c +2
-2-char ifname[64 ]; +char ifname[64 ], chkbuf[64 ];char setup_script[1024 ], down_script[1024 ];int fd; vlan->nb_host_devs++;if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) { -if (check_params (fd_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);
Should use chkbuf in the fprintf.
Following up with a patch series.
Cheers,
Mark.
PATCH 1/3 Revert "Fix output of uninitialized strings"
This reverts commit 8cf07dcbe7691dbe4f47563058659dba6ef66b05.
This is a sorry saga.
This commit:
8e4416af45 net: Add parameter checks for VLAN clients
broken '-net socket' and this commit:
ffad4116b9 net: Fix -net socket parameter checks
fixed the problem but introduced another problem which this commit:
8cf07dcbe7 Fix output of uninitialized strings
fixed that final problem, but causing us to lose some error reporting information in the process.
Meanwhile Jan posted a patch to mostly re-do ffad4116b9 in a way that fixes the original issue, but without losing the error reporting information. So, let's revert 8cf07dcbe7 and apply Jan's patch.
--- net.c | 30 ++++++++++++++++++++---------- vl.c | 3 ++- 2 files changed, 22 insertions(+), 11 deletions(-)
net.c +20 -10
@@ -1912,7 +1912,8 @@ int net_client_init(const char *device, const char *p)int idx =nic_get_free_idx ();if (check_params (nic_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; }if (idx ==-1 || nb_nics >=MAX_NICS ) {
@@ -1962,7 +1963,8 @@ int net_client_init(const char *device, const char *p) "vlan", "name", "hostname", "restrict", "ip", NULL };if (check_params (slirp_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; }if (get_param_value (buf,sizeof (buf),"hostname" , p)) {
@@ -2012,7 +2014,8 @@ int net_client_init(const char *device, const char *p)char ifname[64 ];if (check_params (tap_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; }if (get_param_value (ifname,sizeof (ifname),"ifname" , p) <=0 ) {
@@ -2032,7 +2035,8 @@ int net_client_init(const char *device, const char *p) vlan->nb_host_devs++;if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {if (check_params (fd_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; } fd =strtol (buf,NULL ,0 );
@@ -2044,7 +2048,8 @@ int net_client_init(const char *device, const char *p) "vlan", "name", "ifname", "script", "downscript", NULL };if (check_params (tap_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; }if (get_param_value (ifname,sizeof (ifname),"ifname" , p) <=0 ) {
@@ -2064,7 +2069,8 @@ int net_client_init(const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {int fd;if (check_params (fd_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; } fd =strtol (buf,NULL ,0 );
@@ -2076,7 +2082,8 @@ int net_client_init(const char *device, const char *p) "vlan", "name", "listen", NULL };if (check_params (listen_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; } ret =net_socket_listen_init (vlan, device, name, buf);
@@ -2085,7 +2092,8 @@ int net_client_init(const char *device, const char *p) "vlan", "name", "connect", NULL };if (check_params (connect_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; } ret =net_socket_connect_init (vlan, device, name, buf);
@@ -2094,7 +2102,8 @@ int net_client_init(const char *device, const char *p) "vlan", "name", "mcast", NULL };if (check_params (mcast_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; } ret =net_socket_mcast_init (vlan, device, name, buf);
@@ -2114,7 +2123,8 @@ int net_client_init(const char *device, const char *p)int vde_port, vde_mode;if (check_params (vde_params, p) <0 ) { -fprintf (stderr,"qemu: invalid parameter in '%s'\n" , p); +fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , + buf, p);return -1 ; } vlan->nb_host_devs++;
vl.c +2 -1
@@ -2227,7 +2227,8 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) NULL };if (check_params (params, str) <0 ) { -fprintf (stderr,"qemu: unknown parameter in '%s'\n" , str); +fprintf (stderr,"qemu: unknown parameter '%s' in '%s'\n" , + buf, str);return -1 ; }
Signature · 1 line
1.6.2.2
PATCH 2/3 net: Real fix for check_params users
From: Jan Kiszka <[email protected]>
OK, last try: 8e4416af45 broke -net socket, ffad4116b9 tried to fix it but broke error reporting of invalid parameters. So this patch widely reverts ffad4116b9 again and intead fixes those callers of check_params that originally suffered from overwritten buffers by using separate ones.
--- net.c | 23 ++++++++++++----------- sysemu.h | 3 ++- vl.c | 39 ++++++++++++++------------------------- 3 files changed, 28 insertions(+), 37 deletions(-)
net.c +12 -11
@@ -1911,7 +1911,7 @@ int net_client_init(const char *device, const char *p)uint8_t *macaddr;int idx =nic_get_free_idx (); -if (check_params (nic_params, p) <0 ) { +if (check_params (buf,sizeof (buf), nic_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -1962,7 +1962,7 @@ int net_client_init(const char *device, const char *p)static const char *const slirp_params[] = {"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,NULL }; -if (check_params (slirp_params, p) <0 ) { +if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2013,7 +2013,7 @@ int net_client_init(const char *device, const char *p) };char ifname[64 ]; -if (check_params (tap_params, p) <0 ) { +if (check_params (buf,sizeof (buf), tap_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2029,12 +2029,12 @@ int net_client_init(const char *device, const char *p)#elif defined (_AIX)#else if (!strcmp (device,"tap" )) { -char ifname[64 ]; +char ifname[64 ], chkbuf[64 ];char setup_script[1024 ], down_script[1024 ];int fd; vlan->nb_host_devs++;if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) { -if (check_params (fd_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2047,7 +2047,7 @@ int net_client_init(const char *device, const char *p)static const char *const tap_params[] = {"vlan" ,"name" ,"ifname" ,"script" ,"downscript" ,NULL }; -if (check_params (tap_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), tap_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2066,9 +2066,10 @@ int net_client_init(const char *device, const char *p) } else#endif if (!strcmp (device,"socket" )) { +char chkbuf[64 ];if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {int fd; -if (check_params (fd_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2081,7 +2082,7 @@ int net_client_init(const char *device, const char *p)static const char *const listen_params[] = {"vlan" ,"name" ,"listen" ,NULL }; -if (check_params (listen_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), listen_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2091,7 +2092,7 @@ int net_client_init(const char *device, const char *p)static const char *const connect_params[] = {"vlan" ,"name" ,"connect" ,NULL }; -if (check_params (connect_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), connect_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2101,7 +2102,7 @@ int net_client_init(const char *device, const char *p)static const char *const mcast_params[] = {"vlan" ,"name" ,"mcast" ,NULL }; -if (check_params (mcast_params, p) <0 ) { +if (check_params (chkbuf,sizeof (chkbuf), mcast_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
@@ -2122,7 +2123,7 @@ int net_client_init(const char *device, const char *p)char vde_sock[1024 ], vde_group[512 ];int vde_port, vde_mode; -if (check_params (vde_params, p) <0 ) { +if (check_params (buf,sizeof (buf), vde_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , buf, p);return -1 ;
sysemu.h +2 -1
@@ -267,7 +267,8 @@ void usb_info(Monitor *mon);int get_param_value (char *buf,int buf_size,const char *tag,const char *str); -int check_params (const char *const *params,const char *str); +int check_params (char *buf,int buf_size, +const char *const *params,const char *str);void register_devices (void );
vl.c +14 -25
@@ -1835,45 +1835,34 @@ int get_param_value(char *buf, int buf_size,return 0 ; } -int check_params (const char *const *params,const char *str) +int check_params (char *buf,int buf_size, +const char *const *params,const char *str) { -int name_buf_size =1 ;const char *p; -char *name_buf; -int i, len; -int ret =0 ; - -for (i =0 ; params[i] !=NULL ; i++) { - len =strlen (params[i]) +1 ; -if (len > name_buf_size) { - name_buf_size = len; - } - } - name_buf =qemu_malloc (name_buf_size); +int i; p = str;while (*p !='\0' ) { - p =get_opt_name (name_buf, name_buf_size, p,'=' ); + p =get_opt_name (buf, buf_size, p,'=' );if (*p !='=' ) { - ret =-1 ; -break ; +return -1 ; } p++; -for (i =0 ; params[i] !=NULL ; i++) -if (!strcmp (params[i], name_buf)) +for (i =0 ; params[i] !=NULL ; i++) { +if (!strcmp (params[i], buf)) {break ; + } + }if (params[i] ==NULL ) { - ret =-1 ; -break ; +return -1 ; } p =get_opt_value (NULL ,0 , p); -if (*p !=',' ) +if (*p !=',' ) {break ; + } p++; } - -qemu_free (name_buf); -return ret; +return 0 ; }/***********************************************************/
@@ -2226,7 +2215,7 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)"cache" ,"format" ,"serial" ,"werror" , NULL }; -if (check_params (params, str) <0 ) { +if (check_params (buf,sizeof (buf), params, str) <0 ) {fprintf (stderr,"qemu: unknown parameter '%s' in '%s'\n" , buf, str);return -1 ;
Signature · 1 line
1.6.2.2
PATCH 3/3 net: fix error reporting for some net parameter checks
A small bit of confusion between buffers is causing errors like:
qemu: invalid parameter '10' in 'script=/etc/qemu-ifup,fd=10'
instead of:
qemu: invalid parameter 'script' in 'script=/etc/qemu-ifup,fd=10'
--- net.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)
net.c +6 -6
@@ -2036,7 +2036,7 @@ int net_client_init(const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } fd =strtol (buf,NULL ,0 );
@@ -2049,7 +2049,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), tap_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; }if (get_param_value (ifname,sizeof (ifname),"ifname" , p) <=0 ) {
@@ -2071,7 +2071,7 @@ int net_client_init(const char *device, const char *p)int fd;if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } fd =strtol (buf,NULL ,0 );
@@ -2084,7 +2084,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), listen_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } ret =net_socket_listen_init (vlan, device, name, buf);
@@ -2094,7 +2094,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), connect_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } ret =net_socket_connect_init (vlan, device, name, buf);
@@ -2104,7 +2104,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), mcast_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } ret =net_socket_mcast_init (vlan, device, name, buf);
Signature · 1 line
1.6.2.2
[Qemu-devel] Re: [PATCH 3/3] net: fix error reporting for some net parameter checks
Quoted 63 lines · Mark McLoughlin
A small bit of confusion between buffers is causing errors like:
qemu: invalid parameter '10' in 'script=/etc/qemu-ifup,fd=10'
instead of:
qemu: invalid parameter 'script' in 'script=/etc/qemu-ifup,fd=10'
Signed-off-by Mark McLoughlin <[email protected]>--- net.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-)net.c +5
-5@@ -2036,7 +2036,7 @@ int net_client_init(const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"fd" , p) >0 ) {if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } fd =strtol (buf,NULL ,0 );@@ -2049,7 +2049,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), tap_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; }if (get_param_value (ifname,sizeof (ifname),"ifname" , p) <=0 ) {@@ -2071,7 +2071,7 @@ int net_client_init(const char *device, const char *p)int fd;if (check_params (chkbuf,sizeof (chkbuf), fd_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } fd =strtol (buf,NULL ,0 );@@ -2084,7 +2084,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), listen_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } ret =net_socket_listen_init (vlan, device, name, buf);@@ -2094,7 +2094,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), connect_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } ret =net_socket_connect_init (vlan, device, name, buf);
net.c int net_client_init(const char *device, const char *p) · line 2110
Quoted 8 lines
net.c +1
-1@@ -2104,7 +2104,7 @@ int net_client_init(const char *device, const char *p) };if (check_params (chkbuf,sizeof (chkbuf), mcast_params, p) <0 ) {fprintf (stderr,"qemu: invalid parameter '%s' in '%s'\n" , - buf, p); + chkbuf, p);return -1 ; } ret =net_socket_mcast_init (vlan, device, name, buf);
Ack for all three.
(My dear. I promise to never touch these param checks again.)
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 04/11] net: Real fix for check_params users
In reply to Mark McLoughlinQuoted 11 lines · Mark McLoughlin
Quoted 7 lines · Jan Kiszka
OK, last try:
ea053add70broke -net socket,ffad4116b9tried to fix it but broke error reporting of invalid parameters. So this patch widely revertsffad4116b9again and intead fixes those callers ofcheck_paramsthat originally suffered from overwritten buffers by using separate ones.Signed-off-by Jan Kiszka <[email protected]>Okay, I think we should revert Kevin's fix from master and replace it with this one.
Agreed. I wasn't aware of this one.
Kevin
PATCH 5/11 net: Improve parameter error reporting
In reply to Jan KiszkaAs host network devices can also be instantiated via the monitor, errors should then be reported to the related monitor instead of stderr. This requires larger refactoring, so this patch starts small with introducing a helper to catch both cases and convert net_client_init as well as net_slirp_redir.
---
hw/pci-hotplug.c | 7 ++- net.c | 131 ++++++++++++++++++++++++++++-------------------------- net.h | 2 - vl.c | 2 - 4 files changed, 75 insertions(+), 67 deletions(-)
hw/pci-hotplug.c +4 -3
@@ -33,11 +33,12 @@#include "virtio-blk.h" #if defined(TARGET_I386 ) || defined(TARGET_X86_64 ) -static PCIDevice *qemu_pci_hot_add_nic (PCIBus *pci_bus,const char *opts) +static PCIDevice *qemu_pci_hot_add_nic (Monitor *mon,PCIBus *pci_bus, +const char *opts) {int ret; - ret =net_client_init ("nic" , opts); + ret =net_client_init (mon,"nic" , opts);if (ret <0 )return NULL ;return pci_nic_init (pci_bus, &nd_table[ret],-1 ,"rtl8139" );
@@ -151,7 +152,7 @@ void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type, }if (strcmp (type,"nic" ) ==0 ) - dev =qemu_pci_hot_add_nic (pci_bus, opts); + dev =qemu_pci_hot_add_nic (mon, pci_bus, opts);else if (strcmp (type,"storage" ) ==0 ) dev =qemu_pci_hot_add_storage (mon, pci_bus, opts);else
net.c +69 -62
299 lines not on this page · raw message
net.h +1 -1
@@ -108,7 +108,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,void net_checksum_calculate (uint8_t *data,int length);/* from net.c */ -int net_client_init (const char *device,const char *p); +int net_client_init (Monitor *mon,const char *device,const char *p);void net_client_uninit (NICInfo *nd);int net_client_parse (const char *str);void net_slirp_smb (const char *exported_dir);
vl.c +1 -1
@@ -2730,7 +2730,7 @@ static int usb_device_add(const char *devname, int is_hotplug) }else if (strstart (devname,"net:" , &p)) {int nic = nb_nics; -if (net_client_init ("nic" , p) <0 ) +if (net_client_init (NULL ,"nic" , p) <0 )return -1 ; nd_table[nic].model ="usb" ; dev =usb_net_init (&nd_table[nic]);
PATCH 6/11 slirp: Reorder initialization
In reply to Jan KiszkaThis patch reorders the initialization of slirp itself as well as its associated features smb and redirection. So far the first reference to slirp triggered the initialization, independent of the actual -net user option which may carry additional parameters. Now we save any request to add a smb export or some redirections until the actual initialization of the stack. This also allows to move a few parameters that were passed via global variable into the argument list of net_slirp_init.
---
net.c | 119 ++++++++++++++++++++++++++++++++++++++++-------------- slirp/libslirp.h | 2 - slirp/slirp.c | 2 - 3 files changed, 90 insertions(+), 33 deletions(-)
net.c +88 -31
@@ -551,11 +551,21 @@ static void config_error(Monitor *mon, const char *fmt, ...)/* slirp network adapter */ +struct slirp_config_str { +struct slirp_config_str *next; +const char *str; +}; +static int slirp_inited; -static int slirp_restrict; -static char *slirp_ip; +static struct slirp_config_str *slirp_redirs; +#ifndef _WIN32 +static const char *slirp_smb_export; +#endif static VLANClientState *slirp_vc; +static void slirp_smb (const char *exported_dir); +static void slirp_redirection (Monitor *mon,const char *redir_str); +int slirp_can_output (void ) {return !slirp_vc ||qemu_can_send_packet (slirp_vc);
@@ -593,7 +603,8 @@ static void net_slirp_cleanup(VLANClientState *vc) slirp_in_use =0 ; } -static int net_slirp_init (VLANState *vlan,const char *model,const char *name) +static int net_slirp_init (VLANState *vlan,const char *model,const char *name, +int restricted,const char *ip) {if (slirp_in_use) {/* slirp only supports a single instance so far */
@@ -601,31 +612,41 @@ static int net_slirp_init(VLANState *vlan, const char *model, const char *name) }if (!slirp_inited) { slirp_inited =1 ; -slirp_init (slirp_restrict, slirp_ip); +slirp_init (restricted, ip); + +while (slirp_redirs) { +struct slirp_config_str *config = slirp_redirs; + +slirp_redirection (NULL , config->str); + slirp_redirs = config->next; +qemu_free (config); + } +#ifndef _WIN32 +if (slirp_smb_export) { +slirp_smb (slirp_smb_export); + } +#endif } - slirp_vc =qemu_new_vlan_client (vlan, model, name, - slirp_receive,NULL , net_slirp_cleanup,NULL ); + + slirp_vc =qemu_new_vlan_client (vlan, model, name, slirp_receive, +NULL , net_slirp_cleanup,NULL ); slirp_vc->info_str[0 ] ='\0' ; slirp_in_use =1 ;return 0 ; } -void net_slirp_redir (Monitor *mon,const char *redir_str) +static void slirp_redirection (Monitor *mon,const char *redir_str) { -int is_udp; -char buf[256 ], *r; -const char *p;struct in_addr guest_addr;int host_port, guest_port; - -if (!slirp_inited) { - slirp_inited =1 ; -slirp_init (slirp_restrict, slirp_ip); - } +const char *p; +char buf[256 ], *r; +int is_udp; p = redir_str; -if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { goto fail_syntax; + }if (!strcmp (buf,"tcp" ) || buf[0 ] =='\0' ) { is_udp =0 ; }else if (!strcmp (buf,"udp" )) {
@@ -634,23 +655,28 @@ void net_slirp_redir(Monitor *mon, const char *redir_str) goto fail_syntax; } -if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { goto fail_syntax; + } host_port =strtol (buf, &r,0 ); -if (r == buf) +if (r == buf) { goto fail_syntax; + } -if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { goto fail_syntax; + }if (buf[0 ] =='\0' ) {pstrcpy (buf,sizeof (buf),"10.0.2.15" ); } -if (!inet_aton (buf, &guest_addr)) +if (!inet_aton (buf, &guest_addr)) { goto fail_syntax; + } guest_port =strtol (p, &r,0 ); -if (r == p) +if (r == p) { goto fail_syntax; + }if (slirp_redir (is_udp, host_port, guest_addr, guest_port) <0 ) {config_error (mon,"could not set up redirection '%s'\n" , redir_str);
@@ -661,6 +687,25 @@ void net_slirp_redir(Monitor *mon, const char *redir_str)config_error (mon,"invalid redirection format '%s'\n" , redir_str); } +void net_slirp_redir (Monitor *mon,const char *redir_str) +{ +struct slirp_config_str *config; + +if (!slirp_inited) { +if (mon) { +monitor_printf (mon,"user mode network stack not in use\n" ); + }else { + config =qemu_malloc (sizeof (*config)); + config->str = redir_str; + config->next = slirp_redirs; + slirp_redirs = config; + } +return ; + } + +slirp_redirection (mon, redir_str); +} +#ifndef _WIN32static char smb_dir[1024 ];
@@ -696,18 +741,12 @@ static void smb_exit(void)erase_dir (smb_dir); } -/* automatic user mode samba server configuration */ -void net_slirp_smb (const char *exported_dir) +static void slirp_smb (const char *exported_dir) {char smb_conf[1024 ];char smb_cmdline[1024 ];FILE *f; -if (!slirp_inited) { - slirp_inited =1 ; -slirp_init (slirp_restrict, slirp_ip); - } -/* XXX: better tmp dir construction */ snprintf (smb_dir,sizeof (smb_dir),"/tmp/qemu-smb.%ld" , (long )getpid ());if (mkdir (smb_dir,0700 ) <0 ) {
@@ -751,7 +790,21 @@ void net_slirp_smb(const char *exported_dir) slirp_add_exec(0, smb_cmdline, 4, 139); } +/* automatic user mode samba server configuration */ +void net_slirp_smb (const char *exported_dir) +{ +if (slirp_smb_export) { +fprintf (stderr,"-smb given twice\n" ); +exit (1 ); + } + slirp_smb_export = exported_dir; +if (slirp_inited) { +slirp_smb (exported_dir); + } +} +#endif /* !defined(_WIN32) */ +void do_info_slirp (Monitor *mon) {slirp_stats ();
@@ -1885,6 +1938,9 @@ int net_client_init(Monitor *mon, const char *device, const char *p)static const char *const slirp_params[] = {"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,NULL }; +int restricted =0 ; +char *ip =NULL ; +if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) {config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p); ret =-1 ;
@@ -1894,13 +1950,14 @@ int net_client_init(Monitor *mon, const char *device, const char *p)pstrcpy (slirp_hostname,sizeof (slirp_hostname), buf); }if (get_param_value (buf,sizeof (buf),"restrict" , p)) { - slirp_restrict = (buf[0 ] =='y' ) ?1 :0 ; + restricted = (buf[0 ] =='y' ) ?1 :0 ; }if (get_param_value (buf,sizeof (buf),"ip" , p)) { - slirp_ip =strdup (buf); + ip =qemu_strdup (buf); } vlan->nb_host_devs++; - ret =net_slirp_init (vlan, device, name); + ret =net_slirp_init (vlan, device, name, restricted, ip); +qemu_free (ip); }else if (!strcmp (device,"channel" )) {long port;char name[20 ], *devname;
slirp/libslirp.h +1 -1
@@ -5,7 +5,7 @@extern "C" {#endif -void slirp_init (int restricted,char *special_ip); +void slirp_init (int restricted,const char *special_ip);void slirp_select_fill (int *pnfds,fd_set *readfds,fd_set *writefds,fd_set *xfds);
slirp/slirp.c +1 -1
@@ -171,7 +171,7 @@ static void slirp_cleanup(void)static void slirp_state_save (QEMUFile *f,void *opaque);static int slirp_state_load (QEMUFile *f,void *opaque,int version_id); -void slirp_init (int restricted,char *special_ip) +void slirp_init (int restricted,const char *special_ip) {// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
PATCH 7/11 Introduce get_next_param_value
In reply to Jan KiszkaIn order to parse multiple instances of the same param=value pair, introduce get_next_param_value which can pass back to string parsing position after reading a parameter value.
---
sysemu.h | 2 ++ vl.c | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-)
sysemu.h +2 -0
@@ -257,6 +257,8 @@ const char *get_opt_name(char *buf, int buf_size, const char *p, char delim);const char *get_opt_value (char *buf,int buf_size,const char *p);int get_param_value (char *buf,int buf_size,const char *tag,const char *str); +int get_next_param_value (char *buf,int buf_size, +const char *tag,const char **pstr);int check_params (char *buf,int buf_size,const char *const *params,const char *str);
vl.c +13 -4
@@ -1844,20 +1844,23 @@ const char *get_opt_value(char *buf, int buf_size, const char *p)return p; } -int get_param_value (char *buf,int buf_size, -const char *tag,const char *str) +int get_next_param_value (char *buf,int buf_size, +const char *tag,const char **pstr) {const char *p;char option[128 ]; - p = str; + p = *pstr;for (;;) { p =get_opt_name (option,sizeof (option), p,'=' );if (*p !='=' )break ; p++;if (!strcmp (tag, option)) { - (void )get_opt_value (buf, buf_size, p); + *pstr =get_opt_value (buf, buf_size, p); +if (**pstr ==',' ) { + (*pstr)++; + }return strlen (buf); }else { p =get_opt_value (NULL ,0 , p);
@@ -1869,6 +1872,12 @@ int get_param_value(char *buf, int buf_size,return 0 ; } +int get_param_value (char *buf,int buf_size, +const char *tag,const char *str) +{ +return get_next_param_value (buf, buf_size, tag, &str); +} +int check_params (char *buf,int buf_size,const char *const *params,const char *str) {
PATCH 8/11 slirp: Move smb, redir, tftp and bootp parameters and -net channel
In reply to Jan KiszkaSo far a couple of slirp-related parameters were expressed via stand-alone command line options. This it inconsistent and unintuitive. Moreover, it prevents both dynamically reconfigured (host_net_add/ delete) and multi-instance slirp.
This patch refactors the configuration by turning -smb, -redir, -tftp and -bootp as well as -net channel into options of "-net user". The old stand-alone command line options are still processed, but no longer advertised. This allows smooth migration of management applications to to the new syntax and also the extension of that syntax later in this series.
---
net.c | 157 +++++++++++++++++++++++++++++++---------- net.h | 3 + qemu-options.hx | 209 +++++++++++++++++++++++++++++------------------------- slirp/bootp.c | 4 + slirp/libslirp.h | 5 + slirp/main.h | 2 + slirp/slirp.c | 10 ++- slirp/tftp.c | 6 +- vl.c | 6 +- 9 files changed, 254 insertions(+), 148 deletions(-)
net.c +120 -37
@@ -551,13 +551,18 @@ static void config_error(Monitor *mon, const char *fmt, ...)/* slirp network adapter */ +#define SLIRP_CFG_REDIR 1 +struct slirp_config_str {struct slirp_config_str *next; -const char *str; +int flags; +char str[1024 ]; };static int slirp_inited; -static struct slirp_config_str *slirp_redirs; +static struct slirp_config_str *slirp_configs; +const char *legacy_tftp_prefix; +const char *legacy_bootp_filename;#ifndef _WIN32static const char *slirp_smb_export;#endif
@@ -565,6 +570,7 @@ static VLANClientState *slirp_vc;static void slirp_smb (const char *exported_dir);static void slirp_redirection (Monitor *mon,const char *redir_str); +static void vmchannel_init (Monitor *mon,const char *config_str);int slirp_can_output (void ) {
@@ -603,25 +609,40 @@ static void net_slirp_cleanup(VLANClientState *vc) slirp_in_use =0 ; } -static int net_slirp_init (VLANState *vlan,const char *model,const char *name, -int restricted,const char *ip) +static int net_slirp_init (Monitor *mon,VLANState *vlan,const char *model, +const char *name,int restricted,const char *ip, +const char *tftp_export,const char *bootfile, +const char *smb_export) {if (slirp_in_use) {/* slirp only supports a single instance so far */ return -1 ; }if (!slirp_inited) { +if (!tftp_export) { + tftp_export = legacy_tftp_prefix; + } +if (!bootfile) { + bootfile = legacy_bootp_filename; + } slirp_inited =1 ; -slirp_init (restricted, ip); +slirp_init (restricted, ip, tftp_export, bootfile); -while (slirp_redirs) { -struct slirp_config_str *config = slirp_redirs; +while (slirp_configs) { +struct slirp_config_str *config = slirp_configs; -slirp_redirection (NULL , config->str); - slirp_redirs = config->next; +if (config->flags &SLIRP_CFG_REDIR ) { +slirp_redirection (mon, config->str); + }else { +vmchannel_init (mon, config->str); + } + slirp_configs = config->next;qemu_free (config); }#ifndef _WIN32 +if (smb_export) { + slirp_smb_export = smb_export; + }if (slirp_smb_export) {slirp_smb (slirp_smb_export); }
@@ -696,9 +717,10 @@ void net_slirp_redir(Monitor *mon, const char *redir_str)monitor_printf (mon,"user mode network stack not in use\n" ); }else { config =qemu_malloc (sizeof (*config)); - config->str = redir_str; - config->next = slirp_redirs; - slirp_redirs = config; +pstrcpy (config->str,sizeof (config->str), redir_str); + config->flags =SLIRP_CFG_REDIR ; + config->next = slirp_configs; + slirp_configs = config; }return ; }
@@ -827,6 +849,36 @@ static void vmchannel_read(void *opaque, const uint8_t *buf, int size)slirp_socket_recv (4 , vmc->port, buf, size); } +static void vmchannel_init (Monitor *mon,const char *config_str) +{ +struct VMChannel *vmc; +char *devname; +char name[20 ]; +int port; + + port =strtol (config_str, &devname,10 ); +if (port <1 || port >65535 || *devname !=':' ) { +config_error (mon,"invalid vmchannel port number\n" ); +return ; + } + devname++; + + vmc =qemu_malloc (sizeof (struct VMChannel )); +snprintf (name,sizeof (name),"vmchannel%d" , port); + vmc->hd =qemu_chr_open (name, devname,NULL ); +if (!vmc->hd) { +config_error (mon,"could not open vmchannel device '%s'\n" , devname); +qemu_free (vmc); +return ; + } + vmc->port = port; + +slirp_add_exec (3 , vmc->hd,4 , port); +qemu_chr_add_handlers (vmc->hd, vmchannel_can_read, vmchannel_read, +NULL , vmc); +return ; +} +#endif /* CONFIG_SLIRP */ #if !defined(_WIN32)
@@ -1936,10 +1988,16 @@ int net_client_init(Monitor *mon, const char *device, const char *p)#ifdef CONFIG_SLIRP if (!strcmp (device,"user" )) {static const char *const slirp_params[] = { -"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,NULL +"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,"tftp" ,"bootfile" , +"smb" ,"redir" ,"channel" ,NULL }; +struct slirp_config_str *config; +char *tftp_export =NULL ; +char *bootfile =NULL ; +char *smb_export =NULL ;int restricted =0 ;char *ip =NULL ; +const char *q;if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) {config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p);
@@ -1955,34 +2013,59 @@ int net_client_init(Monitor *mon, const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"ip" , p)) { ip =qemu_strdup (buf); } +if (get_param_value (buf,sizeof (buf),"tftp" , p)) { + tftp_export =qemu_strdup (buf); + } +if (get_param_value (buf,sizeof (buf),"bootfile" , p)) { + bootfile =qemu_strdup (buf); + } +if (get_param_value (buf,sizeof (buf),"smb" , p)) { + smb_export =qemu_strdup (buf); + } + q = p; +while (1 ) { + config =qemu_malloc (sizeof (*config)); +if (!get_next_param_value (config->str,sizeof (config->str), +"redir" , &q)) { +break ; + } + config->flags =SLIRP_CFG_REDIR ; + config->next = slirp_configs; + slirp_configs = config; + config =NULL ; + } + q = p; +while (1 ) { + config =qemu_malloc (sizeof (*config)); +if (!get_next_param_value (config->str,sizeof (config->str), +"channel" , &q)) { +break ; + } + config->flags =0 ; + config->next = slirp_configs; + slirp_configs = config; + config =NULL ; + } +qemu_free (config); vlan->nb_host_devs++; - ret =net_slirp_init (vlan, device, name, restricted, ip); + ret =net_slirp_init (mon, vlan, device, name, restricted, ip, + tftp_export, bootfile, smb_export);qemu_free (ip); +qemu_free (tftp_export); +qemu_free (bootfile); + qemu_free(smb_export); }else if (!strcmp (device,"channel" )) { -long port; -char name[20 ], *devname; -struct VMChannel *vmc; - - port =strtol (p, &devname,10 ); - devname++; -if (port <1 || port >65535 ) { -config_error (mon,"vmchannel wrong port number\n" ); - ret =-1 ; - goto out; - } - vmc =malloc (sizeof (struct VMChannel )); -snprintf (name,20 ,"vmchannel%ld" , port); - vmc->hd =qemu_chr_open (name, devname,NULL ); -if (!vmc->hd) { -config_error (mon,"could not open vmchannel device '%s'\n" , - devname); - ret =-1 ; - goto out; +if (!slirp_inited) { +struct slirp_config_str *config; + + config =qemu_malloc (sizeof (*config)); +pstrcpy (config->str,sizeof (config->str), p); + config->flags =0 ; + config->next = slirp_configs; + slirp_configs = config; + }else { +vmchannel_init (mon, p); } - vmc->port = port; -slirp_add_exec (3 , vmc->hd,4 , port); -qemu_chr_add_handlers (vmc->hd, vmchannel_can_read, vmchannel_read, -NULL , vmc); ret =0 ; } else#endif
net.h +3 -0
@@ -108,6 +108,9 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,void net_checksum_calculate (uint8_t *data,int length);/* from net.c */ +extern const char *legacy_tftp_prefix; +extern const char *legacy_bootp_filename; +int net_client_init (Monitor *mon,const char *device,const char *p);void net_client_uninit (NICInfo *nd);int net_client_parse (const char *str);
qemu-options.hx +111 -98
233 lines not on this page · raw message
slirp/bootp.c +2 -2
@@ -38,7 +38,7 @@ typedef struct {static BOOTPClient bootp_clients[NB_ADDR ]; -const char *bootp_filename; +char bootp_filename[PATH_MAX ] ="" ;static const uint8_t rfc1533_cookie[] = {RFC1533_COOKIE };
@@ -249,7 +249,7 @@ static void bootp_reply(const struct bootp_t *bp) *q++ =DHCPACK ; } -if (bootp_filename) +if (bootp_filename[0 ] !=0 )snprintf ((char *)rbp->bp_file,sizeof (rbp->bp_file),"%s" , bootp_filename);
slirp/libslirp.h +2 -3
@@ -5,7 +5,8 @@extern "C" {#endif -void slirp_init (int restricted,const char *special_ip); +void slirp_init (int restricted,const char *special_ip,const char *tftp_path, +const char *bootfile);void slirp_select_fill (int *pnfds,fd_set *readfds,fd_set *writefds,fd_set *xfds);
@@ -23,9 +24,7 @@ int slirp_redir(int is_udp, int host_port,int slirp_add_exec (int do_pty,const void *args,int addr_low_byte,int guest_port); -extern const char *tftp_prefix;extern char slirp_hostname[33 ]; -extern const char *bootp_filename;void slirp_stats (void ); void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf,
slirp/main.h +2 -0
@@ -46,6 +46,8 @@ extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ];extern const char *slirp_special_ip;extern int slirp_restrict; +extern char tftp_prefix[PATH_MAX ]; +extern char bootp_filename[PATH_MAX ];#define PROTO_SLIP 0x1#ifdef USE_PPP
slirp/slirp.c +8 -2
@@ -171,7 +171,8 @@ static void slirp_cleanup(void)static void slirp_state_save (QEMUFile *f,void *opaque);static int slirp_state_load (QEMUFile *f,void *opaque,int version_id); -void slirp_init (int restricted,const char *special_ip) +void slirp_init (int restricted,const char *special_ip,const char *tftp_path, +const char *bootfile) {// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
@@ -202,7 +203,12 @@ void slirp_init(int restricted, const char *special_ip)if (special_ip) slirp_special_ip = special_ip; - +if (tftp_path) { +pstrcpy (tftp_prefix,sizeof (tftp_prefix), tftp_path); + } +if (bootfile) { +pstrcpy (bootp_filename,sizeof (bootp_filename), bootfile); + }inet_aton (slirp_special_ip, &special_addr); alias_addr.s_addr = special_addr.s_addr |htonl (CTL_ALIAS );getouraddr ();
slirp/tftp.c +3 -3
@@ -37,7 +37,7 @@ struct tftp_session {static struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX ]; -const char *tftp_prefix; +char tftp_prefix[PATH_MAX ] ="" ;static void tftp_session_update (struct tftp_session *spt) {
@@ -335,7 +335,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)/* only allow exported prefixes */ -if (!tftp_prefix) { +if (tftp_prefix[0 ] ==0 ) {tftp_send_error (spt,2 ,"Access violation" , tp);return ; }
@@ -370,7 +370,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)int tsize =atoi (value);struct stat stat_p; -if (tsize ==0 && tftp_prefix) { +if (tsize ==0 && tftp_prefix[0 ] !=0 ) {char buffer[1024 ];int len;
vl.c +3 -3
@@ -5150,14 +5150,14 @@ int main(int argc, char **argv, char **envp)break ;#ifdef CONFIG_SLIRP case QEMU_OPTION_tftp: - tftp_prefix = optarg; + legacy_tftp_prefix = optarg;break ;case QEMU_OPTION_bootp: - bootp_filename = optarg; + legacy_bootp_filename = optarg;break ;#ifndef _WIN32case QEMU_OPTION_smb: -net_slirp_smb (optarg); +net_slirp_smb (optarg);break ;#endif case QEMU_OPTION_redir:
Re: [Qemu-devel] [PATCH 08/11] slirp: Move smb, redir, tftp and bootp parameters and -net channel
Quoted 13 lines · Jan Kiszka
So far a couple of slirp-related parameters were expressed via stand-alone command line options. This it inconsistent and unintuitive. Moreover, it prevents both dynamically reconfigured (host_net_add/ delete) and multi-instance slirp.
This patch refactors the configuration by turning -smb, -redir, -tftp and -bootp as well as -net channel into options of "-net user". The old stand-alone command line options are still processed, but no longer advertised. This allows smooth migration of management applications to to the new syntax and also the extension of that syntax later in this series.
Signed-off-by Jan Kiszka <[email protected]>
...
slirp/main.h extern int tcp_keepintvl; · line 50
Quoted 10 lines
slirp/main.h +2
-0@@ -46,6 +46,8 @@ extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ];extern const char *slirp_special_ip;extern int slirp_restrict; +extern char tftp_prefix[PATH_MAX ]; +extern char bootp_filename[PATH_MAX ];
This wouldn't build for me without including limits.h here
Cheers,
Mark.
Re: [Qemu-devel] [PATCH 08/11] slirp: Move smb, redir, tftp and bootp parameters and -net channel
Quoted 15 lines · Mark McLoughlin
Quoted 13 lines · Jan Kiszka
So far a couple of slirp-related parameters were expressed via stand-alone command line options. This it inconsistent and unintuitive. Moreover, it prevents both dynamically reconfigured (host_net_add/ delete) and multi-instance slirp.
This patch refactors the configuration by turning -smb, -redir, -tftp and -bootp as well as -net channel into options of "-net user". The old stand-alone command line options are still processed, but no longer advertised. This allows smooth migration of management applications to to the new syntax and also the extension of that syntax later in this series.
Signed-off-by Jan Kiszka <[email protected]>....
Quoted 12 lines
slirp/main.h extern int tcp_keepintvl; · line 50
Quoted 10 lines
slirp/main.h +2
-0@@ -46,6 +46,8 @@ extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ];extern const char *slirp_special_ip;extern int slirp_restrict; +extern char tftp_prefix[PATH_MAX ]; +extern char bootp_filename[PATH_MAX ];This wouldn't build for me without including
limits.hhere
Please use v2 (see
http://permalink.gmane.org/gmane.comp.emulators.qemu/43080).
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 08/11] slirp: Move smb, redir, tftp and bootp parameters and -net channel
In reply to Mark McLoughlinQuoted 4 lines
slirp/main.h extern int tcp_keepintvl; · line 50
Quoted 2 lines
slirp/main.h +2
-0+extern char tftp_prefix[PATH_MAX ]; +extern char bootp_filename[PATH_MAX ];This wouldn't build for me without including
limits.hhere
It still won't work. You can't assume PATH_MAX is defined at all.
Paul
Re: [Qemu-devel] [PATCH 08/11] slirp: Move smb, redir, tftp and bootp parameters and -net channel
Quoted 6 lines · Paul Brook
Quoted 3 lines
slirp/main.h extern int tcp_keepintvl; · line 50
Quoted 2 lines
slirp/main.h +2
-0+extern char tftp_prefix[PATH_MAX ]; +extern char bootp_filename[PATH_MAX ];This wouldn't build for me without including
limits.hhereIt still won't work. You can't assume
PATH_MAXis defined at all.
You are right, one cannot always assume its there, but we already do:
block.c: char tmp_filename[PATH_MAX]; block.c: char backing_filename[PATH_MAX]; qemu-char.c: char pty_name[PATH_MAX];
...
So there must be a way to make all platforms happy qemu builds against. Otherwise I wouldn't have used it in the first place.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 08/11] slirp: Move smb, redir, tftp and bootp parameters and -net channel
Quoted 7 lines
Quoted 1 line
It still won't work. You can't assume
PATH_MAXis defined at all.You are right, one cannot always assume its there, but we already do:
block.c: char tmp_filename[PATH_MAX]; block.c: char backing_filename[PATH_MAX]; qemu-char.c: char pty_name[PATH_MAX];
I consider these to be bugs, with the possible exception of qemu-char.c which appears to be part of an OpenBSD workaround.
Paul
PATCH 9/11 slirp: Rework internal configuration
In reply to Jan KiszkaThe user mode IP stack is currently only minially configurable /wrt to its virtual IP addresses. This is unfortunate if some guest has a fixed idea of which IP addresses to use.
Therefore this patch prepares the stack for fully configurable IP addresses and masks. The user interface and default addresses are kept yet, they will be enhanced in the following patch.
---
slirp/bootp.c | 26 ++++------ slirp/ctl.h | 7 --- slirp/ip_icmp.c | 15 ++---- slirp/ip_input.c | 9 ++- slirp/main.h | 9 ++- slirp/misc.c | 9 ++- slirp/misc.h | 4 + slirp/slirp.c | 143 +++++++++++++++++++++++++++++++---------------------- slirp/slirp.h | 1 slirp/socket.c | 13 ++--- slirp/tcp_input.c | 16 +++--- slirp/tcp_subr.c | 120 ++++++++++++-------------------------------- slirp/udp.c | 23 +++++---- 13 files changed, 176 insertions(+), 219 deletions(-) delete mode 100644 slirp/ctl.h
slirp/bootp.c +10 -16
@@ -27,8 +27,6 @@#define NB_ADDR 16 -#define START_ADDR 15 -#define LEASE_TIME (24 * 3600) typedef struct {
@@ -62,7 +60,7 @@ static BOOTPClient *get_new_addr(struct in_addr *paddr) found: bc = &bootp_clients[i]; bc->allocated =1 ; - paddr->s_addr =htonl (ntohl (special_addr.s_addr) | (i +START_ADDR )); + paddr->s_addr = vdhcp_startaddr.s_addr +htonl (i);return bc; }
@@ -70,12 +68,12 @@ static BOOTPClient *request_addr(const struct in_addr *paddr, const uint8_t *macaddr) {uint32_t req_addr =ntohl (paddr->s_addr); -uint32_t spec_addr =ntohl (special_addr.s_addr); +uint32_t dhcp_addr =ntohl (vdhcp_startaddr.s_addr);BOOTPClient *bc; -if (req_addr >= (spec_addr |START_ADDR ) && - req_addr < (spec_addr | (NB_ADDR +START_ADDR ))) { - bc = &bootp_clients[(req_addr &0xff ) -START_ADDR ]; +if (req_addr >= dhcp_addr && + req_addr < (dhcp_addr +NB_ADDR )) { + bc = &bootp_clients[req_addr - dhcp_addr];if (!bc->allocated || !memcmp (macaddr, bc->macaddr,6 )) { bc->allocated =1 ;return bc;
@@ -97,7 +95,7 @@ static BOOTPClient *find_addr(struct in_addr *paddr, const uint8_t *macaddr) found: bc = &bootp_clients[i]; bc->allocated =1 ; - paddr->s_addr =htonl (ntohl (special_addr.s_addr) | (i +START_ADDR )); + paddr->s_addr = vdhcp_startaddr.s_addr +htonl (i);return bc; }
@@ -154,7 +152,6 @@ static void bootp_reply(const struct bootp_t *bp)struct mbuf *m;struct bootp_t *rbp;struct sockaddr_in saddr, daddr; -struct in_addr dns_addr;const struct in_addr *preq_addr;int dhcp_msg_type, val;uint8_t *q;
@@ -216,7 +213,7 @@ static void bootp_reply(const struct bootp_t *bp) } } - saddr.sin_addr.s_addr =htonl (ntohl (special_addr.s_addr) |CTL_ALIAS ); + saddr.sin_addr = vhost_addr; saddr.sin_port =htons (BOOTP_SERVER ); daddr.sin_port =htons (BOOTP_CLIENT );
@@ -260,10 +257,8 @@ static void bootp_reply(const struct bootp_t *bp) *q++ =RFC1533_NETMASK ; *q++ =4 ; - *q++ =0xff ; - *q++ =0xff ; - *q++ =0xff ; - *q++ =0x00 ; +memcpy (q, &vnetwork_mask,4 ); + q +=4 ;if (!slirp_restrict) { *q++ =RFC1533_GATEWAY ;
@@ -273,8 +268,7 @@ static void bootp_reply(const struct bootp_t *bp) *q++ =RFC1533_DNS ; *q++ =4 ; - dns_addr.s_addr =htonl (ntohl (special_addr.s_addr) |CTL_DNS ); -memcpy (q, &dns_addr,4 ); +memcpy (q, &vnameserver_addr,4 ); q +=4 ; }
slirp/ctl.h deleted +0 -7
@@ -1,7 +0,0 @@ -#define CTL_CMD 0 -#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/ip_icmp.c +6 -9
@@ -110,7 +110,7 @@ icmp_input(struct mbuf *m, int hlen)case ICMP_ECHO : icp->icmp_type =ICMP_ECHOREPLY ; ip->ip_len += hlen;/* since ip_input subtracts this */ -if (ip->ip_dst.s_addr == alias_addr.s_addr) { +if (ip->ip_dst.s_addr == vhost_addr.s_addr) {icmp_reflect (m); }else {struct socket *so;
@@ -134,16 +134,13 @@ icmp_input(struct mbuf *m, int hlen)/* Send the packet */ addr.sin_family =AF_INET ; -if ((so->so_faddr.s_addr &htonl (0xffffff00 )) == special_addr.s_addr) { +if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) == + vnetwork_addr.s_addr) {/* It's an alias */ -switch (ntohl (so->so_faddr.s_addr) &0xff ) { -case CTL_DNS : +if (so->so_faddr.s_addr == vnameserver_addr.s_addr) { addr.sin_addr = dns_addr; -break ; -case CTL_ALIAS : -default : + }else { addr.sin_addr = loopback_addr; -break ; } }else { addr.sin_addr = so->so_faddr;
@@ -302,7 +299,7 @@ icmp_error(struct mbuf *msrc, u_char type, u_char code, int minsize, ip->ip_ttl =MAXTTL ; ip->ip_p =IPPROTO_ICMP ; ip->ip_dst = ip->ip_src;/* ip adresses */ - ip->ip_src = alias_addr; + ip->ip_src = vhost_addr; (void )ip_output ((struct socket *)NULL , m);
slirp/ip_input.c +5 -4
@@ -134,18 +134,19 @@ ip_input(struct mbuf *m) }if (slirp_restrict) { -if (memcmp (&ip->ip_dst.s_addr, &special_addr,3 )) { +if ((ip->ip_dst.s_addr & vnetwork_mask.s_addr) == + vnetwork_addr.s_addr) {if (ip->ip_dst.s_addr ==0xffffffff && ip->ip_p !=IPPROTO_UDP ) goto bad; }else { -int host =ntohl (ip->ip_dst.s_addr) &0xff ;struct ex_list *ex_ptr; -if (host ==0xff ) +if ((ip->ip_dst.s_addr & ~vnetwork_mask.s_addr) == + ~vnetwork_mask.s_addr) goto bad;for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) -if (ex_ptr->ex_addr == host) +if (ex_ptr->ex_addr.s_addr == ip->ip_dst.s_addr)break ;if (!ex_ptr)
slirp/main.h +5 -4
@@ -32,9 +32,11 @@ extern char *slirp_tty;extern char *exec_shell;extern u_int curtime;extern fd_set *global_readfds, *global_writefds, *global_xfds; -extern struct in_addr ctl_addr; -extern struct in_addr special_addr; -extern struct in_addr alias_addr; +extern struct in_addr vnetwork_addr; +extern struct in_addr vnetwork_mask; +extern struct in_addr vhost_addr; +extern struct in_addr vdhcp_startaddr; +extern struct in_addr vnameserver_addr;extern struct in_addr our_addr;extern struct in_addr loopback_addr;extern struct in_addr dns_addr;
@@ -44,7 +46,6 @@ extern int towrite_max;extern int ppp_exit;extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ]; -extern const char *slirp_special_ip;extern int slirp_restrict;extern char tftp_prefix[PATH_MAX ];extern char bootp_filename[PATH_MAX ];
slirp/misc.c +5 -4
@@ -112,15 +112,16 @@ remque(void *a)/* #endif */ -int -add_exec (struct ex_list **ex_ptr,int do_pty,char *exec,int addr,int port) +int add_exec (struct ex_list **ex_ptr,int do_pty,char *exec, +struct in_addr addr,int port) {struct ex_list *tmp_ptr;/* First, check if the port is "bound" */ for (tmp_ptr = *ex_ptr; tmp_ptr; tmp_ptr = tmp_ptr->ex_next) { -if (port == tmp_ptr->ex_fport && addr == tmp_ptr->ex_addr) -return -1 ; +if (port == tmp_ptr->ex_fport && + addr.s_addr == tmp_ptr->ex_addr.s_addr) +return -1 ; } tmp_ptr = *ex_ptr;
slirp/misc.h +2 -2
@@ -10,7 +10,7 @@struct ex_list {int ex_pty;/* Do we want a pty? */ -int ex_addr;/* The last byte of the address */ +struct in_addr ex_addr;/* Server address */ int ex_fport;/* Port to telnet to */ const char *ex_exec;/* Command line of what to exec */ struct ex_list *ex_next;
@@ -74,7 +74,7 @@ void redir_x _P((u_int32_t, int, int, int)); void getouraddr _P((void)); void slirp_insque _P((void *, void *)); void slirp_remque _P((void *)); -int add_exec _P((struct ex_list **, int, char *, int, int)); +int add_exec _P((struct ex_list **, int, char *, struct in_addr, int)); int slirp_openpty _P((int *, int *));int fork_exec (struct socket *so,const char *ex,int do_pty); void snooze_hup _P((int));
slirp/slirp.c +83 -60
275 lines not on this page · raw message
slirp/slirp.h +0 -1
@@ -214,7 +214,6 @@ int inet_aton _P((const char *cp, struct in_addr *ia));#include "if.h" #include "main.h" #include "misc.h" -#include "ctl.h" #ifdef USE_PPP #include "ppp/pppd.h" #include "ppp/ppp.h"
slirp/socket.c +5 -8
@@ -550,16 +550,13 @@ sosendto(struct socket *so, struct mbuf *m)DEBUG_ARG ("m = %lx" , (long )m); addr.sin_family =AF_INET ; -if ((so->so_faddr.s_addr &htonl (0xffffff00 )) == special_addr.s_addr) { +if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) == + vnetwork_addr.s_addr) {/* It's an alias */ -switch (ntohl (so->so_faddr.s_addr) &0xff ) { -case CTL_DNS : +if (so->so_faddr.s_addr == vnameserver_addr.s_addr) { addr.sin_addr = dns_addr; -break ; -case CTL_ALIAS : -default : + }else { addr.sin_addr = loopback_addr; -break ; } }else addr.sin_addr = so->so_faddr;
@@ -647,7 +644,7 @@ solisten(u_int port, u_int32_t laddr, u_int lport, int flags)getsockname (s,(struct sockaddr *)&addr,&addrlen); so->so_fport = addr.sin_port;if (addr.sin_addr.s_addr ==0 || addr.sin_addr.s_addr == loopback_addr.s_addr) - so->so_faddr = alias_addr; + so->so_faddr = vhost_addr;else so->so_faddr = addr.sin_addr;
slirp/tcp_input.c +9 -7
@@ -359,11 +359,12 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso) m->m_len -=sizeof (struct tcpiphdr )+off-sizeof (struct tcphdr );if (slirp_restrict) { -for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) +for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {if (ex_ptr->ex_fport == ti->ti_dport && - (ntohl (ti->ti_dst.s_addr) &0xff ) == ex_ptr->ex_addr) + ti->ti_dst.s_addr == ex_ptr->ex_addr.s_addr) {break ; - + } + }if (!ex_ptr) goto drop; }
@@ -639,9 +640,10 @@ findso:* If this is destined for the control address, then flag to * tcp_ctl once connected, otherwise connect */ -if ((so->so_faddr.s_addr&htonl (0xffffff00 )) == special_addr.s_addr) { -int lastbyte=ntohl (so->so_faddr.s_addr) &0xff ; -if (lastbyte!=CTL_ALIAS && lastbyte!=CTL_DNS ) { +if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) == + vnetwork_addr.s_addr) { +if (so->so_faddr.s_addr != vhost_addr.s_addr && + so->so_faddr.s_addr != vnameserver_addr.s_addr) {#if 0 if (lastbyte==CTL_CMD || lastbyte==CTL_EXEC ) {/* Command or exec adress */
@@ -652,7 +654,7 @@ findso:/* May be an add exec */ for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) {if (ex_ptr->ex_fport == so->so_fport && - lastbyte == ex_ptr->ex_addr) { + so->so_faddr.s_addr == ex_ptr->ex_addr.s_addr) { so->so_state |=SS_CTL ;break ; }
slirp/tcp_subr.c +33 -87
140 lines not on this page · raw message
slirp/udp.c +13 -10
@@ -314,12 +314,14 @@ int udp_output(struct socket *so, struct mbuf *m,struct sockaddr_in saddr, daddr; saddr = *addr; -if ((so->so_faddr.s_addr &htonl (0xffffff00 )) == special_addr.s_addr) { -if ((so->so_faddr.s_addr &htonl (0x000000ff )) ==htonl (0xff )) - saddr.sin_addr.s_addr = alias_addr.s_addr; -else if (addr->sin_addr.s_addr == loopback_addr.s_addr || - (ntohl (so->so_faddr.s_addr) &0xff ) !=CTL_ALIAS ) - saddr.sin_addr.s_addr = so->so_faddr.s_addr; +if ((so->so_faddr.s_addr & vnetwork_mask.s_addr) == vnetwork_addr.s_addr) { +if ((so->so_faddr.s_addr & ~vnetwork_mask.s_addr) == + ~vnetwork_mask.s_addr) { + saddr.sin_addr = vhost_addr; + }else if (addr->sin_addr.s_addr == loopback_addr.s_addr || + so->so_faddr.s_addr != vhost_addr.s_addr) { + saddr.sin_addr = so->so_faddr; + } } daddr.sin_addr = so->so_laddr; daddr.sin_port = so->so_lport;
@@ -654,11 +656,12 @@ udp_listen(u_int port, u_int32_t laddr, u_int lport, int flags)getsockname (so->s,(struct sockaddr *)&addr,&addrlen); so->so_fport = addr.sin_port; -if (addr.sin_addr.s_addr ==0 || addr.sin_addr.s_addr == loopback_addr.s_addr) - so->so_faddr = alias_addr; -else +if (addr.sin_addr.s_addr ==0 || + addr.sin_addr.s_addr == loopback_addr.s_addr) { + so->so_faddr = vhost_addr; + }else { so->so_faddr = addr.sin_addr; - + } so->so_lport = lport; so->so_laddr.s_addr = laddr;if (flags !=SS_FACCEPTONCE )
PATCH 10/11 slirp: Rework external configuration interface
In reply to Jan KiszkaWith the internal IP configuration made more flexible, we can now enhance the user interface. This patch adds a number of new options to "-net user": net (address and mask), host, dhcpstart, dns and smbserver. It also renames "redir" to "hostfwd" and "channel" to "guestfwd" in order to (hopefully) clarify their meanings. The format of guestfwd is extended so that the user can define not only the port but also the virtual server's IP address the forwarding starts from.
---
net.c | 295 +++++++++++++++++++++++++++++++++++++++++------------- qemu-options.hx | 52 ++++++---- slirp/libslirp.h | 17 ++- slirp/main.h | 1 slirp/slirp.c | 46 ++++---- 5 files changed, 289 insertions(+), 122 deletions(-)
net.c +224 -71
@@ -551,12 +551,14 @@ static void config_error(Monitor *mon, const char *fmt, ...)/* slirp network adapter */ -#define SLIRP_CFG_REDIR 1 +#define SLIRP_CFG_HOSTFWD 1 +#define SLIRP_CFG_LEGACY 2struct slirp_config_str {struct slirp_config_str *next;int flags;char str[1024 ]; +int legacy_format; };static int slirp_inited;
@@ -568,9 +570,10 @@ static const char *slirp_smb_export;#endif static VLANClientState *slirp_vc; -static void slirp_smb (const char *exported_dir); -static void slirp_redirection (Monitor *mon,const char *redir_str); -static void vmchannel_init (Monitor *mon,const char *config_str); +static void slirp_smb (const char *exported_dir,struct in_addr vserver_addr); +static void slirp_hostfwd (Monitor *mon,const char *redir_str); +static void slirp_guestfwd (Monitor *mon,const char *config_str, +int legacy_format);int slirp_can_output (void ) {
@@ -610,15 +613,32 @@ static void net_slirp_cleanup(VLANClientState *vc) }static int net_slirp_init (Monitor *mon,VLANState *vlan,const char *model, -const char *name,int restricted,const char *ip, -const char *tftp_export,const char *bootfile, -const char *smb_export) +const char *name,int restricted, +const char *vnetwork,const char *vhost, +const char *vhostname,const char *tftp_export, +const char *bootfile,const char *vdhcp_start, +const char *vnameserver,const char *smb_export, +const char *vsmbserver) {if (slirp_in_use) {/* slirp only supports a single instance so far */ return -1 ; }if (!slirp_inited) { +/* default settings according to historic slirp */ +struct in_addr net = { .s_addr =htonl (0x0a000000 ) };/* 10.0.0.0 */ +struct in_addr mask = { .s_addr =htonl (0xff000000 ) };/* 255.0.0.0 */ +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 */ +#ifndef _WIN32 +struct in_addr smbsrv = { .s_addr =0 }; +#endif +char buf[20 ]; +uint32_t addr; +int shift; +char *end; +if (!tftp_export) { tftp_export = legacy_tftp_prefix; }
@@ -626,15 +646,83 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model, bootfile = legacy_bootp_filename; } slirp_inited =1 ; -slirp_init (restricted, ip, tftp_export, bootfile); + +if (vnetwork) { +if (get_str_sep (buf,sizeof (buf), &vnetwork,'/' ) <0 ) { +if (!inet_aton (vnetwork, &net)) { +return -1 ; + } + addr =ntohl (net.s_addr); +if (!(addr &0x80000000 )) { + mask.s_addr =htonl (0xff000000 );/* class A */ + }else if ((addr &0xfff00000 ) ==0xac100000 ) { + mask.s_addr =htonl (0xfff00000 );/* priv. 172.16.0.0/12 */ + }else if ((addr &0xc0000000 ) ==0x80000000 ) { + mask.s_addr =htonl (0xffff0000 );/* class B */ + }else if ((addr &0xffff0000 ) ==0xc0a80000 ) { + mask.s_addr =htonl (0xffff0000 );/* priv. 192.168.0.0/16 */ + }else if ((addr &0xffff0000 ) ==0xc6120000 ) { + mask.s_addr =htonl (0xfffe0000 );/* tests 198.18.0.0/15 */ + }else if ((addr &0xe0000000 ) ==0xe0000000 ) { + mask.s_addr =htonl (0xffffff00 );/* class C */ + }else { + mask.s_addr =htonl (0xfffffff0 );/* multicast/reserved */ + } + }else { +if (!inet_aton (buf, &net)) { +return -1 ; + } + shift =strtol (vnetwork, &end,10 ); +if (*end !='\0' ) { +if (!inet_aton (vnetwork, &mask)) { +return -1 ; + } + }else if (shift <4 || shift >32 ) { +return -1 ; + }else { + mask.s_addr =htonl (0xffffffff << (32 - shift)); + } + } + net.s_addr &= mask.s_addr; + host.s_addr = net.s_addr | (htonl (0x0202 ) & ~mask.s_addr); + dhcp.s_addr = net.s_addr | (htonl (0x020f ) & ~mask.s_addr); + dns.s_addr = net.s_addr | (htonl (0x0203 ) & ~mask.s_addr); + } + +if (vhost && !inet_aton (vhost, &host)) { +return -1 ; + } +if ((host.s_addr & mask.s_addr) != net.s_addr) { +return -1 ; + } + +if (vdhcp_start && !inet_aton (vdhcp_start, &dhcp)) { +return -1 ; + } +if ((dhcp.s_addr & mask.s_addr) != net.s_addr || + dhcp.s_addr == host.s_addr || dhcp.s_addr == dns.s_addr) { +return -1 ; + } + +if (vnameserver && !inet_aton (vnameserver, &dns)) { +return -1 ; + } +if ((dns.s_addr & mask.s_addr) != net.s_addr || + dns.s_addr == host.s_addr) { +return -1 ; + } + +slirp_init (restricted, net, mask, host, vhostname, tftp_export, + bootfile, dhcp, dns);while (slirp_configs) {struct slirp_config_str *config = slirp_configs; -if (config->flags &SLIRP_CFG_REDIR ) { -slirp_redirection (mon, config->str); +if (config->flags &SLIRP_CFG_HOSTFWD ) { +slirp_hostfwd (mon, config->str); }else { -vmchannel_init (mon, config->str); +slirp_guestfwd (mon, config->str, + config->flags &SLIRP_CFG_LEGACY ); } slirp_configs = config->next;qemu_free (config);
@@ -643,8 +731,11 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,if (smb_export) { slirp_smb_export = smb_export; } +if (vsmbserver && !inet_aton (vsmbserver, &smbsrv)) { +return -1 ; + }if (slirp_smb_export) { -slirp_smb (slirp_smb_export); +slirp_smb (slirp_smb_export, smbsrv); }#endif }
@@ -656,13 +747,14 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,return 0 ; } -static void slirp_redirection (Monitor *mon,const char *redir_str) +static void slirp_hostfwd (Monitor *mon,const char *redir_str) { -struct in_addr guest_addr; +struct in_addr guest_addr = { .s_addr =0 };int host_port, guest_port;const char *p; -char buf[256 ], *r; +char buf[256 ];int is_udp; +char *end; p = redir_str;if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) {
@@ -679,33 +771,31 @@ static void slirp_redirection(Monitor *mon, const char *redir_str)if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { goto fail_syntax; } - host_port =strtol (buf, &r,0 ); -if (r == buf) { + host_port =strtol (buf, &end,0 ); +if (*end !='\0' || host_port <1 || host_port >65535 ) { goto fail_syntax; }if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { goto fail_syntax; } -if (buf[0 ] =='\0' ) { -pstrcpy (buf,sizeof (buf),"10.0.2.15" ); - } -if (!inet_aton (buf, &guest_addr)) { +if (buf[0 ] !='\0' && !inet_aton (buf, &guest_addr)) { goto fail_syntax; } - guest_port =strtol (p, &r,0 ); -if (r == p) { + guest_port =strtol (p, &end,0 ); +if (*end !='\0' || guest_port <1 || guest_port >65535 ) { goto fail_syntax; }if (slirp_redir (is_udp, host_port, guest_addr, guest_port) <0 ) { -config_error (mon,"could not set up redirection '%s'\n" , redir_str); +config_error (mon,"could not set up host forwarding rule '%s'\n" , + redir_str); }return ; fail_syntax: -config_error (mon,"invalid redirection format '%s'\n" , redir_str); +config_error (mon,"invalid host forwarding rule '%s'\n" , redir_str); }void net_slirp_redir (Monitor *mon,const char *redir_str)
@@ -718,14 +808,14 @@ void net_slirp_redir(Monitor *mon, const char *redir_str) }else { config =qemu_malloc (sizeof (*config));pstrcpy (config->str,sizeof (config->str), redir_str); - config->flags =SLIRP_CFG_REDIR ; + config->flags =SLIRP_CFG_HOSTFWD ; config->next = slirp_configs; slirp_configs = config; }return ; } -slirp_redirection (mon, redir_str); +slirp_hostfwd (mon, redir_str); }#ifndef _WIN32
@@ -763,7 +853,7 @@ static void smb_exit(void)erase_dir (smb_dir); } -static void slirp_smb (const char *exported_dir) +static void slirp_smb (const char *exported_dir,struct in_addr vserver_addr) {char smb_conf[1024 ];char smb_cmdline[1024 ];
@@ -809,19 +899,24 @@ static void slirp_smb(const char *exported_dir)snprintf (smb_cmdline,sizeof (smb_cmdline),"%s -s %s" ,SMBD_COMMAND , smb_conf); -slirp_add_exec (0 , smb_cmdline,4 ,139 ); +if (slirp_add_exec (0 , smb_cmdline, vserver_addr,139 ) <0 ) { +fprintf (stderr,"conflicting/invalid smbserver address\n" ); +exit (1 ); + } }/* automatic user mode samba server configuration */ void net_slirp_smb (const char *exported_dir) { +struct in_addr vserver_addr = { .s_addr =0 }; +if (slirp_smb_export) {fprintf (stderr,"-smb given twice\n" );exit (1 ); } slirp_smb_export = exported_dir;if (slirp_inited) { -slirp_smb (exported_dir); +slirp_smb (exported_dir, vserver_addr); } }
@@ -832,51 +927,85 @@ void do_info_slirp(Monitor *mon)slirp_stats (); } -struct VMChannel { +struct GuestFwd {CharDriverState *hd; +struct in_addr server;int port; }; -static int vmchannel_can_read (void *opaque) +static int guestfwd_can_read (void *opaque) { -struct VMChannel *vmc = (struct VMChannel *)opaque; -return slirp_socket_can_recv (4 , vmc->port); +struct GuestFwd *fwd = opaque; +return slirp_socket_can_recv (fwd->server, fwd->port); } -static void vmchannel_read (void *opaque,const uint8_t *buf,int size) +static void guestfwd_read (void *opaque,const uint8_t *buf,int size) { -struct VMChannel *vmc = (struct VMChannel *)opaque; -slirp_socket_recv (4 , vmc->port, buf, size); +struct GuestFwd *fwd = opaque; +slirp_socket_recv (fwd->server, fwd->port, buf, size); } -static void vmchannel_init (Monitor *mon,const char *config_str) +static void slirp_guestfwd (Monitor *mon,const char *config_str, +int legacy_format) { -struct VMChannel *vmc; -char *devname; -char name[20 ]; +struct in_addr server = { .s_addr =0 }; +struct GuestFwd *fwd; +const char *p; +char buf[128 ]; +char *end;int port; - port =strtol (config_str, &devname,10 ); -if (port <1 || port >65535 || *devname !=':' ) { -config_error (mon,"invalid vmchannel port number\n" ); -return ; + p = config_str; +if (legacy_format) { +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { + goto fail_syntax; + } + }else { +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { + goto fail_syntax; + } +if (strcmp (buf,"tcp" ) && buf[0 ] !='\0' ) { + goto fail_syntax; + } +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { + goto fail_syntax; + } +if (buf[0 ] !='\0' && !inet_aton (buf, &server)) { + goto fail_syntax; + } +if (get_str_sep (buf,sizeof (buf), &p,'-' ) <0 ) { + goto fail_syntax; + } + } + port =strtol (buf, &end,10 ); +if (*end !='\0' || port <1 || port >65535 ) { + goto fail_syntax; } - devname++; - vmc =qemu_malloc (sizeof (struct VMChannel )); -snprintf (name,sizeof (name),"vmchannel%d" , port); - vmc->hd =qemu_chr_open (name, devname,NULL ); -if (!vmc->hd) { -config_error (mon,"could not open vmchannel device '%s'\n" , devname); -qemu_free (vmc); + fwd =qemu_malloc (sizeof (struct GuestFwd )); +snprintf (buf,sizeof (buf),"guestfwd.tcp:%d" , port); + fwd->hd =qemu_chr_open (buf, p,NULL ); +if (!fwd->hd) { +config_error (mon,"could not open guest forwarding device '%s'\n" , + buf); +qemu_free (fwd);return ; } - vmc->port = port; + fwd->server = server; + fwd->port = port; -slirp_add_exec (3 , vmc->hd,4 , port); -qemu_chr_add_handlers (vmc->hd, vmchannel_can_read, vmchannel_read, -NULL , vmc); +if (slirp_add_exec (3 , fwd->hd, server, port) <0 ) { +config_error (mon,"conflicting/invalid host:port in guest forwarding " +"rule '%s'\n" , config_str); +qemu_free (fwd); +return ; + } +qemu_chr_add_handlers (fwd->hd, guestfwd_can_read, guestfwd_read, +NULL , fwd);return ; + + fail_syntax: +config_error (mon,"invalid guest forwarding rule '%s'\n" , config_str); }#endif /* CONFIG_SLIRP */
@@ -1988,15 +2117,21 @@ int net_client_init(Monitor *mon, const char *device, const char *p)#ifdef CONFIG_SLIRP if (!strcmp (device,"user" )) {static const char *const slirp_params[] = { -"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,"tftp" ,"bootfile" , -"smb" ,"redir" ,"channel" ,NULL +"vlan" ,"name" ,"hostname" ,"restrict" ,"net" ,"host" , +"tftp" ,"bootfile" ,"dhcpstart" ,"dns" ,"smb" ,"smbserver" , +"hostfwd" ,"guestfwd" ,NULL };struct slirp_config_str *config; +int restricted =0 ; +char *vnet =NULL ; +char *vhost =NULL ; +char *vhostname =NULL ;char *tftp_export =NULL ;char *bootfile =NULL ; +char *vdhcp_start =NULL ; +char *vnamesrv =NULL ;char *smb_export =NULL ; -int restricted =0 ; -char *ip =NULL ; +char *vsmbsrv =NULL ;const char *q;if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) {
@@ -2004,14 +2139,23 @@ int net_client_init(Monitor *mon, const char *device, const char *p) ret =-1 ; goto out; } +if (get_param_value (buf,sizeof (buf),"net" , p)) { + vnet =qemu_strdup (buf); + } +if (get_param_value (buf,sizeof (buf),"host" , p)) { + vhost =qemu_strdup (buf); + }if (get_param_value (buf,sizeof (buf),"hostname" , p)) { -pstrcpy (slirp_hostname,sizeof (slirp_hostname), buf); + vhostname =qemu_strdup (buf); }if (get_param_value (buf,sizeof (buf),"restrict" , p)) { restricted = (buf[0 ] =='y' ) ?1 :0 ; } -if (get_param_value (buf,sizeof (buf),"ip" , p)) { - ip =qemu_strdup (buf); +if (get_param_value (buf,sizeof (buf),"dhcpstart" , p)) { + vdhcp_start =qemu_strdup (buf); + } +if (get_param_value (buf,sizeof (buf),"dns" , p)) { + vnamesrv =qemu_strdup (buf); }if (get_param_value (buf,sizeof (buf),"tftp" , p)) { tftp_export =qemu_strdup (buf);
@@ -2021,15 +2165,18 @@ int net_client_init(Monitor *mon, const char *device, const char *p) }if (get_param_value (buf,sizeof (buf),"smb" , p)) { smb_export =qemu_strdup (buf); +if (get_param_value (buf,sizeof (buf),"smbserver" , p)) { + vsmbsrv =qemu_strdup (buf); + } } q = p;while (1 ) { config =qemu_malloc (sizeof (*config));if (!get_next_param_value (config->str,sizeof (config->str), -"redir" , &q)) { +"hostfwd" , &q)) {break ; } - config->flags =SLIRP_CFG_REDIR ; + config->flags =SLIRP_CFG_HOSTFWD ; config->next = slirp_configs; slirp_configs = config; config =NULL ;
@@ -2038,7 +2185,7 @@ int net_client_init(Monitor *mon, const char *device, const char *p)while (1 ) { config =qemu_malloc (sizeof (*config));if (!get_next_param_value (config->str,sizeof (config->str), -"channel" , &q)) { +"guestfwd" , &q)) {break ; } config->flags =0 ;
@@ -2048,23 +2195,29 @@ int net_client_init(Monitor *mon, const char *device, const char *p) }qemu_free (config); vlan->nb_host_devs++; - ret =net_slirp_init (mon, vlan, device, name, restricted, ip, - tftp_export, bootfile, smb_export); -qemu_free (ip); + ret =net_slirp_init (mon, vlan, device, name, restricted, vnet, vhost, + vhostname, tftp_export, bootfile, vdhcp_start, + vnamesrv, smb_export, vsmbsrv); +qemu_free (vnet); +qemu_free (vhost); +qemu_free (vhostname);qemu_free (tftp_export);qemu_free (bootfile); +qemu_free (vdhcp_start); +qemu_free (vnamesrv);qemu_free (smb_export); +qemu_free (vsmbsrv); }else if (!strcmp (device,"channel" )) {if (!slirp_inited) {struct slirp_config_str *config; config =qemu_malloc (sizeof (*config));pstrcpy (config->str,sizeof (config->str), p); - config->flags =0 ; + config->flags =SLIRP_CFG_LEGACY ; config->next = slirp_configs; slirp_configs = config; }else { -vmchannel_init (mon, p); +slirp_guestfwd (mon, p,1 ); } ret =0 ; }else
qemu-options.hx +34 -18
107 lines not on this page · raw message
slirp/libslirp.h +9 -8
@@ -5,8 +5,11 @@extern "C" {#endif -void slirp_init (int restricted,const char *special_ip,const char *tftp_path, -const char *bootfile); +void 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 vnameserver);void slirp_select_fill (int *pnfds,fd_set *readfds,fd_set *writefds,fd_set *xfds);
@@ -21,15 +24,13 @@ void slirp_output(const uint8_t *pkt, int pkt_len);int slirp_redir (int is_udp,int host_port,struct in_addr guest_addr,int guest_port); -int slirp_add_exec (int do_pty,const void *args,int addr_low_byte, +int slirp_add_exec (int do_pty,const void *args,struct in_addr guest_addr,int guest_port); -extern char slirp_hostname[33 ]; -void slirp_stats (void ); -void slirp_socket_recv (int addr_low_byte,int guest_port,const uint8_t *buf, -int size); -size_t slirp_socket_can_recv (int addr_low_byte,int guest_port); +void slirp_socket_recv (struct in_addr guest_addr,int guest_port, +const uint8_t *buf,int size); +size_t slirp_socket_can_recv (struct in_addr guest_addr,int guest_port); #ifdef __cplusplus }
slirp/main.h +1 -0
@@ -47,6 +47,7 @@ extern int ppp_exit;extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ];extern int slirp_restrict; +extern char slirp_hostname[33 ];extern char tftp_prefix[PATH_MAX ];extern char bootp_filename[PATH_MAX ];
slirp/slirp.c +21 -25
87 lines not on this page · raw message
Re: [Qemu-devel] [PATCH 10/11] slirp: Rework external configuration interface
Quoted 9 lines · Jan Kiszka
With the internal IP configuration made more flexible, we can now enhance the user interface. This patch adds a number of new options to "-net user": net (address and mask), host, dhcpstart, dns and smbserver. It also renames "redir" to "hostfwd" and "channel" to "guestfwd" in order to (hopefully) clarify their meanings. The format of guestfwd is extended so that the user can define not only the port but also the virtual server's IP address the forwarding starts from.
Signed-off-by Jan Kiszka <[email protected]>
...
net.c int net_client_init(Monitor *mon, const char *device, const char *p) · line 2122
Quoted 9 lines
net.c +3
-2@@ -1988,15 +2117,21 @@ int net_client_init(Monitor *mon, const char *device, const char *p) #ifdef CONFIG_SLIRP if (!strcmp(device, "user")) { static const char * const slirp_params[] = { - "vlan", "name", "hostname", "restrict", "ip", "tftp", "bootfile", - "smb", "redir", "channel", NULL + "vlan", "name", "hostname", "restrict", "net", "host", + "tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver", + "hostfwd", "guestfwd", NULL
You're renaming "redir" and "channel" here which isn't a big deal since you've only introduced them in the previous patch, but it would be better to use the final names in the original patch.
More importantly, though, you've dropped the "ip" parameter which is in the 0.10.x releases. We can't just drop existing parameters.
By way of meta-comment, some of these patches are much harder to review than they need to be, because e.g. you're doing lots of cleanups together with the real changes, or not breaking changes into smaller chunks.
Cheers,
Mark.
Re: [Qemu-devel] [PATCH 10/11] slirp: Rework external configuration interface
Quoted 13 lines · Mark McLoughlin
Quoted 9 lines · Jan Kiszka
With the internal IP configuration made more flexible, we can now enhance the user interface. This patch adds a number of new options to "-net user": net (address and mask), host, dhcpstart, dns and smbserver. It also renames "redir" to "hostfwd" and "channel" to "guestfwd" in order to (hopefully) clarify their meanings. The format of guestfwd is extended so that the user can define not only the port but also the virtual server's IP address the forwarding starts from.
Signed-off-by Jan Kiszka <[email protected]>....
Quoted 13 lines
net.c int net_client_init(Monitor *mon, const char *device, const char *p) · line 2122
Quoted 9 lines
net.c +3
-2@@ -1988,15 +2117,21 @@ int net_client_init(Monitor *mon, const char *device, const char *p) #ifdef CONFIG_SLIRP if (!strcmp(device, "user")) { static const char * const slirp_params[] = { - "vlan", "name", "hostname", "restrict", "ip", "tftp", "bootfile", - "smb", "redir", "channel", NULL + "vlan", "name", "hostname", "restrict", "net", "host", + "tftp", "bootfile", "dhcpstart", "dns", "smb", "smbserver", + "hostfwd", "guestfwd", NULLYou're renaming "redir" and "channel" here which isn't a big deal since you've only introduced them in the previous patch, but it would be better to use the final names in the original patch.
Well, the purpose of the original patch was only to pull "redir" and "channel" as-is into the -net parameter list, not to refactor the interface otherwise.
Quoted 3 lines
More importantly, though, you've dropped the "ip" parameter which is in the 0.10.x releases. We can't just drop existing parameters.
OK, I see the problem - though this parameter was probable rarely used (it was undocumented and suffered from the poor configurability). Will have a closer look.
Quoted 5 lines
By way of meta-comment, some of these patches are much harder to review than they need to be, because e.g. you're doing lots of cleanups together with the real changes, or not breaking changes into smaller chunks.
There might be a few coding style updates included, when I touch related lines. Or please give some (or the most annoying) example.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Re: [Qemu-devel] [PATCH 10/11] slirp: Rework external configuration interface
Quoted 7 lines · Jan Kiszka
Quoted 3 lines
You're renaming "redir" and "channel" here which isn't a big deal since you've only introduced them in the previous patch, but it would be better to use the final names in the original patch.
Well, the purpose of the original patch was only to pull "redir" and "channel" as-is into the -net parameter list, not to refactor the interface otherwise.
It's a bisectability thing - we shouldn't introduce parameters in a patch that we intend to rename in a subsequent patch.
e.g. if a distro cherry-picked this patch, we'd have options in the wild that aren't available upstream.
Quoted 7 lines
Quoted 1 line
More importantly, though, you've dropped the "ip" parameter which is
in
Quoted 1 line
the 0.10.x releases. We can't just drop existing parameters.
OK, I see the problem - though this parameter was probable rarely used (it was undocumented and suffered from the poor configurability). Will have a closer look.
Great. Probably best to re-send 7-11 with both of these things fixed up.
Quoted 9 lines
Quoted 1 line
By way of meta-comment, some of these patches are much harder to
review
Quoted 3 lines
than they need to be, because e.g. you're doing lots of cleanups together with the real changes, or not breaking changes into smaller chunks.
There might be a few coding style updates included, when I touch related
lines. Or please give some (or the most annoying) example.
Okay:
- In "Avoid zombie processes after fork_exec" you needlessly re-arrange the code in launch_script() - it could have very reasonably been an easy to review +6 hunk rather than a -24/+36 hunk if you'd split the cleanup out into its own patch
- "Real fix for check_params users" could have been split into the revert followed by the better fix
- In "Improve parameter error reporting", you replace a strdup() with qemu_strdup(), unrelated to the goal of the patch
- In "Reorder initialization", you change the formatting of the args to the qemu_new_vlan_client() call - conflicted with my patches
- In the same patch you've added a whole pile of braces in what was net_slirp_redir() - made re-basing onto Alexander's slirp stuff that bit more involved
- You could have split up "slirp: Move smb, redir, tftp and bootp parameters and -net channel", maybe even made a separate patch for each move
- It's very hard to understand why each of the changes in "slirp:
Rework internal configuration" is needed and it's a big patch - e.g. you completely re-wrote tcp_ctl(). Could that have been done with a cleanup patch with no functional changes followed by the actual functional changes?
- "slirp: Rework external configuration interface" introduces several new slirp options. Surely should be possible to split up into smaller patches.
Cheers,
Mark.
Re: [Qemu-devel] [PATCH 10/11] slirp: Rework external configuration interface
Quoted 10 lines · Mark McLoughlin
Quoted 6 lines · Jan Kiszka
Quoted 3 lines
You're renaming "redir" and "channel" here which isn't a big deal since you've only introduced them in the previous patch, but it would be better to use the final names in the original patch.
Well, the purpose of the original patch was only to pull "redir" and "channel" as-is into the -net parameter list, not to refactor the interface otherwise.
It's a bisectability thing - we shouldn't introduce parameters in a patch that we intend to rename in a subsequent patch.
I do not only rename them, I also change their syntax.
Quoted 3 lines
e.g. if a distro cherry-picked this patch, we'd have options in the wild that aren't available upstream.
If distros cherry-pick transient public interface changes, I really can't help - or I would consequently have to merge internal, external interface rework and the final hostfwd syntax extension into a single patch. I don't think this is desired either.
Quoted 32 lines
Quoted 7 lines
Quoted 2 lines
More importantly, though, you've dropped the "ip" parameter which is
in
Quoted 1 line
the 0.10.x releases. We can't just drop existing parameters.
OK, I see the problem - though this parameter was probable rarely used (it was undocumented and suffered from the poor configurability). Will have a closer look.
Great. Probably best to re-send 7-11 with both of these things fixed up.
Quoted 8 lines
Quoted 1 line
By way of meta-comment, some of these patches are much harder to
review
Quoted 3 lines
than they need to be, because e.g. you're doing lots of cleanups together with the real changes, or not breaking changes into smaller chunks.
There might be a few coding style updates included, when I touch related
lines. Or please give some (or the most annoying) example.Okay:
- In "Avoid zombie processes after
fork_exec" you needlessly re-arrange the code inlaunch_script()- it could have very reasonably been an easy to review +6 hunk rather than a -24/+36 hunk if you'd split the cleanup out into its own patch- "Real fix for
check_paramsusers" could have been split into the revert followed by the better fix- In "Improve parameter error reporting", you replace a
strdup()withqemu_strdup(), unrelated to the goal of the patch
Quoted 7 lines
- In "Reorder initialization", you change the formatting of the args to the
qemu_new_vlan_client()call - conflicted with my patches- In the same patch you've added a whole pile of braces in what was
net_slirp_redir()- made re-basing onto Alexander's slirp stuff that bit more involved
Agreed (though the last conflict was not only related to that hunk), some could have just been dropped, others split up without too much effort.
Quoted 3 lines
- You could have split up "slirp: Move smb, redir, tftp and bootp parameters and -net channel", maybe even made a separate patch for each move
But that would have been overkill (they share a lot).
Quoted 6 lines
- It's very hard to understand why each of the changes in "slirp:
Rework internal configuration" is needed and it's a big patch - e.g. you completely re-wrotetcp_ctl(). Could that have been done with a cleanup patch with no functional changes followed by the actual functional changes?
Yes, tcp_ctl could have been sanitized beforehand. But the rest is related to scope of the patch.
Quoted 4 lines
- "slirp: Rework external configuration interface" introduces several new slirp options. Surely should be possible to split up into smaller patches.
Not impossible, but significant additional effort.
Thanks for the detailed comments! Will try harder to avoid the needless mixups in the future.
Jan
PATCH 11/11 slirp: Bind support for host forwarding rules
In reply to Jan KiszkaExtend the hostfwd rule format so that the user can specify on which host interface qemu should listen for incoming connections. If omitted, binding will takes place against all interfaces.
---
net.c | 28 +++++++++++++++++++++------- qemu-options.hx | 11 ++++++----- slirp/libslirp.h | 2 +- slirp/slirp.c | 8 ++++---- slirp/socket.c | 10 +++++----- slirp/socket.h | 2 +- slirp/tcp_subr.c | 13 +++++++------ slirp/udp.c | 7 ++++--- slirp/udp.h | 2 +- 9 files changed, 50 insertions(+), 33 deletions(-)
net.c +21 -7
@@ -571,7 +571,8 @@ static const char *slirp_smb_export;static VLANClientState *slirp_vc;static void slirp_smb (const char *exported_dir,struct in_addr vserver_addr); -static void slirp_hostfwd (Monitor *mon,const char *redir_str); +static void slirp_hostfwd (Monitor *mon,const char *redir_str, +int legacy_format);static void slirp_guestfwd (Monitor *mon,const char *config_str,int legacy_format);
@@ -719,7 +720,8 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,struct slirp_config_str *config = slirp_configs;if (config->flags &SLIRP_CFG_HOSTFWD ) { -slirp_hostfwd (mon, config->str); +slirp_hostfwd (mon, config->str, + config->flags &SLIRP_CFG_LEGACY ); }else {slirp_guestfwd (mon, config->str, config->flags &SLIRP_CFG_LEGACY );
@@ -747,8 +749,10 @@ static int net_slirp_init(Monitor *mon, VLANState *vlan, const char *model,return 0 ; } -static void slirp_hostfwd (Monitor *mon,const char *redir_str) +static void slirp_hostfwd (Monitor *mon,const char *redir_str, +int legacy_format) { +struct in_addr host_addr = { .s_addr =INADDR_ANY };struct in_addr guest_addr = { .s_addr =0 };int host_port, guest_port;const char *p;
@@ -768,7 +772,16 @@ static void slirp_hostfwd(Monitor *mon, const char *redir_str) goto fail_syntax; } -if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { +if (!legacy_format) { +if (get_str_sep (buf,sizeof (buf), &p,':' ) <0 ) { + goto fail_syntax; + } +if (buf[0 ] !='\0' && !inet_aton (buf, &host_addr)) { + goto fail_syntax; + } + } + +if (get_str_sep (buf,sizeof (buf), &p, legacy_format ?':' :'-' ) <0 ) { goto fail_syntax; } host_port =strtol (buf, &end,0 );
@@ -788,7 +801,8 @@ static void slirp_hostfwd(Monitor *mon, const char *redir_str) goto fail_syntax; } -if (slirp_redir (is_udp, host_port, guest_addr, guest_port) <0 ) { +if (slirp_redir (is_udp, host_addr, host_port, + guest_addr, guest_port) <0 ) {config_error (mon,"could not set up host forwarding rule '%s'\n" , redir_str); }
@@ -808,14 +822,14 @@ void net_slirp_redir(Monitor *mon, const char *redir_str) }else { config =qemu_malloc (sizeof (*config));pstrcpy (config->str,sizeof (config->str), redir_str); - config->flags =SLIRP_CFG_HOSTFWD ; + config->flags =SLIRP_CFG_HOSTFWD |SLIRP_CFG_LEGACY ; config->next = slirp_configs; slirp_configs = config; }return ; } -slirp_hostfwd (mon, redir_str); +slirp_hostfwd (mon, redir_str,1 ); }#ifndef _WIN32
qemu-options.hx +6 -5
@@ -859,11 +859,12 @@ Note that a SAMBA server must be installed on the host OS in @file{/usr/sbin/smbd}. QEMU was tested successfully with smbd versions from Red Hat 9, Fedora Core 3 and OpenSUSE 11.x. -@item hostfwd=[tcp|udp]:@var{hostport}:[@var{guestaddr}]:@var{guestport} +@item hostfwd=[tcp|udp]:[@var{hostaddr}]:@var{hostport}-[@var{guestaddr}]:@var{guestport} Redirect incoming TCP or UDP connections to the host port @var{hostport} to the guest IP address @var{guestaddr} on guest port @var{guestport}. If @var{guestaddr} is not specified, its value is x.x.x.15 (default first address -given by the built-in DHCP server). If no connection type is specified, TCP is +given by the built-in DHCP server). By specifying @var{hostaddr}, the rule can +be bound to a specific host interface. If no connection type is set, TCP is used. This option can be given multiple times. For example, to redirect host X11 connection from screen 1 to guest
@@ -871,7 +872,7 @@ screen 0, use the following: @example # on the host -qemu -net user,hostfwd=tcp:6001::6000 [...] +qemu -net user,hostfwd=tcp:127.0.0.1:6001-:6000 [...] # this host xterm should open in the guest X11 server xterm -display :1 @end example
@@ -889,8 +890,8 @@ Then when you use on the host @code{telnet localhost 5555}, you connect to the guest telnet server. @item guestfwd=[tcp]:@var{server}:@var{port}-@var{dev} -Forward guest TCP connections to port @var{port} on the host to character -device @var{dev}. This option can be given multiple times. +Forward guest TCP connections to the IP address @var{server} on port @var{port} +to the character device @var{dev}. This option can be given multiple times. @end table
slirp/libslirp.h +1 -1
@@ -22,7 +22,7 @@ void slirp_input(const uint8_t *pkt, int pkt_len);int slirp_can_output (void );void slirp_output (const uint8_t *pkt,int pkt_len); -int slirp_redir (int is_udp,int host_port, +int slirp_redir (int is_udp,struct in_addr host_addr,int host_port,struct in_addr guest_addr,int guest_port);int slirp_add_exec (int do_pty,const void *args,struct in_addr guest_addr,int guest_port);
slirp/slirp.c +4 -4
@@ -747,19 +747,19 @@ void if_encap(const uint8_t *ip_data, int ip_data_len) } } -int slirp_redir (int is_udp,int host_port, +int slirp_redir (int is_udp,struct in_addr host_addr,int host_port,struct in_addr guest_addr,int guest_port) {if (!guest_addr.s_addr) { guest_addr = vdhcp_startaddr; }if (is_udp) { -if (!udp_listen (htons (host_port), guest_addr.s_addr, +if (!udp_listen (host_addr.s_addr,htons (host_port), guest_addr.s_addr,htons (guest_port),0 ))return -1 ; }else { -if (!solisten (htons (host_port), guest_addr.s_addr, -htons (guest_port),0 )) +if (!tcp_listen (host_addr.s_addr,htons (host_port), guest_addr.s_addr, +htons (guest_port),0 ))return -1 ; }return 0 ;
slirp/socket.c +5 -5
@@ -581,17 +581,17 @@ sosendto(struct socket *so, struct mbuf *m) }/* -* XXX This should really be tcp_listen +* Listen for incoming TCP connections */ struct socket * -solisten (u_int port,u_int32_t laddr,u_int lport,int flags) +tcp_listen (u_int32_t haddr,u_int hport,u_int32_t laddr,u_int lport,int flags) {struct sockaddr_in addr;struct socket *so;int s, opt =1 ;socklen_t addrlen =sizeof (addr); -DEBUG_CALL ("solisten" ); +DEBUG_CALL ("tcp_listen" );DEBUG_ARG ("port = %d" , port);DEBUG_ARG ("laddr = %x" , laddr);DEBUG_ARG ("lport = %d" , lport);
@@ -620,8 +620,8 @@ solisten(u_int port, u_int32_t laddr, u_int lport, int flags) so->so_laddr.s_addr = laddr;/* Ditto */ addr.sin_family =AF_INET ; - addr.sin_addr.s_addr =INADDR_ANY ; - addr.sin_port = port; + addr.sin_addr.s_addr = haddr; + addr.sin_port = hport; if (((s = socket(AF_INET,SOCK_STREAM,0)) < 0) || (setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int)) < 0) ||
slirp/socket.h +1 -1
@@ -82,7 +82,7 @@ int sosendoob _P((struct socket *)); int sowrite _P((struct socket *)); void sorecvfrom _P((struct socket *)); int sosendto _P((struct socket *, struct mbuf *)); -struct socket * solisten _P((u_int, u_int32_t, u_int, int)); +struct socket * tcp_listen _P((u_int32_t, u_int, u_int32_t, u_int, int)); void soisfconnecting _P((register struct socket *)); void soisfconnected _P((register struct socket *)); void soisfdisconnected _P((struct socket *));
slirp/tcp_subr.c +7 -6
@@ -970,7 +970,7 @@ do_prompt: laddr =htonl ((n1 <<24 ) | (n2 <<16 ) | (n3 <<8 ) | (n4)); lport =htons ((n5 <<8 ) | (n6)); -if ((so =solisten (0 , laddr, lport,SS_FACCEPTONCE )) ==NULL ) +if ((so =tcp_listen (INADDR_ANY ,0 , laddr, lport,SS_FACCEPTONCE )) ==NULL )return 1 ; n6 =ntohs (so->so_fport);
@@ -1002,7 +1002,7 @@ do_prompt: laddr =htonl ((n1 <<24 ) | (n2 <<16 ) | (n3 <<8 ) | (n4)); lport =htons ((n5 <<8 ) | (n6)); -if ((so =solisten (0 , laddr, lport,SS_FACCEPTONCE )) ==NULL ) +if ((so =tcp_listen (INADDR_ANY ,0 , laddr, lport,SS_FACCEPTONCE )) ==NULL )return 1 ; n6 =ntohs (so->so_fport);
@@ -1042,7 +1042,7 @@ do_prompt: lport += m->m_data[i] -'0' ; }if (m->m_data[m->m_len-1 ] =='\0' && lport !=0 && - (so =solisten (0 , so->so_laddr.s_addr,htons (lport),SS_FACCEPTONCE )) !=NULL ) + (so =tcp_listen (INADDR_ANY ,0 , so->so_laddr.s_addr,htons (lport),SS_FACCEPTONCE )) !=NULL ) m->m_len =snprintf (m->m_data, m->m_hdr.mh_size,"%d" ,ntohs (so->so_fport)) +1 ;return 1 ;
@@ -1057,7 +1057,7 @@ do_prompt:/* The %256s is for the broken mIRC */ if (sscanf (bptr,"DCC CHAT %256s %u %u" , buff, &laddr, &lport) ==3 ) { -if ((so =solisten (0 ,htonl (laddr),htons (lport),SS_FACCEPTONCE )) ==NULL ) +if ((so =tcp_listen (INADDR_ANY ,0 ,htonl (laddr),htons (lport),SS_FACCEPTONCE )) ==NULL )return 1 ; m->m_len = bptr - m->m_data;/* Adjust length */
@@ -1066,7 +1066,7 @@ do_prompt: (unsigned long )ntohl (so->so_faddr.s_addr), ntohs(so->so_fport), 1); }else if (sscanf (bptr,"DCC SEND %256s %u %u %u" , buff, &laddr, &lport, &n1) ==4 ) { -if ((so =solisten (0 ,htonl (laddr),htons (lport),SS_FACCEPTONCE )) ==NULL ) +if ((so =tcp_listen (INADDR_ANY ,0 ,htonl (laddr),htons (lport),SS_FACCEPTONCE )) ==NULL )return 1 ; m->m_len = bptr - m->m_data;/* Adjust length */
@@ -1075,7 +1075,7 @@ do_prompt: (unsigned long )ntohl (so->so_faddr.s_addr), ntohs(so->so_fport), n1, 1); }else if (sscanf (bptr,"DCC MOVE %256s %u %u %u" , buff, &laddr, &lport, &n1) ==4 ) { -if ((so =solisten (0 ,htonl (laddr),htons (lport),SS_FACCEPTONCE )) ==NULL ) +if ((so =tcp_listen (INADDR_ANY ,0 ,htonl (laddr),htons (lport),SS_FACCEPTONCE )) ==NULL )return 1 ; m->m_len = bptr - m->m_data;/* Adjust length */
@@ -1191,6 +1191,7 @@ do_prompt:/* try to get udp port between 6970 - 7170 */ for (p =6970 ; p <7071 ; p++) {if (udp_listen (htons (p), +INADDR_ANY , so->so_laddr.s_addr,htons (lport),SS_FACCEPTONCE )) {
slirp/udp.c +4 -3
@@ -629,7 +629,8 @@ struct cu_header { }struct socket * -udp_listen (u_int port,u_int32_t laddr,u_int lport,int flags) +udp_listen (u_int32_t haddr,u_int hport,u_int32_t laddr,u_int lport, +int flags) {struct sockaddr_in addr;struct socket *so;
@@ -644,8 +645,8 @@ udp_listen(u_int port, u_int32_t laddr, u_int lport, int flags)insque (so,&udb); addr.sin_family =AF_INET ; - addr.sin_addr.s_addr =INADDR_ANY ; - addr.sin_port = port; + addr.sin_addr.s_addr = haddr; + addr.sin_port = hport;if (bind (so->s,(struct sockaddr *)&addr, addrlen) <0 ) {udp_detach (so);
slirp/udp.h +1 -1
@@ -101,7 +101,7 @@ void udp_input _P((register struct mbuf *, int)); int udp_output _P((struct socket *, struct mbuf *, struct sockaddr_in *)); int udp_attach _P((struct socket *)); void udp_detach _P((struct socket *)); -struct socket * udp_listen _P((u_int, u_int32_t, u_int, int)); +struct socket * udp_listen _P((u_int32_t, u_int, u_int32_t, u_int, int));int udp_output2 (struct socket *so,struct mbuf *m,struct sockaddr_in *saddr,struct sockaddr_in *daddr,int iptos);
Quoted 10 lines · Jan Kiszka
This series starts with four networking-related fixes and then focuses on a grand refactoring of the slirp user space IP stack configuration.
The major contribution is that the virtual IP addresses used by slirp can now be (almost) freely configured. This enables sophisticated virtual network setups, specifically with guests that depends on specific addresses.
Find this series also at
git://git.kiszka.org/qemu.gitqueues/net
Quoted 13 lines
Jan Kiszka (11):
net: Don't deliver to disabled interfaces inqemu_sendv_packet
net: Fix and improved ordered packet delivery
slirp: Avoid zombie processes afterfork_exec
net: Real fix forcheck_paramsusers
net: Improve parameter error reporting
slirp: Reorder initialization
Introduceget_next_param_value
slirp: Move smb, redir, tftp and bootp parameters and -net channel
slirp: Rework internal configuration
slirp: Rework external configuration interface
slirp: Bind support for host forwarding rules
With this series applied, I get:
CC slirp/cksum.o
In file included from /home/anthony/git/qemu/slirp/slirp.h:216,
from /home/anthony/git/qemu/slirp/cksum.c:34:/home/anthony/git/qemu/slirp/main.h:51: error: ‘PATH_MAX’ undeclared here (not in a function)
make: *** [slirp/cksum.o] Error 1
Regards,
Anthony Liguori
Quoted 25 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
This series starts with four networking-related fixes and then focuses on a grand refactoring of the slirp user space IP stack configuration.
The major contribution is that the virtual IP addresses used by slirp can now be (almost) freely configured. This enables sophisticated virtual network setups, specifically with guests that depends on specific addresses.
Find this series also at
git://git.kiszka.org/qemu.gitqueues/netQuoted 13 lines
Jan Kiszka (11):
net: Don't deliver to disabled interfaces inqemu_sendv_packet
net: Fix and improved ordered packet delivery
slirp: Avoid zombie processes afterfork_exec
net: Real fix forcheck_paramsusers
net: Improve parameter error reporting
slirp: Reorder initialization
Introduceget_next_param_value
slirp: Move smb, redir, tftp and bootp parameters and -net channel
slirp: Rework internal configuration
slirp: Rework external configuration interface
slirp: Bind support for host forwarding rules
Quoted 8 lines
With this series applied, I get:
CC
slirp/cksum.o
In file included from/home/anthony/git/qemu/slirp/slirp.h:216,
from/home/anthony/git/qemu/slirp/cksum.c:34:/home/anthony/git/qemu/slirp/main.h:51: error: ‘PATH_MAX’ undeclared here (not in a function)
make: *** [slirp/cksum.o] Error 1
Hmpf.
As I can't reproduce here: Does this add-on patch make it build?
slirp/main.h +2 -0
@@ -9,6 +9,8 @@#include <sys/select.h> #endif +#include <limit.h> +#define TOWRITEMAX 512extern struct timeval tt;
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
PATCH v2 8/11 slirp: Move smb, redir, tftp and bootp parameters and -net channel
Quoted 43 lines · Jan Kiszka
Quoted 24 lines · Anthony Liguori
Quoted 10 lines · Jan Kiszka
This series starts with four networking-related fixes and then focuses on a grand refactoring of the slirp user space IP stack configuration.
The major contribution is that the virtual IP addresses used by slirp can now be (almost) freely configured. This enables sophisticated virtual network setups, specifically with guests that depends on specific addresses.
Find this series also at
git://git.kiszka.org/qemu.gitqueues/netQuoted 13 lines
Jan Kiszka (11):
net: Don't deliver to disabled interfaces inqemu_sendv_packet
net: Fix and improved ordered packet delivery
slirp: Avoid zombie processes afterfork_exec
net: Real fix forcheck_paramsusers
net: Improve parameter error reporting
slirp: Reorder initialization
Introduceget_next_param_value
slirp: Move smb, redir, tftp and bootp parameters and -net channel
slirp: Rework internal configuration
slirp: Rework external configuration interface
slirp: Bind support for host forwarding rulesQuoted 8 lines
With this series applied, I get:
CC
slirp/cksum.o
In file included from/home/anthony/git/qemu/slirp/slirp.h:216,
from/home/anthony/git/qemu/slirp/cksum.c:34:/home/anthony/git/qemu/slirp/main.h:51: error: ‘PATH_MAX’ undeclared here (not in a function)
make: *** [slirp/cksum.o] Error 1Hmpf.
As I can't reproduce here: Does this add-on patch make it build?
slirp/main.h +0
-0
slirp/main.h line 13
Quoted 5 lines
slirp/main.h +2
-0@@ -9,6 +9,8 @@#include <sys/select.h> #endif +#include <limit.h> +
This should have been "limits", of course. Here is an updated patch 8:
--------->
So far a couple of slirp-related parameters were expressed via stand-alone command line options. This it inconsistent and unintuitive. Moreover, it prevents both dynamically reconfigured (host_net_add/ delete) and multi-instance slirp.
This patch refactors the configuration by turning -smb, -redir, -tftp and -bootp as well as -net channel into options of "-net user". The old stand-alone command line options are still processed, but no longer advertised. This allows smooth migration of management applications to to the new syntax and also the extension of that syntax later in this series.
---
net.c | 157 +++++++++++++++++++++++++++++++---------- net.h | 3 + qemu-options.hx | 209 +++++++++++++++++++++++++++++------------------------- slirp/bootp.c | 4 + slirp/libslirp.h | 5 + slirp/main.h | 4 + slirp/slirp.c | 10 ++- slirp/tftp.c | 6 +- vl.c | 6 +- 9 files changed, 256 insertions(+), 148 deletions(-)
net.c +120 -37
@@ -551,13 +551,18 @@ static void config_error(Monitor *mon, const char *fmt, ...)/* slirp network adapter */ +#define SLIRP_CFG_REDIR 1 +struct slirp_config_str {struct slirp_config_str *next; -const char *str; +int flags; +char str[1024 ]; };static int slirp_inited; -static struct slirp_config_str *slirp_redirs; +static struct slirp_config_str *slirp_configs; +const char *legacy_tftp_prefix; +const char *legacy_bootp_filename;#ifndef _WIN32static const char *slirp_smb_export;#endif
@@ -565,6 +570,7 @@ static VLANClientState *slirp_vc;static void slirp_smb (const char *exported_dir);static void slirp_redirection (Monitor *mon,const char *redir_str); +static void vmchannel_init (Monitor *mon,const char *config_str);int slirp_can_output (void ) {
@@ -603,25 +609,40 @@ static void net_slirp_cleanup(VLANClientState *vc) slirp_in_use =0 ; } -static int net_slirp_init (VLANState *vlan,const char *model,const char *name, -int restricted,const char *ip) +static int net_slirp_init (Monitor *mon,VLANState *vlan,const char *model, +const char *name,int restricted,const char *ip, +const char *tftp_export,const char *bootfile, +const char *smb_export) {if (slirp_in_use) {/* slirp only supports a single instance so far */ return -1 ; }if (!slirp_inited) { +if (!tftp_export) { + tftp_export = legacy_tftp_prefix; + } +if (!bootfile) { + bootfile = legacy_bootp_filename; + } slirp_inited =1 ; -slirp_init (restricted, ip); +slirp_init (restricted, ip, tftp_export, bootfile); -while (slirp_redirs) { -struct slirp_config_str *config = slirp_redirs; +while (slirp_configs) { +struct slirp_config_str *config = slirp_configs; -slirp_redirection (NULL , config->str); - slirp_redirs = config->next; +if (config->flags &SLIRP_CFG_REDIR ) { +slirp_redirection (mon, config->str); + }else { +vmchannel_init (mon, config->str); + } + slirp_configs = config->next;qemu_free (config); }#ifndef _WIN32 +if (smb_export) { + slirp_smb_export = smb_export; + }if (slirp_smb_export) {slirp_smb (slirp_smb_export); }
@@ -696,9 +717,10 @@ void net_slirp_redir(Monitor *mon, const char *redir_str)monitor_printf (mon,"user mode network stack not in use\n" ); }else { config =qemu_malloc (sizeof (*config)); - config->str = redir_str; - config->next = slirp_redirs; - slirp_redirs = config; +pstrcpy (config->str,sizeof (config->str), redir_str); + config->flags =SLIRP_CFG_REDIR ; + config->next = slirp_configs; + slirp_configs = config; }return ; }
@@ -827,6 +849,36 @@ static void vmchannel_read(void *opaque, const uint8_t *buf, int size)slirp_socket_recv (4 , vmc->port, buf, size); } +static void vmchannel_init (Monitor *mon,const char *config_str) +{ +struct VMChannel *vmc; +char *devname; +char name[20 ]; +int port; + + port =strtol (config_str, &devname,10 ); +if (port <1 || port >65535 || *devname !=':' ) { +config_error (mon,"invalid vmchannel port number\n" ); +return ; + } + devname++; + + vmc =qemu_malloc (sizeof (struct VMChannel )); +snprintf (name,sizeof (name),"vmchannel%d" , port); + vmc->hd =qemu_chr_open (name, devname,NULL ); +if (!vmc->hd) { +config_error (mon,"could not open vmchannel device '%s'\n" , devname); +qemu_free (vmc); +return ; + } + vmc->port = port; + +slirp_add_exec (3 , vmc->hd,4 , port); +qemu_chr_add_handlers (vmc->hd, vmchannel_can_read, vmchannel_read, +NULL , vmc); +return ; +} +#endif /* CONFIG_SLIRP */ #if !defined(_WIN32)
@@ -1936,10 +1988,16 @@ int net_client_init(Monitor *mon, const char *device, const char *p)#ifdef CONFIG_SLIRP if (!strcmp (device,"user" )) {static const char *const slirp_params[] = { -"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,NULL +"vlan" ,"name" ,"hostname" ,"restrict" ,"ip" ,"tftp" ,"bootfile" , +"smb" ,"redir" ,"channel" ,NULL }; +struct slirp_config_str *config; +char *tftp_export =NULL ; +char *bootfile =NULL ; +char *smb_export =NULL ;int restricted =0 ;char *ip =NULL ; +const char *q;if (check_params (buf,sizeof (buf), slirp_params, p) <0 ) {config_error (mon,"invalid parameter '%s' in '%s'\n" , buf, p);
@@ -1955,34 +2013,59 @@ int net_client_init(Monitor *mon, const char *device, const char *p)if (get_param_value (buf,sizeof (buf),"ip" , p)) { ip =qemu_strdup (buf); } +if (get_param_value (buf,sizeof (buf),"tftp" , p)) { + tftp_export =qemu_strdup (buf); + } +if (get_param_value (buf,sizeof (buf),"bootfile" , p)) { + bootfile =qemu_strdup (buf); + } +if (get_param_value (buf,sizeof (buf),"smb" , p)) { + smb_export =qemu_strdup (buf); + } + q = p; +while (1 ) { + config =qemu_malloc (sizeof (*config)); +if (!get_next_param_value (config->str,sizeof (config->str), +"redir" , &q)) { +break ; + } + config->flags =SLIRP_CFG_REDIR ; + config->next = slirp_configs; + slirp_configs = config; + config =NULL ; + } + q = p; +while (1 ) { + config =qemu_malloc (sizeof (*config)); +if (!get_next_param_value (config->str,sizeof (config->str), +"channel" , &q)) { +break ; + } + config->flags =0 ; + config->next = slirp_configs; + slirp_configs = config; + config =NULL ; + } +qemu_free (config); vlan->nb_host_devs++; - ret =net_slirp_init (vlan, device, name, restricted, ip); + ret =net_slirp_init (mon, vlan, device, name, restricted, ip, + tftp_export, bootfile, smb_export);qemu_free (ip); +qemu_free (tftp_export); +qemu_free (bootfile); + qemu_free(smb_export); }else if (!strcmp (device,"channel" )) { -long port; -char name[20 ], *devname; -struct VMChannel *vmc; - - port =strtol (p, &devname,10 ); - devname++; -if (port <1 || port >65535 ) { -config_error (mon,"vmchannel wrong port number\n" ); - ret =-1 ; - goto out; - } - vmc =malloc (sizeof (struct VMChannel )); -snprintf (name,20 ,"vmchannel%ld" , port); - vmc->hd =qemu_chr_open (name, devname,NULL ); -if (!vmc->hd) { -config_error (mon,"could not open vmchannel device '%s'\n" , - devname); - ret =-1 ; - goto out; +if (!slirp_inited) { +struct slirp_config_str *config; + + config =qemu_malloc (sizeof (*config)); +pstrcpy (config->str,sizeof (config->str), p); + config->flags =0 ; + config->next = slirp_configs; + slirp_configs = config; + }else { +vmchannel_init (mon, p); } - vmc->port = port; -slirp_add_exec (3 , vmc->hd,4 , port); -qemu_chr_add_handlers (vmc->hd, vmchannel_can_read, vmchannel_read, -NULL , vmc); ret =0 ; } else#endif
net.h +3 -0
@@ -108,6 +108,9 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,void net_checksum_calculate (uint8_t *data,int length);/* from net.c */ +extern const char *legacy_tftp_prefix; +extern const char *legacy_bootp_filename; +int net_client_init (Monitor *mon,const char *device,const char *p);void net_client_uninit (NICInfo *nd);int net_client_parse (const char *str);
qemu-options.hx +111 -98
233 lines not on this page · raw message
slirp/bootp.c +2 -2
@@ -38,7 +38,7 @@ typedef struct {static BOOTPClient bootp_clients[NB_ADDR ]; -const char *bootp_filename; +char bootp_filename[PATH_MAX ] ="" ;static const uint8_t rfc1533_cookie[] = {RFC1533_COOKIE };
@@ -249,7 +249,7 @@ static void bootp_reply(const struct bootp_t *bp) *q++ =DHCPACK ; } -if (bootp_filename) +if (bootp_filename[0 ] !=0 )snprintf ((char *)rbp->bp_file,sizeof (rbp->bp_file),"%s" , bootp_filename);
slirp/libslirp.h +2 -3
@@ -5,7 +5,8 @@extern "C" {#endif -void slirp_init (int restricted,const char *special_ip); +void slirp_init (int restricted,const char *special_ip,const char *tftp_path, +const char *bootfile);void slirp_select_fill (int *pnfds,fd_set *readfds,fd_set *writefds,fd_set *xfds);
@@ -23,9 +24,7 @@ int slirp_redir(int is_udp, int host_port,int slirp_add_exec (int do_pty,const void *args,int addr_low_byte,int guest_port); -extern const char *tftp_prefix;extern char slirp_hostname[33 ]; -extern const char *bootp_filename;void slirp_stats (void ); void slirp_socket_recv(int addr_low_byte, int guest_port, const uint8_t *buf,
slirp/main.h +4 -0
@@ -9,6 +9,8 @@#include <sys/select.h> #endif +#include <limits.h> +#define TOWRITEMAX 512extern struct timeval tt;
@@ -46,6 +48,8 @@ extern int tcp_keepintvl;extern uint8_t client_ethaddr[6 ];extern const char *slirp_special_ip;extern int slirp_restrict; +extern char tftp_prefix[PATH_MAX ]; +extern char bootp_filename[PATH_MAX ];#define PROTO_SLIP 0x1#ifdef USE_PPP
slirp/slirp.c +8 -2
@@ -171,7 +171,8 @@ static void slirp_cleanup(void)static void slirp_state_save (QEMUFile *f,void *opaque);static int slirp_state_load (QEMUFile *f,void *opaque,int version_id); -void slirp_init (int restricted,const char *special_ip) +void slirp_init (int restricted,const char *special_ip,const char *tftp_path, +const char *bootfile) {// debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
@@ -202,7 +203,12 @@ void slirp_init(int restricted, const char *special_ip)if (special_ip) slirp_special_ip = special_ip; - +if (tftp_path) { +pstrcpy (tftp_prefix,sizeof (tftp_prefix), tftp_path); + } +if (bootfile) { +pstrcpy (bootp_filename,sizeof (bootp_filename), bootfile); + }inet_aton (slirp_special_ip, &special_addr); alias_addr.s_addr = special_addr.s_addr |htonl (CTL_ALIAS );getouraddr ();
slirp/tftp.c +3 -3
@@ -37,7 +37,7 @@ struct tftp_session {static struct tftp_session tftp_sessions[TFTP_SESSIONS_MAX ]; -const char *tftp_prefix; +char tftp_prefix[PATH_MAX ] ="" ;static void tftp_session_update (struct tftp_session *spt) {
@@ -335,7 +335,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)/* only allow exported prefixes */ -if (!tftp_prefix) { +if (tftp_prefix[0 ] ==0 ) {tftp_send_error (spt,2 ,"Access violation" , tp);return ; }
@@ -370,7 +370,7 @@ static void tftp_handle_rrq(struct tftp_t *tp, int pktlen)int tsize =atoi (value);struct stat stat_p; -if (tsize ==0 && tftp_prefix) { +if (tsize ==0 && tftp_prefix[0 ] !=0 ) {char buffer[1024 ];int len;
vl.c +3 -3
@@ -5146,14 +5146,14 @@ int main(int argc, char **argv, char **envp)break ;#ifdef CONFIG_SLIRP case QEMU_OPTION_tftp: - tftp_prefix = optarg; + legacy_tftp_prefix = optarg;break ;case QEMU_OPTION_bootp: - bootp_filename = optarg; + legacy_bootp_filename = optarg;break ;#ifndef _WIN32case QEMU_OPTION_smb: -net_slirp_smb (optarg); +net_slirp_smb (optarg);break ;#endif case QEMU_OPTION_redir: