VirtualBox

Changeset 36353 in vbox


Ignore:
Timestamp:
Mar 23, 2011 7:08:02 AM (14 years ago)
Author:
vboxsync
Message:

NAT/arp: cosmetic. verfication of updating of pair moved to slirp_arp_cache_update_or_add,
helper functions _update and _add are hidden and asserts on invalid pair adding.

Location:
trunk/src/VBox/Devices/Network/slirp
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Network/slirp/slirp.c

    r36352 r36353  
    20202020}
    20212021
     2022/* updates the arp cache
     2023 * @note: this is helper function, slirp_arp_cache_update_or_add should be used.
     2024 * @returns 0 - if has found and updated
     2025 *          1 - if hasn't found.
     2026 */
     2027static inline int slirp_arp_cache_update(PNATState pData, uint32_t dst, const uint8_t *mac)
     2028{
     2029    struct arp_cache_entry *ac;
     2030    Assert((   memcmp(mac, broadcast_ethaddr, ETH_ALEN)
     2031            && memcmp(mac, zerro_ethaddr, ETH_ALEN)));
     2032    LIST_FOREACH(ac, &pData->arp_cache, list)
     2033    {
     2034        if (!memcmp(ac->ether, mac, ETH_ALEN))
     2035        {
     2036            ac->ip = dst;
     2037            return 0;
     2038        }
     2039    }
     2040    return 1;
     2041}
     2042/**
     2043 * add entry to the arp cache
     2044 * @note: this is helper function, slirp_arp_cache_update_or_add should be used.
     2045 */
     2046
     2047static inline void slirp_arp_cache_add(PNATState pData, uint32_t ip, const uint8_t *ether)
     2048{
     2049    struct arp_cache_entry *ac = NULL;
     2050    Assert((   memcmp(ether, broadcast_ethaddr, ETH_ALEN)
     2051            && memcmp(ether, zerro_ethaddr, ETH_ALEN)));
     2052    ac = RTMemAllocZ(sizeof(struct arp_cache_entry));
     2053    if (ac == NULL)
     2054    {
     2055        Log(("NAT: Can't allocate arp cache entry\n"));
     2056        return;
     2057    }
     2058    ac->ip = ip;
     2059    memcpy(ac->ether, ether, ETH_ALEN);
     2060    LIST_INSERT_HEAD(&pData->arp_cache, ac, list);
     2061}
     2062
     2063/* updates or adds entry to the arp cache
     2064 * @returns 0 - if has found and updated
     2065 *          1 - if hasn't found.
     2066 */
    20222067int slirp_arp_cache_update_or_add(PNATState pData, uint32_t dst, const uint8_t *mac)
    20232068{
     2069    if (   !memcmp(mac, broadcast_ethaddr, ETH_ALEN)
     2070        || !memcmp(mac, zerro_ethaddr, ETH_ALEN))
     2071    {
     2072        static bool fBroadcastEtherAddReported;
     2073        if (!fBroadcastEtherAddReported)
     2074        {
     2075            LogRel(("NAT: Attept to add pair [%R[ether]:%R[IP4]] was ignored\n",
     2076                    mac, &dst));
     2077            fBroadcastEtherAddReported = true;
     2078        }
     2079        return 1;
     2080    }
    20242081    if (slirp_arp_cache_update(pData, dst, mac))
    20252082        slirp_arp_cache_add(pData, dst, mac);
     
    20282085}
    20292086
    2030 /* updates the arp cache
    2031  * @returns 0 - if has found and updated
    2032  *          1 - if hasn't found.
    2033  */
    2034 int slirp_arp_cache_update(PNATState pData, uint32_t dst, const uint8_t *mac)
    2035 {
    2036     struct arp_cache_entry *ac;
    2037     if (!memcmp(mac, broadcast_ethaddr, ETH_ALEN))
    2038         return 1;
    2039     LIST_FOREACH(ac, &pData->arp_cache, list)
    2040     {
    2041         if (!memcmp(ac->ether, mac, ETH_ALEN))
    2042         {
    2043             ac->ip = dst;
    2044             return 0;
    2045         }
    2046     }
    2047     return 1;
    2048 }
    2049 
    2050 void slirp_arp_cache_add(PNATState pData, uint32_t ip, const uint8_t *ether)
    2051 {
    2052     struct arp_cache_entry *ac = NULL;
    2053     ac = RTMemAllocZ(sizeof(struct arp_cache_entry));
    2054     if (ac == NULL)
    2055     {
    2056         Log(("NAT: Can't allocate arp cache entry\n"));
    2057         return;
    2058     }
    2059     ac->ip = ip;
    2060     if(!memcmp(ether, broadcast_ethaddr, ETH_ALEN))
    2061     {
    2062         static bool fBroadcastEtherAddReported;
    2063         if (!fBroadcastEtherAddReported)
    2064         {
    2065             LogRel(("NAT: Attept to add pair [%R[ether]:%R[IP4]] was ignored\n",
    2066                     ether, ip));
    2067             fBroadcastEtherAddReported = true;
    2068         }
    2069         RTMemFree(ac);
    2070         return;
    2071     }
    2072     memcpy(ac->ether, ether, ETH_ALEN);
    2073     LIST_INSERT_HEAD(&pData->arp_cache, ac, list);
    2074 }
    20752087
    20762088void slirp_set_mtu(PNATState pData, int mtu)
  • trunk/src/VBox/Devices/Network/slirp/slirp.h

    r35346 r36353  
    344344/*slirp.c*/
    345345void slirp_arp_who_has(PNATState pData, uint32_t dst);
    346 int slirp_arp_cache_update(PNATState pData, uint32_t dst, const uint8_t *mac);
    347 void slirp_arp_cache_add(PNATState pData, uint32_t ip, const uint8_t *ether);
    348346int slirp_arp_cache_update_or_add(PNATState pData, uint32_t dst, const uint8_t *mac);
    349347int slirp_init_dns_list(PNATState pData);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette