Skip to content

Commit 0f963b7

Browse files
Nikolay Aleksandrovdavem330
authored andcommitted
bridge: netlink: add support for default_pvid
Add IFLA_BR_VLAN_DEFAULT_PVID to allow setting/getting bridge's default_pvid via netlink. Signed-off-by: Nikolay Aleksandrov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 93870cc commit 0f963b7

File tree

4 files changed

+21
-8
lines changed

4 files changed

+21
-8
lines changed

include/uapi/linux/if_link.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ enum {
262262
IFLA_BR_NF_CALL_IPTABLES,
263263
IFLA_BR_NF_CALL_IP6TABLES,
264264
IFLA_BR_NF_CALL_ARPTABLES,
265+
IFLA_BR_VLAN_DEFAULT_PVID,
265266
__IFLA_BR_MAX,
266267
};
267268

net/bridge/br_netlink.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,7 @@ static const struct nla_policy br_policy[IFLA_BR_MAX + 1] = {
784784
[IFLA_BR_NF_CALL_IPTABLES] = { .type = NLA_U8 },
785785
[IFLA_BR_NF_CALL_IP6TABLES] = { .type = NLA_U8 },
786786
[IFLA_BR_NF_CALL_ARPTABLES] = { .type = NLA_U8 },
787+
[IFLA_BR_VLAN_DEFAULT_PVID] = { .type = NLA_U16 },
787788
};
788789

789790
static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
@@ -847,6 +848,14 @@ static int br_changelink(struct net_device *brdev, struct nlattr *tb[],
847848
if (err)
848849
return err;
849850
}
851+
852+
if (data[IFLA_BR_VLAN_DEFAULT_PVID]) {
853+
__u16 defpvid = nla_get_u16(data[IFLA_BR_VLAN_DEFAULT_PVID]);
854+
855+
err = __br_vlan_set_default_pvid(br, defpvid);
856+
if (err)
857+
return err;
858+
}
850859
#endif
851860

852861
if (data[IFLA_BR_GROUP_FWD_MASK]) {
@@ -1007,6 +1016,7 @@ static size_t br_get_size(const struct net_device *brdev)
10071016
nla_total_size(sizeof(u8)) + /* IFLA_BR_VLAN_FILTERING */
10081017
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
10091018
nla_total_size(sizeof(__be16)) + /* IFLA_BR_VLAN_PROTOCOL */
1019+
nla_total_size(sizeof(u16)) + /* IFLA_BR_VLAN_DEFAULT_PVID */
10101020
#endif
10111021
nla_total_size(sizeof(u16)) + /* IFLA_BR_GROUP_FWD_MASK */
10121022
nla_total_size(sizeof(struct ifla_bridge_id)) + /* IFLA_BR_ROOT_ID */
@@ -1094,7 +1104,8 @@ static int br_fill_info(struct sk_buff *skb, const struct net_device *brdev)
10941104
return -EMSGSIZE;
10951105

10961106
#ifdef CONFIG_BRIDGE_VLAN_FILTERING
1097-
if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto))
1107+
if (nla_put_be16(skb, IFLA_BR_VLAN_PROTOCOL, br->vlan_proto) ||
1108+
nla_put_u16(skb, IFLA_BR_VLAN_DEFAULT_PVID, br->default_pvid))
10981109
return -EMSGSIZE;
10991110
#endif
11001111
#ifdef CONFIG_BRIDGE_IGMP_SNOOPING

net/bridge/br_private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ int __br_vlan_set_proto(struct net_bridge *br, __be16 proto);
690690
int br_vlan_set_proto(struct net_bridge *br, unsigned long val);
691691
int br_vlan_init(struct net_bridge *br);
692692
int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val);
693+
int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid);
693694
int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags);
694695
int nbp_vlan_delete(struct net_bridge_port *port, u16 vid);
695696
void nbp_vlan_flush(struct net_bridge_port *port);

net/bridge/br_vlan.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -727,14 +727,19 @@ static void br_vlan_disable_default_pvid(struct net_bridge *br)
727727
br->default_pvid = 0;
728728
}
729729

730-
static int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
730+
int __br_vlan_set_default_pvid(struct net_bridge *br, u16 pvid)
731731
{
732732
const struct net_bridge_vlan *pvent;
733733
struct net_bridge_port *p;
734734
u16 old_pvid;
735735
int err = 0;
736736
unsigned long *changed;
737737

738+
if (!pvid) {
739+
br_vlan_disable_default_pvid(br);
740+
return 0;
741+
}
742+
738743
changed = kcalloc(BITS_TO_LONGS(BR_MAX_PORTS), sizeof(unsigned long),
739744
GFP_KERNEL);
740745
if (!changed)
@@ -825,12 +830,7 @@ int br_vlan_set_default_pvid(struct net_bridge *br, unsigned long val)
825830
err = -EPERM;
826831
goto unlock;
827832
}
828-
829-
if (!pvid)
830-
br_vlan_disable_default_pvid(br);
831-
else
832-
err = __br_vlan_set_default_pvid(br, pvid);
833-
833+
err = __br_vlan_set_default_pvid(br, pvid);
834834
unlock:
835835
rtnl_unlock();
836836
return err;

0 commit comments

Comments
 (0)