Date: Fri, 14 Nov 2008 07:08:39 GMT From: Qing Li <qingli@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 152965 for review Message-ID: <200811140708.mAE78d1I085611@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=152965 Change 152965 by qingli@FreeBSD-newarp on 2008/11/14 07:08:22 IFC - changelist# 152951 Affected files ... .. //depot/projects/arp-v2/src/sys/net/if.c#6 integrate Differences ... ==== //depot/projects/arp-v2/src/sys/net/if.c#6 (text+ko) ==== @@ -27,7 +27,7 @@ * SUCH DAMAGE. * * @(#)if.c 8.5 (Berkeley) 1/9/95 - * $FreeBSD: src/sys/net/if.c,v 1.281 2008/06/26 23:05:28 rwatson Exp $ + * $FreeBSD: src/sys/net/if.c,v 1.290 2008/11/06 15:26:09 bz Exp $ */ #include "opt_compat.h" @@ -56,10 +56,12 @@ #include <sys/taskqueue.h> #include <sys/domain.h> #include <sys/jail.h> +#include <sys/vimage.h> #include <machine/stdarg.h> #include <vm/uma.h> #include <net/if.h> +#include <net/if_arp.h> #include <net/if_clone.h> #include <net/if_dl.h> #include <net/if_types.h> @@ -172,10 +174,11 @@ struct ifnet * ifnet_byindex(u_short idx) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; IFNET_RLOCK(); - ifp = ifindex_table[idx].ife_ifnet; + ifp = V_ifindex_table[idx].ife_ifnet; IFNET_RUNLOCK(); return (ifp); } @@ -183,15 +186,17 @@ static void ifnet_setbyindex(u_short idx, struct ifnet *ifp) { + INIT_VNET_NET(curvnet); IFNET_WLOCK_ASSERT(); - ifindex_table[idx].ife_ifnet = ifp; + V_ifindex_table[idx].ife_ifnet = ifp; } struct ifaddr * ifaddr_byindex(u_short idx) { + INIT_VNET_NET(curvnet); struct ifaddr *ifa; IFNET_RLOCK(); @@ -203,10 +208,11 @@ struct cdev * ifdev_byindex(u_short idx) { + INIT_VNET_NET(curvnet); struct cdev *cdev; IFNET_RLOCK(); - cdev = ifindex_table[idx].ife_dev; + cdev = V_ifindex_table[idx].ife_dev; IFNET_RUNLOCK(); return (cdev); } @@ -214,9 +220,10 @@ static void ifdev_setbyindex(u_short idx, struct cdev *cdev) { + INIT_VNET_NET(curvnet); IFNET_WLOCK(); - ifindex_table[idx].ife_dev = cdev; + V_ifindex_table[idx].ife_dev = cdev; IFNET_WUNLOCK(); } @@ -256,7 +263,7 @@ /* only support interface specific ioctls */ if (IOCGROUP(cmd) != 'i') return (EOPNOTSUPP); - idx = minor(dev); + idx = dev2unit(dev); if (idx == 0) { /* * special network device, not interface. @@ -283,6 +290,7 @@ static int netkqfilter(struct cdev *dev, struct knote *kn) { + INIT_VNET_NET(curvnet); struct knlist *klist; struct ifnet *ifp; int idx; @@ -295,9 +303,9 @@ return (EINVAL); } - idx = minor(dev); + idx = dev2unit(dev); if (idx == 0) { - klist = &ifklist; + klist = &V_ifklist; } else { ifp = ifnet_byindex(idx); if (ifp == NULL) @@ -352,10 +360,12 @@ static void if_init(void *dummy __unused) { + INIT_VNET_NET(curvnet); + IFNET_LOCK_INIT(); - TAILQ_INIT(&ifnet); - TAILQ_INIT(&ifg_head); - knlist_init(&ifklist, NULL, NULL, NULL, NULL); + TAILQ_INIT(&V_ifnet); + TAILQ_INIT(&V_ifg_head); + knlist_init(&V_ifklist, NULL, NULL, NULL, NULL); if_grow(); /* create initial table */ ifdev_setbyindex(0, make_dev(&net_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "network")); @@ -372,17 +382,18 @@ static void if_grow(void) { + INIT_VNET_NET(curvnet); u_int n; struct ifindex_entry *e; - if_indexlim <<= 1; - n = if_indexlim * sizeof(*e); + V_if_indexlim <<= 1; + n = V_if_indexlim * sizeof(*e); e = malloc(n, M_IFNET, M_WAITOK | M_ZERO); - if (ifindex_table != NULL) { - memcpy((caddr_t)e, (caddr_t)ifindex_table, n/2); - free((caddr_t)ifindex_table, M_IFNET); + if (V_ifindex_table != NULL) { + memcpy((caddr_t)e, (caddr_t)V_ifindex_table, n/2); + free((caddr_t)V_ifindex_table, M_IFNET); } - ifindex_table = e; + V_ifindex_table = e; } /* @@ -393,6 +404,7 @@ struct ifnet* if_alloc(u_char type) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; ifp = malloc(sizeof(struct ifnet), M_IFNET, M_WAITOK|M_ZERO); @@ -403,7 +415,7 @@ * * XXX: should be locked! */ - for (ifp->if_index = 1; ifp->if_index <= if_index; ifp->if_index++) { + for (ifp->if_index = 1; ifp->if_index <= V_if_index; ifp->if_index++) { if (ifnet_byindex(ifp->if_index) == NULL) break; } @@ -412,9 +424,9 @@ free(ifp, M_IFNET); return (NULL); } - if (ifp->if_index > if_index) - if_index = ifp->if_index; - if (if_index >= if_indexlim) + if (ifp->if_index > V_if_index) + V_if_index = ifp->if_index; + if (V_if_index >= V_if_indexlim) if_grow(); ifp->if_type = type; @@ -455,6 +467,7 @@ void if_free_type(struct ifnet *ifp, u_char type) { + INIT_VNET_NET(curvnet); /* ifp->if_vnet can be NULL here ! */ if (ifp != ifnet_byindex(ifp->if_index)) { if_printf(ifp, "%s: value was not if_alloced, skipping\n", @@ -466,8 +479,8 @@ ifnet_setbyindex(ifp->if_index, NULL); /* XXX: should be locked with if_findindex() */ - while (if_index > 0 && ifnet_byindex(if_index) == NULL) - if_index--; + while (V_if_index > 0 && ifnet_byindex(V_if_index) == NULL) + V_if_index--; IFNET_WUNLOCK(); if (if_com_free[type] != NULL) @@ -492,6 +505,7 @@ void if_attach(struct ifnet *ifp) { + INIT_VNET_NET(curvnet); unsigned socksize, ifasize; int namelen, masklen; struct sockaddr_dl *sdl; @@ -526,7 +540,7 @@ #endif ifdev_setbyindex(ifp->if_index, make_dev(&net_cdevsw, - unit2minor(ifp->if_index), UID_ROOT, GID_WHEEL, 0600, "%s/%s", + ifp->if_index, UID_ROOT, GID_WHEEL, 0600, "%s/%s", net_cdevsw.d_name, ifp->if_xname)); make_dev_alias(ifdev_byindex(ifp->if_index), "%s%d", net_cdevsw.d_name, ifp->if_index); @@ -584,7 +598,7 @@ ifp->if_snd.altq_ifp = ifp; IFNET_WLOCK(); - TAILQ_INSERT_TAIL(&ifnet, ifp, if_link); + TAILQ_INSERT_TAIL(&V_ifnet, ifp, if_link); IFNET_WUNLOCK(); if (domain_init_status >= 2) @@ -607,11 +621,12 @@ static void if_attachdomain(void *dummy) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; int s; s = splnet(); - TAILQ_FOREACH(ifp, &ifnet, if_link) + TAILQ_FOREACH(ifp, &V_ifnet, if_link) if_attachdomain1(ifp); splx(s); } @@ -717,6 +732,7 @@ void if_detach(struct ifnet *ifp) { + INIT_VNET_NET(ifp->if_vnet); struct ifaddr *ifa; struct radix_node_head *rnh; int s; @@ -726,9 +742,9 @@ int found = 0; IFNET_WLOCK(); - TAILQ_FOREACH(iter, &ifnet, if_link) + TAILQ_FOREACH(iter, &V_ifnet, if_link) if (iter == ifp) { - TAILQ_REMOVE(&ifnet, ifp, if_link); + TAILQ_REMOVE(&V_ifnet, ifp, if_link); found = 1; break; } @@ -794,7 +810,7 @@ for (i = 1; i <= AF_MAX; i++) { int j; for (j = 0; j < rt_numfibs; j++) { - if ((rnh = rt_tables[j][i]) == NULL) + if ((rnh = V_rt_tables[j][i]) == NULL) continue; RADIX_NODE_HEAD_LOCK(rnh); (void) rnh->rnh_walktree(rnh, if_rtdel, ifp); @@ -832,6 +848,7 @@ int if_addgroup(struct ifnet *ifp, const char *groupname) { + INIT_VNET_NET(ifp->if_vnet); struct ifg_list *ifgl; struct ifg_group *ifg = NULL; struct ifg_member *ifgm; @@ -860,7 +877,7 @@ return (ENOMEM); } - TAILQ_FOREACH(ifg, &ifg_head, ifg_next) + TAILQ_FOREACH(ifg, &V_ifg_head, ifg_next) if (!strcmp(ifg->ifg_group, groupname)) break; @@ -876,7 +893,7 @@ ifg->ifg_refcnt = 0; TAILQ_INIT(&ifg->ifg_members); EVENTHANDLER_INVOKE(group_attach_event, ifg); - TAILQ_INSERT_TAIL(&ifg_head, ifg, ifg_next); + TAILQ_INSERT_TAIL(&V_ifg_head, ifg, ifg_next); } ifg->ifg_refcnt++; @@ -901,6 +918,7 @@ int if_delgroup(struct ifnet *ifp, const char *groupname) { + INIT_VNET_NET(ifp->if_vnet); struct ifg_list *ifgl; struct ifg_member *ifgm; @@ -927,7 +945,7 @@ } if (--ifgl->ifgl_group->ifg_refcnt == 0) { - TAILQ_REMOVE(&ifg_head, ifgl->ifgl_group, ifg_next); + TAILQ_REMOVE(&V_ifg_head, ifgl->ifgl_group, ifg_next); EVENTHANDLER_INVOKE(group_detach_event, ifgl->ifgl_group); free(ifgl->ifgl_group, M_TEMP); } @@ -990,6 +1008,7 @@ static int if_getgroupmembers(struct ifgroupreq *data) { + INIT_VNET_NET(curvnet); struct ifgroupreq *ifgr = data; struct ifg_group *ifg; struct ifg_member *ifgm; @@ -997,7 +1016,7 @@ int len, error; IFNET_RLOCK(); - TAILQ_FOREACH(ifg, &ifg_head, ifg_next) + TAILQ_FOREACH(ifg, &V_ifg_head, ifg_next) if (!strcmp(ifg->ifg_group, ifgr->ifgr_name)) break; if (ifg == NULL) { @@ -1099,11 +1118,12 @@ struct ifaddr * ifa_ifwithaddr(struct sockaddr *addr) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; struct ifaddr *ifa; IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &ifnet, if_link) + TAILQ_FOREACH(ifp, &V_ifnet, if_link) TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != addr->sa_family) continue; @@ -1129,11 +1149,12 @@ struct ifaddr * ifa_ifwithbroadaddr(struct sockaddr *addr) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; struct ifaddr *ifa; IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &ifnet, if_link) + TAILQ_FOREACH(ifp, &V_ifnet, if_link) TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != addr->sa_family) continue; @@ -1156,17 +1177,18 @@ struct ifaddr * ifa_ifwithdstaddr(struct sockaddr *addr) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; struct ifaddr *ifa; IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &ifnet, if_link) { + TAILQ_FOREACH(ifp, &V_ifnet, if_link) { if ((ifp->if_flags & IFF_POINTOPOINT) == 0) continue; TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { if (ifa->ifa_addr->sa_family != addr->sa_family) continue; - if (ifa->ifa_dstaddr && + if (ifa->ifa_dstaddr != NULL && sa_equal(addr, ifa->ifa_dstaddr)) goto done; } @@ -1184,6 +1206,7 @@ struct ifaddr * ifa_ifwithnet(struct sockaddr *addr) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; struct ifaddr *ifa; struct ifaddr *ifa_maybe = (struct ifaddr *) 0; @@ -1196,7 +1219,7 @@ */ if (af == AF_LINK) { struct sockaddr_dl *sdl = (struct sockaddr_dl *)addr; - if (sdl->sdl_index && sdl->sdl_index <= if_index) + if (sdl->sdl_index && sdl->sdl_index <= V_if_index) return (ifaddr_byindex(sdl->sdl_index)); } @@ -1205,7 +1228,7 @@ * addresses in this address family. */ IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &ifnet, if_link) { + TAILQ_FOREACH(ifp, &V_ifnet, if_link) { TAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { char *cp, *cp2, *cp3; @@ -1220,7 +1243,7 @@ * The trouble is that we don't know the * netmask for the remote end. */ - if (ifa->ifa_dstaddr != 0 && + if (ifa->ifa_dstaddr != NULL && sa_equal(addr, ifa->ifa_dstaddr)) goto done; } else { @@ -1427,6 +1450,7 @@ struct ifnet *ifp = (struct ifnet *)arg; int link_state = ifp->if_link_state; int link; + CURVNET_SET(ifp->if_vnet); /* Notify that the link state has changed. */ rt_ifmsg(ifp); @@ -1463,6 +1487,7 @@ if (log_link_state_change) log(LOG_NOTICE, "%s: link state changed to %s\n", ifp->if_xname, (link_state == LINK_STATE_UP) ? "UP" : "DOWN" ); + CURVNET_RESTORE(); } /* @@ -1525,16 +1550,24 @@ static void if_slowtimo(void *arg) { + VNET_ITERATOR_DECL(vnet_iter); struct ifnet *ifp; int s = splimp(); IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &ifnet, if_link) { - if (ifp->if_timer == 0 || --ifp->if_timer) - continue; - if (ifp->if_watchdog) - (*ifp->if_watchdog)(ifp); + VNET_LIST_RLOCK(); + VNET_FOREACH(vnet_iter) { + CURVNET_SET(vnet_iter); + INIT_VNET_NET(vnet_iter); + TAILQ_FOREACH(ifp, &V_ifnet, if_link) { + if (ifp->if_timer == 0 || --ifp->if_timer) + continue; + if (ifp->if_watchdog) + (*ifp->if_watchdog)(ifp); + } + CURVNET_RESTORE(); } + VNET_LIST_RUNLOCK(); IFNET_RUNLOCK(); splx(s); timeout(if_slowtimo, (void *)0, hz / IFNET_SLOWHZ); @@ -1547,10 +1580,11 @@ struct ifnet * ifunit(const char *name) { + INIT_VNET_NET(curvnet); struct ifnet *ifp; IFNET_RLOCK(); - TAILQ_FOREACH(ifp, &ifnet, if_link) { + TAILQ_FOREACH(ifp, &V_ifnet, if_link) { if (strncmp(name, ifp->if_xname, IFNAMSIZ) == 0) break; } @@ -2119,6 +2153,7 @@ static int ifconf(u_long cmd, caddr_t data) { + INIT_VNET_NET(curvnet); struct ifconf *ifc = (struct ifconf *)data; #ifdef __amd64__ struct ifconf32 *ifc32 = (struct ifconf32 *)data; @@ -2154,7 +2189,7 @@ valid_len = 0; IFNET_RLOCK(); /* could sleep XXX */ - TAILQ_FOREACH(ifp, &ifnet, if_link) { + TAILQ_FOREACH(ifp, &V_ifnet, if_link) { int addrs; /* @@ -2279,14 +2314,14 @@ struct ifmultiaddr *ifma; struct sockaddr *dupsa; - MALLOC(ifma, struct ifmultiaddr *, sizeof *ifma, M_IFMADDR, mflags | + ifma = malloc(sizeof *ifma, M_IFMADDR, mflags | M_ZERO); if (ifma == NULL) return (NULL); - MALLOC(dupsa, struct sockaddr *, sa->sa_len, M_IFMADDR, mflags); + dupsa = malloc(sa->sa_len, M_IFMADDR, mflags); if (dupsa == NULL) { - FREE(ifma, M_IFMADDR); + free(ifma, M_IFMADDR); return (NULL); } bcopy(sa, dupsa, sa->sa_len); @@ -2301,10 +2336,10 @@ return (ifma); } - MALLOC(dupsa, struct sockaddr *, llsa->sa_len, M_IFMADDR, mflags); + dupsa = malloc(llsa->sa_len, M_IFMADDR, mflags); if (dupsa == NULL) { - FREE(ifma->ifma_addr, M_IFMADDR); - FREE(ifma, M_IFMADDR); + free(ifma->ifma_addr, M_IFMADDR); + free(ifma, M_IFMADDR); return (NULL); } bcopy(llsa, dupsa, llsa->sa_len); @@ -2329,9 +2364,9 @@ ("if_freemulti: protospec not NULL")); if (ifma->ifma_lladdr != NULL) - FREE(ifma->ifma_lladdr, M_IFMADDR); - FREE(ifma->ifma_addr, M_IFMADDR); - FREE(ifma, M_IFMADDR); + free(ifma->ifma_lladdr, M_IFMADDR); + free(ifma->ifma_addr, M_IFMADDR); + free(ifma, M_IFMADDR); } /* @@ -2449,13 +2484,13 @@ } if (llsa != NULL) - FREE(llsa, M_IFMADDR); + free(llsa, M_IFMADDR); return (0); free_llsa_out: if (llsa != NULL) - FREE(llsa, M_IFMADDR); + free(llsa, M_IFMADDR); unlock_out: IF_ADDR_UNLOCK(ifp); @@ -2478,9 +2513,10 @@ int lastref; #ifdef INVARIANTS struct ifnet *oifp; + INIT_VNET_NET(ifp->if_vnet); IFNET_RLOCK(); - TAILQ_FOREACH(oifp, &ifnet, if_link) + TAILQ_FOREACH(oifp, &V_ifnet, if_link) if (ifp == oifp) break; if (ifp != oifp) @@ -2522,6 +2558,9 @@ void if_delmulti_ifma(struct ifmultiaddr *ifma) { +#ifdef DIAGNOSTIC + INIT_VNET_NET(curvnet); +#endif struct ifnet *ifp; int lastref; @@ -2533,7 +2572,7 @@ struct ifnet *oifp; IFNET_RLOCK(); - TAILQ_FOREACH(oifp, &ifnet, if_link) + TAILQ_FOREACH(oifp, &V_ifnet, if_link) if (ifp == oifp) break; if (ifp != oifp) {
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200811140708.mAE78d1I085611>