2019-06-04 08:11:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2007-06-13 19:07:54 +00:00
|
|
|
/*
|
|
|
|
* VLAN netlink control interface
|
|
|
|
*
|
|
|
|
* Copyright (c) 2007 Patrick McHardy <kaber@trash.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/netdevice.h>
|
|
|
|
#include <linux/if_vlan.h>
|
2011-05-27 13:12:25 +00:00
|
|
|
#include <linux/module.h>
|
2007-09-17 18:56:21 +00:00
|
|
|
#include <net/net_namespace.h>
|
2007-06-13 19:07:54 +00:00
|
|
|
#include <net/netlink.h>
|
|
|
|
#include <net/rtnetlink.h>
|
|
|
|
#include "vlan.h"
|
|
|
|
|
|
|
|
|
|
|
|
static const struct nla_policy vlan_policy[IFLA_VLAN_MAX + 1] = {
|
|
|
|
[IFLA_VLAN_ID] = { .type = NLA_U16 },
|
|
|
|
[IFLA_VLAN_FLAGS] = { .len = sizeof(struct ifla_vlan_flags) },
|
|
|
|
[IFLA_VLAN_EGRESS_QOS] = { .type = NLA_NESTED },
|
|
|
|
[IFLA_VLAN_INGRESS_QOS] = { .type = NLA_NESTED },
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
[IFLA_VLAN_PROTOCOL] = { .type = NLA_U16 },
|
2007-06-13 19:07:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static const struct nla_policy vlan_map_policy[IFLA_VLAN_QOS_MAX + 1] = {
|
|
|
|
[IFLA_VLAN_QOS_MAPPING] = { .len = sizeof(struct ifla_vlan_qos_mapping) },
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
static inline int vlan_validate_qos_map(struct nlattr *attr)
|
|
|
|
{
|
|
|
|
if (!attr)
|
|
|
|
return 0;
|
netlink: make validation more configurable for future strictness
We currently have two levels of strict validation:
1) liberal (default)
- undefined (type >= max) & NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
- garbage at end of message accepted
2) strict (opt-in)
- NLA_UNSPEC attributes accepted
- attribute length >= expected accepted
Split out parsing strictness into four different options:
* TRAILING - check that there's no trailing data after parsing
attributes (in message or nested)
* MAXTYPE - reject attrs > max known type
* UNSPEC - reject attributes with NLA_UNSPEC policy entries
* STRICT_ATTRS - strictly validate attribute size
The default for future things should be *everything*.
The current *_strict() is a combination of TRAILING and MAXTYPE,
and is renamed to _deprecated_strict().
The current regular parsing has none of this, and is renamed to
*_parse_deprecated().
Additionally it allows us to selectively set one of the new flags
even on old policies. Notably, the UNSPEC flag could be useful in
this case, since it can be arranged (by filling in the policy) to
not be an incompatible userspace ABI change, but would then going
forward prevent forgetting attribute entries. Similar can apply
to the POLICY flag.
We end up with the following renames:
* nla_parse -> nla_parse_deprecated
* nla_parse_strict -> nla_parse_deprecated_strict
* nlmsg_parse -> nlmsg_parse_deprecated
* nlmsg_parse_strict -> nlmsg_parse_deprecated_strict
* nla_parse_nested -> nla_parse_nested_deprecated
* nla_validate_nested -> nla_validate_nested_deprecated
Using spatch, of course:
@@
expression TB, MAX, HEAD, LEN, POL, EXT;
@@
-nla_parse(TB, MAX, HEAD, LEN, POL, EXT)
+nla_parse_deprecated(TB, MAX, HEAD, LEN, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression NLH, HDRLEN, TB, MAX, POL, EXT;
@@
-nlmsg_parse_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
+nlmsg_parse_deprecated_strict(NLH, HDRLEN, TB, MAX, POL, EXT)
@@
expression TB, MAX, NLA, POL, EXT;
@@
-nla_parse_nested(TB, MAX, NLA, POL, EXT)
+nla_parse_nested_deprecated(TB, MAX, NLA, POL, EXT)
@@
expression START, MAX, POL, EXT;
@@
-nla_validate_nested(START, MAX, POL, EXT)
+nla_validate_nested_deprecated(START, MAX, POL, EXT)
@@
expression NLH, HDRLEN, MAX, POL, EXT;
@@
-nlmsg_validate(NLH, HDRLEN, MAX, POL, EXT)
+nlmsg_validate_deprecated(NLH, HDRLEN, MAX, POL, EXT)
For this patch, don't actually add the strict, non-renamed versions
yet so that it breaks compile if I get it wrong.
Also, while at it, make nla_validate and nla_parse go down to a
common __nla_validate_parse() function to avoid code duplication.
Ultimately, this allows us to have very strict validation for every
new caller of nla_parse()/nlmsg_parse() etc as re-introduced in the
next patch, while existing things will continue to work as is.
In effect then, this adds fully strict validation for any new command.
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2019-04-26 12:07:28 +00:00
|
|
|
return nla_validate_nested_deprecated(attr, IFLA_VLAN_QOS_MAX,
|
|
|
|
vlan_map_policy, NULL);
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
|
2017-06-25 21:56:01 +00:00
|
|
|
static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-06-13 19:07:54 +00:00
|
|
|
{
|
|
|
|
struct ifla_vlan_flags *flags;
|
|
|
|
u16 id;
|
|
|
|
int err;
|
|
|
|
|
2007-07-12 02:42:31 +00:00
|
|
|
if (tb[IFLA_ADDRESS]) {
|
2018-05-17 19:29:47 +00:00
|
|
|
if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
|
2007-07-12 02:42:31 +00:00
|
|
|
return -EINVAL;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
|
|
|
if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
|
2007-07-12 02:42:31 +00:00
|
|
|
return -EADDRNOTAVAIL;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-07-12 02:42:31 +00:00
|
|
|
}
|
|
|
|
|
2018-05-17 19:29:47 +00:00
|
|
|
if (!data) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "VLAN properties not specified");
|
2007-06-13 19:07:54 +00:00
|
|
|
return -EINVAL;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
if (data[IFLA_VLAN_PROTOCOL]) {
|
|
|
|
switch (nla_get_be16(data[IFLA_VLAN_PROTOCOL])) {
|
2014-03-12 17:04:15 +00:00
|
|
|
case htons(ETH_P_8021Q):
|
|
|
|
case htons(ETH_P_8021AD):
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
break;
|
|
|
|
default:
|
2018-05-17 19:29:47 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN protocol");
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
return -EPROTONOSUPPORT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-06-13 19:07:54 +00:00
|
|
|
if (data[IFLA_VLAN_ID]) {
|
|
|
|
id = nla_get_u16(data[IFLA_VLAN_ID]);
|
2018-05-17 19:29:47 +00:00
|
|
|
if (id >= VLAN_VID_MASK) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN id");
|
2007-06-13 19:07:54 +00:00
|
|
|
return -ERANGE;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
if (data[IFLA_VLAN_FLAGS]) {
|
|
|
|
flags = nla_data(data[IFLA_VLAN_FLAGS]);
|
2008-07-06 04:26:57 +00:00
|
|
|
if ((flags->flags & flags->mask) &
|
2009-11-25 07:54:54 +00:00
|
|
|
~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
|
2019-04-18 17:35:31 +00:00
|
|
|
VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP |
|
|
|
|
VLAN_FLAG_BRIDGE_BINDING)) {
|
2018-05-17 19:29:47 +00:00
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN flags");
|
2007-06-13 19:07:54 +00:00
|
|
|
return -EINVAL;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
err = vlan_validate_qos_map(data[IFLA_VLAN_INGRESS_QOS]);
|
2018-05-17 19:29:47 +00:00
|
|
|
if (err < 0) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid ingress QOS map");
|
2007-06-13 19:07:54 +00:00
|
|
|
return err;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
err = vlan_validate_qos_map(data[IFLA_VLAN_EGRESS_QOS]);
|
2018-05-17 19:29:47 +00:00
|
|
|
if (err < 0) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "Invalid egress QOS map");
|
2007-06-13 19:07:54 +00:00
|
|
|
return err;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-06-25 21:56:00 +00:00
|
|
|
static int vlan_changelink(struct net_device *dev, struct nlattr *tb[],
|
|
|
|
struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-06-13 19:07:54 +00:00
|
|
|
{
|
|
|
|
struct ifla_vlan_flags *flags;
|
|
|
|
struct ifla_vlan_qos_mapping *m;
|
|
|
|
struct nlattr *attr;
|
2020-01-07 09:42:25 +00:00
|
|
|
int rem, err;
|
2007-06-13 19:07:54 +00:00
|
|
|
|
|
|
|
if (data[IFLA_VLAN_FLAGS]) {
|
|
|
|
flags = nla_data(data[IFLA_VLAN_FLAGS]);
|
2020-01-07 09:42:25 +00:00
|
|
|
err = vlan_dev_change_flags(dev, flags->flags, flags->mask);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
if (data[IFLA_VLAN_INGRESS_QOS]) {
|
|
|
|
nla_for_each_nested(attr, data[IFLA_VLAN_INGRESS_QOS], rem) {
|
|
|
|
m = nla_data(attr);
|
|
|
|
vlan_dev_set_ingress_priority(dev, m->to, m->from);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (data[IFLA_VLAN_EGRESS_QOS]) {
|
|
|
|
nla_for_each_nested(attr, data[IFLA_VLAN_EGRESS_QOS], rem) {
|
|
|
|
m = nla_data(attr);
|
2020-01-07 09:42:25 +00:00
|
|
|
err = vlan_dev_set_egress_priority(dev, m->from, m->to);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-08 08:53:51 +00:00
|
|
|
static int vlan_newlink(struct net *src_net, struct net_device *dev,
|
2017-06-25 21:55:59 +00:00
|
|
|
struct nlattr *tb[], struct nlattr *data[],
|
|
|
|
struct netlink_ext_ack *extack)
|
2007-06-13 19:07:54 +00:00
|
|
|
{
|
2011-12-08 04:11:15 +00:00
|
|
|
struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
|
2007-06-13 19:07:54 +00:00
|
|
|
struct net_device *real_dev;
|
2016-07-14 16:00:10 +00:00
|
|
|
unsigned int max_mtu;
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
__be16 proto;
|
2007-06-13 19:07:54 +00:00
|
|
|
int err;
|
|
|
|
|
2018-05-17 19:29:47 +00:00
|
|
|
if (!data[IFLA_VLAN_ID]) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "VLAN id not specified");
|
2007-06-13 19:07:54 +00:00
|
|
|
return -EINVAL;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
|
2018-05-17 19:29:47 +00:00
|
|
|
if (!tb[IFLA_LINK]) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "link not specified");
|
2007-06-13 19:07:54 +00:00
|
|
|
return -EINVAL;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
|
|
|
|
2009-11-08 08:53:51 +00:00
|
|
|
real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
|
2018-05-17 19:29:47 +00:00
|
|
|
if (!real_dev) {
|
|
|
|
NL_SET_ERR_MSG_MOD(extack, "link does not exist");
|
2007-06-13 19:07:54 +00:00
|
|
|
return -ENODEV;
|
2018-05-17 19:29:47 +00:00
|
|
|
}
|
2007-06-13 19:07:54 +00:00
|
|
|
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
if (data[IFLA_VLAN_PROTOCOL])
|
|
|
|
proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]);
|
|
|
|
else
|
|
|
|
proto = htons(ETH_P_8021Q);
|
|
|
|
|
|
|
|
vlan->vlan_proto = proto;
|
2013-04-19 02:04:29 +00:00
|
|
|
vlan->vlan_id = nla_get_u16(data[IFLA_VLAN_ID]);
|
|
|
|
vlan->real_dev = real_dev;
|
2017-11-02 12:49:08 +00:00
|
|
|
dev->priv_flags |= (real_dev->priv_flags & IFF_XMIT_DST_RELEASE);
|
2013-04-19 02:04:29 +00:00
|
|
|
vlan->flags = VLAN_FLAG_REORDER_HDR;
|
2007-06-13 19:07:54 +00:00
|
|
|
|
2018-05-17 19:29:47 +00:00
|
|
|
err = vlan_check_real_dev(real_dev, vlan->vlan_proto, vlan->vlan_id,
|
|
|
|
extack);
|
2007-06-13 19:07:54 +00:00
|
|
|
if (err < 0)
|
|
|
|
return err;
|
|
|
|
|
2016-07-14 16:00:10 +00:00
|
|
|
max_mtu = netif_reduces_vlan_mtu(real_dev) ? real_dev->mtu - VLAN_HLEN :
|
|
|
|
real_dev->mtu;
|
2007-06-13 19:07:54 +00:00
|
|
|
if (!tb[IFLA_MTU])
|
2016-07-14 16:00:10 +00:00
|
|
|
dev->mtu = max_mtu;
|
|
|
|
else if (dev->mtu > max_mtu)
|
2007-06-13 19:07:54 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2017-06-25 21:56:00 +00:00
|
|
|
err = vlan_changelink(dev, tb, data, extack);
|
2020-01-07 09:42:24 +00:00
|
|
|
if (!err)
|
|
|
|
err = register_vlan_dev(dev, extack);
|
|
|
|
if (err)
|
|
|
|
vlan_dev_uninit(dev);
|
|
|
|
return err;
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t vlan_qos_map_size(unsigned int n)
|
|
|
|
{
|
|
|
|
if (n == 0)
|
|
|
|
return 0;
|
|
|
|
/* IFLA_VLAN_{EGRESS,INGRESS}_QOS + n * IFLA_VLAN_QOS_MAPPING */
|
|
|
|
return nla_total_size(sizeof(struct nlattr)) +
|
|
|
|
nla_total_size(sizeof(struct ifla_vlan_qos_mapping)) * n;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t vlan_get_size(const struct net_device *dev)
|
|
|
|
{
|
2011-12-08 04:11:15 +00:00
|
|
|
struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
|
2007-06-13 19:07:54 +00:00
|
|
|
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
return nla_total_size(2) + /* IFLA_VLAN_PROTOCOL */
|
|
|
|
nla_total_size(2) + /* IFLA_VLAN_ID */
|
2013-10-07 21:19:58 +00:00
|
|
|
nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
|
2007-06-13 19:07:54 +00:00
|
|
|
vlan_qos_map_size(vlan->nr_ingress_mappings) +
|
|
|
|
vlan_qos_map_size(vlan->nr_egress_mappings);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
|
|
|
|
{
|
2011-12-08 04:11:15 +00:00
|
|
|
struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
|
2007-06-13 19:07:54 +00:00
|
|
|
struct vlan_priority_tci_mapping *pm;
|
|
|
|
struct ifla_vlan_flags f;
|
|
|
|
struct ifla_vlan_qos_mapping m;
|
|
|
|
struct nlattr *nest;
|
|
|
|
unsigned int i;
|
|
|
|
|
net: vlan: add 802.1ad support
Add support for 802.1ad VLAN devices. This mainly consists of checking for
ETH_P_8021AD in addition to ETH_P_8021Q in a couple of places and check
offloading capabilities based on the used protocol.
Configuration is done using "ip link":
# ip link add link eth0 eth0.1000 \
type vlan proto 802.1ad id 1000
# ip link add link eth0.1000 eth0.1000.1000 \
type vlan proto 802.1q id 1000
52:54:00:12:34:56 > 92:b1:54:28:e4:8c, ethertype 802.1Q (0x8100), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 0, offset 0, flags [DF], proto ICMP (1), length 84)
20.1.0.2 > 20.1.0.1: ICMP echo request, id 3003, seq 8, length 64
92:b1:54:28:e4:8c > 52:54:00:12:34:56, ethertype 802.1Q-QinQ (0x88a8), length 106: vlan 1000, p 0, ethertype 802.1Q, vlan 1000, p 0, ethertype IPv4, (tos 0x0, ttl 64, id 47944, offset 0, flags [none], proto ICMP (1), length 84)
20.1.0.1 > 20.1.0.2: ICMP echo reply, id 3003, seq 8, length 64
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
2013-04-19 02:04:31 +00:00
|
|
|
if (nla_put_be16(skb, IFLA_VLAN_PROTOCOL, vlan->vlan_proto) ||
|
|
|
|
nla_put_u16(skb, IFLA_VLAN_ID, vlan->vlan_id))
|
2012-04-02 00:50:45 +00:00
|
|
|
goto nla_put_failure;
|
2007-06-13 19:07:54 +00:00
|
|
|
if (vlan->flags) {
|
|
|
|
f.flags = vlan->flags;
|
|
|
|
f.mask = ~0;
|
2012-04-02 00:50:45 +00:00
|
|
|
if (nla_put(skb, IFLA_VLAN_FLAGS, sizeof(f), &f))
|
|
|
|
goto nla_put_failure;
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
if (vlan->nr_ingress_mappings) {
|
2019-04-26 09:13:06 +00:00
|
|
|
nest = nla_nest_start_noflag(skb, IFLA_VLAN_INGRESS_QOS);
|
2007-06-13 19:07:54 +00:00
|
|
|
if (nest == NULL)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(vlan->ingress_priority_map); i++) {
|
|
|
|
if (!vlan->ingress_priority_map[i])
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m.from = i;
|
|
|
|
m.to = vlan->ingress_priority_map[i];
|
2012-04-02 00:50:45 +00:00
|
|
|
if (nla_put(skb, IFLA_VLAN_QOS_MAPPING,
|
|
|
|
sizeof(m), &m))
|
|
|
|
goto nla_put_failure;
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
nla_nest_end(skb, nest);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (vlan->nr_egress_mappings) {
|
2019-04-26 09:13:06 +00:00
|
|
|
nest = nla_nest_start_noflag(skb, IFLA_VLAN_EGRESS_QOS);
|
2007-06-13 19:07:54 +00:00
|
|
|
if (nest == NULL)
|
|
|
|
goto nla_put_failure;
|
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) {
|
|
|
|
for (pm = vlan->egress_priority_map[i]; pm;
|
|
|
|
pm = pm->next) {
|
|
|
|
if (!pm->vlan_qos)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
m.from = pm->priority;
|
|
|
|
m.to = (pm->vlan_qos >> 13) & 0x7;
|
2012-04-02 00:50:45 +00:00
|
|
|
if (nla_put(skb, IFLA_VLAN_QOS_MAPPING,
|
|
|
|
sizeof(m), &m))
|
|
|
|
goto nla_put_failure;
|
2007-06-13 19:07:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
nla_nest_end(skb, nest);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
nla_put_failure:
|
|
|
|
return -EMSGSIZE;
|
|
|
|
}
|
|
|
|
|
2015-01-20 14:15:44 +00:00
|
|
|
static struct net *vlan_get_link_net(const struct net_device *dev)
|
|
|
|
{
|
|
|
|
struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
|
|
|
|
|
|
|
|
return dev_net(real_dev);
|
|
|
|
}
|
|
|
|
|
2007-06-13 19:07:54 +00:00
|
|
|
struct rtnl_link_ops vlan_link_ops __read_mostly = {
|
|
|
|
.kind = "vlan",
|
|
|
|
.maxtype = IFLA_VLAN_MAX,
|
|
|
|
.policy = vlan_policy,
|
2011-12-08 04:11:15 +00:00
|
|
|
.priv_size = sizeof(struct vlan_dev_priv),
|
2007-06-13 19:07:54 +00:00
|
|
|
.setup = vlan_setup,
|
|
|
|
.validate = vlan_validate,
|
|
|
|
.newlink = vlan_newlink,
|
|
|
|
.changelink = vlan_changelink,
|
2008-01-21 08:25:50 +00:00
|
|
|
.dellink = unregister_vlan_dev,
|
2007-06-13 19:07:54 +00:00
|
|
|
.get_size = vlan_get_size,
|
|
|
|
.fill_info = vlan_fill_info,
|
2015-01-20 14:15:44 +00:00
|
|
|
.get_link_net = vlan_get_link_net,
|
2007-06-13 19:07:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
int __init vlan_netlink_init(void)
|
|
|
|
{
|
|
|
|
return rtnl_link_register(&vlan_link_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
void __exit vlan_netlink_fini(void)
|
|
|
|
{
|
|
|
|
rtnl_link_unregister(&vlan_link_ops);
|
|
|
|
}
|
|
|
|
|
|
|
|
MODULE_ALIAS_RTNL_LINK("vlan");
|