vlan: introduce functions to do mass addition/deletion of vids by another device
Jiri Pirko [Thu, 8 Dec 2011 04:11:19 +0000 (04:11 +0000)]
Introduce functions handy to copy vlan ids from one driver's list to
another.

Signed-off-by: Jiri Pirko <jpirko@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

include/linux/if_vlan.h
net/8021q/vlan_core.c

index 0c96913..13aff1e 100644 (file)
@@ -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
 
 /**
index 329e031..1414c93 100644 (file)
@@ -321,3 +321,47 @@ void vlan_vid_del(struct net_device *dev, unsigned short vid)
        }
 }
 EXPORT_SYMBOL(vlan_vid_del);
+
+int vlan_vids_add_by_dev(struct net_device *dev,
+                        const struct net_device *by_dev)
+{
+       struct vlan_vid_info *vid_info;
+       int err;
+
+       ASSERT_RTNL();
+
+       if (!by_dev->vlan_info)
+               return 0;
+
+       list_for_each_entry(vid_info, &by_dev->vlan_info->vid_list, list) {
+               err = vlan_vid_add(dev, vid_info->vid);
+               if (err)
+                       goto unwind;
+       }
+       return 0;
+
+unwind:
+       list_for_each_entry_continue_reverse(vid_info,
+                                            &by_dev->vlan_info->vid_list,
+                                            list) {
+               vlan_vid_del(dev, vid_info->vid);
+       }
+
+       return err;
+}
+EXPORT_SYMBOL(vlan_vids_add_by_dev);
+
+void vlan_vids_del_by_dev(struct net_device *dev,
+                         const struct net_device *by_dev)
+{
+       struct vlan_vid_info *vid_info;
+
+       ASSERT_RTNL();
+
+       if (!by_dev->vlan_info)
+               return;
+
+       list_for_each_entry(vid_info, &by_dev->vlan_info->vid_list, list)
+               vlan_vid_del(dev, vid_info->vid);
+}
+EXPORT_SYMBOL(vlan_vids_del_by_dev);