Changeset 40291 in vbox for trunk/src/VBox/Devices
- Timestamp:
- Feb 29, 2012 11:15:54 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/slirp.c
r40287 r40291 1475 1475 AssertCompileSize(struct arphdr, 28); 1476 1476 1477 static void arp_output(PNATState pData, const uint8_t *pcu8EtherSource, const struct arphdr *pcARPHeaderSource, uint32_t ip4TargetAddress) 1478 { 1479 struct ethhdr *pEtherHeaderResponse; 1480 struct arphdr *pARPHeaderResponse; 1481 uint32_t ip4TargetAddressInHostFormat; 1482 struct mbuf *pMbufResponse; 1483 1484 Assert((pcu8EtherSource)); 1485 if (!pcu8EtherSource) 1486 return; 1487 ip4TargetAddressInHostFormat = RT_N2H_U32(ip4TargetAddress); 1488 1489 pMbufResponse = m_getcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR); 1490 if (!pMbufResponse) 1491 return; 1492 pEtherHeaderResponse = mtod(pMbufResponse, struct ethhdr *); 1493 /* @note: if_encap will swap src and dst*/ 1494 memcpy(pEtherHeaderResponse->h_source, pcu8EtherSource, ETH_ALEN); 1495 pMbufResponse->m_data += ETH_HLEN; 1496 pARPHeaderResponse = mtod(pMbufResponse, struct arphdr *); 1497 pMbufResponse->m_len = sizeof(struct arphdr); 1498 1499 pARPHeaderResponse->ar_hrd = RT_H2N_U16_C(1); 1500 pARPHeaderResponse->ar_pro = RT_H2N_U16_C(ETH_P_IP); 1501 pARPHeaderResponse->ar_hln = ETH_ALEN; 1502 pARPHeaderResponse->ar_pln = 4; 1503 pARPHeaderResponse->ar_op = RT_H2N_U16_C(ARPOP_REPLY); 1504 memcpy(pARPHeaderResponse->ar_sha, special_ethaddr, ETH_ALEN); 1505 1506 if (!slirpMbufTagService(pData, pMbufResponse, (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask))) 1507 { 1508 static bool fTagErrorReported; 1509 if (!fTagErrorReported) 1510 { 1511 LogRel(("NAT: couldn't add the tag(PACKET_SERVICE:%d)\n", 1512 (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask))); 1513 fTagErrorReported = true; 1514 } 1515 } 1516 pARPHeaderResponse->ar_sha[5] = (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask); 1517 1518 memcpy(pARPHeaderResponse->ar_sip, pcARPHeaderSource->ar_tip, 4); 1519 memcpy(pARPHeaderResponse->ar_tha, pcARPHeaderSource->ar_sha, ETH_ALEN); 1520 memcpy(pARPHeaderResponse->ar_tip, pcARPHeaderSource->ar_sip, 4); 1521 if_encap(pData, ETH_P_ARP, pMbufResponse, ETH_ENCAP_URG); 1522 } 1477 1523 /** 1478 1524 * @note This function will free m! … … 1497 1543 || CTL_CHECK(ip4TargetAddress, CTL_ALIAS) 1498 1544 || CTL_CHECK(ip4TargetAddress, CTL_TFTP)) 1499 { 1500 struct ethhdr *pEtherHeaderResponse; 1501 struct arphdr *pARPHeaderResponse; 1502 uint32_t ip4TargetAddressInHostFormat; 1503 struct mbuf *pMbufResponse; 1504 ip4TargetAddressInHostFormat = RT_N2H_U32(ip4TargetAddress); 1505 1506 pMbufResponse = m_getcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR); 1507 if (!pMbufResponse) 1508 break; 1509 pEtherHeaderResponse = mtod(pMbufResponse, struct ethhdr *); 1510 /* @note: if_encap will swap src and dst*/ 1511 memcpy(pEtherHeaderResponse->h_source, pEtherHeader->h_source, ETH_ALEN); 1512 pMbufResponse->m_data += ETH_HLEN; 1513 pARPHeaderResponse = mtod(pMbufResponse, struct arphdr *); 1514 pMbufResponse->m_len = sizeof(struct arphdr); 1515 1516 pARPHeaderResponse->ar_hrd = RT_H2N_U16_C(1); 1517 pARPHeaderResponse->ar_pro = RT_H2N_U16_C(ETH_P_IP); 1518 pARPHeaderResponse->ar_hln = ETH_ALEN; 1519 pARPHeaderResponse->ar_pln = 4; 1520 pARPHeaderResponse->ar_op = RT_H2N_U16_C(ARPOP_REPLY); 1521 memcpy(pARPHeaderResponse->ar_sha, special_ethaddr, ETH_ALEN); 1522 1523 if (!slirpMbufTagService(pData, pMbufResponse, (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask))) 1524 { 1525 static bool fTagErrorReported; 1526 if (!fTagErrorReported) 1527 { 1528 LogRel(("NAT: couldn't add the tag(PACKET_SERVICE:%d) to mbuf:%p\n", 1529 (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask), m)); 1530 fTagErrorReported = true; 1531 } 1532 } 1533 pARPHeaderResponse->ar_sha[5] = (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask); 1534 1535 memcpy(pARPHeaderResponse->ar_sip, pARPHeader->ar_tip, 4); 1536 memcpy(pARPHeaderResponse->ar_tha, pARPHeader->ar_sha, ETH_ALEN); 1537 memcpy(pARPHeaderResponse->ar_tip, pARPHeader->ar_sip, 4); 1538 if_encap(pData, ETH_P_ARP, pMbufResponse, ETH_ENCAP_URG); 1539 } 1545 arp_output(pData, pEtherHeader->h_source, pARPHeader, ip4TargetAddress); 1540 1546 1541 1547 /* Gratuitous ARP */
Note:
See TracChangeset
for help on using the changeset viewer.