net: Call add/kill vid ndo on vlan filter feature toggling
authorGal Pressman <galp@mellanox.com>
Wed, 28 Mar 2018 14:46:54 +0000 (17:46 +0300)
committerDavid S. Miller <davem@davemloft.net>
Fri, 30 Mar 2018 13:58:59 +0000 (09:58 -0400)
NETIF_F_HW_VLAN_[CS]TAG_FILTER features require more than just a bit
flip in dev->features in order to keep the driver in a consistent state.
These features notify the driver of each added/removed vlan, but toggling
of vlan-filter does not notify the driver accordingly for each of the
existing vlans.

This patch implements a similar solution to NETIF_F_RX_UDP_TUNNEL_PORT
behavior (which notifies the driver about UDP ports in the same manner
that vids are reported).

Each toggling of the features propagates to the 8021q module, which
iterates over the vlans and call add/kill ndo accordingly.

Signed-off-by: Gal Pressman <galp@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/linux/if_vlan.h
include/linux/netdevice.h
net/8021q/vlan.c
net/8021q/vlan.h
net/8021q/vlan_core.c
net/core/dev.c

index c4a1cff9c76861b3eef7b1eea97d8591532bf798..24d1976c1e617d4536638e94667926ddbb89fdc7 100644 (file)
@@ -83,6 +83,30 @@ static inline bool is_vlan_dev(const struct net_device *dev)
 #define skb_vlan_tag_get_id(__skb)     ((__skb)->vlan_tci & VLAN_VID_MASK)
 #define skb_vlan_tag_get_prio(__skb)   ((__skb)->vlan_tci & VLAN_PRIO_MASK)
 
+static inline int vlan_get_rx_ctag_filter_info(struct net_device *dev)
+{
+       ASSERT_RTNL();
+       return notifier_to_errno(call_netdevice_notifiers(NETDEV_CVLAN_FILTER_PUSH_INFO, dev));
+}
+
+static inline void vlan_drop_rx_ctag_filter_info(struct net_device *dev)
+{
+       ASSERT_RTNL();
+       call_netdevice_notifiers(NETDEV_CVLAN_FILTER_DROP_INFO, dev);
+}
+
+static inline int vlan_get_rx_stag_filter_info(struct net_device *dev)
+{
+       ASSERT_RTNL();
+       return notifier_to_errno(call_netdevice_notifiers(NETDEV_SVLAN_FILTER_PUSH_INFO, dev));
+}
+
+static inline void vlan_drop_rx_stag_filter_info(struct net_device *dev)
+{
+       ASSERT_RTNL();
+       call_netdevice_notifiers(NETDEV_SVLAN_FILTER_DROP_INFO, dev);
+}
+
 /**
  *     struct vlan_pcpu_stats - VLAN percpu rx/tx stats
  *     @rx_packets: number of received packets
index 2a2d9cf50aa2560068e1d7c719a1e87e4ef8079b..da44dab492e36ff322db0c1f96d7e4eeec9e27e8 100644 (file)
@@ -2349,6 +2349,10 @@ enum netdev_cmd {
        NETDEV_UDP_TUNNEL_PUSH_INFO,
        NETDEV_UDP_TUNNEL_DROP_INFO,
        NETDEV_CHANGE_TX_QUEUE_LEN,
+       NETDEV_CVLAN_FILTER_PUSH_INFO,
+       NETDEV_CVLAN_FILTER_DROP_INFO,
+       NETDEV_SVLAN_FILTER_PUSH_INFO,
+       NETDEV_SVLAN_FILTER_DROP_INFO,
 };
 const char *netdev_cmd_to_name(enum netdev_cmd cmd);
 
index bad01b14a4ad6b5d4e61ac5e0ed93022755223ab..5505ee6ebdbe63ec717bad318f1385d41e5e3582 100644 (file)
@@ -360,6 +360,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
        struct vlan_dev_priv *vlan;
        bool last = false;
        LIST_HEAD(list);
+       int err;
 
        if (is_vlan_dev(dev)) {
                int err = __vlan_device_event(dev, event);
@@ -489,6 +490,26 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,
                vlan_group_for_each_dev(grp, i, vlandev)
                        call_netdevice_notifiers(event, vlandev);
                break;
+
+       case NETDEV_CVLAN_FILTER_PUSH_INFO:
+               err = vlan_filter_push_vids(vlan_info, htons(ETH_P_8021Q));
+               if (err)
+                       return notifier_from_errno(err);
+               break;
+
+       case NETDEV_CVLAN_FILTER_DROP_INFO:
+               vlan_filter_drop_vids(vlan_info, htons(ETH_P_8021Q));
+               break;
+
+       case NETDEV_SVLAN_FILTER_PUSH_INFO:
+               err = vlan_filter_push_vids(vlan_info, htons(ETH_P_8021AD));
+               if (err)
+                       return notifier_from_errno(err);
+               break;
+
+       case NETDEV_SVLAN_FILTER_DROP_INFO:
+               vlan_filter_drop_vids(vlan_info, htons(ETH_P_8021AD));
+               break;
        }
 
 out:
index a8ba51030b75e4433f6f8ff792c32a216473d8c4..e23aac3e4d377e8d4b574e66cd0c12ed8be01c27 100644 (file)
@@ -97,6 +97,9 @@ static inline struct net_device *vlan_find_dev(struct net_device *real_dev,
                if (((dev) = __vlan_group_get_device((grp), (i) / VLAN_N_VID, \
                                                            (i) % VLAN_N_VID)))
 
+int vlan_filter_push_vids(struct vlan_info *vlan_info, __be16 proto);
+void vlan_filter_drop_vids(struct vlan_info *vlan_info, __be16 proto);
+
 /* found in vlan_dev.c */
 void vlan_dev_set_ingress_priority(const struct net_device *dev,
                                   u32 skb_prio, u16 vlan_prio);
index 45c9bf5ff3a0c1f33d5e9443f9237b1277df6502..c8d7abdc046306da668d3733d42550e7a31081dc 100644 (file)
@@ -165,13 +165,12 @@ struct vlan_vid_info {
        int refcount;
 };
 
-static bool vlan_hw_filter_capable(const struct net_device *dev,
-                                    const struct vlan_vid_info *vid_info)
+bool vlan_hw_filter_capable(const struct net_device *dev, __be16 proto)
 {
-       if (vid_info->proto == htons(ETH_P_8021Q) &&
+       if (proto == htons(ETH_P_8021Q) &&
            dev->features & NETIF_F_HW_VLAN_CTAG_FILTER)
                return true;
-       if (vid_info->proto == htons(ETH_P_8021AD) &&
+       if (proto == htons(ETH_P_8021AD) &&
            dev->features & NETIF_F_HW_VLAN_STAG_FILTER)
                return true;
        return false;
@@ -202,11 +201,73 @@ static struct vlan_vid_info *vlan_vid_info_alloc(__be16 proto, u16 vid)
        return vid_info;
 }
 
+static int vlan_add_rx_filter_info(struct net_device *dev, __be16 proto, u16 vid)
+{
+       if (!vlan_hw_filter_capable(dev, proto))
+               return 0;
+
+       if (netif_device_present(dev))
+               return dev->netdev_ops->ndo_vlan_rx_add_vid(dev, proto, vid);
+       else
+               return -ENODEV;
+}
+
+static int vlan_kill_rx_filter_info(struct net_device *dev, __be16 proto, u16 vid)
+{
+       if (!vlan_hw_filter_capable(dev, proto))
+               return 0;
+
+       if (netif_device_present(dev))
+               return dev->netdev_ops->ndo_vlan_rx_kill_vid(dev, proto, vid);
+       else
+               return -ENODEV;
+}
+
+int vlan_filter_push_vids(struct vlan_info *vlan_info, __be16 proto)
+{
+       struct net_device *real_dev = vlan_info->real_dev;
+       struct vlan_vid_info *vlan_vid_info;
+       int err;
+
+       list_for_each_entry(vlan_vid_info, &vlan_info->vid_list, list) {
+               if (vlan_vid_info->proto == proto) {
+                       err = vlan_add_rx_filter_info(real_dev, proto,
+                                                     vlan_vid_info->vid);
+                       if (err)
+                               goto unwind;
+               }
+       }
+
+       return 0;
+
+unwind:
+       list_for_each_entry_continue_reverse(vlan_vid_info,
+                                            &vlan_info->vid_list, list) {
+               if (vlan_vid_info->proto == proto)
+                       vlan_kill_rx_filter_info(real_dev, proto,
+                                                vlan_vid_info->vid);
+       }
+
+       return err;
+}
+EXPORT_SYMBOL(vlan_filter_push_vids);
+
+void vlan_filter_drop_vids(struct vlan_info *vlan_info, __be16 proto)
+{
+       struct vlan_vid_info *vlan_vid_info;
+
+       list_for_each_entry(vlan_vid_info, &vlan_info->vid_list, list)
+               if (vlan_vid_info->proto == proto)
+                       vlan_kill_rx_filter_info(vlan_info->real_dev,
+                                                vlan_vid_info->proto,
+                                                vlan_vid_info->vid);
+}
+EXPORT_SYMBOL(vlan_filter_drop_vids);
+
 static int __vlan_vid_add(struct vlan_info *vlan_info, __be16 proto, u16 vid,
                          struct vlan_vid_info **pvid_info)
 {
        struct net_device *dev = vlan_info->real_dev;
-       const struct net_device_ops *ops = dev->netdev_ops;
        struct vlan_vid_info *vid_info;
        int err;
 
@@ -214,16 +275,12 @@ static int __vlan_vid_add(struct vlan_info *vlan_info, __be16 proto, u16 vid,
        if (!vid_info)
                return -ENOMEM;
 
-       if (vlan_hw_filter_capable(dev, vid_info)) {
-               if (netif_device_present(dev))
-                       err = ops->ndo_vlan_rx_add_vid(dev, proto, vid);
-               else
-                       err = -ENODEV;
-               if (err) {
-                       kfree(vid_info);
-                       return err;
-               }
+       err = vlan_add_rx_filter_info(dev, proto, vid);
+       if (err) {
+               kfree(vid_info);
+               return err;
        }
+
        list_add(&vid_info->list, &vlan_info->vid_list);
        vlan_info->nr_vids++;
        *pvid_info = vid_info;
@@ -270,21 +327,15 @@ static void __vlan_vid_del(struct vlan_info *vlan_info,
                           struct vlan_vid_info *vid_info)
 {
        struct net_device *dev = vlan_info->real_dev;
-       const struct net_device_ops *ops = dev->netdev_ops;
        __be16 proto = vid_info->proto;
        u16 vid = vid_info->vid;
        int err;
 
-       if (vlan_hw_filter_capable(dev, vid_info)) {
-               if (netif_device_present(dev))
-                       err = ops->ndo_vlan_rx_kill_vid(dev, proto, vid);
-               else
-                       err = -ENODEV;
-               if (err) {
-                       pr_warn("failed to kill vid %04x/%d for device %s\n",
-                               proto, vid, dev->name);
-               }
-       }
+       err = vlan_kill_rx_filter_info(dev, proto, vid);
+       if (err)
+               pr_warn("failed to kill vid %04x/%d for device %s\n",
+                       proto, vid, dev->name);
+
        list_del(&vid_info->list);
        kfree(vid_info);
        vlan_info->nr_vids--;
index eca5458b2753dc5103f79519ba1c8d087a471e7e..1ddb6b9c58a87da4446f23f04ff7589b47cb1cfa 100644 (file)
@@ -1584,6 +1584,8 @@ const char *netdev_cmd_to_name(enum netdev_cmd cmd)
        N(RESEND_IGMP) N(PRECHANGEMTU) N(CHANGEINFODATA) N(BONDING_INFO)
        N(PRECHANGEUPPER) N(CHANGELOWERSTATE) N(UDP_TUNNEL_PUSH_INFO)
        N(UDP_TUNNEL_DROP_INFO) N(CHANGE_TX_QUEUE_LEN)
+       N(CVLAN_FILTER_PUSH_INFO) N(CVLAN_FILTER_DROP_INFO)
+       N(SVLAN_FILTER_PUSH_INFO) N(SVLAN_FILTER_DROP_INFO)
        };
 #undef N
        return "UNKNOWN_NETDEV_EVENT";
@@ -7665,6 +7667,24 @@ sync_lower:
                        }
                }
 
+               if (diff & NETIF_F_HW_VLAN_CTAG_FILTER) {
+                       if (features & NETIF_F_HW_VLAN_CTAG_FILTER) {
+                               dev->features = features;
+                               err |= vlan_get_rx_ctag_filter_info(dev);
+                       } else {
+                               vlan_drop_rx_ctag_filter_info(dev);
+                       }
+               }
+
+               if (diff & NETIF_F_HW_VLAN_STAG_FILTER) {
+                       if (features & NETIF_F_HW_VLAN_STAG_FILTER) {
+                               dev->features = features;
+                               err |= vlan_get_rx_stag_filter_info(dev);
+                       } else {
+                               vlan_drop_rx_stag_filter_info(dev);
+                       }
+               }
+
                dev->features = features;
        }