Changeset 19839 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- May 19, 2009 7:01:23 PM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/bootp.c
r19748 r19839 41 41 bc->allocated = 1; 42 42 paddr->s_addr = htonl(ntohl(special_addr.s_addr) | (i + START_ADDR)); 43 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 44 bc->addr.s_addr = paddr->s_addr; 45 #endif 43 46 return bc; 44 47 } … … 127 130 } 128 131 129 #ifndef VBOX_WITH _NAT_SERVICE132 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 130 133 static void bootp_reply(PNATState pData, struct bootp_t *bp) 131 134 #else … … 135 138 BOOTPClient *bc; 136 139 struct mbuf *m; /* XXX: @todo vasily - it'd be better to reuse this mbuf here */ 137 #ifdef VBOX_WITH _NAT_SERVICE140 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 138 141 struct bootp_t *bp = mtod(m0, struct bootp_t *); 139 142 struct ethhdr *eh; … … 189 192 return; 190 193 191 #ifndef VBOX_WITH _NAT_SERVICE194 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 192 195 /* XXX: this is a hack to get the client mac address */ 193 196 memcpy(client_ethaddr, bp->bp_hwaddr, 6); … … 196 199 if ((m = m_get(pData)) == NULL) 197 200 return; 198 #ifdef VBOX_WITH _NAT_SERVICE201 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 199 202 eh = mtod(m, struct ethhdr *); 200 203 memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest*/ … … 218 221 return; 219 222 } 220 #ifdef VBOX_WITH _NAT_SERVICE223 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 221 224 memcpy(bc->macaddr, bp->bp_hwaddr, 6); 222 225 #else … … 242 245 243 246 /* Address/port of the DHCP server. */ 244 #ifndef VBOX_WITH _NAT_SERVICE247 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 245 248 saddr.sin_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS); 246 249 #else … … 398 401 399 402 if (bp->bp_op == BOOTP_REQUEST) 400 #ifndef VBOX_WITH _NAT_SERVICE403 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 401 404 bootp_reply(pData, bp); 402 405 #else -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
r19313 r19839 539 539 { 540 540 int new_m_size; 541 #ifdef VBOX_WITH_NAT_SERVICE 542 struct ethhdr *eh, *eh0; 543 eh0 = (struct ethhdr *)msrc->m_dat; 544 eh = (struct ethhdr *)m->m_dat; 545 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 546 #endif 547 m->m_data += if_maxlinkhdr; 541 m_adj(m, if_maxlinkhdr); 548 542 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; 549 543 if (new_m_size>m->m_size) 550 544 m_inc(m, new_m_size); 551 545 } 546 /* XXX (vasily - r) not very safe code here add M_EXT assertion, 547 * need replace code here with more safe constructions 548 */ 549 Assert((m->m_flags & M_EXT) == 0 && (msrc->m_flags & M_EXT) == 0); 552 550 memcpy(m->m_data, msrc->m_data, msrc->m_len); 553 551 m->m_len = msrc->m_len; /* copy msrc to m */ -
trunk/src/VBox/Devices/Network/slirp/ip_output.c
r19525 r19839 45 45 #include <slirp.h> 46 46 47 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 48 char * rt_lookup_in_cache(PNATState pData, uint32_t dst) 49 { 50 int i; 51 /* temporary do for dhcp client */ 52 for(i = 0; i < NB_ADDR; i++) 53 { 54 if ( bootp_clients[i].allocated 55 && bootp_clients[i].addr.s_addr == dst) 56 { 57 return &bootp_clients[i].macaddr[0]; 58 } 59 } 60 if (dst != 0) 61 { 62 return pData->slirp_ethaddr; 63 } 64 return NULL; 65 } 66 #endif 47 67 48 68 /* … … 107 127 ip->ip_sum = 0; 108 128 ip->ip_sum = cksum(m, hlen); 109 110 #ifdef VBOX_WITH_NAT_SERVICE 111 { 112 struct ethhdr *eh, *eh0; 113 eh = (struct ethhdr *)m->m_dat; 114 eh0 = (struct ethhdr *)m0->m_dat; 115 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 116 } 117 #endif 129 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 130 /* Current TCP/IP stack hasn't routing information at 131 * all so we need to calculate destination ethernet address 132 */ 133 { 134 extern uint8_t zerro_ethaddr[ETH_ALEN]; 135 struct ethhdr *eh; 136 eh = (struct ethhdr *)MBUF_HEAD(m); 137 if (memcmp(eh->h_source, zerro_ethaddr, ETH_ALEN) == 0) { 138 char *dst = rt_lookup_in_cache(pData, ip->ip_dst.s_addr); 139 if (dst != NULL) { 140 memcpy(eh->h_source, dst, ETH_ALEN); 141 } 142 } 143 } 144 #endif 145 118 146 if_output(pData, so, m); 119 147 goto done; … … 150 178 for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) 151 179 { 152 #ifdef VBOX_WITH _NAT_SERVICE180 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 153 181 struct ethhdr *eh0; 154 182 struct ethhdr *eh; … … 163 191 } 164 192 #ifdef VBOX_WITH_NAT_SERVICE 165 eh0 = (struct ethhdr *) m0->m_dat;166 eh = (struct ethhdr *) m->m_dat;193 eh0 = (struct ethhdr *)MBUF_HEAD(m0); 194 eh = (struct ethhdr *)MBUF_HEAD(m); 167 195 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 168 196 #endif 169 m ->m_data += if_maxlinkhdr;197 m_adj(m, if_maxlinkhdr); 170 198 mhip = mtod(m, struct ip *); 171 199 *mhip = *ip; -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r19689 r19839 201 201 }; 202 202 203 staticconst uint8_t zerro_ethaddr[6] =203 const uint8_t zerro_ethaddr[6] = 204 204 { 205 205 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 … … 660 660 #else 661 661 special_addr.s_addr = u32NetAddr; 662 #endif 663 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 664 pData->slirp_ethaddr = &special_ethaddr; 662 665 #endif 663 666 alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); … … 1399 1402 } 1400 1403 1401 #ifndef VBOX_WITH _NAT_SERVICE1404 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 1402 1405 #define ETH_ALEN 6 1403 1406 #define ETH_HLEN 14 … … 1450 1453 1451 1454 mr = m_get(pData); 1452 #ifdef VBOX_WITH _NAT_SERVICE1455 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 1453 1456 reh = mtod(mr, struct ethhdr *); 1454 1457 memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/ 1455 Log4(("NAT: arp:[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]->[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]\n", 1456 reh->h_source[0], reh->h_source[1], reh->h_source[2], reh->h_source[3], reh->h_source[4], reh->h_source[5], 1457 reh->h_dest[0], reh->h_dest[1], reh->h_dest[2], reh->h_dest[3], reh->h_dest[4], reh->h_dest[5])); 1458 Log4(("NAT: arp:%R[ether]->%R[ether]\n", 1459 reh->h_source, reh->h_dest)); 1458 1460 Log4(("NAT: arp: %R[IP4]\n", &tip)); 1459 1461 #endif … … 1524 1526 return; 1525 1527 } 1526 Log4(("NAT: in:[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]->[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]\n", 1527 eh->h_source[0], eh->h_source[1], eh->h_source[2], eh->h_source[3], eh->h_source[4], eh->h_source[5], 1528 eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], eh->h_dest[3], eh->h_dest[4], eh->h_dest[5])); 1529 #ifdef VBOX_WITH_NAT_SERVICE 1528 Log4(("NAT: in:%R[ether]->%R[ether]\n", eh->h_source, eh->h_dest)); 1529 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 1530 1530 if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) == 0) 1531 1531 { … … 1598 1598 } 1599 1599 1600 #ifndef VBOX_WITH _NAT_SERVICE1600 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 1601 1601 memcpy(eh->h_dest, client_ethaddr, ETH_ALEN); 1602 1602 memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1); … … 1650 1650 void slirp_set_ethaddr(PNATState pData, const uint8_t *ethaddr) 1651 1651 { 1652 #ifndef VBOX_WITH _NAT_SERVICE1652 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 1653 1653 memcpy(client_ethaddr, ethaddr, ETH_ALEN); 1654 1654 #endif -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r19313 r19839 358 358 359 359 360 # ifdef VBOX_WITH _NAT_SERVICE360 # ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 361 361 # define ETH_ALEN 6 362 362 # define ETH_HLEN 14 -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r19313 r19839 41 41 bool allocated; 42 42 uint8_t macaddr[6]; 43 #ifdef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 44 struct in_addr addr; 45 #endif 43 46 } BOOTPClient; 44 47 … … 126 129 struct in_addr loopback_addr; 127 130 uint32_t netmask; 128 #ifndef VBOX_WITH _NAT_SERVICE131 #ifndef VBOX_WITHOUT_SLIRP_CLIENT_ETHER 129 132 uint8_t client_ethaddr[6]; 133 #else 134 uint8_t *slirp_ethaddr; 130 135 #endif 131 136 struct ex_list *exec_list; -
trunk/src/VBox/Devices/Network/slirp/socket.c
r19545 r19839 593 593 * make it look like that's where it came from, done by udp_output 594 594 */ 595 #ifdef VBOX_WITH_NAT_SERVICE596 {597 struct ethhdr *eh0;598 struct ethhdr *eh;599 Assert(so->so_m);600 eh0 = (struct ethhdr *)so->so_m->m_dat;601 eh = (struct ethhdr *)m->m_dat;602 603 memcpy(eh->h_source, eh0->h_source, ETH_ALEN);604 }605 #endif606 595 udp_output(pData, so, m, &addr); 607 596 SOCKET_UNLOCK(so); -
trunk/src/VBox/Devices/Network/slirp/tcp_input.c
r19801 r19839 294 294 tp = sototcpcb(so); 295 295 m = so->so_m; 296 #ifdef VBOX_WITH_NAT_SERVICE 297 { 298 struct ethhdr *eh; 299 300 Assert(m); 301 eh = (struct ethhdr *)m->m_dat; 302 memcpy(so->so_ethaddr, eh->h_source, ETH_ALEN); 303 } 304 #endif 296 305 297 so->so_m = 0; 306 298 ti = so->so_ti; … … 483 475 goto dropwithreset; 484 476 } 485 #ifdef VBOX_WITH_NAT_SERVICE486 Assert(m);487 so->so_m = m; /* save the initial packet */488 {489 struct ethhdr *eh0;490 eh0 = (struct ethhdr *)m->m_dat;491 }492 #endif493 477 SOCKET_LOCK(so); 494 478 sbreserve(&so->so_snd, tcp_sndspace); -
trunk/src/VBox/Devices/Network/slirp/tcp_output.c
r19318 r19839 378 378 goto out; 379 379 } 380 #ifdef VBOX_WITH_NAT_SERVICE381 {382 struct ethhdr *eh, *eh0;383 eh = (struct ethhdr *)m->m_dat;384 if (so->so_m)385 {386 eh0 = (struct ethhdr *)so->so_m->m_dat;387 memcpy(eh->h_source, eh0->h_source, ETH_ALEN);388 }389 else390 {391 memcpy(eh->h_source, so->so_ethaddr, ETH_ALEN);392 }393 }394 #endif395 380 m->m_data += if_maxlinkhdr; 396 381 m->m_len = hdrlen; … … 442 427 goto out; 443 428 } 444 #ifdef VBOX_WITH_NAT_SERVICE445 {446 struct ethhdr *eh;447 eh = (struct ethhdr *)m->m_dat;448 memcpy(eh->h_source, so->so_ethaddr, ETH_ALEN);449 }450 #endif451 429 m->m_data += if_maxlinkhdr; 452 430 m->m_len = hdrlen;
Note:
See TracChangeset
for help on using the changeset viewer.