VirtualBox

Ignore:
Timestamp:
Oct 27, 2010 1:27:08 PM (14 years ago)
Author:
vboxsync
Message:

vboxnetflt: tap link state fix for linux kernels 2.6.36 and above (#5328)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c

    r32856 r33506  
    19061906}
    19071907
     1908#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 36)
     1909/**
     1910 * Helper for detecting TAP devices.
     1911 */
     1912static bool vboxNetFltIsTapDevice(PVBOXNETFLTINS pThis, struct net_device *pDev)
     1913{
     1914    if (pDev->ethtool_ops && pDev->ethtool_ops->get_drvinfo)
     1915    {
     1916        struct ethtool_drvinfo Info;
     1917
     1918        memset(&Info, 0, sizeof(Info));
     1919        Info.cmd = ETHTOOL_GDRVINFO;
     1920        pDev->ethtool_ops->get_drvinfo(pDev, &Info);
     1921        Log3(("vboxNetFltIsTapDevice: driver=%s version=%s bus_info=%s\n",
     1922              Info.driver, Info.version, Info.bus_info));
     1923
     1924        return !strncmp(Info.driver,   "tun", 4)
     1925            && !strncmp(Info.bus_info, "tap", 4);
     1926    }
     1927
     1928    return false;
     1929}
     1930
     1931/**
     1932 * Helper for updating the link state of TAP devices.
     1933 * Only TAP devices are affected.
     1934 */
     1935static void vboxNetFltSetTapLinkState(PVBOXNETFLTINS pThis, struct net_device *pDev, bool fLinkUp)
     1936{
     1937    if (vboxNetFltIsTapDevice(pThis, pDev))
     1938    {
     1939        Log3(("vboxNetFltSetTapLinkState: bringing %s tap device link state\n",
     1940              fLinkUp ? "up" : "down"));
     1941        netif_tx_lock_bh(pDev);
     1942        if (fLinkUp)
     1943            netif_carrier_on(pDev);
     1944        else
     1945            netif_carrier_off(pDev);
     1946        netif_tx_unlock_bh(pDev);
     1947    }
     1948}
     1949#else /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) */
     1950DECLINLINE(void) vboxNetFltSetTapLinkState(PVBOXNETFLTINS pThis, struct net_device *pDev, bool fLinkUp)
     1951{
     1952    /* Nothing to do for pre-2.6.36 kernels. */
     1953}
     1954#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 36) */
     1955
    19081956/**
    19091957 * Internal worker for vboxNetFltLinuxNotifierCallback.
     
    19481996    vboxNetFltLinuxQdiscInstall(pThis, pDev);
    19491997#endif /* VBOXNETFLT_WITH_QDISC */
     1998
     1999    /*
     2000     * If attaching to TAP interface we need to bring the link state up
     2001     * starting from 2.6.36 kernel.
     2002     */
     2003    vboxNetFltSetTapLinkState(pThis, pDev, true);
    19502004
    19512005    /*
     
    23212375    if (fRegistered)
    23222376    {
     2377        vboxNetFltSetTapLinkState(pThis, pDev, false);
     2378
    23232379#ifndef VBOXNETFLT_LINUX_NO_XMIT_QUEUE
    23242380        skb_queue_purge(&pThis->u.s.XmitQueue);
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