Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *	VLAN netlink control interface
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * 	Copyright (c) 2007 Patrick McHardy <kaber@trash.net>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/if_vlan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <net/net_namespace.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <net/netlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <net/rtnetlink.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include "vlan.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static const struct nla_policy vlan_policy[IFLA_VLAN_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) 	[IFLA_VLAN_ID]		= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) 	[IFLA_VLAN_FLAGS]	= { .len = sizeof(struct ifla_vlan_flags) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	[IFLA_VLAN_EGRESS_QOS]	= { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	[IFLA_VLAN_INGRESS_QOS] = { .type = NLA_NESTED },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 	[IFLA_VLAN_PROTOCOL]	= { .type = NLA_U16 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) static const struct nla_policy vlan_map_policy[IFLA_VLAN_QOS_MAX + 1] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	[IFLA_VLAN_QOS_MAPPING] = { .len = sizeof(struct ifla_vlan_qos_mapping) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) static inline int vlan_validate_qos_map(struct nlattr *attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	if (!attr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 	return nla_validate_nested_deprecated(attr, IFLA_VLAN_QOS_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 					      vlan_map_policy, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) static int vlan_validate(struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 			 struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	struct ifla_vlan_flags *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	u16 id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	if (tb[IFLA_ADDRESS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 		if (nla_len(tb[IFLA_ADDRESS]) != ETH_ALEN) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 			NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 		if (!is_valid_ether_addr(nla_data(tb[IFLA_ADDRESS]))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 			NL_SET_ERR_MSG_MOD(extack, "Invalid link address");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 			return -EADDRNOTAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	if (!data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		NL_SET_ERR_MSG_MOD(extack, "VLAN properties not specified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	if (data[IFLA_VLAN_PROTOCOL]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		switch (nla_get_be16(data[IFLA_VLAN_PROTOCOL])) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 		case htons(ETH_P_8021Q):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 		case htons(ETH_P_8021AD):
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 			NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN protocol");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 			return -EPROTONOSUPPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (data[IFLA_VLAN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		id = nla_get_u16(data[IFLA_VLAN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		if (id >= VLAN_VID_MASK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN id");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 			return -ERANGE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	if (data[IFLA_VLAN_FLAGS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 		flags = nla_data(data[IFLA_VLAN_FLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		if ((flags->flags & flags->mask) &
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		    ~(VLAN_FLAG_REORDER_HDR | VLAN_FLAG_GVRP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		      VLAN_FLAG_LOOSE_BINDING | VLAN_FLAG_MVRP |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		      VLAN_FLAG_BRIDGE_BINDING)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			NL_SET_ERR_MSG_MOD(extack, "Invalid VLAN flags");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	err = vlan_validate_qos_map(data[IFLA_VLAN_INGRESS_QOS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		NL_SET_ERR_MSG_MOD(extack, "Invalid ingress QOS map");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	err = vlan_validate_qos_map(data[IFLA_VLAN_EGRESS_QOS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	if (err < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		NL_SET_ERR_MSG_MOD(extack, "Invalid egress QOS map");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static int vlan_changelink(struct net_device *dev, struct nlattr *tb[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 			   struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 			   struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct ifla_vlan_flags *flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	struct ifla_vlan_qos_mapping *m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	struct nlattr *attr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	int rem, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	if (data[IFLA_VLAN_FLAGS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		flags = nla_data(data[IFLA_VLAN_FLAGS]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		err = vlan_dev_change_flags(dev, flags->flags, flags->mask);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 			return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	if (data[IFLA_VLAN_INGRESS_QOS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		nla_for_each_nested(attr, data[IFLA_VLAN_INGRESS_QOS], rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			m = nla_data(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 			vlan_dev_set_ingress_priority(dev, m->to, m->from);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	if (data[IFLA_VLAN_EGRESS_QOS]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		nla_for_each_nested(attr, data[IFLA_VLAN_EGRESS_QOS], rem) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			m = nla_data(attr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 			err = vlan_dev_set_egress_priority(dev, m->from, m->to);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 			if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 				return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int vlan_newlink(struct net *src_net, struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 			struct nlattr *tb[], struct nlattr *data[],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 			struct netlink_ext_ack *extack)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct net_device *real_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	unsigned int max_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	__be16 proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (!data[IFLA_VLAN_ID]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		NL_SET_ERR_MSG_MOD(extack, "VLAN id not specified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	if (!tb[IFLA_LINK]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 		NL_SET_ERR_MSG_MOD(extack, "link not specified");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	real_dev = __dev_get_by_index(src_net, nla_get_u32(tb[IFLA_LINK]));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	if (!real_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 		NL_SET_ERR_MSG_MOD(extack, "link does not exist");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (data[IFLA_VLAN_PROTOCOL])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		proto = nla_get_be16(data[IFLA_VLAN_PROTOCOL]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		proto = htons(ETH_P_8021Q);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	vlan->vlan_proto = proto;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	vlan->vlan_id	 = nla_get_u16(data[IFLA_VLAN_ID]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	vlan->real_dev	 = real_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	dev->priv_flags |= (real_dev->priv_flags & IFF_XMIT_DST_RELEASE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	vlan->flags	 = VLAN_FLAG_REORDER_HDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	err = vlan_check_real_dev(real_dev, vlan->vlan_proto, vlan->vlan_id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 				  extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	if (err < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	max_mtu = netif_reduces_vlan_mtu(real_dev) ? real_dev->mtu - VLAN_HLEN :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 						     real_dev->mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	if (!tb[IFLA_MTU])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		dev->mtu = max_mtu;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	else if (dev->mtu > max_mtu)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	err = vlan_changelink(dev, tb, data, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		err = register_vlan_dev(dev, extack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		vlan_dev_uninit(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) static inline size_t vlan_qos_map_size(unsigned int n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	if (n == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	/* IFLA_VLAN_{EGRESS,INGRESS}_QOS + n * IFLA_VLAN_QOS_MAPPING */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	return nla_total_size(sizeof(struct nlattr)) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	       nla_total_size(sizeof(struct ifla_vlan_qos_mapping)) * n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static size_t vlan_get_size(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return nla_total_size(2) +	/* IFLA_VLAN_PROTOCOL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	       nla_total_size(2) +	/* IFLA_VLAN_ID */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	       nla_total_size(sizeof(struct ifla_vlan_flags)) + /* IFLA_VLAN_FLAGS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	       vlan_qos_map_size(vlan->nr_ingress_mappings) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	       vlan_qos_map_size(vlan->nr_egress_mappings);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static int vlan_fill_info(struct sk_buff *skb, const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	struct vlan_priority_tci_mapping *pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	struct ifla_vlan_flags f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	struct ifla_vlan_qos_mapping m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	struct nlattr *nest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	unsigned int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	if (nla_put_be16(skb, IFLA_VLAN_PROTOCOL, vlan->vlan_proto) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	    nla_put_u16(skb, IFLA_VLAN_ID, vlan->vlan_id))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (vlan->flags) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		f.flags = vlan->flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		f.mask  = ~0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		if (nla_put(skb, IFLA_VLAN_FLAGS, sizeof(f), &f))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	if (vlan->nr_ingress_mappings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		nest = nla_nest_start_noflag(skb, IFLA_VLAN_INGRESS_QOS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		if (nest == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 		for (i = 0; i < ARRAY_SIZE(vlan->ingress_priority_map); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 			if (!vlan->ingress_priority_map[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 				continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 			m.from = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 			m.to   = vlan->ingress_priority_map[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 			if (nla_put(skb, IFLA_VLAN_QOS_MAPPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 				    sizeof(m), &m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 				goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	if (vlan->nr_egress_mappings) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 		nest = nla_nest_start_noflag(skb, IFLA_VLAN_EGRESS_QOS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 		if (nest == NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		for (i = 0; i < ARRAY_SIZE(vlan->egress_priority_map); i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 			for (pm = vlan->egress_priority_map[i]; pm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 			     pm = pm->next) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 				if (!pm->vlan_qos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 					continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 				m.from = pm->priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 				m.to   = (pm->vlan_qos >> 13) & 0x7;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 				if (nla_put(skb, IFLA_VLAN_QOS_MAPPING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 					    sizeof(m), &m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 					goto nla_put_failure;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		nla_nest_end(skb, nest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) nla_put_failure:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	return -EMSGSIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) static struct net *vlan_get_link_net(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	struct net_device *real_dev = vlan_dev_priv(dev)->real_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	return dev_net(real_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) struct rtnl_link_ops vlan_link_ops __read_mostly = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	.kind		= "vlan",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	.maxtype	= IFLA_VLAN_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	.policy		= vlan_policy,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	.priv_size	= sizeof(struct vlan_dev_priv),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	.setup		= vlan_setup,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	.validate	= vlan_validate,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.newlink	= vlan_newlink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	.changelink	= vlan_changelink,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	.dellink	= unregister_vlan_dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	.get_size	= vlan_get_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	.fill_info	= vlan_fill_info,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	.get_link_net	= vlan_get_link_net,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) int __init vlan_netlink_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	return rtnl_link_register(&vlan_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) void __exit vlan_netlink_fini(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	rtnl_link_unregister(&vlan_link_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) MODULE_ALIAS_RTNL_LINK("vlan");