if.c (132362) | if.c (132712) |
---|---|
1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if.c 8.5 (Berkeley) 1/9/95 | 1/* 2 * Copyright (c) 1980, 1986, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 13 unchanged lines hidden (view full) --- 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)if.c 8.5 (Berkeley) 1/9/95 |
30 * $FreeBSD: head/sys/net/if.c 132362 2004-07-18 19:53:35Z rwatson $ | 30 * $FreeBSD: head/sys/net/if.c 132712 2004-07-27 23:20:45Z rwatson $ |
31 */ 32 33#include "opt_compat.h" 34#include "opt_inet6.h" 35#include "opt_inet.h" 36#include "opt_mac.h" 37 38#include <sys/param.h> --- 6 unchanged lines hidden (view full) --- 45#include <sys/proc.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> 48#include <sys/protosw.h> 49#include <sys/kernel.h> 50#include <sys/sockio.h> 51#include <sys/syslog.h> 52#include <sys/sysctl.h> | 31 */ 32 33#include "opt_compat.h" 34#include "opt_inet6.h" 35#include "opt_inet.h" 36#include "opt_mac.h" 37 38#include <sys/param.h> --- 6 unchanged lines hidden (view full) --- 45#include <sys/proc.h> 46#include <sys/socket.h> 47#include <sys/socketvar.h> 48#include <sys/protosw.h> 49#include <sys/kernel.h> 50#include <sys/sockio.h> 51#include <sys/syslog.h> 52#include <sys/sysctl.h> |
53#include <sys/taskqueue.h> |
|
53#include <sys/domain.h> 54#include <sys/jail.h> 55#include <machine/stdarg.h> 56 57#include <net/if.h> 58#include <net/if_arp.h> 59#include <net/if_clone.h> 60#include <net/if_dl.h> --- 26 unchanged lines hidden (view full) --- 87static int if_findindex(struct ifnet *); 88static void if_qflush(struct ifaltq *); 89static void if_route(struct ifnet *, int flag, int fam); 90static void if_slowtimo(void *); 91static void if_unroute(struct ifnet *, int flag, int fam); 92static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 93static int if_rtdel(struct radix_node *, void *); 94static int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *); | 54#include <sys/domain.h> 55#include <sys/jail.h> 56#include <machine/stdarg.h> 57 58#include <net/if.h> 59#include <net/if_arp.h> 60#include <net/if_clone.h> 61#include <net/if_dl.h> --- 26 unchanged lines hidden (view full) --- 88static int if_findindex(struct ifnet *); 89static void if_qflush(struct ifaltq *); 90static void if_route(struct ifnet *, int flag, int fam); 91static void if_slowtimo(void *); 92static void if_unroute(struct ifnet *, int flag, int fam); 93static void link_rtrequest(int, struct rtentry *, struct rt_addrinfo *); 94static int if_rtdel(struct radix_node *, void *); 95static int ifhwioctl(u_long, struct ifnet *, caddr_t, struct thread *); |
96static void if_start_deferred(void *context, int pending); |
|
95#ifdef INET6 96/* 97 * XXX: declare here to avoid to include many inet6 related files.. 98 * should be more generalized? 99 */ 100extern void nd6_setmtu(struct ifnet *); 101#endif 102 --- 257 unchanged lines hidden (view full) --- 360void 361if_attach(struct ifnet *ifp) 362{ 363 unsigned socksize, ifasize; 364 int namelen, masklen; 365 struct sockaddr_dl *sdl; 366 struct ifaddr *ifa; 367 | 97#ifdef INET6 98/* 99 * XXX: declare here to avoid to include many inet6 related files.. 100 * should be more generalized? 101 */ 102extern void nd6_setmtu(struct ifnet *); 103#endif 104 --- 257 unchanged lines hidden (view full) --- 362void 363if_attach(struct ifnet *ifp) 364{ 365 unsigned socksize, ifasize; 366 int namelen, masklen; 367 struct sockaddr_dl *sdl; 368 struct ifaddr *ifa; 369 |
370 TASK_INIT(&ifp->if_starttask, 0, if_start_deferred, ifp); |
|
368 IF_AFDATA_LOCK_INIT(ifp); 369 ifp->if_afdata_initialized = 0; 370 IFNET_WLOCK(); 371 TAILQ_INSERT_TAIL(&ifnet, ifp, if_link); 372 IFNET_WUNLOCK(); 373 /* 374 * XXX - 375 * The old code would work if the interface passed a pre-existing --- 602 unchanged lines hidden (view full) --- 978 ifq->ifq_tail = 0; 979 ifq->ifq_len = 0; 980} 981 982/* 983 * Handle interface watchdog timer routines. Called 984 * from softclock, we decrement timers (if set) and 985 * call the appropriate interface routine on expiration. | 371 IF_AFDATA_LOCK_INIT(ifp); 372 ifp->if_afdata_initialized = 0; 373 IFNET_WLOCK(); 374 TAILQ_INSERT_TAIL(&ifnet, ifp, if_link); 375 IFNET_WUNLOCK(); 376 /* 377 * XXX - 378 * The old code would work if the interface passed a pre-existing --- 602 unchanged lines hidden (view full) --- 981 ifq->ifq_tail = 0; 982 ifq->ifq_len = 0; 983} 984 985/* 986 * Handle interface watchdog timer routines. Called 987 * from softclock, we decrement timers (if set) and 988 * call the appropriate interface routine on expiration. |
989 * 990 * XXXRW: Note that because timeouts run with Giant, if_watchdog() is called 991 * holding Giant. If we switch to an MPSAFE callout, we likely need to grab 992 * Giant before entering if_watchdog() on an IFF_NEEDSGIANT interface. |
|
986 */ 987static void 988if_slowtimo(void *arg) 989{ 990 struct ifnet *ifp; 991 int s = splimp(); 992 993 IFNET_RLOCK(); --- 840 unchanged lines hidden (view full) --- 1834 1835 retval = printf("%s: ", ifp->if_xname); 1836 va_start(ap, fmt); 1837 retval += vprintf(fmt, ap); 1838 va_end(ap); 1839 return (retval); 1840} 1841 | 993 */ 994static void 995if_slowtimo(void *arg) 996{ 997 struct ifnet *ifp; 998 int s = splimp(); 999 1000 IFNET_RLOCK(); --- 840 unchanged lines hidden (view full) --- 1841 1842 retval = printf("%s: ", ifp->if_xname); 1843 va_start(ap, fmt); 1844 retval += vprintf(fmt, ap); 1845 va_end(ap); 1846 return (retval); 1847} 1848 |
1849/* 1850 * When an interface is marked IFF_NEEDSGIANT, its if_start() routine cannot 1851 * be called without Giant. However, we often can't acquire the Giant lock 1852 * at those points; instead, we run it via a task queue that holds Giant via 1853 * if_start_deferred. 1854 * 1855 * XXXRW: We need to make sure that the ifnet isn't fully detached until any 1856 * outstanding if_start_deferred() tasks that will run after the free. This 1857 * probably means waiting in if_detach(). 1858 */ 1859void 1860if_start(struct ifnet *ifp) 1861{ 1862 1863 NET_ASSERT_GIANT(); 1864 1865 if ((ifp->if_flags & IFF_NEEDSGIANT) != 0 && debug_mpsafenet != 0) { 1866 if (mtx_owned(&Giant)) 1867 (*(ifp)->if_start)(ifp); 1868 else 1869 taskqueue_enqueue(taskqueue_swi_giant, 1870 &ifp->if_starttask); 1871 } else 1872 (*(ifp)->if_start)(ifp); 1873} 1874 1875static void 1876if_start_deferred(void *context, int pending) 1877{ 1878 struct ifnet *ifp; 1879 1880 /* 1881 * This code must be entered with Giant, and should never run if 1882 * we're not running with debug.mpsafenet. 1883 */ 1884 KASSERT(debug_mpsafenet != 0, ("if_start_deferred: debug.mpsafenet")); 1885 GIANT_REQUIRED; 1886 1887 ifp = (struct ifnet *)context; 1888 (ifp->if_start)(ifp); 1889} 1890 |
|
1842SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 1843SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); | 1891SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); 1892SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); |