Changeset 21004 in vbox
- Timestamp:
- Jun 27, 2009 5:14:39 AM (15 years ago)
- Location:
- trunk/src/VBox/Devices/Network
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/DrvNAT.cpp
r20959 r21004 642 642 * Validate the port forwarding config. 643 643 */ 644 if (!CFGMR3AreValuesValid(pNode, "Protocol\0UDP\0HostPort\0GuestPort\0GuestIP\0 "))644 if (!CFGMR3AreValuesValid(pNode, "Protocol\0UDP\0HostPort\0GuestPort\0GuestIP\0BindIP\0")) 645 645 return PDMDRV_SET_ERROR(pThis->pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, N_("Unknown configuration in port forwarding")); 646 646 … … 669 669 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"Protocol\" string failed"), iInstance); 670 670 671 #define DOGETIP(rc, status, x) \ 672 do { \ 673 char sz##x[32]; \ 674 rc = CFGMR3QueryString(pNode, #x, &sz ## x[0], sizeof(sz ## x)); \ 675 if (rc == VERR_CFGM_VALUE_NOT_FOUND) \ 676 RTStrPrintf(sz ## x, sizeof(sz ## x), "%d.%d.%d.%d", \ 677 (Network & 0xFF000000) >> 24, (Network & 0xFF0000) >> 16, (Network & 0xFF00) >> 8, (Network & 0xE0) | 15); \ 678 else if (RT_FAILURE(rc)) \ 679 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"" #x "\" string failed"), iInstance); \ 680 status = inet_aton(sz ## x, &x); \ 681 }while(0) 682 683 #define GETIP(x) \ 684 do \ 685 { \ 686 int status = 0; \ 687 DOGETIP(rc, status, x); \ 688 if (status == 0) \ 689 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, \ 690 N_("NAT#%d: configuration error: invalid \"" #x "\" inet_aton failed"), iInstance); \ 691 }while(0) 692 693 #define GETIP_DEF(x, def) \ 694 do \ 695 { \ 696 int status = 0; \ 697 DOGETIP(rc, status, x); \ 698 if (status == 0 || rc == VERR_CFGM_VALUE_NOT_FOUND) \ 699 x.s_addr = def; \ 700 }while(0) 671 701 /* host port */ 672 702 int32_t iHostPort; … … 682 712 683 713 /* guest address */ 684 char szGuestIP[32];685 rc = CFGMR3QueryString(pNode, "GuestIP", &szGuestIP[0], sizeof(szGuestIP));686 if (rc == VERR_CFGM_VALUE_NOT_FOUND)687 RTStrPrintf(szGuestIP, sizeof(szGuestIP), "%d.%d.%d.%d",688 (Network & 0xFF000000) >> 24, (Network & 0xFF0000) >> 16, (Network & 0xFF00) >> 8, (Network & 0xE0) | 15);689 else if (RT_FAILURE(rc))690 return PDMDrvHlpVMSetError(pThis->pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"GuestIP\" string failed"), iInstance);691 714 struct in_addr GuestIP; 692 if (!inet_aton(szGuestIP, &GuestIP)) 693 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_GUEST_IP, RT_SRC_POS, 694 N_("NAT#%d: configuration error: invalid \"GuestIP\"=\"%s\", inet_aton failed"), iInstance, szGuestIP); 715 GETIP(GuestIP); 695 716 696 717 /* 697 718 * Call slirp about it. 698 719 */ 699 Log(("drvNATConstruct: Redir %d -> %s:%d\n", iHostPort, szGuestIP, iGuestPort)); 700 if (slirp_redir(pThis->pNATState, fUDP, iHostPort, GuestIP, iGuestPort) < 0) 720 struct in_addr BindIP; 721 GETIP_DEF(BindIP, INADDR_ANY); 722 if (slirp_redir(pThis->pNATState, fUDP, BindIP, iHostPort, GuestIP, iGuestPort) < 0) 701 723 return PDMDrvHlpVMSetError(pThis->pDrvIns, VERR_NAT_REDIR_SETUP, RT_SRC_POS, 702 N_("NAT#%d: configuration error: failed to set up redirection of %d to %s:%d. Probably a conflict with existing services or other rules"), iInstance, iHostPort, szGuestIP, iGuestPort); 724 N_("NAT#%d: configuration error: failed to set up redirection of %d to %d. Probably a conflict with existing services or other rules"), iInstance, iHostPort, iGuestPort); 725 #undef GETIP 703 726 } /* for each redir rule */ 704 727 … … 751 774 * Validate the config. 752 775 */ 753 if (!CFGMR3AreValuesValid(pCfgHandle, "PassDomain\0TFTPPrefix\0BootFile\0Network\0NextServer\0DNSProxy\0" 776 if (!CFGMR3AreValuesValid(pCfgHandle, "PassDomain\0TFTPPrefix\0BootFile\0Network" 777 "\0NextServer\0DNSProxy\0BindIP\0" 754 778 "SocketRcvBuf\0SocketSndBuf\0TcpRcvSpace\0TcpSndSpace\0")) 755 779 return PDMDRV_SET_ERROR(pDrvIns, VERR_PDM_DRVINS_UNKNOWN_CFG_VALUES, … … 833 857 slirp_set_dhcp_next_server(pThis->pNATState, pThis->pszNextServer); 834 858 slirp_set_dhcp_dns_proxy(pThis->pNATState, !!fDNSProxy); 835 #define SLIRP_SET_TUNING_VALUE(name, setter) \ 859 char *pszBindIP = NULL; 860 rc = CFGMR3QueryStringAlloc(pCfgHandle, "BindIP", &pszBindIP); 861 if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND) 862 return PDMDrvHlpVMSetError(pDrvIns, rc, RT_SRC_POS, N_("NAT#%d: configuration query for \"BindIP\" string failed"), pDrvIns->iInstance); 863 rc = slirp_set_binding_address(pThis->pNATState, pszBindIP); 864 if (rc != 0) 865 LogRel(("NAT: value of BindIP has been ignored\n")); 866 867 if(pszBindIP != NULL) 868 MMR3HeapFree(pszBindIP); 869 #define SLIRP_SET_TUNING_VALUE(name, setter) \ 836 870 do \ 837 871 { \ -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r20959 r21004 56 56 void slirp_post_sent(PNATState pData, void *pvArg); 57 57 58 int slirp_redir(PNATState pData, int is_udp, int host_port, 59 struct in_addr guest_addr, int guest_port); 58 int slirp_redir(PNATState pData, int is_udp, struct in_addr host_addr, 59 int host_port, struct in_addr guest_addr, 60 int guest_port); 60 61 int slirp_add_exec(PNATState pData, int do_pty, const char *args, int addr_low_byte, 61 62 int guest_port); … … 69 70 void slirp_set_tcp_rcvspace(PNATState pData, int kilobytes); 70 71 void slirp_set_tcp_sndspace(PNATState pData, int kilobytes); 72 73 int slirp_set_binding_address(PNATState, char *addr); 71 74 72 75 #if defined(RT_OS_WINDOWS) -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r20961 r21004 1526 1526 } 1527 1527 1528 int slirp_redir(PNATState pData, int is_udp, int host_port,1528 int slirp_redir(PNATState pData, int is_udp, struct in_addr host_addr, int host_port, 1529 1529 struct in_addr guest_addr, int guest_port) 1530 1530 { … … 1543 1543 if (is_udp) 1544 1544 { 1545 so = udp_listen(pData, h tons(host_port), guest_addr.s_addr,1545 so = udp_listen(pData, host_addr.s_addr, htons(host_port), guest_addr.s_addr, 1546 1546 htons(guest_port), 0); 1547 1547 } 1548 1548 else 1549 1549 { 1550 so = solisten(pData, h tons(host_port), guest_addr.s_addr,1550 so = solisten(pData, host_addr.s_addr, htons(host_port), guest_addr.s_addr, 1551 1551 htons(guest_port), 0); 1552 } 1553 if (so == NULL) 1554 { 1555 return -1; 1552 1556 } 1553 1557 #ifndef VBOX_WITH_SLIRP_ALIAS … … 1705 1709 else 1706 1710 inet_aton(next_server, &pData->tftp_server); 1711 } 1712 1713 int slirp_set_binding_address(PNATState pData, char *addr) 1714 { 1715 if (addr == NULL || (inet_aton(addr, &pData->bindIP) == 0)) 1716 { 1717 pData->bindIP.s_addr = INADDR_ANY; 1718 return 1; 1719 } 1720 return 0; 1707 1721 } 1708 1722 -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r20959 r21004 135 135 char slirp_hostname[33]; 136 136 bool fPassDomain; 137 struct in_addr bindIP; 137 138 /* Stuff from tcp_input.c */ 138 139 struct socket tcb; -
trunk/src/VBox/Devices/Network/slirp/socket.c
r20959 r21004 730 730 */ 731 731 struct socket * 732 solisten(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags)732 solisten(PNATState pData, u_int32_t bind_addr, u_int port, u_int32_t laddr, u_int lport, int flags) 733 733 { 734 734 struct sockaddr_in addr; … … 775 775 776 776 addr.sin_family = AF_INET; 777 addr.sin_addr.s_addr = INADDR_ANY;777 addr.sin_addr.s_addr = bind_addr; 778 778 addr.sin_port = port; 779 779 -
trunk/src/VBox/Devices/Network/slirp/socket.h
r20961 r21004 167 167 void sorecvfrom (PNATState, struct socket *); 168 168 int sosendto (PNATState, struct socket *, struct mbuf *); 169 struct socket * solisten (PNATState, u_int , u_int32_t, u_int, int);169 struct socket * solisten (PNATState, u_int32_t, u_int, u_int32_t, u_int, int); 170 170 void sorwakeup (struct socket *); 171 171 void sowwakeup (struct socket *); -
trunk/src/VBox/Devices/Network/slirp/udp.c
r20959 r21004 382 382 addr.sin_family = AF_INET; 383 383 addr.sin_port = service_port; 384 addr.sin_addr.s_addr = INADDR_ANY;384 addr.sin_addr.s_addr = pData->bindIP.s_addr; 385 385 fd_nonblock(so->s); 386 386 if (bind(so->s, (struct sockaddr *)&addr, sizeof(addr)) < 0) … … 718 718 719 719 struct socket * 720 udp_listen(PNATState pData, u_int port, u_int32_t laddr, u_int lport, int flags)720 udp_listen(PNATState pData, u_int32_t bind_addr, u_int port, u_int32_t laddr, u_int lport, int flags) 721 721 { 722 722 struct sockaddr_in addr; … … 744 744 745 745 addr.sin_family = AF_INET; 746 addr.sin_addr.s_addr = INADDR_ANY;746 addr.sin_addr.s_addr = bind_addr; 747 747 addr.sin_port = port; 748 748 749 749 if (bind(so->s,(struct sockaddr *)&addr, addrlen) < 0) 750 750 { 751 LogRel(("NAT: bind to %R[IP4] has been failed\n", &addr.sin_addr)); 751 752 udp_detach(pData, so); 752 753 return NULL; -
trunk/src/VBox/Devices/Network/slirp/udp.h
r20306 r21004 109 109 u_int8_t udp_tos (struct socket *); 110 110 void udp_emu (PNATState, struct socket *, struct mbuf *); 111 struct socket * udp_listen (PNATState, u_int , u_int32_t, u_int, int);111 struct socket * udp_listen (PNATState, u_int32_t, u_int, u_int32_t, u_int, int); 112 112 int udp_output2(PNATState pData, struct socket *so, struct mbuf *m, 113 113 struct sockaddr_in *saddr, struct sockaddr_in *daddr,
Note:
See TracChangeset
for help on using the changeset viewer.