Commit bb53fc5394201c0cbe3c89a1c9fa5fbd6a3b832c

Authored by Jan Kiszka
Committed by Anthony Liguori
1 parent 9dfd7c7a

slirp: Fix guestfwd for incoming data

Unless a virtual server address was explicitly defined (which is
impossible with the legacy -net channel format), guestfwd did not
properly forwarded host->guest packets. This patch fixes it.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
@@ -1150,7 +1150,7 @@ static void slirp_smb(SlirpState* s, Monitor *mon, const char *exported_dir, @@ -1150,7 +1150,7 @@ static void slirp_smb(SlirpState* s, Monitor *mon, const char *exported_dir,
1150 snprintf(smb_cmdline, sizeof(smb_cmdline), "%s -s %s", 1150 snprintf(smb_cmdline, sizeof(smb_cmdline), "%s -s %s",
1151 SMBD_COMMAND, smb_conf); 1151 SMBD_COMMAND, smb_conf);
1152 1152
1153 - if (slirp_add_exec(s->slirp, 0, smb_cmdline, vserver_addr, 139) < 0) { 1153 + if (slirp_add_exec(s->slirp, 0, smb_cmdline, &vserver_addr, 139) < 0) {
1154 slirp_smb_cleanup(s); 1154 slirp_smb_cleanup(s);
1155 config_error(mon, "conflicting/invalid smbserver address\n"); 1155 config_error(mon, "conflicting/invalid smbserver address\n");
1156 } 1156 }
@@ -1239,16 +1239,17 @@ static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str, @@ -1239,16 +1239,17 @@ static void slirp_guestfwd(SlirpState *s, Monitor *mon, const char *config_str,
1239 qemu_free(fwd); 1239 qemu_free(fwd);
1240 return; 1240 return;
1241 } 1241 }
1242 - fwd->server = server;  
1243 - fwd->port = port;  
1244 - fwd->slirp = s->slirp;  
1245 1242
1246 - if (slirp_add_exec(s->slirp, 3, fwd->hd, server, port) < 0) { 1243 + if (slirp_add_exec(s->slirp, 3, fwd->hd, &server, port) < 0) {
1247 config_error(mon, "conflicting/invalid host:port in guest forwarding " 1244 config_error(mon, "conflicting/invalid host:port in guest forwarding "
1248 "rule '%s'\n", config_str); 1245 "rule '%s'\n", config_str);
1249 qemu_free(fwd); 1246 qemu_free(fwd);
1250 return; 1247 return;
1251 } 1248 }
  1249 + fwd->server = server;
  1250 + fwd->port = port;
  1251 + fwd->slirp = s->slirp;
  1252 +
1252 qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read, 1253 qemu_chr_add_handlers(fwd->hd, guestfwd_can_read, guestfwd_read,
1253 NULL, fwd); 1254 NULL, fwd);
1254 return; 1255 return;
slirp/libslirp.h
@@ -33,7 +33,7 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, @@ -33,7 +33,7 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp,
33 int slirp_remove_hostfwd(Slirp *slirp, int is_udp, 33 int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
34 struct in_addr host_addr, int host_port); 34 struct in_addr host_addr, int host_port);
35 int slirp_add_exec(Slirp *slirp, int do_pty, const void *args, 35 int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
36 - struct in_addr guest_addr, int guest_port); 36 + struct in_addr *guest_addr, int guest_port);
37 37
38 void slirp_connection_info(Slirp *slirp, Monitor *mon); 38 void slirp_connection_info(Slirp *slirp, Monitor *mon);
39 39
slirp/slirp.c
@@ -794,19 +794,19 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, @@ -794,19 +794,19 @@ int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr,
794 } 794 }
795 795
796 int slirp_add_exec(Slirp *slirp, int do_pty, const void *args, 796 int slirp_add_exec(Slirp *slirp, int do_pty, const void *args,
797 - struct in_addr guest_addr, int guest_port) 797 + struct in_addr *guest_addr, int guest_port)
798 { 798 {
799 - if (!guest_addr.s_addr) {  
800 - guest_addr.s_addr = slirp->vnetwork_addr.s_addr | 799 + if (!guest_addr->s_addr) {
  800 + guest_addr->s_addr = slirp->vnetwork_addr.s_addr |
801 (htonl(0x0204) & ~slirp->vnetwork_mask.s_addr); 801 (htonl(0x0204) & ~slirp->vnetwork_mask.s_addr);
802 } 802 }
803 - if ((guest_addr.s_addr & slirp->vnetwork_mask.s_addr) != 803 + if ((guest_addr->s_addr & slirp->vnetwork_mask.s_addr) !=
804 slirp->vnetwork_addr.s_addr || 804 slirp->vnetwork_addr.s_addr ||
805 - guest_addr.s_addr == slirp->vhost_addr.s_addr ||  
806 - guest_addr.s_addr == slirp->vnameserver_addr.s_addr) { 805 + guest_addr->s_addr == slirp->vhost_addr.s_addr ||
  806 + guest_addr->s_addr == slirp->vnameserver_addr.s_addr) {
807 return -1; 807 return -1;
808 } 808 }
809 - return add_exec(&slirp->exec_list, do_pty, (char *)args, guest_addr, 809 + return add_exec(&slirp->exec_list, do_pty, (char *)args, *guest_addr,
810 htons(guest_port)); 810 htons(guest_port));
811 } 811 }
812 812