Changeset 39287 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- Nov 14, 2011 9:41:52 AM (13 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/slirp.c
r39248 r39287 54 54 # include <sys/ioctl.h> 55 55 # include <poll.h> 56 # include <netinet/in.h> 56 57 #else 57 58 # include <Winnls.h> … … 681 682 dns_alias_load(pData); 682 683 } 684 #ifdef VBOX_WITH_NAT_SEND2HOME 685 /* @todo: we should know all interfaces available on host. */ 686 pData->pInSockAddrHomeAddress = RTMemAllocZ(sizeof(struct sockaddr)); 687 pData->cInHomeAddressSize = 1; 688 inet_aton("192.168.1.25", &pData->pInSockAddrHomeAddress[0].sin_addr); 689 pData->pInSockAddrHomeAddress[0].sin_family = AF_INET; 690 #ifdef RT_OS_DARWIN 691 pData->pInSockAddrHomeAddress[0].sin_len = sizeof(struct sockaddr_in); 692 #endif 693 #endif 683 694 return fNATfailed ? VINF_NAT_DNS : VINF_SUCCESS; 684 695 } -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r39101 r39287 55 55 #include <iprt/dir.h> 56 56 #include <iprt/rand.h> 57 #include <iprt/net.h> 57 58 #include <VBox/types.h> 58 59 … … 515 516 return slirpServiceMbufAlloc(pData, CTL_DNS); 516 517 } 517 #endif 518 518 519 DECLINLINE(bool) slirpIsWideCasting(PNATState pData, uint32_t u32Addr) 520 { 521 bool fWideCasting = false; 522 LogFlowFunc(("Enter: u32Addr:%RTnaipv4\n", u32Addr)); 523 fWideCasting = ( u32Addr == INADDR_BROADCAST 524 || (u32Addr & RT_H2N_U32_C(~pData->netmask)) == RT_H2N_U32_C(~pData->netmask)); 525 LogFlowFunc(("Leave: %RTbool\n", fWideCasting)); 526 return fWideCasting; 527 } 528 #endif 529 -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r38968 r39287 288 288 int cRedirectionsStored; 289 289 struct arp_cache_head arp_cache; 290 /* libalis modules' handlers*/290 /* libalis modules' handlers*/ 291 291 struct proto_handler *ftp_module; 292 292 struct proto_handler *nbt_module; 293 293 struct proto_handler *dns_module; 294 294 #ifdef VBOX_WITH_NAT_SEND2HOME 295 /* array of home addresses */ 296 struct sockaddr_in *pInSockAddrHomeAddress; 297 /* size of pInSockAddrHomeAddress in elements */ 298 int cInHomeAddressSize; 299 #endif 295 300 } NATState; 296 301 -
trunk/src/VBox/Devices/Network/slirp/socket.c
r39269 r39287 38 38 #endif 39 39 40 40 #ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE 41 /** 42 * 43 */ 44 struct socket * soCloneUDPSocketWithForegnAddr(PNATState pData, const struct socket *pSo, uint32_t u32ForeignAddr) 45 { 46 struct socket *pNewSocket = NULL; 47 LogFlowFunc(("Enter: so:%R[natsock], u32ForeignAddr:%RTnaipv4\n", pSo, u32ForeignAddr)); 48 pNewSocket = socreate(); 49 if (!pNewSocket) 50 { 51 LogFunc(("Can't create socket\n")); 52 LogFlowFunc(("Leave: NULL\n")); 53 return NULL; 54 } 55 if (udp_attach(pData, pNewSocket, 0) <= 0) 56 { 57 sofree(pData, pNewSocket); 58 LogFunc(("Can't attach fresh created socket\n")); 59 return NULL; 60 } 61 pNewSocket->so_laddr = pSo->so_laddr; 62 pNewSocket->so_lport = pSo->so_lport; 63 pNewSocket->so_faddr.s_addr = u32ForeignAddr; 64 pNewSocket->so_fport = pSo->so_fport; 65 return pNewSocket; 66 } 67 #endif 68 69 #ifdef VBOX_WITH_NAT_SEND2HOME 70 DECLINLINE(bool) slirpSend2Home(PNATState pData, struct socket *pSo, const void *pvBuf, uint32_t cbBuf, int iFlags) 71 { 72 int idxAddr; 73 int ret = 0; 74 bool fSendDone = false; 75 LogFlowFunc(("Enter pSo:%R[natsock] pvBuf: %p, cbBuf: %d, iFlags: %d\n", pSo, pvBuf, cbBuf, iFlags)); 76 for (idxAddr = 0; idxAddr < pData->cInHomeAddressSize; ++idxAddr) 77 { 78 79 struct socket *pNewSocket = soCloneUDPSocketWithForegnAddr(pData, pSo, pData->pInSockAddrHomeAddress[idxAddr].sin_addr); 80 AssertReturn((pNewSocket, false)); 81 pData->pInSockAddrHomeAddress[idxAddr].sin_port = pSo->so_fport; 82 /* @todo: more verbose on errors, 83 * @note: we shouldn't care if this send fail or not (we're in broadcast). 84 */ 85 LogFunc(("send %d bytes to %RTnaipv4 from %R[natsock]\n", cbBuf, pData->pInSockAddrHomeAddress[idxAddr].sin_addr.s_addr, pNewSocket)); 86 ret = sendto(pNewSocket->s, pvBuf, cbBuf, iFlags, (struct sockaddr *)&pData->pInSockAddrHomeAddress[idxAddr], sizeof(struct sockaddr_in)); 87 if (ret < 0) 88 LogFunc(("Failed to send %d bytes to %RTnaipv4\n", cbBuf, pData->pInSockAddrHomeAddress[idxAddr].sin_addr.s_addr)); 89 fSendDone |= ret > 0; 90 } 91 LogFlowFunc(("Leave %RTbool\n", fSendDone)); 92 return fSendDone; 93 } 94 #endif /* !VBOX_WITH_NAT_SEND2HOME */ 41 95 static void send_icmp_to_guest(PNATState, char *, size_t, const struct sockaddr_in *); 42 96 #ifdef RT_OS_WINDOWS … … 948 1002 ret = sendto(so->s, buf, mlen, 0, 949 1003 (struct sockaddr *)&addr, sizeof (struct sockaddr)); 1004 #ifdef VBOX_WITH_NAT_SEND2HOME 1005 if (slirpIsWideCasting(pData, so->so_faddr.s_addr)) 1006 { 1007 slirpSend2Home(pData, so, buf, mlen, 0); 1008 } 1009 #endif 950 1010 if (buf) 951 1011 RTMemFree(buf); -
trunk/src/VBox/Devices/Network/slirp/socket.h
r28800 r39287 192 192 void sofwdrain (struct socket *); 193 193 194 /** 195 * Creates copy of UDP socket with specified addr 196 * @return copy of the socket with f_addr equal to u32ForeignAddr 197 */ 198 #ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE 199 struct socket * soCloneUDPSocketWithForegnAddr(PNATState pData, const struct socket *so, uint32_t u32ForeignAddr); 200 #endif 201 194 202 #endif /* _SOCKET_H_ */ -
trunk/src/VBox/Devices/Network/slirp/udp.c
r39259 r39287 245 245 goto bad_free_mbuf; 246 246 } 247 if (udp_attach(pData, so, 0) == -1)247 if (udp_attach(pData, so, 0) <= 0) 248 248 { 249 249 Log2(("NAT: IP(id: %hd) udp_attach errno = %d (%s)\n", … … 402 402 { 403 403 saddr.sin_addr.s_addr = so->so_faddr.s_addr; 404 if ( (so->so_faddr.s_addr & RT_H2N_U32(~pData->netmask)) == RT_H2N_U32(~pData->netmask))404 if (slirpIsWideCasting(pData, so->so_faddr.s_addr)) 405 405 { 406 406 /** … … 417 417 else 418 418 saddr.sin_addr.s_addr = addr->sin_addr.s_addr; 419 /* we shouldn't override initial socket */ 420 #ifdef VBOX_WITH_NAT_UDP_SOCKET_CLONE 421 so = soCloneUDPSocketWithForegnAddr(pData, so, addr->sin_addr.s_addr); 422 Assert((so)); 423 #else 419 424 so->so_faddr.s_addr = addr->sin_addr.s_addr; 425 #endif 420 426 } 421 427 } … … 478 484 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; 479 485 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; 486 #if 0 487 so->so_state = SS_ISFCONNECTED; /* validly opened UDP socked always connected */ 488 #endif 480 489 SOCKET_LOCK_CREATE(so); 481 490 QSOCKET_LOCK(udb);
Note:
See TracChangeset
for help on using the changeset viewer.