2017-11-18 14:26:50 +00:00
|
|
|
/*-
|
|
|
|
* SPDX-License-Identifier: BSD-4-Clause
|
|
|
|
*
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
* Copyright (c) 1999 Bill Paul <wpaul@ctr.columbia.edu>
|
|
|
|
* Copyright (c) 2012 ADARA Networks, Inc.
|
|
|
|
* All rights reserved.
|
2023-09-23 20:27:49 +00:00
|
|
|
*
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
* Portions of this software were developed by Robert N. M. Watson under
|
|
|
|
* contract to ADARA Networks, Inc.
|
1999-03-15 01:22:01 +00:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Bill Paul.
|
|
|
|
* 4. Neither the name of the author nor the names of any co-contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL Bill Paul OR THE VOICES IN HIS HEAD
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
|
|
|
|
* THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/sockio.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <net/ethernet.h>
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_vlan_var.h>
|
|
|
|
#include <net/route.h>
|
|
|
|
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#include "ifconfig.h"
|
|
|
|
|
2006-07-09 06:10:23 +00:00
|
|
|
#define NOTAG ((u_short) -1)
|
2024-05-21 16:35:01 +00:00
|
|
|
#define NOPROTO ((u_short) -1)
|
2006-07-09 06:10:23 +00:00
|
|
|
|
2020-10-21 21:28:20 +00:00
|
|
|
static const char proto_8021Q[] = "802.1q";
|
|
|
|
static const char proto_8021ad[] = "802.1ad";
|
2021-01-19 23:22:07 +00:00
|
|
|
static const char proto_qinq[] = "qinq";
|
2020-10-21 21:28:20 +00:00
|
|
|
|
2006-07-09 06:10:23 +00:00
|
|
|
static struct vlanreq params = {
|
|
|
|
.vlr_tag = NOTAG,
|
2024-05-21 16:35:01 +00:00
|
|
|
.vlr_proto = NOPROTO,
|
2006-07-09 06:10:23 +00:00
|
|
|
};
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2023-05-23 17:02:12 +00:00
|
|
|
vlan_status(if_ctx *ctx)
|
1999-03-15 01:22:01 +00:00
|
|
|
{
|
2023-06-14 13:00:49 +00:00
|
|
|
struct vlanreq vreq = {};
|
|
|
|
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
|
1999-03-15 01:22:01 +00:00
|
|
|
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) == -1)
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
return;
|
|
|
|
printf("\tvlan: %d", vreq.vlr_tag);
|
2020-10-21 21:28:20 +00:00
|
|
|
printf(" vlanproto: ");
|
|
|
|
switch (vreq.vlr_proto) {
|
|
|
|
case ETHERTYPE_VLAN:
|
|
|
|
printf(proto_8021Q);
|
|
|
|
break;
|
|
|
|
case ETHERTYPE_QINQ:
|
|
|
|
printf(proto_8021ad);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
printf("0x%04x", vreq.vlr_proto);
|
|
|
|
}
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCGVLANPCP, &ifr) != -1)
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
printf(" vlanpcp: %u", ifr.ifr_vlan_pcp);
|
|
|
|
printf(" parent interface: %s", vreq.vlr_parent[0] == '\0' ?
|
|
|
|
"<none>" : vreq.vlr_parent);
|
|
|
|
printf("\n");
|
2006-07-09 06:10:23 +00:00
|
|
|
}
|
1999-03-15 01:22:01 +00:00
|
|
|
|
2020-10-21 21:28:20 +00:00
|
|
|
static int
|
|
|
|
vlan_match_ethervid(const char *name)
|
|
|
|
{
|
|
|
|
return (strchr(name, '.') != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
vlan_parse_ethervid(const char *name)
|
|
|
|
{
|
|
|
|
char ifname[IFNAMSIZ];
|
|
|
|
char *cp;
|
2023-04-02 17:54:31 +00:00
|
|
|
unsigned int vid;
|
2020-10-21 21:28:20 +00:00
|
|
|
|
|
|
|
strlcpy(ifname, name, IFNAMSIZ);
|
|
|
|
if ((cp = strrchr(ifname, '.')) == NULL)
|
|
|
|
return;
|
|
|
|
/*
|
|
|
|
* Derive params from interface name: "parent.vid".
|
|
|
|
*/
|
|
|
|
*cp++ = '\0';
|
|
|
|
if ((*cp < '1') || (*cp > '9'))
|
|
|
|
errx(1, "invalid vlan tag");
|
|
|
|
|
|
|
|
vid = *cp++ - '0';
|
2023-04-02 17:54:31 +00:00
|
|
|
while ((*cp >= '0') && (*cp <= '9')) {
|
2020-10-21 21:28:20 +00:00
|
|
|
vid = (vid * 10) + (*cp++ - '0');
|
2023-04-02 17:54:31 +00:00
|
|
|
if (vid >= 0xFFF)
|
|
|
|
errx(1, "invalid vlan tag");
|
|
|
|
}
|
|
|
|
if (*cp != '\0')
|
2020-10-21 21:28:20 +00:00
|
|
|
errx(1, "invalid vlan tag");
|
|
|
|
|
2022-01-17 09:30:26 +00:00
|
|
|
/*
|
|
|
|
* allow "devX.Y vlandev devX vlan Y" syntax
|
|
|
|
*/
|
|
|
|
if (params.vlr_tag == NOTAG || params.vlr_tag == vid)
|
|
|
|
params.vlr_tag = vid;
|
|
|
|
else
|
|
|
|
errx(1, "ambiguous vlan specification");
|
|
|
|
|
|
|
|
/* Restrict overriding interface name */
|
|
|
|
if (params.vlr_parent[0] == '\0' || !strcmp(params.vlr_parent, ifname))
|
|
|
|
strlcpy(params.vlr_parent, ifname, IFNAMSIZ);
|
|
|
|
else
|
|
|
|
errx(1, "ambiguous vlan specification");
|
2020-10-21 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2006-07-09 06:10:23 +00:00
|
|
|
static void
|
2023-06-13 06:10:41 +00:00
|
|
|
vlan_create(if_ctx *ctx, struct ifreq *ifr)
|
2006-07-09 06:10:23 +00:00
|
|
|
{
|
2020-10-21 21:28:20 +00:00
|
|
|
vlan_parse_ethervid(ifr->ifr_name);
|
|
|
|
|
2006-07-09 06:10:23 +00:00
|
|
|
if (params.vlr_tag != NOTAG || params.vlr_parent[0] != '\0') {
|
|
|
|
/*
|
|
|
|
* One or both parameters were specified, make sure both.
|
|
|
|
*/
|
|
|
|
if (params.vlr_tag == NOTAG)
|
|
|
|
errx(1, "must specify a tag for vlan create");
|
|
|
|
if (params.vlr_parent[0] == '\0')
|
|
|
|
errx(1, "must specify a parent device for vlan create");
|
2024-05-21 16:35:01 +00:00
|
|
|
if (params.vlr_proto == NOPROTO)
|
|
|
|
params.vlr_proto = ETHERTYPE_VLAN;
|
2006-07-09 06:10:23 +00:00
|
|
|
ifr->ifr_data = (caddr_t) ¶ms;
|
|
|
|
}
|
2023-06-13 06:10:41 +00:00
|
|
|
ifcreate_ioctl(ctx, ifr);
|
2006-07-09 06:10:23 +00:00
|
|
|
}
|
1999-03-15 01:22:01 +00:00
|
|
|
|
2006-07-09 06:10:23 +00:00
|
|
|
static void
|
2023-06-13 06:10:41 +00:00
|
|
|
vlan_cb(if_ctx *ctx __unused, void *arg __unused)
|
2006-07-09 06:10:23 +00:00
|
|
|
{
|
|
|
|
if ((params.vlr_tag != NOTAG) ^ (params.vlr_parent[0] != '\0'))
|
|
|
|
errx(1, "both vlan and vlandev must be specified");
|
1999-03-15 01:22:01 +00:00
|
|
|
}
|
|
|
|
|
2004-12-08 19:18:07 +00:00
|
|
|
static void
|
2006-07-09 06:10:23 +00:00
|
|
|
vlan_set(int s, struct ifreq *ifr)
|
|
|
|
{
|
|
|
|
if (params.vlr_tag != NOTAG && params.vlr_parent[0] != '\0') {
|
2024-05-21 16:35:01 +00:00
|
|
|
if (params.vlr_proto == NOPROTO)
|
|
|
|
params.vlr_proto = ETHERTYPE_VLAN;
|
2006-07-09 06:10:23 +00:00
|
|
|
ifr->ifr_data = (caddr_t) ¶ms;
|
|
|
|
if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1)
|
|
|
|
err(1, "SIOCSETVLAN");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:02:12 +00:00
|
|
|
static void
|
|
|
|
setvlantag(if_ctx *ctx, const char *val, int dummy __unused)
|
1999-03-15 01:22:01 +00:00
|
|
|
{
|
2023-06-14 13:00:49 +00:00
|
|
|
struct vlanreq vreq = {};
|
|
|
|
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
|
2006-07-09 06:10:23 +00:00
|
|
|
u_long ul;
|
|
|
|
char *endp;
|
2005-10-04 11:48:03 +00:00
|
|
|
|
|
|
|
ul = strtoul(val, &endp, 0);
|
|
|
|
if (*endp != '\0')
|
|
|
|
errx(1, "invalid value for vlan");
|
2006-07-09 06:10:23 +00:00
|
|
|
params.vlr_tag = ul;
|
2005-10-04 11:48:03 +00:00
|
|
|
/* check if the value can be represented in vlr_tag */
|
2006-07-09 06:10:23 +00:00
|
|
|
if (params.vlr_tag != ul)
|
2005-10-04 11:48:03 +00:00
|
|
|
errx(1, "value for vlan out of range");
|
2006-07-09 06:10:23 +00:00
|
|
|
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) {
|
2024-05-21 16:35:01 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the current settings if the interface has already
|
|
|
|
* been configured.
|
|
|
|
*/
|
|
|
|
if (vreq.vlr_parent[0] != '\0') {
|
|
|
|
if (params.vlr_parent[0] == '\0')
|
|
|
|
strlcpy(params.vlr_parent, vreq.vlr_parent, IFNAMSIZ);
|
|
|
|
if (params.vlr_proto == NOPROTO)
|
|
|
|
params.vlr_proto = vreq.vlr_proto;
|
|
|
|
}
|
2023-05-23 17:02:12 +00:00
|
|
|
vlan_set(ctx->io_s, &ifr);
|
2022-07-18 22:25:56 +00:00
|
|
|
}
|
2008-12-15 01:06:49 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 17:02:12 +00:00
|
|
|
static void
|
|
|
|
setvlandev(if_ctx *ctx, const char *val, int dummy __unused)
|
2008-12-15 01:06:49 +00:00
|
|
|
{
|
2023-06-14 13:00:49 +00:00
|
|
|
struct vlanreq vreq = {};
|
|
|
|
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
|
1999-03-15 01:22:01 +00:00
|
|
|
|
2008-12-15 01:06:49 +00:00
|
|
|
strlcpy(params.vlr_parent, val, sizeof(params.vlr_parent));
|
2008-12-15 01:44:23 +00:00
|
|
|
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1)
|
2023-05-23 17:02:12 +00:00
|
|
|
vlan_set(ctx->io_s, &ifr);
|
1999-03-15 01:22:01 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 17:02:12 +00:00
|
|
|
static void
|
|
|
|
setvlanproto(if_ctx *ctx, const char *val, int dummy __unused)
|
2020-10-21 21:28:20 +00:00
|
|
|
{
|
2023-06-14 13:00:49 +00:00
|
|
|
struct vlanreq vreq = {};
|
|
|
|
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
|
2020-10-21 21:28:20 +00:00
|
|
|
|
|
|
|
if (strncasecmp(proto_8021Q, val,
|
|
|
|
strlen(proto_8021Q)) == 0) {
|
|
|
|
params.vlr_proto = ETHERTYPE_VLAN;
|
2021-01-19 23:22:07 +00:00
|
|
|
} else if ((strncasecmp(proto_8021ad, val, strlen(proto_8021ad)) == 0)
|
|
|
|
|| (strncasecmp(proto_qinq, val, strlen(proto_qinq)) == 0)) {
|
2020-10-21 21:28:20 +00:00
|
|
|
params.vlr_proto = ETHERTYPE_QINQ;
|
|
|
|
} else
|
|
|
|
errx(1, "invalid value for vlanproto");
|
|
|
|
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) {
|
2024-05-21 16:35:01 +00:00
|
|
|
/*
|
|
|
|
* Retrieve the current settings if the interface has already
|
|
|
|
* been configured.
|
|
|
|
*/
|
|
|
|
if (vreq.vlr_parent[0] != '\0') {
|
|
|
|
if (params.vlr_parent[0] == '\0')
|
|
|
|
strlcpy(params.vlr_parent, vreq.vlr_parent, IFNAMSIZ);
|
|
|
|
if (params.vlr_tag == NOTAG)
|
|
|
|
params.vlr_tag = vreq.vlr_tag;
|
|
|
|
}
|
2023-05-23 17:02:12 +00:00
|
|
|
vlan_set(ctx->io_s, &ifr);
|
2022-07-18 22:25:56 +00:00
|
|
|
}
|
2020-10-21 21:28:20 +00:00
|
|
|
}
|
|
|
|
|
2023-05-23 17:02:12 +00:00
|
|
|
static void
|
|
|
|
setvlanpcp(if_ctx *ctx, const char *val, int dummy __unused)
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
{
|
|
|
|
u_long ul;
|
|
|
|
char *endp;
|
2023-06-14 13:00:49 +00:00
|
|
|
struct ifreq ifr = {};
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
|
|
|
|
ul = strtoul(val, &endp, 0);
|
|
|
|
if (*endp != '\0')
|
|
|
|
errx(1, "invalid value for vlanpcp");
|
|
|
|
if (ul > 7)
|
|
|
|
errx(1, "value for vlanpcp out of range");
|
|
|
|
ifr.ifr_vlan_pcp = ul;
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCSVLANPCP, &ifr) == -1)
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
err(1, "SIOCSVLANPCP");
|
|
|
|
}
|
|
|
|
|
2023-05-23 17:02:12 +00:00
|
|
|
static void
|
2023-06-01 11:54:02 +00:00
|
|
|
unsetvlandev(if_ctx *ctx, const char *val __unused, int dummy __unused)
|
1999-03-15 01:22:01 +00:00
|
|
|
{
|
2023-06-14 13:00:49 +00:00
|
|
|
struct vlanreq vreq = {};
|
|
|
|
struct ifreq ifr = { .ifr_data = (caddr_t)&vreq };
|
2005-09-29 23:38:24 +00:00
|
|
|
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) == -1)
|
1999-03-15 01:22:01 +00:00
|
|
|
err(1, "SIOCGETVLAN");
|
|
|
|
|
2006-07-09 06:10:23 +00:00
|
|
|
bzero((char *)&vreq.vlr_parent, sizeof(vreq.vlr_parent));
|
|
|
|
vreq.vlr_tag = 0;
|
|
|
|
|
2023-06-14 13:00:49 +00:00
|
|
|
if (ioctl_ctx(ctx, SIOCSETVLAN, (caddr_t)&ifr) == -1)
|
1999-03-15 01:22:01 +00:00
|
|
|
err(1, "SIOCSETVLAN");
|
|
|
|
}
|
2004-12-08 19:18:07 +00:00
|
|
|
|
|
|
|
static struct cmd vlan_cmds[] = {
|
2008-12-15 01:44:23 +00:00
|
|
|
DEF_CLONE_CMD_ARG("vlan", setvlantag),
|
|
|
|
DEF_CLONE_CMD_ARG("vlandev", setvlandev),
|
2020-10-21 21:28:20 +00:00
|
|
|
DEF_CLONE_CMD_ARG("vlanproto", setvlanproto),
|
Add support to priority code point (PCP) that is an 3-bit field
which refers to IEEE 802.1p class of service and maps to the frame
priority level.
Values in order of priority are: 1 (Background (lowest)),
0 (Best effort (default)), 2 (Excellent effort),
3 (Critical applications), 4 (Video, < 100ms latency),
5 (Video, < 10ms latency), 6 (Internetwork control) and
7 (Network control (highest)).
Example of usage:
root# ifconfig em0.1 create
root# ifconfig em0.1 vlanpcp 3
Note:
The review D801 includes the pf(4) part, but as discussed with kristof,
we won't commit the pf(4) bits for now.
The credits of the original code is from rwatson.
Differential Revision: https://reviews.freebsd.org/D801
Reviewed by: gnn, adrian, loos
Discussed with: rwatson, glebius, kristof
Tested by: many including Matthew Grooms <mgrooms__shrew.net>
Obtained from: pfSense
Relnotes: Yes
2016-06-06 09:51:58 +00:00
|
|
|
DEF_CMD_ARG("vlanpcp", setvlanpcp),
|
2008-10-02 20:03:41 +00:00
|
|
|
/* NB: non-clone cmds */
|
|
|
|
DEF_CMD_ARG("vlan", setvlantag),
|
|
|
|
DEF_CMD_ARG("vlandev", setvlandev),
|
2020-10-21 21:28:20 +00:00
|
|
|
DEF_CMD_ARG("vlanproto", setvlanproto),
|
2005-09-29 23:38:24 +00:00
|
|
|
/* XXX For compatibility. Should become DEF_CMD() some day. */
|
|
|
|
DEF_CMD_OPTARG("-vlandev", unsetvlandev),
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("vlanmtu", IFCAP_VLAN_MTU, setifcap),
|
2023-06-19 17:37:52 +00:00
|
|
|
DEF_CMD("-vlanmtu", IFCAP_VLAN_MTU, clearifcap),
|
2004-12-08 19:18:07 +00:00
|
|
|
DEF_CMD("vlanhwtag", IFCAP_VLAN_HWTAGGING, setifcap),
|
2023-06-19 17:37:52 +00:00
|
|
|
DEF_CMD("-vlanhwtag", IFCAP_VLAN_HWTAGGING, clearifcap),
|
2008-08-28 22:13:44 +00:00
|
|
|
DEF_CMD("vlanhwfilter", IFCAP_VLAN_HWFILTER, setifcap),
|
2023-06-19 17:37:52 +00:00
|
|
|
DEF_CMD("-vlanhwfilter", IFCAP_VLAN_HWFILTER, clearifcap),
|
2010-02-20 23:01:09 +00:00
|
|
|
DEF_CMD("vlanhwtso", IFCAP_VLAN_HWTSO, setifcap),
|
2023-06-19 17:42:46 +00:00
|
|
|
DEF_CMD("-vlanhwtso", IFCAP_VLAN_HWTSO, clearifcap),
|
2011-12-17 15:44:34 +00:00
|
|
|
DEF_CMD("vlanhwcsum", IFCAP_VLAN_HWCSUM, setifcap),
|
2023-06-19 17:37:52 +00:00
|
|
|
DEF_CMD("-vlanhwcsum", IFCAP_VLAN_HWCSUM, clearifcap),
|
2004-12-08 19:18:07 +00:00
|
|
|
};
|
|
|
|
static struct afswtch af_vlan = {
|
|
|
|
.af_name = "af_vlan",
|
|
|
|
.af_af = AF_UNSPEC,
|
2004-12-31 19:46:27 +00:00
|
|
|
.af_other_status = vlan_status,
|
2004-12-08 19:18:07 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static __constructor void
|
|
|
|
vlan_ctor(void)
|
|
|
|
{
|
2009-06-23 23:49:52 +00:00
|
|
|
size_t i;
|
2004-12-08 19:18:07 +00:00
|
|
|
|
2015-09-27 07:51:18 +00:00
|
|
|
for (i = 0; i < nitems(vlan_cmds); i++)
|
2004-12-08 19:18:07 +00:00
|
|
|
cmd_register(&vlan_cmds[i]);
|
|
|
|
af_register(&af_vlan);
|
2005-10-04 11:48:03 +00:00
|
|
|
callback_register(vlan_cb, NULL);
|
2020-10-21 21:28:20 +00:00
|
|
|
clone_setdefcallback_prefix("vlan", vlan_create);
|
|
|
|
clone_setdefcallback_filter(vlan_match_ethervid, vlan_create);
|
2004-12-08 19:18:07 +00:00
|
|
|
}
|