Changeset 22941 in vbox
- Timestamp:
- Sep 11, 2009 6:19:44 AM (15 years ago)
- Location:
- trunk/src/VBox/Devices/Network/slirp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/ip_output.c
r22905 r22941 131 131 } 132 132 #endif 133 /* Current TCP/IP stack hasn't routing information at 134 * all so we need to calculate destination ethernet address 135 */ 136 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 137 eh = (struct ethhdr *)MBUF_HEAD(m); 138 #else 139 /*todo: make prepend */ 140 m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT); 141 Assert(m); 142 eh = mtod(m, struct ethhdr *); 143 m_adj(m, ETH_HLEN); /*let the rest of code do it job*/ 144 #endif 145 if (memcmp(eh->h_source, zerro_ethaddr, ETH_ALEN) == 0) 146 { 147 rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst); 148 if (rc != 0) 149 goto bad; 150 } 151 else 152 { 153 memcpy(eth_dst, eh->h_source, ETH_ALEN); 154 rc = 0; /*some times we've already know where to send packet*/ 155 } 156 133 /* Current TCP/IP stack hasn't routing information at 134 * all so we need to calculate destination ethernet address 135 */ 136 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 137 eh = (struct ethhdr *)MBUF_HEAD(m); 138 if (memcmp(eh->h_source, zerro_ethaddr, ETH_ALEN) == 0) 139 { 140 rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst); 141 if (rc != 0) 142 goto bad; 143 } 144 else 145 { 146 memcpy(eth_dst, eh->h_source, ETH_ALEN); 147 rc = 0; /*some times we've already know where to send packet*/ 148 } 149 #else 150 /* 151 * (vvl) Note: Here we should care about dhcp and other services 152 * aware of ethernet address 153 */ 154 rc = rt_lookup_in_cache(pData, ip->ip_dst.s_addr, eth_dst); 155 if (rc != 0) 156 goto bad; 157 #endif 157 158 /* 158 159 * If small enough for interface, can just send directly. … … 165 166 ip->ip_sum = cksum(m, hlen); 166 167 167 Assert((rc == 0));168 memcpy(eh->h_source, eth_dst, ETH_ALEN);169 170 168 { 171 169 STAM_PROFILE_START(&pData->StatALIAS_output, a); … … 193 191 STAM_PROFILE_STOP(&pData->StatALIAS_output, a); 194 192 } 193 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 194 /*todo: make prepend */ 195 m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT); 196 Assert(m); 197 eh = mtod(m, struct ethhdr *); 198 #endif 199 memcpy(eh->h_source, eth_dst, ETH_ALEN); 195 200 196 201 if_output(pData, so, m); 197 202 goto done; 198 }203 } 199 204 200 205 /* … … 254 259 #endif 255 260 /* we've calculated eth_dst for first packet */ 256 #ifndef VBOX_WITH_SLIRP_BSD_MBUF257 eh = (struct ethhdr *)MBUF_HEAD(m);258 #else259 m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT);260 Assert(m);261 eh = mtod(m, struct ethhdr *);262 m_adj(m, ETH_HLEN);263 #endif264 Assert((rc == 0));265 266 memcpy(eh->h_source, eth_dst, ETH_ALEN);267 268 261 #if 0 /* No options */ 269 262 if (hlen > sizeof (struct ip)) … … 314 307 ip->ip_sum = cksum(m, hlen); 315 308 316 {317 STAM_PROFILE_START(&pData->StatALIAS_output, a);318 #ifndef VBOX_WITH_SLIRP_BSD_MBUF319 rc = LibAliasOut((m->m_la ? m->m_la : pData->proxy_alias),320 mtod(m, char *), m->m_len);321 #else322 struct m_tag *t;323 if (t = m_tag_find(m, PACKET_TAG_ALIAS, NULL) != 0)324 {325 rc = LibAliasOut((struct libalias *)&t[1], mtod(m, char *), m_length(m, NULL));326 }327 else328 {329 rc = LibAliasOut(pData->proxy_alias, mtod(m, char *),330 m_length(m, NULL));331 }332 if (rc == PKT_ALIAS_IGNORED)333 {334 Log(("NAT: packet was droppped\n"));335 goto bad;336 }337 #endif338 Log2(("NAT: LibAlias return %d\n", rc));339 STAM_PROFILE_STOP(&pData->StatALIAS_output, a);340 }341 342 309 sendorfree: 343 310 for (m = m0; m; m = m0) … … 369 336 #endif 370 337 Log2(("NAT: LibAlias return %d\n", rc)); 338 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 339 eh = (struct ethhdr *)MBUF_HEAD(m); 340 #else 341 m = m_prepend(pData, m, ETH_HLEN, M_DONTWAIT); 342 Assert(m); 343 eh = mtod(m, struct ethhdr *); 344 #endif 345 memcpy(eh->h_source, eth_dst, ETH_ALEN); 346 371 347 if_output(pData, so, m); 372 348 } -
trunk/src/VBox/Devices/Network/slirp/slirp.c
r22873 r22941 274 274 return VERR_NO_MEMORY; 275 275 } 276 LogRel(("NAT: adding %R[IP4] to DNS server list\n", &((struct sockaddr_in *)saddr)->sin_addr)); 277 if ((((struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) { 276 LogRel(("NAT: adding %R[IP4] to DNS server list\n", 277 &((struct sockaddr_in *)saddr)->sin_addr)); 278 if (((( struct sockaddr_in *)saddr)->sin_addr.s_addr & htonl(IN_CLASSA_NET)) == 279 ntohl(INADDR_LOOPBACK & IN_CLASSA_NET)) { 278 280 da->de_addr.s_addr = htonl(ntohl(special_addr.s_addr) | CTL_ALIAS); 279 281 } … … 554 556 555 557 /* Initialise mbufs *after* setting the MTU */ 558 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 556 559 m_init(pData); 560 #else 561 mbuf_init(pData); 562 #endif 557 563 558 564 #ifndef VBOX_WITH_NAT_SERVICE … … 1361 1367 { 1362 1368 case ARPOP_REQUEST: 1369 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1363 1370 mr = m_get(pData); 1364 1371 … … 1372 1379 mr->m_len = sizeof(struct arphdr); 1373 1380 rah = mtod(mr, struct arphdr *); 1381 #else 1382 mr = m_gethdr(pData, M_NOWAIT, MT_HEADER); 1383 rah = mtod(mr, struct arphdr *); 1384 Assert(mr); 1385 mr->m_pkthdr.len = mr->m_len = sizeof(* rah); 1386 mr = m_prepend(pData, mr, ETH_HLEN, M_DONTWAIT); 1387 reh = mtod(mr, struct ethhdr *); 1388 memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/ 1389 #endif 1374 1390 #ifdef VBOX_WITH_NAT_SERVICE 1375 1391 if (tip == special_addr.s_addr) goto arp_ok; … … 1473 1489 } 1474 1490 1491 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1475 1492 m = m_get(pData); 1493 #else 1494 m = m_gethdr(pData, M_NOWAIT, MT_HEADER); 1495 #endif 1476 1496 if (!m) 1477 1497 { 1478 1498 LogRel(("NAT: can't allocate new mbuf\n")); 1499 RTMemFree((void *)pkt); 1479 1500 return; 1480 1501 } … … 1482 1503 /* Note: we add to align the IP header */ 1483 1504 1505 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1484 1506 if (M_FREEROOM(m) < pkt_len) 1485 1507 m_inc(m, pkt_len); … … 1487 1509 m->m_len = pkt_len ; 1488 1510 memcpy(m->m_data, pkt, pkt_len); 1511 #else 1512 if (m_append(pData, m, pkt_len, pkt) != 1) 1513 { 1514 AssertMsgFailed(("Can't append incommin to mbuf")); 1515 RTMemFree(pkt); 1516 m_free(pData, m); 1517 } 1518 #endif 1489 1519 1490 1520 #if 1 … … 1504 1534 updtime(pData); 1505 1535 m_adj(m, ETH_HLEN); 1536 #ifdef VBOX_WITH_SLIRP_BSD_MBUF 1537 M_ASSERTPKTHDR(m); 1538 m->m_pkthdr.header = mtod(m, void *); 1539 #endif 1506 1540 ip_input(pData, m); 1507 1541 break; … … 1527 1561 struct ethhdr *eh; 1528 1562 uint8_t *buf = NULL; 1563 size_t mlen = 0; 1529 1564 STAM_PROFILE_START(&pData->StatIF_encap, a); 1530 1565 1566 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1531 1567 m->m_data -= if_maxlinkhdr; 1532 1568 m->m_len += ETH_HLEN; … … 1538 1574 AssertMsgFailed(("!!Ethernet frame corrupted!!")); 1539 1575 } 1576 #else 1577 M_ASSERTPKTHDR(m); 1578 eh = mtod(m, struct ethhdr *); 1579 #endif 1540 1580 1541 1581 if (memcmp(eh->h_source, special_ethaddr, ETH_ALEN) != 0) … … 1550 1590 } 1551 1591 } 1552 buf = RTMemAlloc(1600); 1592 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1593 mlen = m->m_len; 1594 #else 1595 mlen = m_length(pData, m); 1596 #endif 1597 buf = RTMemAlloc(mlen); 1553 1598 if (buf == NULL) 1554 1599 { … … 1557 1602 } 1558 1603 eh->h_proto = htons(eth_proto); 1559 memcpy(buf, mtod(m, uint8_t *), m->m_len); 1560 slirp_output(pData->pvUser, NULL, buf, m->m_len); 1604 #ifndef VBOX_WITH_SLIRP_BSD_MBUF 1605 memcpy(buf, mtod(m, uint8_t *), mlen); 1606 #else 1607 m_copydata(m, 0, mlen, (char *)buf); 1608 #endif 1609 slirp_output(pData->pvUser, NULL, buf, mlen); 1561 1610 done: 1562 1611 STAM_PROFILE_STOP(&pData->StatIF_encap, a);
Note:
See TracChangeset
for help on using the changeset viewer.