Changeset 55652 in vbox for trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c
- Timestamp:
- May 5, 2015 3:28:45 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxNetFlt/linux/VBoxNetFlt-linux.c
r54461 r55652 28 28 #include <linux/rtnetlink.h> 29 29 #include <linux/miscdevice.h> 30 #include <linux/inetdevice.h> 30 31 #include <linux/ip.h> 31 32 #include <linux/if_vlan.h> 33 #include <net/if_inet6.h> 34 #include <net/addrconf.h> 32 35 33 36 #include <VBox/log.h> … … 1857 1860 } 1858 1861 1862 static int vboxNetFltLinuxNotifierIPv4Callback(struct notifier_block *self, unsigned long ulEventType, void *ptr) 1863 { 1864 PVBOXNETFLTINS pThis = RT_FROM_MEMBER(self, VBOXNETFLTINS, u.s.NotifierIPv4); 1865 struct net_device *pDev; 1866 struct in_ifaddr *ifa = (struct in_ifaddr *)ptr; 1867 int rc = NOTIFY_OK; 1868 1869 pDev = vboxNetFltLinuxRetainNetDev(pThis); 1870 Log(("VBoxNetFlt: %s: IPv4 event %s(0x%lx): addr %RTnaipv4 mask %RTnaipv4\n", 1871 pDev ? netdev_name(pDev) : "<???>", 1872 vboxNetFltLinuxGetNetDevEventName(ulEventType), ulEventType, 1873 ifa->ifa_address, ifa->ifa_mask)); 1874 1875 if (pDev != NULL) 1876 vboxNetFltLinuxReleaseNetDev(pThis, pDev); 1877 1878 if (pThis->pSwitchPort->pfnNotifyHostAddress) 1879 { 1880 bool fAdded; 1881 if (ulEventType == NETDEV_UP) 1882 fAdded = true; 1883 else if (ulEventType == NETDEV_DOWN) 1884 fAdded = false; 1885 else 1886 return NOTIFY_OK; 1887 1888 pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, fAdded, 1889 kIntNetAddrType_IPv4, &ifa->ifa_local); 1890 } 1891 1892 return rc; 1893 } 1894 1895 1896 static int vboxNetFltLinuxNotifierIPv6Callback(struct notifier_block *self, unsigned long ulEventType, void *ptr) 1897 { 1898 PVBOXNETFLTINS pThis = RT_FROM_MEMBER(self, VBOXNETFLTINS, u.s.NotifierIPv6); 1899 struct net_device *pDev; 1900 struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)ptr; 1901 int rc = NOTIFY_OK; 1902 1903 pDev = vboxNetFltLinuxRetainNetDev(pThis); 1904 Log(("VBoxNetFlt: %s: IPv6 event %s(0x%lx): %RTnaipv6\n", 1905 pDev ? netdev_name(pDev) : "<???>", 1906 vboxNetFltLinuxGetNetDevEventName(ulEventType), ulEventType, 1907 &ifa->addr)); 1908 1909 if (pDev != NULL) 1910 vboxNetFltLinuxReleaseNetDev(pThis, pDev); 1911 1912 if (pThis->pSwitchPort->pfnNotifyHostAddress) 1913 { 1914 bool fAdded; 1915 if (ulEventType == NETDEV_UP) 1916 fAdded = true; 1917 else if (ulEventType == NETDEV_DOWN) 1918 fAdded = false; 1919 else 1920 return NOTIFY_OK; 1921 1922 pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, fAdded, 1923 kIntNetAddrType_IPv6, &ifa->addr); 1924 } 1925 1926 return rc; 1927 } 1928 1929 1859 1930 bool vboxNetFltOsMaybeRediscovered(PVBOXNETFLTINS pThis) 1860 1931 { … … 2053 2124 dev_put(pDev); 2054 2125 } 2126 2127 unregister_inet6addr_notifier(&pThis->u.s.NotifierIPv6); 2128 unregister_inetaddr_notifier(&pThis->u.s.NotifierIPv4); 2129 2055 2130 Log(("vboxNetFltOsDeleteInstance: this=%p: Notifier removed.\n", pThis)); 2056 2131 unregister_netdevice_notifier(&pThis->u.s.Notifier); … … 2079 2154 || !try_module_get(THIS_MODULE)) 2080 2155 return VERR_INTNET_FLT_IF_FAILED; 2156 2157 if (pThis->pSwitchPort->pfnNotifyHostAddress) 2158 { 2159 struct net *net = dev_net(pThis->u.s.pDev); 2160 struct net_device *dev; 2161 2162 rcu_read_lock(); 2163 for_each_netdev_rcu(net, dev) 2164 { 2165 struct in_device *in_dev; 2166 struct inet6_dev *in6_dev; 2167 2168 /* 2169 * IPv4 2170 */ 2171 in_dev = __in_dev_get_rcu(dev); 2172 if (in_dev != NULL) 2173 { 2174 for_ifa(in_dev) { 2175 if (ifa->ifa_address == htonl(INADDR_LOOPBACK)) 2176 goto continue_netdev; 2177 2178 Log(("%s: %s: IPv4: addr %RTnaipv4 mask %RTnaipv4\n", 2179 __FUNCTION__, netdev_name(dev), 2180 ifa->ifa_address, ifa->ifa_mask)); 2181 2182 pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, 2183 /* :fAdded */ true, kIntNetAddrType_IPv4, &ifa->ifa_address); 2184 } endfor_ifa(in_dev); 2185 } 2186 2187 /* 2188 * IPv6 2189 */ 2190 in6_dev = __in6_dev_get(dev); 2191 if (in6_dev != NULL) 2192 { 2193 struct inet6_ifaddr *ifa; 2194 2195 read_lock_bh(&in6_dev->lock); 2196 list_for_each_entry(ifa, &in6_dev->addr_list, if_list) 2197 { 2198 Log(("%s: %s: IPv6: addr %RTnaipv6/%u\n", 2199 __FUNCTION__, netdev_name(dev), 2200 &ifa->addr, (unsigned)ifa->prefix_len)); 2201 2202 pThis->pSwitchPort->pfnNotifyHostAddress(pThis->pSwitchPort, 2203 /* :fAdded */ true, kIntNetAddrType_IPv6, &ifa->addr); 2204 } 2205 read_unlock_bh(&in6_dev->lock); 2206 } 2207 2208 continue_netdev: 2209 /* continue */; 2210 } 2211 rcu_read_unlock(); 2212 2213 Log(("%s: pfnNotifyHostAddress is set, register notifiers\n", __FUNCTION__)); 2214 2215 pThis->u.s.NotifierIPv4.notifier_call = vboxNetFltLinuxNotifierIPv4Callback; 2216 err = register_inetaddr_notifier(&pThis->u.s.NotifierIPv4); 2217 if (err) 2218 LogRel(("%s: failed to register IPv4 notifier: error %d\n", 2219 __FUNCTION__, err)); 2220 2221 pThis->u.s.NotifierIPv6.notifier_call = vboxNetFltLinuxNotifierIPv6Callback; 2222 err = register_inet6addr_notifier(&pThis->u.s.NotifierIPv6); 2223 if (err) 2224 LogRel(("%s: failed to register IPv6 notifier: error %d\n", 2225 __FUNCTION__, err)); 2226 } 2227 else 2228 Log(("%s: uwe: pfnNotifyHostAddress is NULL\n", __FUNCTION__)); 2081 2229 2082 2230 return VINF_SUCCESS;
Note:
See TracChangeset
for help on using the changeset viewer.