vlan: introduce per-device vlan id list
Subsystems (4)
cover vlan: introduce per-device vlan id list
Many drivers store vlan ids in their private structures.
They are maintaining the private lists in vlan_add_vid and vlan_kill_vid.
This patchset creates an infrastructure of storing vlan ids in one place, vlan core. Another benefit of this is that it allows to keep track of vlan ids needed. For example if eth0 has vlan id 10 on it, then it enters bonding, bonding gets added 10 as well, then eth0 leaves bonding. Final step would remove vlan id 10 from eth1 vlan filter resulting in potentially unfunction vlan device. This patchset fixes this.
Jiri Pirko (6):
vlan: rename vlan_dev_info to vlan_dev_priv
net: make vlan ndo_vlan_rx_[add/kill]_vid return error value
net: introduce vlan_vid_[add/del] and use them instead of direct
[add/kill]_vid ndo calls
vlan: introduce vid list with reference counting
vlan: introduce functions to do mass addition/deletion of vids by
another device
team: use vlan_vids_[addr/del]_by_dev
drivers/net/bonding/bond_main.c | 63 +++--- drivers/net/ethernet/adaptec/starfire.c | 8 +- drivers/net/ethernet/brocade/bna/bnad.c | 12 +- drivers/net/ethernet/cisco/enic/enic_dev.c | 14 +- drivers/net/ethernet/cisco/enic/enic_dev.h | 4 +- drivers/net/ethernet/emulex/benet/be_main.c | 12 +- drivers/net/ethernet/ibm/ehea/ehea_main.c | 21 ++- drivers/net/ethernet/intel/e1000/e1000_main.c | 14 +- drivers/net/ethernet/intel/e1000e/netdev.c | 12 +- drivers/net/ethernet/intel/igb/igb_main.c | 12 +- drivers/net/ethernet/intel/igbvf/netdev.c | 20 +- drivers/net/ethernet/intel/ixgb/ixgb_main.c | 12 +- drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 8 +- drivers/net/ethernet/intel/ixgbevf/ixgbevf_main.c | 8 +- drivers/net/ethernet/mellanox/mlx4/en_netdev.c | 7 +- drivers/net/ethernet/neterion/vxge/vxge-main.c | 6 +- drivers/net/ethernet/qlogic/qlcnic/qlcnic_main.c | 10 +- drivers/net/ethernet/qlogic/qlge/qlge_main.c | 38 ++-- drivers/net/ethernet/tehuti/tehuti.c | 6 +- drivers/net/ethernet/via/via-rhine.c | 10 +- drivers/net/ethernet/via/via-velocity.c | 6 +- drivers/net/macvlan.c | 14 +- drivers/net/team/team.c | 53 ++++-- drivers/net/virtio_net.c | 6 +- drivers/net/vmxnet3/vmxnet3_drv.c | 8 +- drivers/s390/net/qeth_l2_main.c | 18 +- drivers/s390/net/qeth_l3_main.c | 9 +- include/linux/if_vlan.h | 46 +++-- include/linux/netdevice.h | 11 +- net/8021q/vlan.c | 126 ++++------- net/8021q/vlan.h | 38 +++- net/8021q/vlan_core.c | 233 ++++++++++++++++++++- net/8021q/vlan_dev.c | 72 ++++---- net/8021q/vlan_gvrp.c | 4 +- net/8021q/vlan_netlink.c | 10 +- net/8021q/vlanproc.c | 42 ++-- 36 files changed, 662 insertions(+), 331 deletions(-)
Signature · 1 line
1.7.6
PATCH 1/6 vlan: rename vlan_dev_info to vlan_dev_priv
As this structure is priv, name it approprietely. Also for pointer to it use name "vlan".
--- include/linux/if_vlan.h | 2 +- net/8021q/vlan.c | 24 +++++++------- net/8021q/vlan.h | 8 ++-- net/8021q/vlan_core.c | 8 ++-- net/8021q/vlan_dev.c | 72 +++++++++++++++++++++++----------------------- net/8021q/vlan_gvrp.c | 4 +- net/8021q/vlan_netlink.c | 10 +++--- net/8021q/vlanproc.c | 42 +++++++++++++------------- 8 files changed, 85 insertions(+), 85 deletions(-)
include/linux/if_vlan.h +1 -1
@@ -386,7 +386,7 @@ struct vlan_ioctl_args {unsigned int skb_priority;unsigned int name_type;unsigned int bind_type; -unsigned int flag;/* Matches vlan_dev_info flags */ +unsigned int flag;/* Matches vlan_dev_priv flags */ } u;short vlan_qos;
net/8021q/vlan.c +12 -12
@@ -99,7 +99,7 @@ static void vlan_rcu_free(struct rcu_head *rcu)void unregister_vlan_dev (struct net_device *dev,struct list_head *head) { -struct vlan_dev_info *vlan =vlan_dev_info (dev); +struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct net_device *real_dev = vlan->real_dev;const struct net_device_ops *ops = real_dev->netdev_ops;struct vlan_group *grp;
@@ -167,7 +167,7 @@ int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)int register_vlan_dev (struct net_device *dev) { -struct vlan_dev_info *vlan =vlan_dev_info (dev); +struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct net_device *real_dev = vlan->real_dev;const struct net_device_ops *ops = real_dev->netdev_ops;u16 vlan_id = vlan->vlan_id;
@@ -192,7 +192,7 @@ int register_vlan_dev(struct net_device *dev)if (err <0 ) goto out_uninit_applicant; -/* Account for reference in struct vlan_dev_info */ +/* Account for reference in struct vlan_dev_priv */ dev_hold (real_dev);netif_stacked_transfer_operstate (real_dev, dev);
@@ -267,7 +267,7 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)snprintf (name,IFNAMSIZ ,"vlan%.4i" , vlan_id); } - new_dev =alloc_netdev (sizeof (struct vlan_dev_info ), name, vlan_setup); + new_dev =alloc_netdev (sizeof (struct vlan_dev_priv ), name, vlan_setup);if (new_dev ==NULL )return -ENOBUFS ;
@@ -278,10 +278,10 @@ static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)*/ new_dev->mtu = real_dev->mtu; -vlan_dev_info (new_dev)->vlan_id = vlan_id; -vlan_dev_info (new_dev)->real_dev = real_dev; -vlan_dev_info (new_dev)->dent =NULL ; -vlan_dev_info (new_dev)->flags =VLAN_FLAG_REORDER_HDR ; +vlan_dev_priv (new_dev)->vlan_id = vlan_id; +vlan_dev_priv (new_dev)->real_dev = real_dev; +vlan_dev_priv (new_dev)->dent =NULL ; +vlan_dev_priv (new_dev)->flags =VLAN_FLAG_REORDER_HDR ; new_dev->rtnl_link_ops = &vlan_link_ops; err =register_vlan_dev (new_dev);
@@ -298,7 +298,7 @@ out_free_newdev:static void vlan_sync_address (struct net_device *dev,struct net_device *vlandev) { -struct vlan_dev_info *vlan =vlan_dev_info (vlandev); +struct vlan_dev_priv *vlan =vlan_dev_priv (vlandev);/* May be called without an actual change */ if (!compare_ether_addr (vlan->real_dev_addr, dev->dev_addr))
@@ -362,7 +362,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,struct vlan_group *grp;int i, flgs;struct net_device *vlandev; -struct vlan_dev_info *vlan; +struct vlan_dev_priv *vlan;LIST_HEAD (list);if (is_vlan_dev (dev))
@@ -447,7 +447,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,if (!(flgs &IFF_UP ))continue ; - vlan =vlan_dev_info (vlandev); + vlan =vlan_dev_priv (vlandev);if (!(vlan->flags &VLAN_FLAG_LOOSE_BINDING ))dev_change_flags (vlandev, flgs & ~IFF_UP );netif_stacked_transfer_operstate (dev, vlandev);
@@ -465,7 +465,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,if (flgs &IFF_UP )continue ; - vlan =vlan_dev_info (vlandev); + vlan =vlan_dev_priv (vlandev);if (!(vlan->flags &VLAN_FLAG_LOOSE_BINDING ))dev_change_flags (vlandev, flgs |IFF_UP );netif_stacked_transfer_operstate (dev, vlandev);
net/8021q/vlan.h +4 -4
@@ -41,7 +41,7 @@ struct vlan_pcpu_stats { };/** -* struct vlan_dev_info - VLAN private device data +* struct vlan_dev_priv - VLAN private device data * @nr_ingress_mappings: number of ingress priority mappings * @ingress_priority_map: ingress priority mappings * @nr_egress_mappings: number of egress priority mappings
@@ -53,7 +53,7 @@ struct vlan_pcpu_stats {* @dent: proc dir entry * @vlan_pcpu_stats: ptr to percpu rx stats */ -struct vlan_dev_info { +struct vlan_dev_priv {unsigned int nr_ingress_mappings;u32 ingress_priority_map[8 ];unsigned int nr_egress_mappings;
@@ -69,7 +69,7 @@ struct vlan_dev_info {struct vlan_pcpu_stats __percpu *vlan_pcpu_stats; }; -static inline struct vlan_dev_info *vlan_dev_info (const struct net_device *dev) +static inline struct vlan_dev_priv *vlan_dev_priv (const struct net_device *dev) {return netdev_priv (dev); }
@@ -121,7 +121,7 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head);static inline u32 vlan_get_ingress_priority (struct net_device *dev,u16 vlan_tci) { -struct vlan_dev_info *vip =vlan_dev_info (dev); +struct vlan_dev_priv *vip =vlan_dev_priv (dev);return vip->ingress_priority_map[(vlan_tci >>VLAN_PRIO_SHIFT ) &0x7 ]; }
net/8021q/vlan_core.c +4 -4
@@ -36,7 +36,7 @@ bool vlan_do_receive(struct sk_buff **skbp, bool last_handler) skb->pkt_type =PACKET_HOST ; } -if (!(vlan_dev_info (vlan_dev)->flags &VLAN_FLAG_REORDER_HDR )) { +if (!(vlan_dev_priv (vlan_dev)->flags &VLAN_FLAG_REORDER_HDR )) {unsigned int offset = skb->data -skb_mac_header (skb);/*
@@ -55,7 +55,7 @@ bool vlan_do_receive(struct sk_buff **skbp, bool last_handler) skb->priority =vlan_get_ingress_priority (vlan_dev, skb->vlan_tci); skb->vlan_tci =0 ; - rx_stats =this_cpu_ptr (vlan_dev_info (vlan_dev)->vlan_pcpu_stats); + rx_stats =this_cpu_ptr (vlan_dev_priv (vlan_dev)->vlan_pcpu_stats);u64_stats_update_begin (&rx_stats->syncp); rx_stats->rx_packets++;
@@ -90,13 +90,13 @@ EXPORT_SYMBOL(__vlan_find_dev_deep);struct net_device *vlan_dev_real_dev (const struct net_device *dev) { -return vlan_dev_info (dev)->real_dev; +return vlan_dev_priv (dev)->real_dev; }EXPORT_SYMBOL (vlan_dev_real_dev);u16 vlan_dev_vlan_id (const struct net_device *dev) { -return vlan_dev_info (dev)->vlan_id; +return vlan_dev_priv (dev)->vlan_id; }EXPORT_SYMBOL (vlan_dev_vlan_id);
net/8021q/vlan_dev.c +36 -36
262 lines not on this page · raw message
net/8021q/vlan_gvrp.c +2 -2
@@ -29,7 +29,7 @@ static struct garp_application vlan_gvrp_app __read_mostly = {int vlan_gvrp_request_join (const struct net_device *dev) { -const struct vlan_dev_info *vlan =vlan_dev_info (dev); +const struct vlan_dev_priv *vlan =vlan_dev_priv (dev);__be16 vlan_id =htons (vlan->vlan_id); return garp_request_join(vlan->real_dev, &vlan_gvrp_app,
@@ -38,7 +38,7 @@ int vlan_gvrp_request_join(const struct net_device *dev)void vlan_gvrp_request_leave (const struct net_device *dev) { -const struct vlan_dev_info *vlan =vlan_dev_info (dev); +const struct vlan_dev_priv *vlan =vlan_dev_priv (dev);__be16 vlan_id =htons (vlan->vlan_id); garp_request_leave(vlan->real_dev, &vlan_gvrp_app,
net/8021q/vlan_netlink.c +5 -5
@@ -105,7 +105,7 @@ static int vlan_changelink(struct net_device *dev,static int vlan_newlink (struct net *src_net,struct net_device *dev,struct nlattr *tb[],struct nlattr *data[]) { -struct vlan_dev_info *vlan =vlan_dev_info (dev); +struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct net_device *real_dev;int err;
@@ -149,7 +149,7 @@ static inline size_t vlan_qos_map_size(unsigned int n)static size_t vlan_get_size (const struct net_device *dev) { -struct vlan_dev_info *vlan =vlan_dev_info (dev); +struct vlan_dev_priv *vlan =vlan_dev_priv (dev);return nla_total_size (2 ) +/* IFLA_VLAN_ID */ sizeof(struct ifla_vlan_flags) + /* IFLA_VLAN_FLAGS */
@@ -159,14 +159,14 @@ static size_t vlan_get_size(const struct net_device *dev)static int vlan_fill_info (struct sk_buff *skb,const struct net_device *dev) { -struct vlan_dev_info *vlan =vlan_dev_info (dev); +struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct vlan_priority_tci_mapping *pm;struct ifla_vlan_flags f;struct ifla_vlan_qos_mapping m;struct nlattr *nest;unsigned int i; -NLA_PUT_U16 (skb,IFLA_VLAN_ID ,vlan_dev_info (dev)->vlan_id); +NLA_PUT_U16 (skb,IFLA_VLAN_ID ,vlan_dev_priv (dev)->vlan_id);if (vlan->flags) { f.flags = vlan->flags; f.mask = ~0 ;
@@ -218,7 +218,7 @@ struct rtnl_link_ops vlan_link_ops __read_mostly = { .kind = "vlan", .maxtype = IFLA_VLAN_MAX, .policy = vlan_policy, - .priv_size = sizeof(struct vlan_dev_info), + .priv_size = sizeof(struct vlan_dev_priv), .setup = vlan_setup, .validate = vlan_validate, .newlink = vlan_newlink,
net/8021q/vlanproc.c +21 -21
92 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 3/6 net: introduce vlan_vid_[add/del] and use them instead of direct [add/kill]_vid ndo calls
In reply to Jiri PirkoThis patch adds wrapper for ndo_vlan_rx_add_vid/ndo_vlan_rx_kill_vid functions. Check for NETIF_F_HW_VLAN_FILTER feature is done in this wrapper.
--- drivers/net/bonding/bond_main.c | 53 +++++++++++++++++---------------------- drivers/net/macvlan.c | 10 ++----- drivers/net/team/team.c | 34 +++++++++++++++--------- include/linux/if_vlan.h | 12 +++++++++ net/8021q/vlan.c | 14 +++------ net/8021q/vlan_core.c | 23 +++++++++++++++++ 6 files changed, 87 insertions(+), 59 deletions(-)
drivers/net/bonding/bond_main.c +23 -30
@@ -431,17 +431,13 @@ int bond_dev_queue_xmit(struct bonding *bond, struct sk_buff *skb,static int bond_vlan_rx_add_vid (struct net_device *bond_dev,uint16_t vid) {struct bonding *bond =netdev_priv (bond_dev); -struct slave *slave; +struct slave *slave, *stop_at;int i, res;bond_for_each_slave (bond, slave, i) { -struct net_device *slave_dev = slave->dev; -const struct net_device_ops *slave_ops = slave_dev->netdev_ops; - -if ((slave_dev->features &NETIF_F_HW_VLAN_FILTER ) && - slave_ops->ndo_vlan_rx_add_vid) { - slave_ops->ndo_vlan_rx_add_vid (slave_dev, vid); - } + res =vlan_vid_add (slave->dev, vid); +if (res) + goto unwind; } res =bond_add_vlan (bond, vid);
@@ -452,6 +448,14 @@ static int bond_vlan_rx_add_vid(struct net_device *bond_dev, uint16_t vid) }return 0 ; + +unwind: +/* unwind from head to the slave that failed */ + stop_at = slave; +bond_for_each_slave_from_to (bond, slave, i, bond->first_slave, stop_at) +vlan_vid_del (slave->dev, vid); + +return res; }/**
@@ -465,15 +469,8 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)struct slave *slave;int i, res; -bond_for_each_slave (bond, slave, i) { -struct net_device *slave_dev = slave->dev; -const struct net_device_ops *slave_ops = slave_dev->netdev_ops; - -if ((slave_dev->features &NETIF_F_HW_VLAN_FILTER ) && - slave_ops->ndo_vlan_rx_kill_vid) { - slave_ops->ndo_vlan_rx_kill_vid (slave_dev, vid); - } - } +bond_for_each_slave (bond, slave, i) +vlan_vid_del (slave->dev, vid); res =bond_del_vlan (bond, vid);if (res) {
@@ -488,30 +485,26 @@ static int bond_vlan_rx_kill_vid(struct net_device *bond_dev, uint16_t vid)static void bond_add_vlans_on_slave (struct bonding *bond,struct net_device *slave_dev) {struct vlan_entry *vlan; -const struct net_device_ops *slave_ops = slave_dev->netdev_ops; - -if (!(slave_dev->features &NETIF_F_HW_VLAN_FILTER ) || - !(slave_ops->ndo_vlan_rx_add_vid)) -return ; +int res; -list_for_each_entry (vlan, &bond->vlan_list, vlan_list) - slave_ops->ndo_vlan_rx_add_vid (slave_dev, vlan->vlan_id); +list_for_each_entry (vlan, &bond->vlan_list, vlan_list) { + res =vlan_vid_add (slave_dev, vlan->vlan_id); +if (res) +pr_warning ("%s: Failed to add vlan id %d to device %s\n" , + bond->dev->name, vlan->vlan_id, + slave_dev->name); + } }static void bond_del_vlans_from_slave (struct bonding *bond,struct net_device *slave_dev) { -const struct net_device_ops *slave_ops = slave_dev->netdev_ops;struct vlan_entry *vlan; -if (!(slave_dev->features &NETIF_F_HW_VLAN_FILTER ) || - !(slave_ops->ndo_vlan_rx_kill_vid)) -return ; -list_for_each_entry (vlan, &bond->vlan_list, vlan_list) {if (!vlan->vlan_id)continue ; - slave_ops->ndo_vlan_rx_kill_vid (slave_dev, vlan->vlan_id); +vlan_vid_del (slave_dev, vlan->vlan_id); } }
drivers/net/macvlan.c +3 -7
@@ -26,6 +26,7 @@#include <linux/etherdevice.h> #include <linux/ethtool.h> #include <linux/if_arp.h> +#include <linux/if_vlan.h> #include <linux/if_link.h> #include <linux/if_macvlan.h> #include <net/rtnetlink.h>
@@ -525,11 +526,8 @@ static int macvlan_vlan_rx_add_vid(struct net_device *dev, {struct macvlan_dev *vlan =netdev_priv (dev);struct net_device *lowerdev = vlan->lowerdev; -const struct net_device_ops *ops = lowerdev->netdev_ops; -if (ops->ndo_vlan_rx_add_vid) -return ops->ndo_vlan_rx_add_vid (lowerdev, vid); -return 0 ; +return vlan_vid_add (lowerdev, vid); } static int macvlan_vlan_rx_kill_vid(struct net_device *dev,
@@ -537,10 +535,8 @@ static int macvlan_vlan_rx_kill_vid(struct net_device *dev, {struct macvlan_dev *vlan =netdev_priv (dev);struct net_device *lowerdev = vlan->lowerdev; -const struct net_device_ops *ops = lowerdev->netdev_ops; -if (ops->ndo_vlan_rx_kill_vid) -return ops->ndo_vlan_rx_kill_vid (lowerdev, vid); +vlan_vid_del (lowerdev, vid);return 0 ; }
drivers/net/team/team.c +21 -13
@@ -18,6 +18,7 @@#include <linux/ctype.h> #include <linux/notifier.h> #include <linux/netdevice.h> +#include <linux/if_vlan.h> #include <linux/if_arp.h> #include <linux/socket.h> #include <linux/etherdevice.h>
@@ -906,17 +907,28 @@ static int team_vlan_rx_add_vid(struct net_device *dev, uint16_t vid) {struct team *team =netdev_priv (dev);struct team_port *port; +int err; -rcu_read_lock (); -list_for_each_entry_rcu (port, &team->port_list, list) { -const struct net_device_ops *ops = port->dev->netdev_ops; - -if (ops->ndo_vlan_rx_add_vid) - ops->ndo_vlan_rx_add_vid (port->dev, vid); +/* +* Alhough this is reader, it's guarded by team lock. It's not possible +* to traverse list in reverse under rcu_read_lock +*/ +mutex_lock (&team->lock); +list_for_each_entry (port, &team->port_list, list) { + err =vlan_vid_add (port->dev, vid); +if (err) + goto unwind; } -rcu_read_unlock (); +mutex_unlock (&team->lock);return 0 ; + +unwind: +list_for_each_entry_continue_reverse (port, &team->port_list, list) +vlan_vid_del (port->dev, vid); +mutex_unlock (&team->lock); + +return err; }static int team_vlan_rx_kill_vid (struct net_device *dev,uint16_t vid)
@@ -925,12 +937,8 @@ static int team_vlan_rx_kill_vid(struct net_device *dev, uint16_t vid)struct team_port *port;rcu_read_lock (); -list_for_each_entry_rcu (port, &team->port_list, list) { -const struct net_device_ops *ops = port->dev->netdev_ops; - -if (ops->ndo_vlan_rx_kill_vid) - ops->ndo_vlan_rx_kill_vid (port->dev, vid); - } +list_for_each_entry_rcu (port, &team->port_list, list) +vlan_vid_del (port->dev, vid);rcu_read_unlock ();return 0 ;
include/linux/if_vlan.h +12 -0
@@ -109,6 +109,9 @@ extern u16 vlan_dev_vlan_id(const struct net_device *dev);extern bool vlan_do_receive (struct sk_buff **skb,bool last_handler);extern struct sk_buff *vlan_untag (struct sk_buff *skb); +extern int vlan_vid_add (struct net_device *dev,unsigned short vid); +extern void vlan_vid_del (struct net_device *dev,unsigned short vid); +#else static inline struct net_device *__vlan_find_dev_deep (struct net_device *real_dev,u16 vlan_id)
@@ -139,6 +142,15 @@ static inline struct sk_buff *vlan_untag(struct sk_buff *skb) {return skb; } + +static inline int vlan_vid_add (struct net_device *dev,unsigned short vid) +{ +return 0 ; +} + +static inline void vlan_vid_del (struct net_device *dev,unsigned short vid) +{ +}#endif /**
net/8021q/vlan.c +5 -9
@@ -101,7 +101,6 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head) {struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct net_device *real_dev = vlan->real_dev; -const struct net_device_ops *ops = real_dev->netdev_ops;struct vlan_group *grp;u16 vlan_id = vlan->vlan_id;
@@ -114,8 +113,8 @@ void unregister_vlan_dev(struct net_device *dev, struct list_head *head)* HW accelerating devices or SW vlan input packet processing if * VLAN is not 0 (leave it there for 802.1p). */ -if (vlan_id && (real_dev->features &NETIF_F_HW_VLAN_FILTER )) - ops->ndo_vlan_rx_kill_vid (real_dev, vlan_id); +if (vlan_id) +vlan_vid_del (real_dev, vlan_id); grp->nr_vlans--;
@@ -169,7 +168,6 @@ int register_vlan_dev(struct net_device *dev) {struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct net_device *real_dev = vlan->real_dev; -const struct net_device_ops *ops = real_dev->netdev_ops;u16 vlan_id = vlan->vlan_id;struct vlan_group *grp, *ngrp =NULL ;int err;
@@ -207,8 +205,7 @@ int register_vlan_dev(struct net_device *dev)if (ngrp) {rcu_assign_pointer (real_dev->vlgrp, ngrp); } -if (real_dev->features &NETIF_F_HW_VLAN_FILTER ) - ops->ndo_vlan_rx_add_vid (real_dev, vlan_id); +vlan_vid_add (real_dev, vlan_id);return 0 ;
@@ -369,11 +366,10 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,__vlan_device_event (dev, event);if ((event ==NETDEV_UP ) && - (dev->features &NETIF_F_HW_VLAN_FILTER ) && - dev->netdev_ops->ndo_vlan_rx_add_vid) { + (dev->features &NETIF_F_HW_VLAN_FILTER )) {pr_info ("adding VLAN 0 to HW filter on device %s\n" , dev->name); - dev->netdev_ops->ndo_vlan_rx_add_vid (dev,0 ); +vlan_vid_add (dev,0 ); } grp =rtnl_dereference (dev->vlgrp);
net/8021q/vlan_core.c +23 -0
@@ -146,3 +146,26 @@ err_free:kfree_skb (skb);return NULL ; } + +int vlan_vid_add (struct net_device *dev,unsigned short vid) +{ +const struct net_device_ops *ops = dev->netdev_ops; + +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + ops->ndo_vlan_rx_add_vid) { +return ops->ndo_vlan_rx_add_vid (dev, vid); + } +return 0 ; +} +EXPORT_SYMBOL (vlan_vid_add); + +void vlan_vid_del (struct net_device *dev,unsigned short vid) +{ +const struct net_device_ops *ops = dev->netdev_ops; + +if ((dev->features &NETIF_F_HW_VLAN_FILTER ) && + ops->ndo_vlan_rx_kill_vid) { + ops->ndo_vlan_rx_kill_vid (dev, vid); + } +} +EXPORT_SYMBOL (vlan_vid_del);
Signature · 1 line
1.7.6
PATCH 4/6 vlan: introduce vid list with reference counting
In reply to Jiri PirkoThis allows to keep track of vids needed to be in rx vlan filters of devices even if they are used in bond/team etc.
vlan_info as well as vlan_group previously was, is allocated when first vid is added and dealocated whan last vid is deleted.
vlan_group definition is moved to private header.
--- include/linux/if_vlan.h | 17 +---- include/linux/netdevice.h | 3 +- net/8021q/vlan.c | 90 ++++++++---------------- net/8021q/vlan.h | 30 +++++++- net/8021q/vlan_core.c | 168 ++++++++++++++++++++++++++++++++++++++++++-- 5 files changed, 219 insertions(+), 89 deletions(-)
include/linux/if_vlan.h +1 -16
@@ -74,22 +74,7 @@ static inline struct vlan_ethhdr *vlan_eth_hdr(const struct sk_buff *skb)/* found in socket.c */ extern void vlan_ioctl_set (int (*hook)(struct net *,void __user *)); -/* if this changes, algorithm will have to be reworked because this -* depends on completely exhausting the VLAN identifier space. Thus -* it gives constant time look-up, but in many cases it wastes memory. -*/ -#define VLAN_GROUP_ARRAY_SPLIT_PARTS 8 -#define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS) - -struct vlan_group { -struct net_device *real_dev;/* The ethernet(like) device -* the vlan is attached to. -*/ -unsigned int nr_vlans; -struct hlist_node hlist;/* linked list */ -struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS ]; -struct rcu_head rcu; -}; +struct vlan_info ;static inline int is_vlan_dev (struct net_device *dev) {
include/linux/netdevice.h +1 -2
@@ -55,7 +55,6 @@#include <linux/netdev_features.h> -struct vlan_group ;struct netpoll_info ;struct phy_device ;/* 802.11 specific */
@@ -1096,7 +1095,7 @@ struct net_device {/* Protocol specific pointers */ #if IS_ENABLED (CONFIG_VLAN_8021Q ) -struct vlan_group __rcu *vlgrp;/* VLAN group */ +struct vlan_info __rcu *vlan_info;/* VLAN info */ #endif #if IS_ENABLED (CONFIG_NET_DSA )struct dsa_switch_tree *dsa_ptr;/* dsa specific data */
net/8021q/vlan.c +30 -60
166 lines not on this page · raw message
net/8021q/vlan.h +27 -3
@@ -3,6 +3,7 @@#include <linux/if_vlan.h> #include <linux/u64_stats_sync.h> +#include <linux/list.h> /**
@@ -74,6 +75,29 @@ static inline struct vlan_dev_priv *vlan_dev_priv(const struct net_device *dev)return netdev_priv (dev); } +/* if this changes, algorithm will have to be reworked because this +* depends on completely exhausting the VLAN identifier space. Thus +* it gives constant time look-up, but in many cases it wastes memory. +*/ +#define VLAN_GROUP_ARRAY_SPLIT_PARTS 8 +#define VLAN_GROUP_ARRAY_PART_LEN (VLAN_N_VID/VLAN_GROUP_ARRAY_SPLIT_PARTS) + +struct vlan_group { +unsigned int nr_vlan_devs; +struct hlist_node hlist;/* linked list */ +struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS ]; +}; + +struct vlan_info { +struct net_device *real_dev;/* The ethernet(like) device +* the vlan is attached to. +*/ +struct vlan_group grp; +struct list_head vid_list; +unsigned int nr_vids; +struct rcu_head rcu; +}; +static inline struct net_device *vlan_group_get_device (struct vlan_group *vg,u16 vlan_id) {
@@ -97,10 +121,10 @@ static inline void vlan_group_set_device(struct vlan_group *vg,static inline struct net_device *vlan_find_dev (struct net_device *real_dev,u16 vlan_id) { -struct vlan_group *grp =rcu_dereference_rtnl (real_dev->vlgrp); +struct vlan_info *vlan_info =rcu_dereference_rtnl (real_dev->vlan_info); -if (grp) -return vlan_group_get_device (grp, vlan_id); +if (vlan_info) +return vlan_group_get_device (&vlan_info->grp, vlan_id);return NULL ; }
net/8021q/vlan_core.c +160 -8
195 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 5/6 vlan: introduce functions to do mass addition/deletion of vids by another device
In reply to Jiri PirkoIntroduce functions handy to copy vlan ids from one driver's list to another.
--- include/linux/if_vlan.h | 15 +++++++++++++++ net/8021q/vlan_core.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 0 deletions(-)
include/linux/if_vlan.h +15 -0
@@ -97,6 +97,10 @@ extern struct sk_buff *vlan_untag(struct sk_buff *skb);extern int vlan_vid_add (struct net_device *dev,unsigned short vid);extern void vlan_vid_del (struct net_device *dev,unsigned short vid); +extern int vlan_vids_add_by_dev (struct net_device *dev, +const struct net_device *by_dev); +extern void vlan_vids_del_by_dev (struct net_device *dev, +const struct net_device *by_dev);#else static inline struct net_device *__vlan_find_dev_deep (struct net_device *real_dev,u16 vlan_id)
@@ -136,6 +140,17 @@ static inline int vlan_vid_add(struct net_device *dev, unsigned short vid)static inline void vlan_vid_del (struct net_device *dev,unsigned short vid) { } + +static inline int vlan_vids_add_by_dev (struct net_device *dev, +const struct net_device *by_dev) +{ +return 0 ; +} + +static inline void vlan_vids_del_by_dev (struct net_device *dev, +const struct net_device *by_dev) +{ +}#endif /**
net/8021q/vlan_core.c +44 -0
47 lines not on this page · raw message
Signature · 1 line
1.7.6
PATCH 6/6 team: use vlan_vids_[addr/del]_by_dev
In reply to Jiri PirkoSo far when vlan id was added to team device befor port was added, this vid was not added to port's vlan filter. Also after removal, vid stayed in port device's vlan filter. Benefit of new vlan functions to handle this work.
--- drivers/net/team/team.c | 11 +++++++++++ 1 files changed, 11 insertions(+), 0 deletions(-)
drivers/net/team/team.c +11 -0
@@ -588,6 +588,13 @@ static int team_port_add(struct team *team, struct net_device *port_dev) goto err_dev_open; } + err =vlan_vids_add_by_dev (port_dev, dev); +if (err) { +netdev_err (dev,"Failed to add vlan ids to device %s\n" , + portname); + goto err_vids_add; + } + err =netdev_set_master (port_dev, dev);if (err) {netdev_err (dev,"Device %s failed to set master\n" , portname);
@@ -615,6 +622,9 @@ err_handler_register:netdev_set_master (port_dev,NULL ); err_set_master: +vlan_vids_del_by_dev (port_dev, dev); + +err_vids_add:dev_close (port_dev); err_dev_open:
@@ -648,6 +658,7 @@ static int team_port_del(struct team *team, struct net_device *port_dev)team_adjust_ops (team);netdev_rx_handler_unregister (port_dev);netdev_set_master (port_dev,NULL ); +vlan_vids_del_by_dev (port_dev, dev);dev_close (port_dev);team_port_leave (team, port);team_port_set_orig_mac (port);
Signature · 1 line
1.7.6
David Miller
maintainerFrom: Jiri Pirko <[email protected]>
Date: Thu, 8 Dec 2011 15:11:14 +0100
Quoted 10 lines
Many drivers store vlan ids in their private structures.
They are maintaining the private lists invlan_add_vidandvlan_kill_vid.This patchset creates an infrastructure of storing vlan ids in one place, vlan core. Another benefit of this is that it allows to keep track of vlan ids needed. For example if eth0 has vlan id 10 on it, then it enters bonding, bonding gets added 10 as well, then eth0 leaves bonding. Final step would remove vlan id 10 from eth1 vlan filter resulting in potentially unfunction vlan device. This patchset fixes this.
Quoted 9 lines
Jiri Pirko (6):
vlan: renamevlan_dev_infotovlan_dev_priv
net: make vlan ndo_vlan_rx_[add/kill]_vid return error value
net: introduce vlan_vid_[add/del] and use them instead of direct
[add/kill]_vid ndo calls
vlan: introduce vid list with reference counting
vlan: introduce functions to do mass addition/deletion of vids by
another device
team: use vlan_vids_[addr/del]_by_dev
All applied.
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [patch net-next 2/6] net: make vlan ndo_vlan_rx_[add/kill]_vid return error value
Quoted 28 lines · Fri, Dec 09, 2011 at 06:45:16AM CET, [email protected] wrote:
Quoted 6 lines · Jiri Pirko
Let caller know the result of adding/removing vlan id to/from vlan filter.
In some drivers I make those functions to just return 0. But in those where there is able to see if hw setup went correctly, return value is set appropriately.
...
Quoted 20 lines
drivers/net/virtio_net.c +2
-1@@ -855,7 +855,7 @@ static void virtnet_set_rx_mode(struct net_device *dev)kfree (buf); } -static void virtnet_vlan_rx_add_vid (struct net_device *dev,u16 vid) +static int virtnet_vlan_rx_add_vid (struct net_device *dev,u16 vid) {struct virtnet_info *vi =netdev_priv (dev);struct scatterlist sg;@@ -865,9 +865,10 @@ static void virtnet_vlan_rx_add_vid(struct net_device *dev, u16 vid)if (!virtnet_send_command (vi,VIRTIO_NET_CTRL_VLAN ,VIRTIO_NET_CTRL_VLAN_ADD , &sg,1 ,0 ))dev_warn (&dev->dev,"Failed to add VLAN ID %d.\n" , vid); +return 0 ; }
Quoted 15 lines
drivers/net/virtio_net.c static void virtnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid) · line 882
Quoted 11 lines
drivers/net/virtio_net.c +2
-1-static void virtnet_vlan_rx_kill_vid (struct net_device *dev,u16 vid) +static int virtnet_vlan_rx_kill_vid (struct net_device *dev,u16 vid) {struct virtnet_info *vi =netdev_priv (dev);struct scatterlist sg;@@ -877,6 +878,7 @@ static void virtnet_vlan_rx_kill_vid(struct net_device *dev, u16 vid)if (!virtnet_send_command (vi,VIRTIO_NET_CTRL_VLAN ,VIRTIO_NET_CTRL_VLAN_DEL , &sg,1 ,0 ))dev_warn (&dev->dev,"Failed to kill VLAN ID %d.\n" , vid); +return 0 ; }Hmm, see that
virtnet_send_command? That's what you're after. You could even replace thedev_warn(), if you're doing something more useful with the result.
I was not sure what value to return here so I let that be as it was. Feel free to post follow-up.
Thanks
Jirka
Quoted 3 lines
Thanks,
Rusty.