Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 1 | #include <linux/skbuff.h> |
| 2 | #include <linux/netdevice.h> |
| 3 | #include <linux/if_vlan.h> |
Herbert Xu | 4ead443 | 2009-03-01 00:11:52 -0800 | [diff] [blame] | 4 | #include <linux/netpoll.h> |
Paul Gortmaker | bc3b2d7 | 2011-07-15 11:47:34 -0400 | [diff] [blame] | 5 | #include <linux/export.h> |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 6 | #include "vlan.h" |
| 7 | |
Florian Zumbiehl | 48cc32d3 | 2012-10-07 15:51:58 +0000 | [diff] [blame] | 8 | bool vlan_do_receive(struct sk_buff **skbp) |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 9 | { |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 10 | struct sk_buff *skb = *skbp; |
| 11 | u16 vlan_id = skb->vlan_tci & VLAN_VID_MASK; |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 12 | struct net_device *vlan_dev; |
Eric Dumazet | 4af429d | 2010-11-10 23:42:00 +0000 | [diff] [blame] | 13 | struct vlan_pcpu_stats *rx_stats; |
Pedro Garcia | ad1afb0 | 2010-07-18 15:38:44 -0700 | [diff] [blame] | 14 | |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 15 | vlan_dev = vlan_find_dev(skb->dev, vlan_id); |
Florian Zumbiehl | 48cc32d3 | 2012-10-07 15:51:58 +0000 | [diff] [blame] | 16 | if (!vlan_dev) |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 17 | return false; |
Patrick McHardy | 9b22ea5 | 2008-11-04 14:49:57 -0800 | [diff] [blame] | 18 | |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 19 | skb = *skbp = skb_share_check(skb, GFP_ATOMIC); |
| 20 | if (unlikely(!skb)) |
| 21 | return false; |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 22 | |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 23 | skb->dev = vlan_dev; |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 24 | if (skb->pkt_type == PACKET_OTHERHOST) { |
| 25 | /* Our lower layer thinks this is not local, let's make sure. |
| 26 | * This allows the VLAN to have a different MAC than the |
| 27 | * underlying device, and still route correctly. */ |
Joe Perches | 53a2b3a | 2012-05-08 18:56:47 +0000 | [diff] [blame] | 28 | if (ether_addr_equal(eth_hdr(skb)->h_dest, vlan_dev->dev_addr)) |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 29 | skb->pkt_type = PACKET_HOST; |
| 30 | } |
| 31 | |
Jiri Pirko | 7da82c0 | 2011-12-08 04:11:15 +0000 | [diff] [blame] | 32 | if (!(vlan_dev_priv(vlan_dev)->flags & VLAN_FLAG_REORDER_HDR)) { |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 33 | unsigned int offset = skb->data - skb_mac_header(skb); |
| 34 | |
| 35 | /* |
| 36 | * vlan_insert_tag expect skb->data pointing to mac header. |
| 37 | * So change skb->data before calling it and change back to |
| 38 | * original position later |
| 39 | */ |
| 40 | skb_push(skb, offset); |
| 41 | skb = *skbp = vlan_insert_tag(skb, skb->vlan_tci); |
| 42 | if (!skb) |
| 43 | return false; |
| 44 | skb_pull(skb, offset + VLAN_HLEN); |
| 45 | skb_reset_mac_len(skb); |
| 46 | } |
| 47 | |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 48 | skb->priority = vlan_get_ingress_priority(vlan_dev, skb->vlan_tci); |
Patrick McHardy | bc1d041 | 2008-07-14 22:49:30 -0700 | [diff] [blame] | 49 | skb->vlan_tci = 0; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 50 | |
Jiri Pirko | 7da82c0 | 2011-12-08 04:11:15 +0000 | [diff] [blame] | 51 | rx_stats = this_cpu_ptr(vlan_dev_priv(vlan_dev)->vlan_pcpu_stats); |
Eric Dumazet | 9793241 | 2009-11-17 04:53:09 +0000 | [diff] [blame] | 52 | |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 53 | u64_stats_update_begin(&rx_stats->syncp); |
Eric Dumazet | 9793241 | 2009-11-17 04:53:09 +0000 | [diff] [blame] | 54 | rx_stats->rx_packets++; |
| 55 | rx_stats->rx_bytes += skb->len; |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 56 | if (skb->pkt_type == PACKET_MULTICAST) |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 57 | rx_stats->rx_multicast++; |
Eric Dumazet | 9618e2f | 2010-06-24 00:55:06 +0000 | [diff] [blame] | 58 | u64_stats_update_end(&rx_stats->syncp); |
Jesse Gross | 3701e51 | 2010-10-20 13:56:06 +0000 | [diff] [blame] | 59 | |
| 60 | return true; |
Patrick McHardy | 7750f40 | 2008-07-08 03:23:36 -0700 | [diff] [blame] | 61 | } |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 62 | |
Jiri Pirko | 1cdfd72 | 2013-01-03 22:48:59 +0000 | [diff] [blame] | 63 | /* Must be invoked with rcu_read_lock. */ |
| 64 | struct net_device *__vlan_find_dev_deep(struct net_device *dev, |
Jiri Pirko | cec9c13 | 2011-07-20 04:54:05 +0000 | [diff] [blame] | 65 | u16 vlan_id) |
| 66 | { |
Jiri Pirko | 1cdfd72 | 2013-01-03 22:48:59 +0000 | [diff] [blame] | 67 | struct vlan_info *vlan_info = rcu_dereference(dev->vlan_info); |
Jiri Pirko | cec9c13 | 2011-07-20 04:54:05 +0000 | [diff] [blame] | 68 | |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 69 | if (vlan_info) { |
| 70 | return vlan_group_get_device(&vlan_info->grp, vlan_id); |
Jiri Pirko | cec9c13 | 2011-07-20 04:54:05 +0000 | [diff] [blame] | 71 | } else { |
| 72 | /* |
Jiri Pirko | 1cdfd72 | 2013-01-03 22:48:59 +0000 | [diff] [blame] | 73 | * Lower devices of master uppers (bonding, team) do not have |
| 74 | * grp assigned to themselves. Grp is assigned to upper device |
| 75 | * instead. |
Jiri Pirko | cec9c13 | 2011-07-20 04:54:05 +0000 | [diff] [blame] | 76 | */ |
Jiri Pirko | 1cdfd72 | 2013-01-03 22:48:59 +0000 | [diff] [blame] | 77 | struct net_device *upper_dev; |
| 78 | |
| 79 | upper_dev = netdev_master_upper_dev_get_rcu(dev); |
| 80 | if (upper_dev) |
| 81 | return __vlan_find_dev_deep(upper_dev, vlan_id); |
Jiri Pirko | cec9c13 | 2011-07-20 04:54:05 +0000 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | return NULL; |
| 85 | } |
| 86 | EXPORT_SYMBOL(__vlan_find_dev_deep); |
| 87 | |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 88 | struct net_device *vlan_dev_real_dev(const struct net_device *dev) |
| 89 | { |
Jiri Pirko | 7da82c0 | 2011-12-08 04:11:15 +0000 | [diff] [blame] | 90 | return vlan_dev_priv(dev)->real_dev; |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 91 | } |
Ben Greear | 116cb42 | 2009-01-26 12:37:53 -0800 | [diff] [blame] | 92 | EXPORT_SYMBOL(vlan_dev_real_dev); |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 93 | |
| 94 | u16 vlan_dev_vlan_id(const struct net_device *dev) |
| 95 | { |
Jiri Pirko | 7da82c0 | 2011-12-08 04:11:15 +0000 | [diff] [blame] | 96 | return vlan_dev_priv(dev)->vlan_id; |
Patrick McHardy | 22d1ba7 | 2008-07-08 03:23:57 -0700 | [diff] [blame] | 97 | } |
Ben Greear | 116cb42 | 2009-01-26 12:37:53 -0800 | [diff] [blame] | 98 | EXPORT_SYMBOL(vlan_dev_vlan_id); |
Herbert Xu | e1c096e | 2009-01-06 10:50:09 -0800 | [diff] [blame] | 99 | |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 100 | static struct sk_buff *vlan_reorder_header(struct sk_buff *skb) |
Jiri Pirko | bcc6d47 | 2011-04-07 19:48:33 +0000 | [diff] [blame] | 101 | { |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 102 | if (skb_cow(skb, skb_headroom(skb)) < 0) |
| 103 | return NULL; |
| 104 | memmove(skb->data - ETH_HLEN, skb->data - VLAN_ETH_HLEN, 2 * ETH_ALEN); |
| 105 | skb->mac_header += VLAN_HLEN; |
Jiri Pirko | bcc6d47 | 2011-04-07 19:48:33 +0000 | [diff] [blame] | 106 | return skb; |
| 107 | } |
| 108 | |
Jiri Pirko | bcc6d47 | 2011-04-07 19:48:33 +0000 | [diff] [blame] | 109 | struct sk_buff *vlan_untag(struct sk_buff *skb) |
| 110 | { |
| 111 | struct vlan_hdr *vhdr; |
| 112 | u16 vlan_tci; |
| 113 | |
| 114 | if (unlikely(vlan_tx_tag_present(skb))) { |
| 115 | /* vlan_tci is already set-up so leave this for another time */ |
| 116 | return skb; |
| 117 | } |
| 118 | |
| 119 | skb = skb_share_check(skb, GFP_ATOMIC); |
| 120 | if (unlikely(!skb)) |
| 121 | goto err_free; |
| 122 | |
| 123 | if (unlikely(!pskb_may_pull(skb, VLAN_HLEN))) |
| 124 | goto err_free; |
| 125 | |
| 126 | vhdr = (struct vlan_hdr *) skb->data; |
| 127 | vlan_tci = ntohs(vhdr->h_vlan_TCI); |
| 128 | __vlan_hwaccel_put_tag(skb, vlan_tci); |
| 129 | |
| 130 | skb_pull_rcsum(skb, VLAN_HLEN); |
| 131 | vlan_set_encap_proto(skb, vhdr); |
| 132 | |
Jiri Pirko | 0b5c9db | 2011-06-10 06:56:58 +0000 | [diff] [blame] | 133 | skb = vlan_reorder_header(skb); |
Jiri Pirko | bcc6d47 | 2011-04-07 19:48:33 +0000 | [diff] [blame] | 134 | if (unlikely(!skb)) |
| 135 | goto err_free; |
| 136 | |
Jiri Pirko | c5114cd | 2011-08-18 21:29:27 -0700 | [diff] [blame] | 137 | skb_reset_network_header(skb); |
| 138 | skb_reset_transport_header(skb); |
Antonio Quartulli | 5316cf9 | 2012-10-02 06:14:17 +0000 | [diff] [blame] | 139 | skb_reset_mac_len(skb); |
| 140 | |
Jiri Pirko | bcc6d47 | 2011-04-07 19:48:33 +0000 | [diff] [blame] | 141 | return skb; |
| 142 | |
| 143 | err_free: |
| 144 | kfree_skb(skb); |
| 145 | return NULL; |
| 146 | } |
Vlad Yasevich | 7885198 | 2013-02-13 12:00:14 +0000 | [diff] [blame] | 147 | EXPORT_SYMBOL(vlan_untag); |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 148 | |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 149 | |
| 150 | /* |
| 151 | * vlan info and vid list |
| 152 | */ |
| 153 | |
| 154 | static void vlan_group_free(struct vlan_group *grp) |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 155 | { |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 156 | int i; |
| 157 | |
| 158 | for (i = 0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) |
| 159 | kfree(grp->vlan_devices_arrays[i]); |
| 160 | } |
| 161 | |
| 162 | static void vlan_info_free(struct vlan_info *vlan_info) |
| 163 | { |
| 164 | vlan_group_free(&vlan_info->grp); |
| 165 | kfree(vlan_info); |
| 166 | } |
| 167 | |
| 168 | static void vlan_info_rcu_free(struct rcu_head *rcu) |
| 169 | { |
| 170 | vlan_info_free(container_of(rcu, struct vlan_info, rcu)); |
| 171 | } |
| 172 | |
| 173 | static struct vlan_info *vlan_info_alloc(struct net_device *dev) |
| 174 | { |
| 175 | struct vlan_info *vlan_info; |
| 176 | |
| 177 | vlan_info = kzalloc(sizeof(struct vlan_info), GFP_KERNEL); |
| 178 | if (!vlan_info) |
| 179 | return NULL; |
| 180 | |
| 181 | vlan_info->real_dev = dev; |
| 182 | INIT_LIST_HEAD(&vlan_info->vid_list); |
| 183 | return vlan_info; |
| 184 | } |
| 185 | |
| 186 | struct vlan_vid_info { |
| 187 | struct list_head list; |
| 188 | unsigned short vid; |
| 189 | int refcount; |
| 190 | }; |
| 191 | |
| 192 | static struct vlan_vid_info *vlan_vid_info_get(struct vlan_info *vlan_info, |
| 193 | unsigned short vid) |
| 194 | { |
| 195 | struct vlan_vid_info *vid_info; |
| 196 | |
| 197 | list_for_each_entry(vid_info, &vlan_info->vid_list, list) { |
| 198 | if (vid_info->vid == vid) |
| 199 | return vid_info; |
| 200 | } |
| 201 | return NULL; |
| 202 | } |
| 203 | |
| 204 | static struct vlan_vid_info *vlan_vid_info_alloc(unsigned short vid) |
| 205 | { |
| 206 | struct vlan_vid_info *vid_info; |
| 207 | |
| 208 | vid_info = kzalloc(sizeof(struct vlan_vid_info), GFP_KERNEL); |
| 209 | if (!vid_info) |
| 210 | return NULL; |
| 211 | vid_info->vid = vid; |
| 212 | |
| 213 | return vid_info; |
| 214 | } |
| 215 | |
| 216 | static int __vlan_vid_add(struct vlan_info *vlan_info, unsigned short vid, |
| 217 | struct vlan_vid_info **pvid_info) |
| 218 | { |
| 219 | struct net_device *dev = vlan_info->real_dev; |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 220 | const struct net_device_ops *ops = dev->netdev_ops; |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 221 | struct vlan_vid_info *vid_info; |
| 222 | int err; |
| 223 | |
| 224 | vid_info = vlan_vid_info_alloc(vid); |
| 225 | if (!vid_info) |
| 226 | return -ENOMEM; |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 227 | |
Michał Mirosław | d2ed273 | 2013-01-29 15:14:16 +0000 | [diff] [blame] | 228 | if (dev->features & NETIF_F_HW_VLAN_FILTER) { |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 229 | err = ops->ndo_vlan_rx_add_vid(dev, vid); |
| 230 | if (err) { |
| 231 | kfree(vid_info); |
| 232 | return err; |
| 233 | } |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 234 | } |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 235 | list_add(&vid_info->list, &vlan_info->vid_list); |
| 236 | vlan_info->nr_vids++; |
| 237 | *pvid_info = vid_info; |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 238 | return 0; |
| 239 | } |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 240 | |
| 241 | int vlan_vid_add(struct net_device *dev, unsigned short vid) |
| 242 | { |
| 243 | struct vlan_info *vlan_info; |
| 244 | struct vlan_vid_info *vid_info; |
| 245 | bool vlan_info_created = false; |
| 246 | int err; |
| 247 | |
| 248 | ASSERT_RTNL(); |
| 249 | |
| 250 | vlan_info = rtnl_dereference(dev->vlan_info); |
| 251 | if (!vlan_info) { |
| 252 | vlan_info = vlan_info_alloc(dev); |
| 253 | if (!vlan_info) |
| 254 | return -ENOMEM; |
| 255 | vlan_info_created = true; |
| 256 | } |
| 257 | vid_info = vlan_vid_info_get(vlan_info, vid); |
| 258 | if (!vid_info) { |
| 259 | err = __vlan_vid_add(vlan_info, vid, &vid_info); |
| 260 | if (err) |
| 261 | goto out_free_vlan_info; |
| 262 | } |
| 263 | vid_info->refcount++; |
| 264 | |
| 265 | if (vlan_info_created) |
| 266 | rcu_assign_pointer(dev->vlan_info, vlan_info); |
| 267 | |
| 268 | return 0; |
| 269 | |
| 270 | out_free_vlan_info: |
| 271 | if (vlan_info_created) |
| 272 | kfree(vlan_info); |
| 273 | return err; |
| 274 | } |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 275 | EXPORT_SYMBOL(vlan_vid_add); |
| 276 | |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 277 | static void __vlan_vid_del(struct vlan_info *vlan_info, |
| 278 | struct vlan_vid_info *vid_info) |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 279 | { |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 280 | struct net_device *dev = vlan_info->real_dev; |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 281 | const struct net_device_ops *ops = dev->netdev_ops; |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 282 | unsigned short vid = vid_info->vid; |
| 283 | int err; |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 284 | |
Michał Mirosław | d2ed273 | 2013-01-29 15:14:16 +0000 | [diff] [blame] | 285 | if (dev->features & NETIF_F_HW_VLAN_FILTER) { |
Jiri Pirko | 5b9ea6e | 2011-12-08 04:11:18 +0000 | [diff] [blame] | 286 | err = ops->ndo_vlan_rx_kill_vid(dev, vid); |
| 287 | if (err) { |
| 288 | pr_warn("failed to kill vid %d for device %s\n", |
| 289 | vid, dev->name); |
| 290 | } |
| 291 | } |
| 292 | list_del(&vid_info->list); |
| 293 | kfree(vid_info); |
| 294 | vlan_info->nr_vids--; |
| 295 | } |
| 296 | |
| 297 | void vlan_vid_del(struct net_device *dev, unsigned short vid) |
| 298 | { |
| 299 | struct vlan_info *vlan_info; |
| 300 | struct vlan_vid_info *vid_info; |
| 301 | |
| 302 | ASSERT_RTNL(); |
| 303 | |
| 304 | vlan_info = rtnl_dereference(dev->vlan_info); |
| 305 | if (!vlan_info) |
| 306 | return; |
| 307 | |
| 308 | vid_info = vlan_vid_info_get(vlan_info, vid); |
| 309 | if (!vid_info) |
| 310 | return; |
| 311 | vid_info->refcount--; |
| 312 | if (vid_info->refcount == 0) { |
| 313 | __vlan_vid_del(vlan_info, vid_info); |
| 314 | if (vlan_info->nr_vids == 0) { |
| 315 | RCU_INIT_POINTER(dev->vlan_info, NULL); |
| 316 | call_rcu(&vlan_info->rcu, vlan_info_rcu_free); |
| 317 | } |
Jiri Pirko | 87002b0 | 2011-12-08 04:11:17 +0000 | [diff] [blame] | 318 | } |
| 319 | } |
| 320 | EXPORT_SYMBOL(vlan_vid_del); |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 321 | |
| 322 | int vlan_vids_add_by_dev(struct net_device *dev, |
| 323 | const struct net_device *by_dev) |
| 324 | { |
| 325 | struct vlan_vid_info *vid_info; |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 326 | struct vlan_info *vlan_info; |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 327 | int err; |
| 328 | |
| 329 | ASSERT_RTNL(); |
| 330 | |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 331 | vlan_info = rtnl_dereference(by_dev->vlan_info); |
| 332 | if (!vlan_info) |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 333 | return 0; |
| 334 | |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 335 | list_for_each_entry(vid_info, &vlan_info->vid_list, list) { |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 336 | err = vlan_vid_add(dev, vid_info->vid); |
| 337 | if (err) |
| 338 | goto unwind; |
| 339 | } |
| 340 | return 0; |
| 341 | |
| 342 | unwind: |
| 343 | list_for_each_entry_continue_reverse(vid_info, |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 344 | &vlan_info->vid_list, |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 345 | list) { |
| 346 | vlan_vid_del(dev, vid_info->vid); |
| 347 | } |
| 348 | |
| 349 | return err; |
| 350 | } |
| 351 | EXPORT_SYMBOL(vlan_vids_add_by_dev); |
| 352 | |
| 353 | void vlan_vids_del_by_dev(struct net_device *dev, |
| 354 | const struct net_device *by_dev) |
| 355 | { |
| 356 | struct vlan_vid_info *vid_info; |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 357 | struct vlan_info *vlan_info; |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 358 | |
| 359 | ASSERT_RTNL(); |
| 360 | |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 361 | vlan_info = rtnl_dereference(by_dev->vlan_info); |
| 362 | if (!vlan_info) |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 363 | return; |
| 364 | |
Dan Carpenter | f9586f7 | 2011-12-13 20:29:43 +0000 | [diff] [blame] | 365 | list_for_each_entry(vid_info, &vlan_info->vid_list, list) |
Jiri Pirko | 348a144 | 2011-12-08 04:11:19 +0000 | [diff] [blame] | 366 | vlan_vid_del(dev, vid_info->vid); |
| 367 | } |
| 368 | EXPORT_SYMBOL(vlan_vids_del_by_dev); |
Jiri Pirko | 9b361c1 | 2012-08-23 03:26:52 +0000 | [diff] [blame] | 369 | |
| 370 | bool vlan_uses_dev(const struct net_device *dev) |
| 371 | { |
Jiri Pirko | 55462cf | 2012-10-14 04:30:56 +0000 | [diff] [blame] | 372 | struct vlan_info *vlan_info; |
| 373 | |
| 374 | ASSERT_RTNL(); |
| 375 | |
| 376 | vlan_info = rtnl_dereference(dev->vlan_info); |
| 377 | if (!vlan_info) |
| 378 | return false; |
| 379 | return vlan_info->grp.nr_vlan_devs ? true : false; |
Jiri Pirko | 9b361c1 | 2012-08-23 03:26:52 +0000 | [diff] [blame] | 380 | } |
| 381 | EXPORT_SYMBOL(vlan_uses_dev); |