From owner-svn-src-all@FreeBSD.ORG Thu Jan 12 18:39:37 2012 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6ED63106566B; Thu, 12 Jan 2012 18:39:37 +0000 (UTC) (envelope-from rwatson@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 528E58FC08; Thu, 12 Jan 2012 18:39:37 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q0CIdb3B021716; Thu, 12 Jan 2012 18:39:37 GMT (envelope-from rwatson@svn.freebsd.org) Received: (from rwatson@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q0CIdbID021713; Thu, 12 Jan 2012 18:39:37 GMT (envelope-from rwatson@svn.freebsd.org) Message-Id: <201201121839.q0CIdbID021713@svn.freebsd.org> From: Robert Watson Date: Thu, 12 Jan 2012 18:39:37 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r230026 - head/sys/net X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jan 2012 18:39:37 -0000 Author: rwatson Date: Thu Jan 12 18:39:37 2012 New Revision: 230026 URL: http://svn.freebsd.org/changeset/base/230026 Log: Clarify throughout the vlan(4) code the difference between a "tag" (the 802.1q-defined 16-bit VID, CFI, and PCP field in host by order) and a VLAN ID (VID). Tags go in packets. VIDs identify VLANs. No functional change is intended, so this should be safe to MFC. Further cleanup with functional changes will be committed separately (for example, renaming vlan_tag/vlan_tag_p, which modify the KPI and KBI). Reviewed by: bz Sponsored by: ADARA Networks, Inc. MFC after: 3 days Modified: head/sys/net/if_vlan.c head/sys/net/if_vlan_var.h Modified: head/sys/net/if_vlan.c ============================================================================== --- head/sys/net/if_vlan.c Thu Jan 12 17:55:22 2012 (r230025) +++ head/sys/net/if_vlan.c Thu Jan 12 18:39:37 2012 (r230026) @@ -114,7 +114,7 @@ struct ifvlan { #endif }; #define ifv_proto ifv_mib.ifvm_proto -#define ifv_tag ifv_mib.ifvm_tag +#define ifv_vid ifv_mib.ifvm_tag #define ifv_encaplen ifv_mib.ifvm_encaplen #define ifv_mtufudge ifv_mib.ifvm_mtufudge #define ifv_mintu ifv_mib.ifvm_mintu @@ -178,7 +178,7 @@ static int vlan_inshash(struct ifvlantru static int vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv); static void vlan_growhash(struct ifvlantrunk *trunk, int howmuch); static __inline struct ifvlan * vlan_gethash(struct ifvlantrunk *trunk, - uint16_t tag); + uint16_t vid); #endif static void trunk_destroy(struct ifvlantrunk *trunk); @@ -198,7 +198,7 @@ static void vlan_link_state(struct ifnet static void vlan_capabilities(struct ifvlan *ifv); static void vlan_trunk_capabilities(struct ifnet *ifp); -static struct ifnet *vlan_clone_match_ethertag(struct if_clone *, +static struct ifnet *vlan_clone_match_ethervid(struct if_clone *, const char *, int *); static int vlan_clone_match(struct if_clone *, const char *); static int vlan_clone_create(struct if_clone *, char *, size_t, caddr_t); @@ -266,9 +266,9 @@ vlan_inshash(struct ifvlantrunk *trunk, KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__)); b = 1 << trunk->hwidth; - i = HASH(ifv->ifv_tag, trunk->hmask); + i = HASH(ifv->ifv_vid, trunk->hmask); LIST_FOREACH(ifv2, &trunk->hash[i], ifv_list) - if (ifv->ifv_tag == ifv2->ifv_tag) + if (ifv->ifv_vid == ifv2->ifv_vid) return (EEXIST); /* @@ -278,7 +278,7 @@ vlan_inshash(struct ifvlantrunk *trunk, */ if (trunk->refcnt > (b * b) / 2) { vlan_growhash(trunk, 1); - i = HASH(ifv->ifv_tag, trunk->hmask); + i = HASH(ifv->ifv_vid, trunk->hmask); } LIST_INSERT_HEAD(&trunk->hash[i], ifv, ifv_list); trunk->refcnt++; @@ -296,7 +296,7 @@ vlan_remhash(struct ifvlantrunk *trunk, KASSERT(trunk->hwidth > 0, ("%s: hwidth not positive", __func__)); b = 1 << trunk->hwidth; - i = HASH(ifv->ifv_tag, trunk->hmask); + i = HASH(ifv->ifv_vid, trunk->hmask); LIST_FOREACH(ifv2, &trunk->hash[i], ifv_list) if (ifv2 == ifv) { trunk->refcnt--; @@ -348,7 +348,7 @@ vlan_growhash(struct ifvlantrunk *trunk, for (i = 0; i < n; i++) while ((ifv = LIST_FIRST(&trunk->hash[i])) != NULL) { LIST_REMOVE(ifv, ifv_list); - j = HASH(ifv->ifv_tag, n2 - 1); + j = HASH(ifv->ifv_vid, n2 - 1); LIST_INSERT_HEAD(&hash2[j], ifv, ifv_list); } free(trunk->hash, M_VLAN); @@ -362,14 +362,14 @@ vlan_growhash(struct ifvlantrunk *trunk, } static __inline struct ifvlan * -vlan_gethash(struct ifvlantrunk *trunk, uint16_t tag) +vlan_gethash(struct ifvlantrunk *trunk, uint16_t vid) { struct ifvlan *ifv; TRUNK_LOCK_RASSERT(trunk); - LIST_FOREACH(ifv, &trunk->hash[HASH(tag, trunk->hmask)], ifv_list) - if (ifv->ifv_tag == tag) + LIST_FOREACH(ifv, &trunk->hash[HASH(vid, trunk->hmask)], ifv_list) + if (ifv->ifv_vid == vid) return (ifv); return (NULL); } @@ -393,19 +393,19 @@ vlan_dumphash(struct ifvlantrunk *trunk) #else static __inline struct ifvlan * -vlan_gethash(struct ifvlantrunk *trunk, uint16_t tag) +vlan_gethash(struct ifvlantrunk *trunk, uint16_t vid) { - return trunk->vlans[tag]; + return trunk->vlans[vid]; } static __inline int vlan_inshash(struct ifvlantrunk *trunk, struct ifvlan *ifv) { - if (trunk->vlans[ifv->ifv_tag] != NULL) + if (trunk->vlans[ifv->ifv_vid] != NULL) return EEXIST; - trunk->vlans[ifv->ifv_tag] = ifv; + trunk->vlans[ifv->ifv_vid] = ifv; trunk->refcnt++; return (0); @@ -415,7 +415,7 @@ static __inline int vlan_remhash(struct ifvlantrunk *trunk, struct ifvlan *ifv) { - trunk->vlans[ifv->ifv_tag] = NULL; + trunk->vlans[ifv->ifv_vid] = NULL; trunk->refcnt--; return (0); @@ -617,17 +617,21 @@ vlan_trunkdev(struct ifnet *ifp) } /* - * Return the 16bit vlan tag for this interface. + * Return the 12-bit VLAN VID for this interface, for use by external + * components such as Infiniband. + * + * XXXRW: Note that the function name here is historical; it should be named + * vlan_vid(). */ static int -vlan_tag(struct ifnet *ifp, uint16_t *tagp) +vlan_tag(struct ifnet *ifp, uint16_t *vidp) { struct ifvlan *ifv; if (ifp->if_type != IFT_L2VLAN) return (EINVAL); ifv = ifp->if_softc; - *tagp = ifv->ifv_tag; + *vidp = ifv->ifv_vid; return (0); } @@ -663,10 +667,10 @@ vlan_setcookie(struct ifnet *ifp, void * } /* - * Return the vlan device present at the specific tag. + * Return the vlan device present at the specific VID. */ static struct ifnet * -vlan_devat(struct ifnet *ifp, uint16_t tag) +vlan_devat(struct ifnet *ifp, uint16_t vid) { struct ifvlantrunk *trunk; struct ifvlan *ifv; @@ -676,7 +680,7 @@ vlan_devat(struct ifnet *ifp, uint16_t t return (NULL); ifp = NULL; TRUNK_RLOCK(trunk); - ifv = vlan_gethash(trunk, tag); + ifv = vlan_gethash(trunk, vid); if (ifv) ifp = ifv->ifv_ifp; TRUNK_RUNLOCK(trunk); @@ -786,11 +790,11 @@ VNET_SYSUNINIT(vnet_vlan_uninit, SI_SUB_ #endif static struct ifnet * -vlan_clone_match_ethertag(struct if_clone *ifc, const char *name, int *tag) +vlan_clone_match_ethervid(struct if_clone *ifc, const char *name, int *vidp) { const char *cp; struct ifnet *ifp; - int t; + int vid; /* Check for . style interface names. */ IFNET_RLOCK_NOSLEEP(); @@ -809,13 +813,13 @@ vlan_clone_match_ethertag(struct if_clon continue; if (*cp == '\0') continue; - t = 0; + vid = 0; for(; *cp >= '0' && *cp <= '9'; cp++) - t = (t * 10) + (*cp - '0'); + vid = (vid * 10) + (*cp - '0'); if (*cp != '\0') continue; - if (tag != NULL) - *tag = t; + if (vidp != NULL) + *vidp = vid; break; } IFNET_RUNLOCK_NOSLEEP(); @@ -828,7 +832,7 @@ vlan_clone_match(struct if_clone *ifc, c { const char *cp; - if (vlan_clone_match_ethertag(ifc, name, NULL) != NULL) + if (vlan_clone_match_ethervid(ifc, name, NULL) != NULL) return (1); if (strncmp(VLANNAME, name, strlen(VLANNAME)) != 0) @@ -848,7 +852,7 @@ vlan_clone_create(struct if_clone *ifc, int wildcard; int unit; int error; - int tag; + int vid; int ethertag; struct ifvlan *ifv; struct ifnet *ifp; @@ -866,6 +870,9 @@ vlan_clone_create(struct if_clone *ifc, * must be configured separately. * The first technique is preferred; the latter two are * supported for backwards compatibilty. + * + * XXXRW: Note historic use of the word "tag" here. New ioctls may be + * called for. */ if (params) { error = copyin(params, &vlr, sizeof(vlr)); @@ -875,7 +882,7 @@ vlan_clone_create(struct if_clone *ifc, if (p == NULL) return ENXIO; /* - * Don't let the caller set up a VLAN tag with + * Don't let the caller set up a VLAN VID with * anything except VLID bits. */ if (vlr.vlr_tag & ~EVL_VLID_MASK) @@ -885,18 +892,18 @@ vlan_clone_create(struct if_clone *ifc, return (error); ethertag = 1; - tag = vlr.vlr_tag; + vid = vlr.vlr_tag; wildcard = (unit < 0); - } else if ((p = vlan_clone_match_ethertag(ifc, name, &tag)) != NULL) { + } else if ((p = vlan_clone_match_ethervid(ifc, name, &vid)) != NULL) { ethertag = 1; unit = -1; wildcard = 0; /* - * Don't let the caller set up a VLAN tag with + * Don't let the caller set up a VLAN VID with * anything except VLID bits. */ - if (tag & ~EVL_VLID_MASK) + if (vid & ~EVL_VLID_MASK) return (EINVAL); } else { ethertag = 0; @@ -958,7 +965,7 @@ vlan_clone_create(struct if_clone *ifc, sdl->sdl_type = IFT_L2VLAN; if (ethertag) { - error = vlan_config(ifv, p, tag); + error = vlan_config(ifv, p, vid); if (error != 0) { /* * Since we've partialy failed, we need to back @@ -1068,10 +1075,10 @@ vlan_transmit(struct ifnet *ifp, struct * packet tag that holds it. */ if (p->if_capenable & IFCAP_VLAN_HWTAGGING) { - m->m_pkthdr.ether_vtag = ifv->ifv_tag; + m->m_pkthdr.ether_vtag = ifv->ifv_vid; m->m_flags |= M_VLANTAG; } else { - m = ether_vlanencap(m, ifv->ifv_tag); + m = ether_vlanencap(m, ifv->ifv_vid); if (m == NULL) { if_printf(ifp, "unable to prepend VLAN header\n"); ifp->if_oerrors++; @@ -1105,7 +1112,7 @@ vlan_input(struct ifnet *ifp, struct mbu { struct ifvlantrunk *trunk = ifp->if_vlantrunk; struct ifvlan *ifv; - uint16_t tag; + uint16_t vid; KASSERT(trunk != NULL, ("%s: no trunk", __func__)); @@ -1114,7 +1121,7 @@ vlan_input(struct ifnet *ifp, struct mbu * Packet is tagged, but m contains a normal * Ethernet frame; the tag is stored out-of-band. */ - tag = EVL_VLANOFTAG(m->m_pkthdr.ether_vtag); + vid = EVL_VLANOFTAG(m->m_pkthdr.ether_vtag); m->m_flags &= ~M_VLANTAG; } else { struct ether_vlan_header *evl; @@ -1130,7 +1137,7 @@ vlan_input(struct ifnet *ifp, struct mbu return; } evl = mtod(m, struct ether_vlan_header *); - tag = EVL_VLANOFTAG(ntohs(evl->evl_tag)); + vid = EVL_VLANOFTAG(ntohs(evl->evl_tag)); /* * Remove the 802.1q header by copying the Ethernet @@ -1155,7 +1162,7 @@ vlan_input(struct ifnet *ifp, struct mbu } TRUNK_RLOCK(trunk); - ifv = vlan_gethash(trunk, tag); + ifv = vlan_gethash(trunk, vid); if (ifv == NULL || !UP_AND_RUNNING(ifv->ifv_ifp)) { TRUNK_RUNLOCK(trunk); m_freem(m); @@ -1172,14 +1179,14 @@ vlan_input(struct ifnet *ifp, struct mbu } static int -vlan_config(struct ifvlan *ifv, struct ifnet *p, uint16_t tag) +vlan_config(struct ifvlan *ifv, struct ifnet *p, uint16_t vid) { struct ifvlantrunk *trunk; struct ifnet *ifp; int error = 0; /* VID numbers 0x0 and 0xFFF are reserved */ - if (tag == 0 || tag == 0xFFF) + if (vid == 0 || vid == 0xFFF) return (EINVAL); if (p->if_type != IFT_ETHER && (p->if_capenable & IFCAP_VLAN_HWTAGGING) == 0) @@ -1211,7 +1218,7 @@ exists: TRUNK_LOCK(trunk); } - ifv->ifv_tag = tag; /* must set this before vlan_inshash() */ + ifv->ifv_vid = vid; /* must set this before vlan_inshash() */ error = vlan_inshash(trunk, ifv); if (error) goto done; @@ -1289,7 +1296,7 @@ exists: done: TRUNK_UNLOCK(trunk); if (error == 0) - EVENTHANDLER_INVOKE(vlan_config, p, ifv->ifv_tag); + EVENTHANDLER_INVOKE(vlan_config, p, ifv->ifv_vid); VLAN_UNLOCK(); return (error); @@ -1377,7 +1384,7 @@ vlan_unconfig_locked(struct ifnet *ifp) * to cleanup anyway. */ if (parent != NULL) - EVENTHANDLER_INVOKE(vlan_unconfig, parent, ifv->ifv_tag); + EVENTHANDLER_INVOKE(vlan_unconfig, parent, ifv->ifv_vid); } /* Handle a reference counted flag that should be set on the parent as well */ @@ -1622,7 +1629,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd break; } /* - * Don't let the caller set up a VLAN tag with + * Don't let the caller set up a VLAN VID with * anything except VLID bits. */ if (vlr.vlr_tag & ~EVL_VLID_MASK) { @@ -1649,7 +1656,7 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd if (TRUNK(ifv) != NULL) { strlcpy(vlr.vlr_parent, PARENT(ifv)->if_xname, sizeof(vlr.vlr_parent)); - vlr.vlr_tag = ifv->ifv_tag; + vlr.vlr_tag = ifv->ifv_vid; } VLAN_UNLOCK(); error = copyout(&vlr, ifr->ifr_data, sizeof(vlr)); Modified: head/sys/net/if_vlan_var.h ============================================================================== --- head/sys/net/if_vlan_var.h Thu Jan 12 17:55:22 2012 (r230025) +++ head/sys/net/if_vlan_var.h Thu Jan 12 18:39:37 2012 (r230026) @@ -108,7 +108,7 @@ struct vlanreq { * received VLAN tag (containing both vlan and priority information) * into the ether_vtag mbuf packet header field: * - * m->m_pkthdr.ether_vtag = vlan_id; // ntohs()? + * m->m_pkthdr.ether_vtag = vtag; // ntohs()? * m->m_flags |= M_VLANTAG; * * to mark the packet m with the specified VLAN tag. @@ -133,15 +133,15 @@ struct vlanreq { #define VLAN_TRUNKDEV(_ifp) \ (_ifp)->if_type == IFT_L2VLAN ? (*vlan_trunkdev_p)((_ifp)) : NULL -#define VLAN_TAG(_ifp, _tag) \ - (_ifp)->if_type == IFT_L2VLAN ? (*vlan_tag_p)((_ifp), (_tag)) : EINVAL +#define VLAN_TAG(_ifp, _vid) \ + (_ifp)->if_type == IFT_L2VLAN ? (*vlan_tag_p)((_ifp), (_vid)) : EINVAL #define VLAN_COOKIE(_ifp) \ (_ifp)->if_type == IFT_L2VLAN ? (*vlan_cookie_p)((_ifp)) : NULL #define VLAN_SETCOOKIE(_ifp, _cookie) \ (_ifp)->if_type == IFT_L2VLAN ? \ (*vlan_setcookie_p)((_ifp), (_cookie)) : EINVAL -#define VLAN_DEVAT(_ifp, _tag) \ - (_ifp)->if_vlantrunk != NULL ? (*vlan_devat_p)((_ifp), (_tag)) : NULL +#define VLAN_DEVAT(_ifp, _vid) \ + (_ifp)->if_vlantrunk != NULL ? (*vlan_devat_p)((_ifp), (_vid)) : NULL extern void (*vlan_trunk_cap_p)(struct ifnet *); extern struct ifnet *(*vlan_trunkdev_p)(struct ifnet *);