diff options
Diffstat (limited to 'sys/net/if.c')
-rw-r--r-- | sys/net/if.c | 83 |
1 files changed, 59 insertions, 24 deletions
diff --git a/sys/net/if.c b/sys/net/if.c index 17f01e9..2e21ae9 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -100,7 +100,7 @@ SYSCTL_NODE(_net, PF_LINK, link, CTLFLAG_RW, 0, "Link layers"); SYSCTL_NODE(_net_link, 0, generic, CTLFLAG_RW, 0, "Generic link-management"); TUNABLE_INT("net.link.ifqmaxlen", &ifqmaxlen); -SYSCTL_UINT(_net_link, OID_AUTO, ifqmaxlen, CTLFLAG_RDTUN, +SYSCTL_INT(_net_link, OID_AUTO, ifqmaxlen, CTLFLAG_RDTUN, &ifqmaxlen, 0, "max send queue size"); /* Log link state change events */ @@ -266,6 +266,7 @@ ifindex_alloc_locked(u_short *idxp) IFNET_WLOCK_ASSERT(); +retry: /* * Try to find an empty slot below V_if_index. If we fail, take the * next slot. @@ -278,10 +279,12 @@ ifindex_alloc_locked(u_short *idxp) /* Catch if_index overflow. */ if (idx < 1) return (ENOSPC); + if (idx >= V_if_indexlim) { + if_grow(); + goto retry; + } if (idx > V_if_index) V_if_index = idx; - if (V_if_index >= V_if_indexlim) - if_grow(); *idxp = idx; return (0); } @@ -351,10 +354,12 @@ vnet_if_init(const void *unused __unused) TAILQ_INIT(&V_ifnet); TAILQ_INIT(&V_ifg_head); + IFNET_WLOCK(); if_grow(); /* create initial table */ + IFNET_WUNLOCK(); vnet_if_clone_init(); } -VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_FIRST, vnet_if_init, +VNET_SYSINIT(vnet_if_init, SI_SUB_INIT_IF, SI_ORDER_SECOND, vnet_if_init, NULL); /* ARGSUSED*/ @@ -365,7 +370,7 @@ if_init(void *dummy __unused) IFNET_LOCK_INIT(); if_clone_init(); } -SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_SECOND, if_init, NULL); +SYSINIT(interfaces, SI_SUB_INIT_IF, SI_ORDER_FIRST, if_init, NULL); #ifdef VIMAGE @@ -373,8 +378,10 @@ static void vnet_if_uninit(const void *unused __unused) { - VNET_ASSERT(TAILQ_EMPTY(&V_ifnet)); - VNET_ASSERT(TAILQ_EMPTY(&V_ifg_head)); + VNET_ASSERT(TAILQ_EMPTY(&V_ifnet), ("%s:%d tailq &V_ifnet=%p " + "not empty", __func__, __LINE__, &V_ifnet)); + VNET_ASSERT(TAILQ_EMPTY(&V_ifg_head), ("%s:%d tailq &V_ifg_head=%p " + "not empty", __func__, __LINE__, &V_ifg_head)); free((caddr_t)V_ifindex_table, M_IFNET); } @@ -385,16 +392,25 @@ VNET_SYSUNINIT(vnet_if_uninit, SI_SUB_INIT_IF, SI_ORDER_FIRST, static void if_grow(void) { + int oldlim; u_int n; struct ifindex_entry *e; - V_if_indexlim <<= 1; - n = V_if_indexlim * sizeof(*e); + IFNET_WLOCK_ASSERT(); + oldlim = V_if_indexlim; + IFNET_WUNLOCK(); + n = (oldlim << 1) * sizeof(*e); e = malloc(n, M_IFNET, M_WAITOK | M_ZERO); + IFNET_WLOCK(); + if (V_if_indexlim != oldlim) { + free(e, M_IFNET); + return; + } if (V_ifindex_table != NULL) { memcpy((caddr_t)e, (caddr_t)V_ifindex_table, n/2); free((caddr_t)V_ifindex_table, M_IFNET); } + V_if_indexlim <<= 1; V_ifindex_table = e; } @@ -2424,10 +2440,13 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) int error; int oif_flags; + CURVNET_SET(so->so_vnet); switch (cmd) { case SIOCGIFCONF: case OSIOCGIFCONF: - return (ifconf(cmd, data)); + error = ifconf(cmd, data); + CURVNET_RESTORE(); + return (error); #ifdef COMPAT_FREEBSD32 case SIOCGIFCONF32: @@ -2439,7 +2458,9 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) ifc.ifc_len = ifc32->ifc_len; ifc.ifc_buf = PTRIN(ifc32->ifc_buf); - return (ifconf(SIOCGIFCONF, (void *)&ifc)); + error = ifconf(SIOCGIFCONF, (void *)&ifc); + CURVNET_RESTORE(); + return (error); } #endif } @@ -2449,42 +2470,55 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) #ifdef VIMAGE case SIOCSIFRVNET: error = priv_check(td, PRIV_NET_SETIFVNET); - if (error) - return (error); - return (if_vmove_reclaim(td, ifr->ifr_name, ifr->ifr_jid)); + if (error == 0) + error = if_vmove_reclaim(td, ifr->ifr_name, + ifr->ifr_jid); + CURVNET_RESTORE(); + return (error); #endif case SIOCIFCREATE: case SIOCIFCREATE2: error = priv_check(td, PRIV_NET_IFCREATE); - if (error) - return (error); - return (if_clone_create(ifr->ifr_name, sizeof(ifr->ifr_name), - cmd == SIOCIFCREATE2 ? ifr->ifr_data : NULL)); + if (error == 0) + error = if_clone_create(ifr->ifr_name, + sizeof(ifr->ifr_name), + cmd == SIOCIFCREATE2 ? ifr->ifr_data : NULL); + CURVNET_RESTORE(); + return (error); case SIOCIFDESTROY: error = priv_check(td, PRIV_NET_IFDESTROY); - if (error) - return (error); - return if_clone_destroy(ifr->ifr_name); + if (error == 0) + error = if_clone_destroy(ifr->ifr_name); + CURVNET_RESTORE(); + return (error); case SIOCIFGCLONERS: - return (if_clone_list((struct if_clonereq *)data)); + error = if_clone_list((struct if_clonereq *)data); + CURVNET_RESTORE(); + return (error); case SIOCGIFGMEMB: - return (if_getgroupmembers((struct ifgroupreq *)data)); + error = if_getgroupmembers((struct ifgroupreq *)data); + CURVNET_RESTORE(); + return (error); } ifp = ifunit_ref(ifr->ifr_name); - if (ifp == NULL) + if (ifp == NULL) { + CURVNET_RESTORE(); return (ENXIO); + } error = ifhwioctl(cmd, ifp, data, td); if (error != ENOIOCTL) { if_rele(ifp); + CURVNET_RESTORE(); return (error); } oif_flags = ifp->if_flags; if (so->so_proto == NULL) { if_rele(ifp); + CURVNET_RESTORE(); return (EOPNOTSUPP); } #ifndef COMPAT_43 @@ -2559,6 +2593,7 @@ ifioctl(struct socket *so, u_long cmd, caddr_t data, struct thread *td) #endif } if_rele(ifp); + CURVNET_RESTORE(); return (error); } |