Changeset 19313 in vbox for trunk/src/VBox/Devices/Network
- Timestamp:
- May 4, 2009 3:16:01 AM (16 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/bootp.c
r18902 r19313 127 127 } 128 128 129 #ifndef VBOX_WITH_NAT_SERVICE 129 130 static void bootp_reply(PNATState pData, struct bootp_t *bp) 131 #else 132 static void bootp_reply(PNATState pData, struct mbuf *m0) 133 #endif 130 134 { 131 135 BOOTPClient *bc; 132 struct mbuf *m; 136 struct mbuf *m; /* XXX: @todo vasily - it'd be better to reuse this mbuf here */ 137 #ifdef VBOX_WITH_NAT_SERVICE 138 struct bootp_t *bp = mtod(m0, struct bootp_t *); 139 struct ethhdr *eh; 140 #endif 133 141 struct bootp_t *rbp; 134 142 struct sockaddr_in saddr, daddr; … … 172 180 return; 173 181 182 #ifndef VBOX_WITH_NAT_SERVICE 174 183 /* XXX: this is a hack to get the client mac address */ 175 184 memcpy(client_ethaddr, bp->bp_hwaddr, 6); 185 #endif 176 186 177 187 if ((m = m_get(pData)) == NULL) 178 188 return; 189 #ifdef VBOX_WITH_NAT_SERVICE 190 eh = mtod(m, struct ethhdr *); 191 memcpy(eh->h_source, bp->bp_hwaddr, ETH_ALEN); /* XXX: if_encap just swap source with dest*/ 192 #endif 179 193 m->m_data += if_maxlinkhdr; /*reserve ether header */ 180 194 rbp = mtod(m, struct bootp_t *); … … 195 209 return; 196 210 } 211 #ifdef VBOX_WITH_NAT_SERVICE 212 memcpy(bc->macaddr, bp->bp_hwaddr, 6); 213 #else 197 214 memcpy(bc->macaddr, client_ethaddr, 6); 215 #endif 198 216 } 199 217 } … … 215 233 216 234 /* Address/port of the DHCP server. */ 235 #ifndef VBOX_WITH_NAT_SERVICE 217 236 saddr.sin_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS); 237 #else 238 saddr.sin_addr.s_addr = special_addr.s_addr; 239 #endif 240 218 241 saddr.sin_port = htons(BOOTP_SERVER); 219 242 … … 350 373 351 374 if (bp->bp_op == BOOTP_REQUEST) 375 #ifndef VBOX_WITH_NAT_SERVICE 352 376 bootp_reply(pData, bp); 353 } 377 #else 378 bootp_reply(pData, m); 379 #endif 380 } -
trunk/src/VBox/Devices/Network/slirp/ip_icmp.c
r18902 r19313 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 541 547 m->m_data += if_maxlinkhdr; 542 548 new_m_size = sizeof(struct ip) + ICMP_MINLEN + msrc->m_len + ICMP_MAXDATALEN; -
trunk/src/VBox/Devices/Network/slirp/ip_output.c
r14964 r19313 63 63 DEBUG_ARG("so = %lx", (long)so); 64 64 DEBUG_ARG("m0 = %lx", (long)m0); 65 Assert(m->m_data == m->m_dat + if_maxlinkhdr); 65 66 66 67 #if 0 /* We do no options */ … … 103 104 ip->ip_sum = cksum(m, hlen); 104 105 106 #ifdef VBOX_WITH_NAT_SERVICE 107 { 108 struct ethhdr *eh, *eh0; 109 eh = (struct ethhdr *)m->m_dat; 110 eh0 = (struct ethhdr *)m0->m_dat; 111 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 112 } 113 #endif 105 114 if_output(pData, so, m); 106 115 goto done; … … 137 146 for (off = hlen + len; off < (u_int16_t)ip->ip_len; off += len) 138 147 { 148 #ifdef VBOX_WITH_NAT_SERVICE 149 struct ethhdr *eh0; 150 struct ethhdr *eh; 151 #endif 139 152 register struct ip *mhip; 140 153 m = m_get(pData); … … 145 158 goto sendorfree; 146 159 } 160 #ifdef VBOX_WITH_NAT_SERVICE 161 eh0 = (struct ethhdr *)m0->m_dat; 162 eh = (struct ethhdr *)m->m_dat; 163 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 164 #endif 147 165 m->m_data += if_maxlinkhdr; 148 166 mhip = mtod(m, struct ip *); -
trunk/src/VBox/Devices/Network/slirp/libslirp.h
r18902 r19313 28 28 #endif 29 29 30 #ifndef VBOX_WITH_NAT_SERVICE 30 31 int slirp_init(PNATState *, const char *, uint32_t, bool, void *); 32 #else 33 int slirp_init(PNATState *, uint32_t, uint32_t, bool, void *); 34 #endif 31 35 void slirp_register_timers(PNATState pData, PPDMDRVINS pDrvIns); 32 36 void slirp_term(PNATState); -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r18902 r19313 196 196 }; 197 197 198 static const uint8_t broadcast_ethaddr[6] = 199 { 200 0xff, 0xff, 0xff, 0xff, 0xff, 0xff 201 }; 202 203 static const uint8_t zerro_ethaddr[6] = 204 { 205 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 206 }; 207 198 208 #ifdef RT_OS_WINDOWS 199 209 # ifndef VBOX_WITH_MULTI_DNS … … 587 597 } 588 598 599 #ifndef VBOX_WITH_NAT_SERVICE 589 600 int slirp_init(PNATState *ppData, const char *pszNetAddr, uint32_t u32Netmask, 590 601 bool fPassDomain, void *pvUser) 602 #else 603 int slirp_init(PNATState *ppData, uint32_t u32NetAddr, uint32_t u32Netmask, 604 bool fPassDomain, void *pvUser) 605 #endif 591 606 { 592 607 int fNATfailed = 0; … … 627 642 m_init(pData); 628 643 644 #ifndef VBOX_WITH_NAT_SERVICE 629 645 inet_aton(pszNetAddr, &special_addr); 646 #else 647 special_addr.s_addr = u32NetAddr; 648 #endif 630 649 alias_addr.s_addr = special_addr.s_addr | htonl(CTL_ALIAS); 631 650 /* @todo: add ability to configure this staff */ … … 1366 1385 } 1367 1386 1387 #ifndef VBOX_WITH_NAT_SERVICE 1368 1388 #define ETH_ALEN 6 1369 1389 #define ETH_HLEN 14 … … 1379 1399 }; 1380 1400 AssertCompileSize(struct ethhdr, 14); 1401 #endif 1381 1402 1382 1403 struct arphdr … … 1407 1428 struct ex_list *ex_ptr; 1408 1429 uint32_t htip; 1430 uint32_t tip; 1409 1431 struct mbuf *mr; 1410 1432 eh = mtod(m, struct ethhdr *); 1411 1433 ah = (struct arphdr *)&eh[1]; 1412 1434 htip = ntohl(*(uint32_t*)ah->ar_tip); 1435 tip = *(uint32_t*)ah->ar_tip; 1413 1436 1414 1437 mr = m_get(pData); 1438 #ifdef VBOX_WITH_NAT_SERVICE 1439 reh = mtod(mr, struct ethhdr *); 1440 memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/ 1441 Log4(("NAT: arp:[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]->[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]\n", 1442 reh->h_source[0], reh->h_source[1], reh->h_source[2], reh->h_source[3], reh->h_source[4], reh->h_source[5], 1443 reh->h_dest[0], reh->h_dest[1], reh->h_dest[2], reh->h_dest[3], reh->h_dest[4], reh->h_dest[5])); 1444 Log4(("NAT: arp: %R[IP4]\n", &tip)); 1445 #endif 1415 1446 mr->m_data += if_maxlinkhdr; 1416 1447 mr->m_len = sizeof(struct arphdr); … … 1421 1452 { 1422 1453 case ARPOP_REQUEST: 1454 #ifdef VBOX_WITH_NAT_SERVICE 1455 if (tip == special_addr.s_addr) goto arp_ok; 1456 #endif 1423 1457 if ((htip & pData->netmask) == ntohl(special_addr.s_addr)) 1424 1458 { … … 1429 1463 for (ex_ptr = exec_list; ex_ptr; ex_ptr = ex_ptr->ex_next) 1430 1464 { 1431 if ((htip & ~pData->netmask) == ex_ptr->ex_addr) 1465 if ((htip & ~pData->netmask) == ex_ptr->ex_addr) 1466 { 1432 1467 goto arp_ok; 1468 } 1433 1469 } 1434 1470 return; … … 1467 1503 int proto; 1468 1504 static bool fWarnedIpv6; 1505 struct ethhdr *eh = (struct ethhdr*)pkt; 1469 1506 1470 1507 if (pkt_len < ETH_HLEN) … … 1473 1510 return; 1474 1511 } 1512 Log4(("NAT: in:[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]->[%hhx:%hhx:%hhx:%hhx:%hhx:%hhx]\n", 1513 eh->h_source[0], eh->h_source[1], eh->h_source[2], eh->h_source[3], eh->h_source[4], eh->h_source[5], 1514 eh->h_dest[0], eh->h_dest[1], eh->h_dest[2], eh->h_dest[3], eh->h_dest[4], eh->h_dest[5])); 1515 #ifdef VBOX_WITH_NAT_SERVICE 1516 if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) == 0) 1517 { 1518 goto drop; 1519 } 1520 #endif 1475 1521 1476 1522 m = m_get(pData); … … 1516 1562 break; 1517 1563 } 1564 drop: 1518 1565 RTMemFree((void *)pkt); 1519 1566 } … … 1529 1576 eh = mtod(m, struct ethhdr *); 1530 1577 1578 #ifndef VBOX_WITH_NAT_SERVICE 1531 1579 memcpy(eh->h_dest, client_ethaddr, ETH_ALEN); 1532 1580 memcpy(eh->h_source, special_ethaddr, ETH_ALEN - 1); 1533 1581 /* XXX: not correct */ 1534 1582 eh->h_source[5] = CTL_ALIAS; 1583 #else 1584 Assert((caddr_t)eh == (caddr_t)m->m_dat); 1585 if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) != 0) 1586 { 1587 memcpy(eh->h_dest, eh->h_source, ETH_ALEN); 1588 memcpy(eh->h_source, special_ethaddr, ETH_ALEN); 1589 Assert(memcmp(eh->h_dest, special_ethaddr, ETH_ALEN) != 0); 1590 Assert(memcmp(eh->h_dest, zerro_ethaddr, ETH_ALEN) != 0); 1591 } 1592 #endif 1535 1593 eh->h_proto = htons(eth_proto); 1536 1594 #if 0 … … 1571 1629 void slirp_set_ethaddr(PNATState pData, const uint8_t *ethaddr) 1572 1630 { 1631 #ifndef VBOX_WITH_NAT_SERVICE 1573 1632 memcpy(client_ethaddr, ethaddr, ETH_ALEN); 1633 #endif 1574 1634 } 1575 1635 -
trunk/src/VBox/Devices/Network/slirp/slirp.h
r17302 r19313 356 356 #define DO_ALIAS(paddr) do {} while (0) 357 357 #endif 358 #endif 358 359 360 # ifdef VBOX_WITH_NAT_SERVICE 361 # define ETH_ALEN 6 362 # define ETH_HLEN 14 363 364 # define ARPOP_REQUEST 1 /* ARP request */ 365 # define ARPOP_REPLY 2 /* ARP reply */ 366 367 struct ethhdr 368 { 369 unsigned char h_dest[ETH_ALEN]; /* destination eth addr */ 370 unsigned char h_source[ETH_ALEN]; /* source ether addr */ 371 unsigned short h_proto; /* packet type ID field */ 372 }; 373 AssertCompileSize(struct ethhdr, 14); 374 # endif 375 #endif -
trunk/src/VBox/Devices/Network/slirp/slirp_state.h
r18902 r19313 126 126 struct in_addr loopback_addr; 127 127 uint32_t netmask; 128 #ifndef VBOX_WITH_NAT_SERVICE 128 129 uint8_t client_ethaddr[6]; 130 #endif 129 131 struct ex_list *exec_list; 130 132 char slirp_hostname[33]; -
trunk/src/VBox/Devices/Network/slirp/socket.c
r18902 r19313 500 500 /* A "normal" UDP packet */ 501 501 struct mbuf *m; 502 struct ethhdr *eh; 502 503 size_t len; 503 504 u_long n; … … 593 594 * make it look like that's where it came from, done by udp_output 594 595 */ 596 #ifdef VBOX_WITH_NAT_SERVICE 597 { 598 struct ethhdr *eh0; 599 struct ethhdr *eh; 600 Assert(so->so_m); 601 eh0 = (struct ethhdr *)so->so_m->m_dat; 602 eh = (struct ethhdr *)m->m_dat; 603 604 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 605 } 606 #endif 595 607 udp_output(pData, so, m, &addr); 596 608 SOCKET_UNLOCK(so); -
trunk/src/VBox/Devices/Network/slirp/socket.h
r18902 r19313 82 82 void (* so_timeout)(PNATState pData, struct socket *so, void *arg); 83 83 void *so_timeout_arg; 84 #endif 85 #ifdef VBOX_WITH_NAT_SERVICE 86 /* storage of source ether address */ 87 unsigned char so_ethaddr[6]; 84 88 #endif 85 89 }; -
trunk/src/VBox/Devices/Network/slirp/tcp_input.c
r17191 r19313 290 290 { 291 291 so = inso; 292 292 Log4(("NAT: tcp_input: %R[natsock]\n", so)); 293 Assert(so->so_m); 293 294 /* Re-set a few variables */ 294 295 tp = sototcpcb(so); 295 296 m = so->so_m; 297 #ifdef VBOX_WITH_NAT_SERVICE 298 { 299 struct ethhdr *eh = (struct ethhdr *)m->m_dat; 300 memcpy(so->so_ethaddr, eh->h_source, ETH_ALEN); 301 } 302 #endif 296 303 so->so_m = 0; 297 304 ti = so->so_ti; … … 474 481 goto dropwithreset; 475 482 } 476 483 #ifdef VBOX_WITH_NAT_SERVICE 484 Assert(m); 485 so->so_m = m; /* save the initial packet */ 486 { 487 struct ethhdr *eh0; 488 eh0 = (struct ethhdr *)m->m_dat; 489 } 490 #endif 477 491 SOCKET_LOCK(so); 478 492 sbreserve(&so->so_snd, tcp_sndspace); … … 776 790 * succeeded or not. So we must time it out. 777 791 */ 792 #ifdef VBOX_WITH_NAT_SERVICE 793 Assert(m); 794 { 795 struct ethhdr *eh0; 796 eh0 = (struct ethhdr *)m->m_dat; 797 } 798 #endif 778 799 so->so_m = m; 779 800 so->so_ti = ti; -
trunk/src/VBox/Devices/Network/slirp/tcp_output.c
r18902 r19313 378 378 goto out; 379 379 } 380 #ifdef VBOX_WITH_NAT_SERVICE 381 { 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 else 390 { 391 memcpy(eh->h_source, so->so_ethaddr, ETH_ALEN); 392 } 393 } 394 #endif 380 395 m->m_data += if_maxlinkhdr; 381 396 m->m_len = hdrlen; … … 427 442 goto out; 428 443 } 444 #ifdef VBOX_WITH_NAT_SERVICE 445 { 446 struct ethhdr *eh; 447 eh = (struct ethhdr *)m->m_dat; 448 memcpy(eh->h_source, so->so_ethaddr, ETH_ALEN); 449 } 450 #endif 429 451 m->m_data += if_maxlinkhdr; 452 #ifndef VBOX_WITH_NAT_SERVICE 453 /* XXX: it's shouldn't be here at all need to be deleted */ 430 454 m->m_data += sizeof(struct ip) 431 455 + sizeof(struct tcphdr); 456 #endif 432 457 m->m_len = hdrlen; 433 458 } … … 577 602 * the template, but need a way to checksum without them. 578 603 */ 604 Assert(m->m_len == (hdrlen + len)); 579 605 m->m_len = hdrlen + len; /* XXX Needed? m_len should be correct */ 580 606 … … 589 615 error = ip_output(m, tp->t_inpcb->inp_options, &tp->t_inpcb->inp_route, 590 616 so->so_options & SO_DONTROUTE, 0); 617 #endif 618 #ifdef VBOX_WITH_NAT_SERVICE 619 { 620 struct ethhdr *eh0, *eh; 621 eh = (struct ethhdr *)m->m_dat; 622 623 if (so->so_m != NULL) 624 { 625 eh0 = (struct ethhdr *)so->so_m->m_dat; 626 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 627 } 628 } 591 629 #endif 592 630 error = ip_output(pData, so, m); -
trunk/src/VBox/Devices/Network/slirp/tcp_subr.c
r17191 r19313 124 124 if ((m = m_get(pData)) == NULL) 125 125 return; 126 #ifdef VBOX_WITH_NAT_SERVICE 127 { 128 struct ethhdr *eh0, *eh; 129 Assert(tp->t_socket->so_m); 130 eh0 = (struct ethhdr *)tp->t_socket->so_m->m_dat; 131 eh = (struct ethhdr *)m->m_dat; 132 memcpy(eh->h_source, eh0->h_source, ETH_ALEN); 133 } 134 #endif 126 135 #ifdef TCP_COMPAT_42 127 136 tlen = 1;
Note:
See TracChangeset
for help on using the changeset viewer.