Changeset 40287 in vbox
- Timestamp:
- Feb 29, 2012 8:38:32 AM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Network/slirp/slirp.c
r40284 r40287 1480 1480 static void arp_input(PNATState pData, struct mbuf *m) 1481 1481 { 1482 struct ethhdr * eh;1483 struct ethhdr *reh;1484 struct arphdr *ah;1485 struct arphdr *rah; 1482 struct ethhdr *pEtherHeader; 1483 struct arphdr *pARPHeader; 1484 uint32_t ip4TargetAddress; 1485 1486 1486 int ar_op; 1487 uint32_t htip; 1488 uint32_t tip; 1489 struct mbuf *mr; 1490 eh = mtod(m, struct ethhdr *); 1491 ah = (struct arphdr *)&eh[1]; 1492 htip = RT_N2H_U32(*(uint32_t*)ah->ar_tip); 1493 tip = *(uint32_t*)ah->ar_tip; 1494 1495 ar_op = RT_N2H_U16(ah->ar_op); 1487 pEtherHeader = mtod(m, struct ethhdr *); 1488 pARPHeader = (struct arphdr *)&pEtherHeader[1]; 1489 1490 ar_op = RT_N2H_U16(pARPHeader->ar_op); 1491 ip4TargetAddress = *(uint32_t*)pARPHeader->ar_tip; 1496 1492 1497 1493 switch (ar_op) 1498 1494 { 1499 1495 case ARPOP_REQUEST: 1500 mr = m_getcl(pData, M_NOWAIT, MT_HEADER, M_PKTHDR); 1501 if (!mr) 1502 break; 1503 reh = mtod(mr, struct ethhdr *); 1504 mr->m_data += ETH_HLEN; 1505 rah = mtod(mr, struct arphdr *); 1506 mr->m_len = sizeof(struct arphdr); 1507 memcpy(reh->h_source, eh->h_source, ETH_ALEN); /* XXX: if_encap will swap src and dst*/ 1508 if ( CTL_CHECK(tip, CTL_DNS) 1509 || CTL_CHECK(tip, CTL_ALIAS) 1510 || CTL_CHECK(tip, CTL_TFTP)) 1496 if ( CTL_CHECK(ip4TargetAddress, CTL_DNS) 1497 || CTL_CHECK(ip4TargetAddress, CTL_ALIAS) 1498 || CTL_CHECK(ip4TargetAddress, CTL_TFTP)) 1511 1499 { 1512 rah->ar_hrd = RT_H2N_U16_C(1); 1513 rah->ar_pro = RT_H2N_U16_C(ETH_P_IP); 1514 rah->ar_hln = ETH_ALEN; 1515 rah->ar_pln = 4; 1516 rah->ar_op = RT_H2N_U16_C(ARPOP_REPLY); 1517 memcpy(rah->ar_sha, special_ethaddr, ETH_ALEN); 1518 1519 if (!slirpMbufTagService(pData, mr, (uint8_t)(htip & ~pData->netmask))) 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))) 1520 1524 { 1521 1525 static bool fTagErrorReported; … … 1523 1527 { 1524 1528 LogRel(("NAT: couldn't add the tag(PACKET_SERVICE:%d) to mbuf:%p\n", 1525 (uint8_t)( htip& ~pData->netmask), m));1529 (uint8_t)(ip4TargetAddressInHostFormat & ~pData->netmask), m)); 1526 1530 fTagErrorReported = true; 1527 1531 } 1528 1532 } 1529 rah->ar_sha[5] = (uint8_t)(htip& ~pData->netmask);1530 1531 memcpy( rah->ar_sip, ah->ar_tip, 4);1532 memcpy( rah->ar_tha, ah->ar_sha, ETH_ALEN);1533 memcpy( rah->ar_tip, ah->ar_sip, 4);1534 if_encap(pData, ETH_P_ARP, mr, ETH_ENCAP_URG);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); 1535 1539 } 1536 else1537 m_freem(pData, mr);1538 1540 1539 1541 /* Gratuitous ARP */ 1540 if ( *(uint32_t *) ah->ar_sip == *(uint32_t *)ah->ar_tip1541 && memcmp( ah->ar_tha, broadcast_ethaddr, ETH_ALEN) == 01542 && memcmp( eh->h_dest, broadcast_ethaddr, ETH_ALEN) == 0)1542 if ( *(uint32_t *)pARPHeader->ar_sip == *(uint32_t *)pARPHeader->ar_tip 1543 && memcmp(pARPHeader->ar_tha, broadcast_ethaddr, ETH_ALEN) == 0 1544 && memcmp(pEtherHeader->h_dest, broadcast_ethaddr, ETH_ALEN) == 0) 1543 1545 { 1544 1546 /* We've received an announce about address assignment, … … 1549 1551 { 1550 1552 LogRel(("NAT: Gratuitous ARP [IP:%RTnaipv4, ether:%RTmac]\n", 1551 ah->ar_sip, ah->ar_sha));1553 pARPHeader->ar_sip, pARPHeader->ar_sha)); 1552 1554 fGratuitousArpReported = true; 1553 1555 } 1554 slirp_arp_cache_update_or_add(pData, *(uint32_t *) ah->ar_sip, &ah->ar_sha[0]);1556 slirp_arp_cache_update_or_add(pData, *(uint32_t *)pARPHeader->ar_sip, &pARPHeader->ar_sha[0]); 1555 1557 } 1556 1558 break; 1557 1559 1558 1560 case ARPOP_REPLY: 1559 slirp_arp_cache_update_or_add(pData, *(uint32_t *) ah->ar_sip, &ah->ar_sha[0]);1561 slirp_arp_cache_update_or_add(pData, *(uint32_t *)pARPHeader->ar_sip, &pARPHeader->ar_sha[0]); 1560 1562 break; 1561 1563
Note:
See TracChangeset
for help on using the changeset viewer.