Changeset 15636 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Dec 18, 2008 7:01:32 AM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
r15522 r15636 71 71 }; 72 72 73 #ifdef VBOX_WITH_SLIRP_ICMP74 73 int 75 74 icmp_init(PNATState pData) … … 265 264 return 0; 266 265 } 267 #endif /* VBOX_WITH_SLIRP_ICMP */268 266 269 267 /* … … 278 276 int status; 279 277 uint32_t dst; 280 #if defined(VBOX_WITH_SLIRP_ICMP) &&!defined(RT_OS_WINDOWS)278 #if !defined(RT_OS_WINDOWS) 281 279 int ttl; 282 280 #endif … … 321 319 { 322 320 case ICMP_ECHO: 323 #ifndef VBOX_WITH_SLIRP_ICMP324 icp->icmp_type = ICMP_ECHOREPLY;325 #endif /* !VBOX_WITH_SLIRP_ICMP */326 327 321 ip->ip_len += hlen; /* since ip_input subtracts this */ 328 322 dst = ip->ip_dst.s_addr; 329 323 if (dst == alias_addr.s_addr) 330 324 { 331 #ifdef VBOX_WITH_SLIRP_ICMP332 325 icp->icmp_type = ICMP_ECHOREPLY; 333 326 ip->ip_dst.s_addr = ip->ip_src.s_addr; 334 327 ip->ip_src.s_addr = dst; 335 #endif /* VBOX_WITH_SLIRP_ICMP */336 328 icmp_reflect(pData, m); 337 329 } … … 339 331 { 340 332 struct sockaddr_in addr; 341 #ifndef VBOX_WITH_SLIRP_ICMP 342 struct socket *so; 343 if ((so = socreate()) == NULL) 344 goto freeit; 345 if (udp_attach(pData, so) == -1) 346 { 347 DEBUG_MISC((dfd,"icmp_input udp_attach errno = %d-%s\n", 348 errno,strerror(errno))); 349 sofree(pData, so); 350 m_free(pData, m); 351 goto end_error; 352 } 353 so->so_m = m; 354 so->so_faddr = ip->ip_dst; 355 so->so_fport = htons(7); 356 so->so_laddr = ip->ip_src; 357 so->so_lport = htons(9); 358 so->so_iptos = ip->ip_tos; 359 so->so_type = IPPROTO_ICMP; 360 so->so_state = SS_ISFCONNECTED; 361 362 addr.sin_family = AF_INET; 363 if ((so->so_faddr.s_addr & htonl(pData->netmask)) == special_addr.s_addr) 364 { 365 /* It's an alias */ 366 switch (ntohl(so->so_faddr.s_addr) & ~pData->netmask) 367 { 368 case CTL_DNS: 369 addr.sin_addr = dns_addr; 370 break; 371 case CTL_ALIAS: 372 default: 373 addr.sin_addr = loopback_addr; 374 break; 375 } 376 } 377 else 378 addr.sin_addr = so->so_faddr; 379 addr.sin_port = so->so_fport; 380 if (sendto(so->s, icmp_ping_msg, strlen(icmp_ping_msg), 0, 381 (struct sockaddr *)&addr, sizeof(addr)) == -1) 382 { 383 DEBUG_MISC((dfd,"icmp_input udp sendto tx errno = %d-%s\n", 384 errno,strerror(errno))); 385 icmp_error(pData, m, ICMP_UNREACH,ICMP_UNREACH_NET, 0,strerror(errno)); 386 udp_detach(pData, so); 387 } 388 #else /* VBOX_WITH_SLIRP_ICMP */ 389 # ifdef RT_OS_WINDOWS 333 #ifdef RT_OS_WINDOWS 390 334 IP_OPTION_INFORMATION ipopt; 391 335 int error; 392 # 336 #endif 393 337 addr.sin_family = AF_INET; 394 338 if ((ip->ip_dst.s_addr & htonl(pData->netmask)) == special_addr.s_addr) … … 408 352 else 409 353 addr.sin_addr.s_addr = ip->ip_dst.s_addr; 410 # 354 #ifndef RT_OS_WINDOWS 411 355 if (pData->icmp_socket.s != -1) 412 356 { … … 427 371 m_free(pData, m); 428 372 } 429 } 373 } 430 374 else 431 375 { 432 /* 376 /* 433 377 * We're freeing the ICMP message, which unable sent or process. 434 378 * That behavior described in rfc 793, we shouldn't notify sender about … … 438 382 return; 439 383 } 440 # 384 #else /* RT_OS_WINDOWS */ 441 385 icmp_attach(pData, m); 442 386 pData->icmp_socket.so_laddr.s_addr = ip->ip_src.s_addr; /* XXX: hack*/ … … 472 416 } 473 417 } 474 # endif /* RT_OS_WINDOWS */ 475 #endif /* VBOX_WITH_SLIRP_ICMP */ 418 #endif /* RT_OS_WINDOWS */ 476 419 } /* if ip->ip_dst.s_addr == alias_addr.s_addr */ 477 420 break; … … 668 611 m->m_len += hlen; 669 612 670 #ifndef VBOX_WITH_SLIRP_ICMP671 /* fill in ip */672 if (optlen > 0)673 {674 /*675 * Strip out original options by copying rest of first676 * mbuf's data back, and adjust the IP length.677 */678 memmove((caddr_t)(ip + 1), (caddr_t)ip + hlen,679 (unsigned )(m->m_len - hlen));680 hlen -= optlen;681 ip->ip_hl = hlen >> 2;682 ip->ip_len -= optlen;683 m->m_len -= optlen;684 }685 ip->ip_ttl = MAXTTL;686 {687 /* swap */688 struct in_addr icmp_dst;689 icmp_dst = ip->ip_dst;690 ip->ip_dst = ip->ip_src;691 ip->ip_src = icmp_dst;692 }693 #endif /* !VBOX_WITH_SLIRP_ICMP */694 695 613 (void ) ip_output(pData, (struct socket *)NULL, m); 696 614 -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.h
r15365 r15636 37 37 #ifndef _NETINET_IP_ICMP_H_ 38 38 #define _NETINET_IP_ICMP_H_ 39 #ifdef VBOX_WITH_SLIRP_ICMP40 39 #include <queue.h> 41 #endif42 40 43 41 /* … … 173 171 void icmp_reflect _P((PNATState, struct mbuf *)); 174 172 175 #ifdef VBOX_WITH_SLIRP_ICMP176 173 struct icmp_msg{ 177 174 LIST_ENTRY(icmp_msg) im_list; … … 184 181 int icmp_init _P((PNATState )); 185 182 struct icmp_msg * icmp_find_original_mbuf _P((PNATState , struct ip *)); 186 #endif /* VBOX_WITH_SLIRP_ICMP */187 183 188 184 #endif -
trunk/src/VBox/Devices/Network/slirp/ip_input.c
r15480 r15636 147 147 } 148 148 149 #ifdef VBOX_WITH_SLIRP_ICMP150 149 ip->ip_ttl--; 151 #endif152 150 /* 153 151 * If offset or IP_MF are set, must reassemble. … … 246 244 struct ipq_t *q = TAILQ_LAST(head, ipqhead); 247 245 if (q == NULL) 248 { 246 { 249 247 /* gak */ 250 248 for (i = 0; i < IPREASS_NHASH; i++) -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r15453 r15636 29 29 # define DO_POLL_EVENTS(rc, error, so, events, label) do {} while (0) 30 30 31 #define DO_CHECK_FD_SET(so, events, fdset) (FD_ISSET((so)->s, (fdset))) 32 33 # ifdef VBOX_WITH_SLIRP_ICMP 34 # define ICMP_ENGAGE_EVENT(so, fdset) \ 31 # define DO_CHECK_FD_SET(so, events, fdset) (FD_ISSET((so)->s, (fdset))) 32 33 # define ICMP_ENGAGE_EVENT(so, fdset) \ 35 34 do { \ 36 35 if (pData->icmp_socket.s != -1) \ 37 36 DO_ENGAGE_EVENT1((so), (fdset), ICMP); \ 38 37 } while (0) 39 # else /* !VBOX_WITH_SLIRP_ICMP */40 # define ICMP_ENGAGE_EVENT(so, fdset) do {} while (0)41 # endif /* !VBOX_WITH_SLIRP_ICMP */42 38 43 39 #else /* defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && defined(RT_OS_WINDOWS) */ … … 361 357 if_init(pData); 362 358 ip_init(pData); 363 #ifdef VBOX_WITH_SLIRP_ICMP364 359 icmp_init(pData); 365 #endif /* VBOX_WITH_SLIRP_ICMP */366 360 367 361 /* Initialise mbufs *after* setting the MTU */ … … 443 437 RTStrFree((char *)(void *)pData->pszDomain); 444 438 445 #ifdef VBOX_WITH_SLIRP_ICMP 446 # ifdef RT_OS_WINDOWS 439 #ifdef RT_OS_WINDOWS 447 440 pData->pfIcmpCloseHandle(pData->icmp_socket.sh); 448 441 FreeLibrary(pData->hmIcmpLibrary); … … 450 443 # else 451 444 closesocket(pData->icmp_socket.s); 452 # endif453 445 #endif 454 446 … … 713 705 if (link_up) 714 706 { 715 #if defined(VBOX_WITH_SLIRP_ICMP) 716 # if defined(RT_OS_WINDOWS) 707 #if defined(RT_OS_WINDOWS) 717 708 if (fIcmp) 718 709 sorecvfrom(pData, &pData->icmp_socket); 719 # 710 #else 720 711 if (pData->icmp_socket.s != -1 && FD_ISSET(pData->icmp_socket.s, readfds)) 721 712 sorecvfrom(pData, &pData->icmp_socket); 722 # endif723 713 #endif 724 714 /* … … 915 905 } 916 906 917 #if 0918 #if defined(VBOX_WITH_SLIRP_ICMP)919 # if defined(RT_OS_WINDOWS)920 if (fIcmp)921 sorecvfrom(pData, &pData->icmp_socket);922 # else923 if (pData->icmp_socket.s != -1 && FD_ISSET(pData->icmp_socket.s, readfds))924 sorecvfrom(pData, &pData->icmp_socket);925 # endif926 #endif927 #endif928 907 } 929 908 -
trunk/src/VBox/Devices/Network/slirp/socket.c
r15597 r15636 13 13 #include <sys/filio.h> 14 14 #endif 15 #if defined (VBOX_WITH_SLIRP_ICMP) && defined(RT_OS_WINDOWS)15 #if defined (RT_OS_WINDOWS) 16 16 #include <iphlpapi.h> 17 17 #include <icmpapi.h> … … 19 19 20 20 21 #ifdef VBOX_WITH_SLIRP_ICMP22 21 static void send_icmp_to_guest(PNATState, char *, size_t, struct socket *, const struct sockaddr_in *); 22 #ifdef RT_OS_WINDOWS 23 23 static void sorecvfrom_icmp_win(PNATState, struct socket *); 24 #e ndif24 #else /* RT_OS_WINDOWS */ 25 25 static void sorecvfrom_icmp_unix(PNATState, struct socket *); 26 #endif /* !RT_OS_WINDOWS */ 26 27 27 28 void … … 443 444 { 444 445 /* This is a "ping" reply */ 445 #if !defined(VBOX_WITH_SLIRP_ICMP) || (defined(VBOX_WITH_SLIRP_ICMP) && !defined(RT_OS_WINDOWS)) 446 #ifdef RT_OS_WINDOWS 447 sorecvfrom_icmp_win(pData, so); 448 #else /* RT_OS_WINDOWS */ 446 449 sorecvfrom_icmp_unix(pData, so); 447 #endif 448 #if defined(VBOX_WITH_SLIRP_ICMP) && defined(RT_OS_WINDOWS) 449 sorecvfrom_icmp_win(pData, so); 450 #endif 450 #endif /* !RT_OS_WINDOWS */ 451 451 udp_detach(pData, so); 452 452 } … … 786 786 } 787 787 788 #ifdef VBOX_WITH_SLIRP_ICMP789 788 static void 790 789 send_icmp_to_guest(PNATState pData, char *buff, size_t len, struct socket *so, const struct sockaddr_in *addr) … … 896 895 } 897 896 898 # 897 #ifdef RT_OS_WINDOWS 899 898 static void 900 899 sorecvfrom_icmp_win(PNATState pData, struct socket *so) … … 960 959 nbytes = (data_len + icr[i].DataSize > m->m_size? m->m_size - data_len: icr[i].DataSize); 961 960 memcpy(icp->icmp_data, icr[i].Data, nbytes); 962 961 963 962 data_len += icr[i].DataSize; 964 963 … … 988 987 data_len = (ip_broken->ip_hl << 2) + 64; 989 988 990 nbytes =(hlen + ICMP_MINLEN + data_len > m->m_size? m->m_size - (hlen + ICMP_MINLEN): data_len); 989 nbytes =(hlen + ICMP_MINLEN + data_len > m->m_size? m->m_size - (hlen + ICMP_MINLEN): data_len); 991 990 memcpy(icp->icmp_data, ip_broken, nbytes); 992 991 icmp_reflect(pData, m); … … 998 997 } 999 998 } 1000 # endif /* RT_OS_WINDOWS */ 1001 #endif /* VBOX_WITH_SLIRP_ICMP */ 1002 999 #else /* RT_OS_WINDOWS */ 1003 1000 static void sorecvfrom_icmp_unix(PNATState pData, struct socket *so) 1004 1001 { … … 1026 1023 else 1027 1024 { 1028 #ifdef VBOX_WITH_SLIRP_ICMP1029 1025 send_icmp_to_guest(pData, buff, len, so, &addr); 1030 #else 1031 icmp_reflect(pData, so->so_m); 1032 so->so_m = 0; /* Don't m_free() it again! */ 1033 #endif 1034 } 1035 } 1036 1026 } 1027 } 1028 #endif /* !RT_OS_WINDOWS */ -
trunk/src/VBox/Devices/Network/slirp/socket.h
r15243 r15636 23 23 struct socket *so_prev; /* For a linked list of sockets */ 24 24 25 #if !defined( VBOX_WITH_SLIRP_ICMP) || !defined(RT_OS_WINDOWS)25 #if !defined(RT_OS_WINDOWS) 26 26 int s; /* The actual socket */ 27 27 #else … … 45 45 u_int16_t so_fport; /* foreign port */ 46 46 u_int16_t so_lport; /* local port */ 47 #ifdef VBOX_WITH_SLIRP_ICMP48 47 u_int16_t so_hlport; /* host local port */ 49 48 struct in_addr so_hladdr; /* local host addr */ 50 #endif51 49 52 50 u_int8_t so_iptos; /* Type of service */ -
trunk/src/VBox/Devices/Network/slirp/udp.c
r15472 r15636 72 72 struct ip save_ip; 73 73 struct socket *so; 74 #ifdef VBOX_WITH_SLIRP_ICMP75 74 int ret; 76 75 int ttl; 77 #endif78 76 79 77 DEBUG_CALL("udp_input"); … … 239 237 udp_emu(pData, so, m); 240 238 241 #ifdef VBOX_WITH_SLIRP_ICMP242 239 ttl = ip->ip_ttl = save_ip.ip_ttl; 243 240 ret = setsockopt(so->s, IPPROTO_IP, IP_TTL, &ttl, sizeof(ttl)); … … 245 242 LogRel(("NAT: Error (%s) occurred while setting TTL(%d) attribute of IP packet to socket %R[natsock]\n", strerror(errno), ip->ip_ttl, so)); 246 243 } 247 #endif 244 248 245 if (sosendto(pData, so, m) == -1) 249 246 { … … 353 350 { 354 351 struct sockaddr_in addr; 355 #ifdef VBOX_WITH_SLIRP_ICMP356 352 struct sockaddr sa_addr; 357 353 socklen_t socklen = sizeof(struct sockaddr); 358 354 int status; 359 #endif360 355 361 356 if ((so->s = socket(AF_INET,SOCK_DGRAM,0)) != -1) … … 388 383 setsockopt(so->s, SOL_SOCKET, SO_BROADCAST, (const char *)&opt, sizeof(opt)); 389 384 insque(pData, so,&udb); 390 #ifdef VBOX_WITH_SLIRP_ICMP391 385 status = getsockname(so->s, &sa_addr, &socklen); 392 386 Assert(status == 0 && sa_addr.sa_family == AF_INET); 393 387 so->so_hlport = ((struct sockaddr_in *)&sa_addr)->sin_port; 394 388 so->so_hladdr.s_addr = ((struct sockaddr_in *)&sa_addr)->sin_addr.s_addr; 395 #endif396 389 } 397 390 } … … 402 395 udp_detach(PNATState pData, struct socket *so) 403 396 { 404 #ifndef VBOX_WITH_SLIRP_ICMP405 closesocket(so->s);406 sofree(pData, so);407 #else /*! VBOX_WITH_SLIRP_ICMP */408 397 if (so != &pData->icmp_socket) 409 398 { … … 411 400 sofree(pData, so); 412 401 } 413 #endif /* VBOX_WITH_SLIRP_ICMP */414 402 } 415 403
Note:
See TracChangeset
for help on using the changeset viewer.