VirtualBox

Changeset 38927 in vbox


Ignore:
Timestamp:
Oct 1, 2011 3:28:49 AM (13 years ago)
Author:
vboxsync
Message:

NAT: Don't let ICMP cache to grow without limitations.

File:
1 edited

Legend:

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

    r37936 r38927  
    8989};
    9090
     91static int icmp_cache_count(PNATState pData);
     92static void icmp_cache_clean(PNATState pData, int iEntries);
     93
    9194int
    9295icmp_init(PNATState pData)
     
    308311}
    309312
     313static int icmp_cache_count(PNATState pData)
     314{
     315    int iIcmpCount = 0;
     316    struct icmp_msg *icm = NULL;
     317    LogFlowFuncEnter();
     318    LIST_FOREACH(icm, &pData->icmp_msg_head, im_list)
     319        iIcmpCount++;
     320    LogFlowFunc(("LEAVE: %d\n", iIcmpCount));
     321    return iIcmpCount;
     322}
     323/**
     324 * iEntries how many entries to leave, if iEntries < 0, clean all
     325 */
     326static void icmp_cache_clean(PNATState pData, int iEntries)
     327{
     328    int iIcmpCount = 0;
     329    struct icmp_msg *icm = NULL;
     330    LogFlowFunc(("iEntries:%d\n", iEntries));
     331    if (iEntries > icmp_cache_count(pData))
     332    {
     333        LogFlowFuncLeave();
     334        return;
     335    }
     336    while(!LIST_EMPTY(&pData->icmp_msg_head))
     337    {
     338        icm = LIST_FIRST(&pData->icmp_msg_head);
     339        if (    iEntries > 0
     340            &&  iIcmpCount < iEntries)
     341        {
     342            iIcmpCount++;
     343            continue;
     344        }
     345
     346        LIST_REMOVE(icm, im_list);
     347        if (icm->im_m)
     348            m_freem(pData, icm->im_m);
     349        RTMemFree(icm);
     350    }
     351    LogFlowFuncLeave();
     352}
     353
    310354static int
    311355icmp_attach(PNATState pData, struct mbuf *m)
     
    319363    icm->im_so = m->m_so;
    320364    LIST_INSERT_HEAD(&pData->icmp_msg_head, icm, im_list);
     365    if (icmp_cache_count(pData) > 100)
     366        icmp_cache_clean(pData, 50);
    321367    return 0;
    322368}
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