summaryrefslogtreecommitdiffstats
path: root/sys/net/if_vlan.c
diff options
context:
space:
mode:
authorglebius <glebius@FreeBSD.org>2015-03-20 21:09:03 +0000
committerglebius <glebius@FreeBSD.org>2015-03-20 21:09:03 +0000
commitf824cda4b81367d7a0a4012bb6f2ae7c2c06b0ef (patch)
tree4e5364a45622aa1530214b00486ee2c0510785d0 /sys/net/if_vlan.c
parent2cfbd6999b4be007ca5f8d1dc66948ef7fd27fe0 (diff)
downloadFreeBSD-src-f824cda4b81367d7a0a4012bb6f2ae7c2c06b0ef.zip
FreeBSD-src-f824cda4b81367d7a0a4012bb6f2ae7c2c06b0ef.tar.gz
Make vlan_config() the signle point of validity checks.
Sponsored by: Nginx, Inc.
Diffstat (limited to 'sys/net/if_vlan.c')
-rw-r--r--sys/net/if_vlan.c45
1 files changed, 12 insertions, 33 deletions
diff --git a/sys/net/if_vlan.c b/sys/net/if_vlan.c
index 713f8ae..c9ff11b 100644
--- a/sys/net/if_vlan.c
+++ b/sys/net/if_vlan.c
@@ -817,14 +817,6 @@ vlan_clone_match_ethervid(const char *name, int *vidp)
*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, char *name, size_t len, caddr_t params)
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, char *name, size_t len, caddr_t params)
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 ifnet *p, uint16_t vid)
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, caddr_t data)
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;
OpenPOWER on IntegriCloud