Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * INET 802.1Q VLAN |
| 3 | * Ethernet-type device handling. |
| 4 | * |
| 5 | * Authors: Ben Greear <greearb@candelatech.com> |
| 6 | * Please send support related email to: vlan@scry.wanfear.com |
| 7 | * VLAN Home Page: http://www.candelatech.com/~greear/vlan.html |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 8 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * Fixes: |
| 10 | * Fix for packet capture - Nick Eggleston <nick@dccinc.com>; |
| 11 | * Add HW acceleration hooks - David S. Miller <davem@redhat.com>; |
| 12 | * Correct all the locking - David S. Miller <davem@redhat.com>; |
| 13 | * Use hash table for VLAN groups - David S. Miller <davem@redhat.com> |
| 14 | * |
| 15 | * This program is free software; you can redistribute it and/or |
| 16 | * modify it under the terms of the GNU General Public License |
| 17 | * as published by the Free Software Foundation; either version |
| 18 | * 2 of the License, or (at your option) any later version. |
| 19 | */ |
| 20 | |
| 21 | #include <asm/uaccess.h> /* for copy_from_user */ |
Randy Dunlap | 4fc268d | 2006-01-11 12:17:47 -0800 | [diff] [blame] | 22 | #include <linux/capability.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #include <linux/module.h> |
| 24 | #include <linux/netdevice.h> |
| 25 | #include <linux/skbuff.h> |
| 26 | #include <net/datalink.h> |
| 27 | #include <linux/mm.h> |
| 28 | #include <linux/in.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <net/p8022.h> |
| 31 | #include <net/arp.h> |
| 32 | #include <linux/rtnetlink.h> |
| 33 | #include <linux/notifier.h> |
| 34 | |
| 35 | #include <linux/if_vlan.h> |
| 36 | #include "vlan.h" |
| 37 | #include "vlanproc.h" |
| 38 | |
| 39 | #define DRV_VERSION "1.8" |
| 40 | |
| 41 | /* Global VLAN variables */ |
| 42 | |
| 43 | /* Our listing of VLAN group(s) */ |
| 44 | static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE]; |
| 45 | #define vlan_grp_hashfn(IDX) ((((IDX) >> VLAN_GRP_HASH_SHIFT) ^ (IDX)) & VLAN_GRP_HASH_MASK) |
| 46 | |
| 47 | static char vlan_fullname[] = "802.1Q VLAN Support"; |
| 48 | static char vlan_version[] = DRV_VERSION; |
| 49 | static char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>"; |
| 50 | static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>"; |
| 51 | |
| 52 | static int vlan_device_event(struct notifier_block *, unsigned long, void *); |
| 53 | static int vlan_ioctl_handler(void __user *); |
| 54 | static int unregister_vlan_dev(struct net_device *, unsigned short ); |
| 55 | |
| 56 | static struct notifier_block vlan_notifier_block = { |
| 57 | .notifier_call = vlan_device_event, |
| 58 | }; |
| 59 | |
| 60 | /* These may be changed at run-time through IOCTLs */ |
| 61 | |
| 62 | /* Determines interface naming scheme. */ |
| 63 | unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD; |
| 64 | |
| 65 | static struct packet_type vlan_packet_type = { |
| 66 | .type = __constant_htons(ETH_P_8021Q), |
| 67 | .func = vlan_skb_recv, /* VLAN receive method */ |
| 68 | }; |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* End of global variables definitions. */ |
| 71 | |
| 72 | /* |
| 73 | * Function vlan_proto_init (pro) |
| 74 | * |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 75 | * Initialize VLAN protocol layer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | * |
| 77 | */ |
| 78 | static int __init vlan_proto_init(void) |
| 79 | { |
| 80 | int err; |
| 81 | |
| 82 | printk(VLAN_INF "%s v%s %s\n", |
| 83 | vlan_fullname, vlan_version, vlan_copyright); |
| 84 | printk(VLAN_INF "All bugs added by %s\n", |
| 85 | vlan_buggyright); |
| 86 | |
| 87 | /* proc file system initialization */ |
| 88 | err = vlan_proc_init(); |
| 89 | if (err < 0) { |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 90 | printk(KERN_ERR |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | "%s %s: can't create entry in proc filesystem!\n", |
| 92 | __FUNCTION__, VLAN_NAME); |
| 93 | return err; |
| 94 | } |
| 95 | |
| 96 | dev_add_pack(&vlan_packet_type); |
| 97 | |
| 98 | /* Register us to receive netdevice events */ |
| 99 | err = register_netdevice_notifier(&vlan_notifier_block); |
| 100 | if (err < 0) { |
| 101 | dev_remove_pack(&vlan_packet_type); |
| 102 | vlan_proc_cleanup(); |
| 103 | return err; |
| 104 | } |
| 105 | |
| 106 | vlan_ioctl_set(vlan_ioctl_handler); |
| 107 | |
| 108 | return 0; |
| 109 | } |
| 110 | |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 111 | /* Cleanup all vlan devices |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | * Note: devices that have been registered that but not |
| 113 | * brought up will exist but have no module ref count. |
| 114 | */ |
| 115 | static void __exit vlan_cleanup_devices(void) |
| 116 | { |
| 117 | struct net_device *dev, *nxt; |
| 118 | |
| 119 | rtnl_lock(); |
Pavel Emelianov | 7562f87 | 2007-05-03 15:13:45 -0700 | [diff] [blame] | 120 | for_each_netdev_safe(dev, nxt) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | if (dev->priv_flags & IFF_802_1Q_VLAN) { |
| 122 | unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev, |
| 123 | VLAN_DEV_INFO(dev)->vlan_id); |
| 124 | |
| 125 | unregister_netdevice(dev); |
| 126 | } |
| 127 | } |
| 128 | rtnl_unlock(); |
| 129 | } |
| 130 | |
| 131 | /* |
| 132 | * Module 'remove' entry point. |
| 133 | * o delete /proc/net/router directory and static entries. |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 134 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | static void __exit vlan_cleanup_module(void) |
| 136 | { |
| 137 | int i; |
| 138 | |
| 139 | vlan_ioctl_set(NULL); |
| 140 | |
| 141 | /* Un-register us from receiving netdevice events */ |
| 142 | unregister_netdevice_notifier(&vlan_notifier_block); |
| 143 | |
| 144 | dev_remove_pack(&vlan_packet_type); |
| 145 | vlan_cleanup_devices(); |
| 146 | |
| 147 | /* This table must be empty if there are no module |
| 148 | * references left. |
| 149 | */ |
| 150 | for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) { |
| 151 | BUG_ON(!hlist_empty(&vlan_group_hash[i])); |
| 152 | } |
| 153 | vlan_proc_cleanup(); |
| 154 | |
| 155 | synchronize_net(); |
| 156 | } |
| 157 | |
| 158 | module_init(vlan_proto_init); |
| 159 | module_exit(vlan_cleanup_module); |
| 160 | |
| 161 | /* Must be invoked with RCU read lock (no preempt) */ |
| 162 | static struct vlan_group *__vlan_find_group(int real_dev_ifindex) |
| 163 | { |
| 164 | struct vlan_group *grp; |
| 165 | struct hlist_node *n; |
| 166 | int hash = vlan_grp_hashfn(real_dev_ifindex); |
| 167 | |
| 168 | hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) { |
| 169 | if (grp->real_dev_ifindex == real_dev_ifindex) |
| 170 | return grp; |
| 171 | } |
| 172 | |
| 173 | return NULL; |
| 174 | } |
| 175 | |
| 176 | /* Find the protocol handler. Assumes VID < VLAN_VID_MASK. |
| 177 | * |
| 178 | * Must be invoked with RCU read lock (no preempt) |
| 179 | */ |
| 180 | struct net_device *__find_vlan_dev(struct net_device *real_dev, |
| 181 | unsigned short VID) |
| 182 | { |
| 183 | struct vlan_group *grp = __vlan_find_group(real_dev->ifindex); |
| 184 | |
| 185 | if (grp) |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 186 | return vlan_group_get_device(grp, VID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | |
| 188 | return NULL; |
| 189 | } |
| 190 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 191 | static void vlan_group_free(struct vlan_group *grp) |
| 192 | { |
| 193 | int i; |
| 194 | |
| 195 | for (i=0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) |
| 196 | kfree(grp->vlan_devices_arrays[i]); |
| 197 | kfree(grp); |
| 198 | } |
| 199 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | static void vlan_rcu_free(struct rcu_head *rcu) |
| 201 | { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 202 | vlan_group_free(container_of(rcu, struct vlan_group, rcu)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | } |
| 204 | |
| 205 | |
| 206 | /* This returns 0 if everything went fine. |
| 207 | * It will return 1 if the group was killed as a result. |
| 208 | * A negative return indicates failure. |
| 209 | * |
| 210 | * The RTNL lock must be held. |
| 211 | */ |
| 212 | static int unregister_vlan_dev(struct net_device *real_dev, |
| 213 | unsigned short vlan_id) |
| 214 | { |
| 215 | struct net_device *dev = NULL; |
| 216 | int real_dev_ifindex = real_dev->ifindex; |
| 217 | struct vlan_group *grp; |
| 218 | int i, ret; |
| 219 | |
| 220 | #ifdef VLAN_DEBUG |
| 221 | printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id); |
| 222 | #endif |
| 223 | |
| 224 | /* sanity check */ |
| 225 | if (vlan_id >= VLAN_VID_MASK) |
| 226 | return -EINVAL; |
| 227 | |
| 228 | ASSERT_RTNL(); |
| 229 | grp = __vlan_find_group(real_dev_ifindex); |
| 230 | |
| 231 | ret = 0; |
| 232 | |
| 233 | if (grp) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 234 | dev = vlan_group_get_device(grp, vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | if (dev) { |
| 236 | /* Remove proc entry */ |
| 237 | vlan_proc_rem_dev(dev); |
| 238 | |
| 239 | /* Take it out of our own structures, but be sure to |
| 240 | * interlock with HW accelerating devices or SW vlan |
| 241 | * input packet processing. |
| 242 | */ |
Stephen Hemminger | d2d1acd | 2007-06-01 09:43:57 -0700 | [diff] [blame] | 243 | if (real_dev->features & NETIF_F_HW_VLAN_FILTER) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | real_dev->vlan_rx_kill_vid(real_dev, vlan_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 246 | vlan_group_set_device(grp, vlan_id, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | synchronize_net(); |
| 248 | |
| 249 | |
| 250 | /* Caller unregisters (and if necessary, puts) |
| 251 | * VLAN device, but we get rid of the reference to |
| 252 | * real_dev here. |
| 253 | */ |
| 254 | dev_put(real_dev); |
| 255 | |
| 256 | /* If the group is now empty, kill off the |
| 257 | * group. |
| 258 | */ |
| 259 | for (i = 0; i < VLAN_VID_MASK; i++) |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 260 | if (vlan_group_get_device(grp, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | break; |
| 262 | |
| 263 | if (i == VLAN_VID_MASK) { |
| 264 | if (real_dev->features & NETIF_F_HW_VLAN_RX) |
| 265 | real_dev->vlan_rx_register(real_dev, NULL); |
| 266 | |
| 267 | hlist_del_rcu(&grp->hlist); |
| 268 | |
| 269 | /* Free the group, after all cpu's are done. */ |
| 270 | call_rcu(&grp->rcu, vlan_rcu_free); |
| 271 | |
| 272 | grp = NULL; |
| 273 | ret = 1; |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 278 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 281 | static int unregister_vlan_device(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | int ret; |
| 284 | |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 285 | ret = unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev, |
| 286 | VLAN_DEV_INFO(dev)->vlan_id); |
| 287 | unregister_netdevice(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 289 | if (ret == 1) |
| 290 | ret = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return ret; |
| 292 | } |
| 293 | |
Patrick McHardy | 2f4284a | 2007-06-13 12:05:41 -0700 | [diff] [blame^] | 294 | /* |
| 295 | * vlan network devices have devices nesting below it, and are a special |
| 296 | * "super class" of normal network devices; split their locks off into a |
| 297 | * separate class since they always nest. |
| 298 | */ |
| 299 | static struct lock_class_key vlan_netdev_xmit_lock_key; |
| 300 | |
| 301 | static int vlan_dev_init(struct net_device *dev) |
| 302 | { |
| 303 | struct net_device *real_dev = VLAN_DEV_INFO(dev)->real_dev; |
| 304 | |
| 305 | /* IFF_BROADCAST|IFF_MULTICAST; ??? */ |
| 306 | dev->flags = real_dev->flags & ~IFF_UP; |
| 307 | dev->iflink = real_dev->ifindex; |
| 308 | dev->state = (real_dev->state & ((1<<__LINK_STATE_NOCARRIER) | |
| 309 | (1<<__LINK_STATE_DORMANT))) | |
| 310 | (1<<__LINK_STATE_PRESENT); |
| 311 | |
| 312 | /* TODO: maybe just assign it to be ETHERNET? */ |
| 313 | dev->type = real_dev->type; |
| 314 | |
| 315 | memcpy(dev->broadcast, real_dev->broadcast, real_dev->addr_len); |
| 316 | memcpy(dev->dev_addr, real_dev->dev_addr, real_dev->addr_len); |
| 317 | dev->addr_len = real_dev->addr_len; |
| 318 | |
| 319 | if (real_dev->features & NETIF_F_HW_VLAN_TX) { |
| 320 | dev->hard_header = real_dev->hard_header; |
| 321 | dev->hard_header_len = real_dev->hard_header_len; |
| 322 | dev->hard_start_xmit = vlan_dev_hwaccel_hard_start_xmit; |
| 323 | dev->rebuild_header = real_dev->rebuild_header; |
| 324 | } else { |
| 325 | dev->hard_header = vlan_dev_hard_header; |
| 326 | dev->hard_header_len = real_dev->hard_header_len + VLAN_HLEN; |
| 327 | dev->hard_start_xmit = vlan_dev_hard_start_xmit; |
| 328 | dev->rebuild_header = vlan_dev_rebuild_header; |
| 329 | } |
| 330 | dev->hard_header_parse = real_dev->hard_header_parse; |
| 331 | |
| 332 | lockdep_set_class(&dev->_xmit_lock, &vlan_netdev_xmit_lock_key); |
| 333 | return 0; |
| 334 | } |
| 335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | static void vlan_setup(struct net_device *new_dev) |
| 337 | { |
| 338 | SET_MODULE_OWNER(new_dev); |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | /* new_dev->ifindex = 0; it will be set when added to |
| 341 | * the global list. |
| 342 | * iflink is set as well. |
| 343 | */ |
| 344 | new_dev->get_stats = vlan_dev_get_stats; |
| 345 | |
| 346 | /* Make this thing known as a VLAN device */ |
| 347 | new_dev->priv_flags |= IFF_802_1Q_VLAN; |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 348 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | /* Set us up to have no queue, as the underlying Hardware device |
| 350 | * can do all the queueing we could want. |
| 351 | */ |
| 352 | new_dev->tx_queue_len = 0; |
| 353 | |
| 354 | /* set up method calls */ |
| 355 | new_dev->change_mtu = vlan_dev_change_mtu; |
Patrick McHardy | 2f4284a | 2007-06-13 12:05:41 -0700 | [diff] [blame^] | 356 | new_dev->init = vlan_dev_init; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | new_dev->open = vlan_dev_open; |
| 358 | new_dev->stop = vlan_dev_stop; |
| 359 | new_dev->set_mac_address = vlan_dev_set_mac_address; |
| 360 | new_dev->set_multicast_list = vlan_dev_set_multicast_list; |
| 361 | new_dev->destructor = free_netdev; |
| 362 | new_dev->do_ioctl = vlan_dev_ioctl; |
| 363 | } |
| 364 | |
Stefan Rompf | ddd7bf9 | 2006-03-20 17:11:41 -0800 | [diff] [blame] | 365 | static void vlan_transfer_operstate(const struct net_device *dev, struct net_device *vlandev) |
| 366 | { |
| 367 | /* Have to respect userspace enforced dormant state |
| 368 | * of real device, also must allow supplicant running |
| 369 | * on VLAN device |
| 370 | */ |
| 371 | if (dev->operstate == IF_OPER_DORMANT) |
| 372 | netif_dormant_on(vlandev); |
| 373 | else |
| 374 | netif_dormant_off(vlandev); |
| 375 | |
| 376 | if (netif_carrier_ok(dev)) { |
| 377 | if (!netif_carrier_ok(vlandev)) |
| 378 | netif_carrier_on(vlandev); |
| 379 | } else { |
| 380 | if (netif_carrier_ok(vlandev)) |
| 381 | netif_carrier_off(vlandev); |
| 382 | } |
| 383 | } |
| 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* Attach a VLAN device to a mac address (ie Ethernet Card). |
| 386 | * Returns the device that was created, or NULL if there was |
| 387 | * an error of some kind. |
| 388 | */ |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 389 | static struct net_device *register_vlan_device(struct net_device *real_dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | unsigned short VLAN_ID) |
| 391 | { |
| 392 | struct vlan_group *grp; |
| 393 | struct net_device *new_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | char name[IFNAMSIZ]; |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 395 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | #ifdef VLAN_DEBUG |
| 398 | printk(VLAN_DBG "%s: if_name -:%s:- vid: %i\n", |
| 399 | __FUNCTION__, eth_IF_name, VLAN_ID); |
| 400 | #endif |
| 401 | |
| 402 | if (VLAN_ID >= VLAN_VID_MASK) |
| 403 | goto out_ret_null; |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | if (real_dev->features & NETIF_F_VLAN_CHALLENGED) { |
| 406 | printk(VLAN_DBG "%s: VLANs not supported on %s.\n", |
| 407 | __FUNCTION__, real_dev->name); |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 408 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | if ((real_dev->features & NETIF_F_HW_VLAN_RX) && |
Stephen Hemminger | d2d1acd | 2007-06-01 09:43:57 -0700 | [diff] [blame] | 412 | !real_dev->vlan_rx_register) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n", |
| 414 | __FUNCTION__, real_dev->name); |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 415 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | } |
| 417 | |
| 418 | if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) && |
Stephen Hemminger | d2d1acd | 2007-06-01 09:43:57 -0700 | [diff] [blame] | 419 | (!real_dev->vlan_rx_add_vid || !real_dev->vlan_rx_kill_vid)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n", |
| 421 | __FUNCTION__, real_dev->name); |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 422 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | } |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | /* The real device must be up and operating in order to |
| 426 | * assosciate a VLAN device with it. |
| 427 | */ |
| 428 | if (!(real_dev->flags & IFF_UP)) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 429 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
| 431 | if (__find_vlan_dev(real_dev, VLAN_ID) != NULL) { |
| 432 | /* was already registered. */ |
| 433 | printk(VLAN_DBG "%s: ALREADY had VLAN registered\n", __FUNCTION__); |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 434 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
| 437 | /* Gotta set up the fields for the device. */ |
| 438 | #ifdef VLAN_DEBUG |
| 439 | printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n", |
| 440 | vlan_name_type); |
| 441 | #endif |
| 442 | switch (vlan_name_type) { |
| 443 | case VLAN_NAME_TYPE_RAW_PLUS_VID: |
| 444 | /* name will look like: eth1.0005 */ |
| 445 | snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID); |
| 446 | break; |
| 447 | case VLAN_NAME_TYPE_PLUS_VID_NO_PAD: |
| 448 | /* Put our vlan.VID in the name. |
| 449 | * Name will look like: vlan5 |
| 450 | */ |
| 451 | snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID); |
| 452 | break; |
| 453 | case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD: |
| 454 | /* Put our vlan.VID in the name. |
| 455 | * Name will look like: eth0.5 |
| 456 | */ |
| 457 | snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID); |
| 458 | break; |
| 459 | case VLAN_NAME_TYPE_PLUS_VID: |
| 460 | /* Put our vlan.VID in the name. |
| 461 | * Name will look like: vlan0005 |
| 462 | */ |
| 463 | default: |
| 464 | snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID); |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 465 | } |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 466 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name, |
| 468 | vlan_setup); |
Arjan van de Ven | 5dd8d1e | 2006-07-03 00:25:33 -0700 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | if (new_dev == NULL) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 471 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* need 4 bytes for extra VLAN header info, |
| 474 | * hope the underlying device can handle it. |
| 475 | */ |
| 476 | new_dev->mtu = real_dev->mtu; |
| 477 | |
Patrick McHardy | 2f4284a | 2007-06-13 12:05:41 -0700 | [diff] [blame^] | 478 | #ifdef VLAN_DEBUG |
| 479 | printk(VLAN_DBG "Allocated new name -:%s:-\n", new_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | VLAN_MEM_DBG("new_dev->priv malloc, addr: %p size: %i\n", |
| 481 | new_dev->priv, |
| 482 | sizeof(struct vlan_dev_info)); |
Patrick McHardy | 2f4284a | 2007-06-13 12:05:41 -0700 | [diff] [blame^] | 483 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | |
| 485 | VLAN_DEV_INFO(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */ |
| 486 | VLAN_DEV_INFO(new_dev)->real_dev = real_dev; |
| 487 | VLAN_DEV_INFO(new_dev)->dent = NULL; |
| 488 | VLAN_DEV_INFO(new_dev)->flags = 1; |
| 489 | |
| 490 | #ifdef VLAN_DEBUG |
| 491 | printk(VLAN_DBG "About to go find the group for idx: %i\n", |
| 492 | real_dev->ifindex); |
| 493 | #endif |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | if (register_netdevice(new_dev)) |
| 496 | goto out_free_newdev; |
| 497 | |
Stefan Rompf | ddd7bf9 | 2006-03-20 17:11:41 -0800 | [diff] [blame] | 498 | vlan_transfer_operstate(real_dev, new_dev); |
| 499 | linkwatch_fire_event(new_dev); /* _MUST_ call rfc2863_policy() */ |
| 500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | /* So, got the sucker initialized, now lets place |
| 502 | * it into our local structure. |
| 503 | */ |
| 504 | grp = __vlan_find_group(real_dev->ifindex); |
| 505 | |
| 506 | /* Note, we are running under the RTNL semaphore |
| 507 | * so it cannot "appear" on us. |
| 508 | */ |
| 509 | if (!grp) { /* need to add a new group */ |
Panagiotis Issaris | 0da974f | 2006-07-21 14:51:30 -0700 | [diff] [blame] | 510 | grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | if (!grp) |
| 512 | goto out_free_unregister; |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 513 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 514 | for (i=0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) { |
| 515 | grp->vlan_devices_arrays[i] = kzalloc( |
| 516 | sizeof(struct net_device *)*VLAN_GROUP_ARRAY_PART_LEN, |
| 517 | GFP_KERNEL); |
| 518 | |
| 519 | if (!grp->vlan_devices_arrays[i]) |
| 520 | goto out_free_arrays; |
| 521 | } |
| 522 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | /* printk(KERN_ALERT "VLAN REGISTER: Allocated new group.\n"); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | grp->real_dev_ifindex = real_dev->ifindex; |
| 525 | |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 526 | hlist_add_head_rcu(&grp->hlist, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]); |
| 528 | |
| 529 | if (real_dev->features & NETIF_F_HW_VLAN_RX) |
| 530 | real_dev->vlan_rx_register(real_dev, grp); |
| 531 | } |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 532 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 533 | vlan_group_set_device(grp, VLAN_ID, new_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | if (vlan_proc_add_dev(new_dev)<0)/* create it's proc entry */ |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 536 | printk(KERN_WARNING "VLAN: failed to add proc entry for %s\n", |
| 537 | new_dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
| 539 | if (real_dev->features & NETIF_F_HW_VLAN_FILTER) |
| 540 | real_dev->vlan_rx_add_vid(real_dev, VLAN_ID); |
| 541 | |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 542 | /* Account for reference in struct vlan_dev_info */ |
| 543 | dev_hold(real_dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | #ifdef VLAN_DEBUG |
| 545 | printk(VLAN_DBG "Allocated new device successfully, returning.\n"); |
| 546 | #endif |
| 547 | return new_dev; |
| 548 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 549 | out_free_arrays: |
| 550 | vlan_group_free(grp); |
| 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | out_free_unregister: |
| 553 | unregister_netdev(new_dev); |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 554 | goto out_ret_null; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | out_free_newdev: |
| 557 | free_netdev(new_dev); |
| 558 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | out_ret_null: |
| 560 | return NULL; |
| 561 | } |
| 562 | |
| 563 | static int vlan_device_event(struct notifier_block *unused, unsigned long event, void *ptr) |
| 564 | { |
| 565 | struct net_device *dev = ptr; |
| 566 | struct vlan_group *grp = __vlan_find_group(dev->ifindex); |
| 567 | int i, flgs; |
| 568 | struct net_device *vlandev; |
| 569 | |
| 570 | if (!grp) |
| 571 | goto out; |
| 572 | |
| 573 | /* It is OK that we do not hold the group lock right now, |
| 574 | * as we run under the RTNL lock. |
| 575 | */ |
| 576 | |
| 577 | switch (event) { |
| 578 | case NETDEV_CHANGE: |
| 579 | /* Propagate real device state to vlan devices */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 581 | vlandev = vlan_group_get_device(grp, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | if (!vlandev) |
| 583 | continue; |
| 584 | |
Stefan Rompf | ddd7bf9 | 2006-03-20 17:11:41 -0800 | [diff] [blame] | 585 | vlan_transfer_operstate(dev, vlandev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } |
| 587 | break; |
| 588 | |
| 589 | case NETDEV_DOWN: |
| 590 | /* Put all VLANs for this dev in the down state too. */ |
| 591 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 592 | vlandev = vlan_group_get_device(grp, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | if (!vlandev) |
| 594 | continue; |
| 595 | |
| 596 | flgs = vlandev->flags; |
| 597 | if (!(flgs & IFF_UP)) |
| 598 | continue; |
| 599 | |
| 600 | dev_change_flags(vlandev, flgs & ~IFF_UP); |
| 601 | } |
| 602 | break; |
| 603 | |
| 604 | case NETDEV_UP: |
| 605 | /* Put all VLANs for this dev in the up state too. */ |
| 606 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 607 | vlandev = vlan_group_get_device(grp, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | if (!vlandev) |
| 609 | continue; |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | flgs = vlandev->flags; |
| 612 | if (flgs & IFF_UP) |
| 613 | continue; |
| 614 | |
| 615 | dev_change_flags(vlandev, flgs | IFF_UP); |
| 616 | } |
| 617 | break; |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | case NETDEV_UNREGISTER: |
| 620 | /* Delete all VLANs for this dev. */ |
| 621 | for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) { |
| 622 | int ret; |
| 623 | |
Dan Aloni | 5c15bde | 2007-03-02 20:44:51 -0800 | [diff] [blame] | 624 | vlandev = vlan_group_get_device(grp, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | if (!vlandev) |
| 626 | continue; |
| 627 | |
| 628 | ret = unregister_vlan_dev(dev, |
| 629 | VLAN_DEV_INFO(vlandev)->vlan_id); |
| 630 | |
| 631 | unregister_netdevice(vlandev); |
| 632 | |
| 633 | /* Group was destroyed? */ |
| 634 | if (ret == 1) |
| 635 | break; |
| 636 | } |
| 637 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 638 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | out: |
| 641 | return NOTIFY_DONE; |
| 642 | } |
| 643 | |
| 644 | /* |
| 645 | * VLAN IOCTL handler. |
| 646 | * o execute requested action or pass command to the device driver |
| 647 | * arg is really a struct vlan_ioctl_args __user *. |
| 648 | */ |
| 649 | static int vlan_ioctl_handler(void __user *arg) |
| 650 | { |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 651 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | unsigned short vid = 0; |
| 653 | struct vlan_ioctl_args args; |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 654 | struct net_device *dev = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | |
| 656 | if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args))) |
| 657 | return -EFAULT; |
| 658 | |
| 659 | /* Null terminate this sucker, just in case. */ |
| 660 | args.device1[23] = 0; |
| 661 | args.u.device2[23] = 0; |
| 662 | |
| 663 | #ifdef VLAN_DEBUG |
| 664 | printk(VLAN_DBG "%s: args.cmd: %x\n", __FUNCTION__, args.cmd); |
| 665 | #endif |
| 666 | |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 667 | rtnl_lock(); |
| 668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | switch (args.cmd) { |
| 670 | case SET_VLAN_INGRESS_PRIORITY_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 671 | case SET_VLAN_EGRESS_PRIORITY_CMD: |
| 672 | case SET_VLAN_FLAG_CMD: |
| 673 | case ADD_VLAN_CMD: |
| 674 | case DEL_VLAN_CMD: |
| 675 | case GET_VLAN_REALDEV_NAME_CMD: |
| 676 | case GET_VLAN_VID_CMD: |
| 677 | err = -ENODEV; |
| 678 | dev = __dev_get_by_name(args.device1); |
| 679 | if (!dev) |
| 680 | goto out; |
| 681 | |
| 682 | err = -EINVAL; |
| 683 | if (args.cmd != ADD_VLAN_CMD && |
| 684 | !(dev->priv_flags & IFF_802_1Q_VLAN)) |
| 685 | goto out; |
| 686 | } |
| 687 | |
| 688 | switch (args.cmd) { |
| 689 | case SET_VLAN_INGRESS_PRIORITY_CMD: |
| 690 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | if (!capable(CAP_NET_ADMIN)) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 692 | break; |
| 693 | vlan_dev_set_ingress_priority(dev, |
| 694 | args.u.skb_priority, |
| 695 | args.vlan_qos); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | break; |
| 697 | |
| 698 | case SET_VLAN_EGRESS_PRIORITY_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 699 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | if (!capable(CAP_NET_ADMIN)) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 701 | break; |
| 702 | err = vlan_dev_set_egress_priority(dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | args.u.skb_priority, |
| 704 | args.vlan_qos); |
| 705 | break; |
| 706 | |
| 707 | case SET_VLAN_FLAG_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 708 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | if (!capable(CAP_NET_ADMIN)) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 710 | break; |
| 711 | err = vlan_dev_set_vlan_flag(dev, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | args.u.flag, |
| 713 | args.vlan_qos); |
| 714 | break; |
| 715 | |
| 716 | case SET_VLAN_NAME_TYPE_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 717 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | if (!capable(CAP_NET_ADMIN)) |
| 719 | return -EPERM; |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 720 | if ((args.u.name_type >= 0) && |
| 721 | (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | vlan_name_type = args.u.name_type; |
| 723 | err = 0; |
| 724 | } else { |
| 725 | err = -EINVAL; |
| 726 | } |
| 727 | break; |
| 728 | |
| 729 | case ADD_VLAN_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 730 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | if (!capable(CAP_NET_ADMIN)) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 732 | break; |
| 733 | if (register_vlan_device(dev, args.u.VID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | err = 0; |
| 735 | } else { |
| 736 | err = -EINVAL; |
| 737 | } |
| 738 | break; |
| 739 | |
| 740 | case DEL_VLAN_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 741 | err = -EPERM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | if (!capable(CAP_NET_ADMIN)) |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 743 | break; |
| 744 | err = unregister_vlan_device(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | break; |
| 746 | |
| 747 | case GET_VLAN_INGRESS_PRIORITY_CMD: |
| 748 | /* TODO: Implement |
| 749 | err = vlan_dev_get_ingress_priority(args); |
| 750 | if (copy_to_user((void*)arg, &args, |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 751 | sizeof(struct vlan_ioctl_args))) { |
| 752 | err = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | } |
| 754 | */ |
| 755 | err = -EINVAL; |
| 756 | break; |
| 757 | case GET_VLAN_EGRESS_PRIORITY_CMD: |
| 758 | /* TODO: Implement |
| 759 | err = vlan_dev_get_egress_priority(args.device1, &(args.args); |
| 760 | if (copy_to_user((void*)arg, &args, |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 761 | sizeof(struct vlan_ioctl_args))) { |
| 762 | err = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | } |
| 764 | */ |
| 765 | err = -EINVAL; |
| 766 | break; |
| 767 | case GET_VLAN_REALDEV_NAME_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 768 | vlan_dev_get_realdev_name(dev, args.u.device2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | if (copy_to_user(arg, &args, |
| 770 | sizeof(struct vlan_ioctl_args))) { |
| 771 | err = -EFAULT; |
| 772 | } |
| 773 | break; |
| 774 | |
| 775 | case GET_VLAN_VID_CMD: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 776 | vlan_dev_get_vid(dev, &vid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | args.u.VID = vid; |
| 778 | if (copy_to_user(arg, &args, |
| 779 | sizeof(struct vlan_ioctl_args))) { |
YOSHIFUJI Hideaki | 122952f | 2007-02-09 23:24:25 +0900 | [diff] [blame] | 780 | err = -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
| 782 | break; |
| 783 | |
| 784 | default: |
| 785 | /* pass on to underlying device instead?? */ |
| 786 | printk(VLAN_DBG "%s: Unknown VLAN CMD: %x \n", |
| 787 | __FUNCTION__, args.cmd); |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 788 | err = -EINVAL; |
| 789 | break; |
Stephen Hemminger | 3ff50b7 | 2007-04-20 17:09:22 -0700 | [diff] [blame] | 790 | } |
Mika Kukkonen | 7eb1b3d | 2005-12-21 18:39:49 -0800 | [diff] [blame] | 791 | out: |
Patrick McHardy | c17d887 | 2007-06-13 12:05:22 -0700 | [diff] [blame] | 792 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | return err; |
| 794 | } |
| 795 | |
| 796 | MODULE_LICENSE("GPL"); |
| 797 | MODULE_VERSION(DRV_VERSION); |