Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 20 Mar 2015 21:09:04 +0000 (UTC)
From:      Gleb Smirnoff <glebius@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r280303 - head/sys/net
Message-ID:  <201503202109.t2KL941E058612@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: glebius
Date: Fri Mar 20 21:09:03 2015
New Revision: 280303
URL: https://svnweb.freebsd.org/changeset/base/280303

Log:
  Make vlan_config() the signle point of validity checks.
  
  Sponsored by:	Nginx, Inc.

Modified:
  head/sys/net/if_vlan.c

Modified: head/sys/net/if_vlan.c
==============================================================================
--- head/sys/net/if_vlan.c	Fri Mar 20 20:42:58 2015	(r280302)
+++ head/sys/net/if_vlan.c	Fri Mar 20 21:09:03 2015	(r280303)
@@ -817,14 +817,6 @@ vlan_clone_match_ethervid(const char *na
 	*cp = '\0';
 	if ((ifp = ifunit(ifname)) == NULL)
 		return (NULL);
-	/*
-	 * We can handle non-ethernet hardware types as long as
-	 * they handle the tagging and headers themselves.
-	 */
-	if (ifp->if_type != IFT_ETHER &&
-	    (ifp->if_capenable & IFCAP_VLAN_HWTAGGING) == 0)
-		return (NULL);
-
 	/* Parse VID. */
 	if (*++cp == '\0')
 		return (NULL);
@@ -892,13 +884,7 @@ vlan_clone_create(struct if_clone *ifc, 
 			return error;
 		p = ifunit(vlr.vlr_parent);
 		if (p == NULL)
-			return ENXIO;
-		/*
-		 * Don't let the caller set up a VLAN VID with
-		 * anything except VLID bits.
-		 */
-		if (vlr.vlr_tag & ~EVL_VLID_MASK)
-			return (EINVAL);
+			return (ENXIO);
 		error = ifc_name2unit(name, &unit);
 		if (error != 0)
 			return (error);
@@ -910,13 +896,6 @@ vlan_clone_create(struct if_clone *ifc, 
 		ethertag = 1;
 		unit = -1;
 		wildcard = 0;
-
-		/*
-		 * Don't let the caller set up a VLAN VID with
-		 * anything except VLID bits.
-		 */
-		if (vid & ~EVL_VLID_MASK)
-			return (EINVAL);
 	} else {
 		ethertag = 0;
 
@@ -1198,14 +1177,22 @@ vlan_config(struct ifvlan *ifv, struct i
 	struct ifnet *ifp;
 	int error = 0;
 
-	/* VID numbers 0x0 and 0xFFF are reserved */
-	if (vid == 0 || vid == 0xFFF)
-		return (EINVAL);
+	/*
+	 * We can handle non-ethernet hardware types as long as
+	 * they handle the tagging and headers themselves.
+	 */
 	if (p->if_type != IFT_ETHER &&
 	    (p->if_capenable & IFCAP_VLAN_HWTAGGING) == 0)
 		return (EPROTONOSUPPORT);
 	if ((p->if_flags & VLAN_IFFLAGS) != VLAN_IFFLAGS)
 		return (EPROTONOSUPPORT);
+	/*
+	 * Don't let the caller set up a VLAN VID with
+	 * anything except VLID bits.
+	 * VID numbers 0x0 and 0xFFF are reserved.
+	 */
+	if (vid == 0 || vid == 0xFFF || (vid & ~EVL_VLID_MASK))
+		return (EINVAL);
 	if (ifv->ifv_trunk)
 		return (EBUSY);
 
@@ -1670,14 +1657,6 @@ vlan_ioctl(struct ifnet *ifp, u_long cmd
 			error = ENOENT;
 			break;
 		}
-		/*
-		 * Don't let the caller set up a VLAN VID with
-		 * anything except VLID bits.
-		 */
-		if (vlr.vlr_tag & ~EVL_VLID_MASK) {
-			error = EINVAL;
-			break;
-		}
 		error = vlan_config(ifv, p, vlr.vlr_tag);
 		if (error)
 			break;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503202109.t2KL941E058612>