aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntonio Quartulli <antonio@open-mesh.com>2013-07-02 05:04:34 -0400
committerAntonio Quartulli <antonio@meshcoding.com>2013-10-19 11:28:08 -0400
commit5d2c05b213377694a2aa8ce1ed9b23f7c39b0569 (patch)
treefbec175cf4dd4cb9b2c699b1b8d93883933fa324
parentbe1db4f6615b5e6156c807ea8985171c215c2d57 (diff)
batman-adv: add per VLAN interface attribute framework
Since batman-adv is now fully VLAN-aware, a proper framework able to handle per-vlan-interface attributes is needed. Those attributes will affect the associated VLAN interface only, rather than the real soft_iface (which would result in every vlan interface having the same attribute configuration). To make the code simpler and easier to extend, attributes associated to the standalone soft_iface are now treated like belonging to yet another vlan having a special vid. This vid is different from the others because it is made up by all zeros and the VLAN_HAS_TAG bit is not set. Signed-off-by: Antonio Quartulli <antonio@open-mesh.com> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
-rw-r--r--net/batman-adv/hard-interface.c2
-rw-r--r--net/batman-adv/main.c5
-rw-r--r--net/batman-adv/soft-interface.c171
-rw-r--r--net/batman-adv/soft-interface.h1
-rw-r--r--net/batman-adv/types.h21
5 files changed, 197 insertions, 3 deletions
diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
index d564af295db4..c5f871f218c6 100644
--- a/net/batman-adv/hard-interface.c
+++ b/net/batman-adv/hard-interface.c
@@ -643,6 +643,8 @@ static int batadv_hard_if_event(struct notifier_block *this,
643 643
644 if (batadv_softif_is_valid(net_dev) && event == NETDEV_REGISTER) { 644 if (batadv_softif_is_valid(net_dev) && event == NETDEV_REGISTER) {
645 batadv_sysfs_add_meshif(net_dev); 645 batadv_sysfs_add_meshif(net_dev);
646 bat_priv = netdev_priv(net_dev);
647 batadv_softif_create_vlan(bat_priv, BATADV_NO_FLAGS);
646 return NOTIFY_DONE; 648 return NOTIFY_DONE;
647 } 649 }
648 650
diff --git a/net/batman-adv/main.c b/net/batman-adv/main.c
index 80f60d1144f0..22075511c448 100644
--- a/net/batman-adv/main.c
+++ b/net/batman-adv/main.c
@@ -113,6 +113,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
113 spin_lock_init(&bat_priv->gw.list_lock); 113 spin_lock_init(&bat_priv->gw.list_lock);
114 spin_lock_init(&bat_priv->tvlv.container_list_lock); 114 spin_lock_init(&bat_priv->tvlv.container_list_lock);
115 spin_lock_init(&bat_priv->tvlv.handler_list_lock); 115 spin_lock_init(&bat_priv->tvlv.handler_list_lock);
116 spin_lock_init(&bat_priv->softif_vlan_list_lock);
116 117
117 INIT_HLIST_HEAD(&bat_priv->forw_bat_list); 118 INIT_HLIST_HEAD(&bat_priv->forw_bat_list);
118 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list); 119 INIT_HLIST_HEAD(&bat_priv->forw_bcast_list);
@@ -122,6 +123,7 @@ int batadv_mesh_init(struct net_device *soft_iface)
122 INIT_LIST_HEAD(&bat_priv->tt.roam_list); 123 INIT_LIST_HEAD(&bat_priv->tt.roam_list);
123 INIT_HLIST_HEAD(&bat_priv->tvlv.container_list); 124 INIT_HLIST_HEAD(&bat_priv->tvlv.container_list);
124 INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list); 125 INIT_HLIST_HEAD(&bat_priv->tvlv.handler_list);
126 INIT_HLIST_HEAD(&bat_priv->softif_vlan_list);
125 127
126 ret = batadv_originator_init(bat_priv); 128 ret = batadv_originator_init(bat_priv);
127 if (ret < 0) 129 if (ret < 0)
@@ -131,9 +133,6 @@ int batadv_mesh_init(struct net_device *soft_iface)
131 if (ret < 0) 133 if (ret < 0)
132 goto err; 134 goto err;
133 135
134 batadv_tt_local_add(soft_iface, soft_iface->dev_addr,
135 BATADV_NO_FLAGS, BATADV_NULL_IFINDEX);
136
137 ret = batadv_bla_init(bat_priv); 136 ret = batadv_bla_init(bat_priv);
138 if (ret < 0) 137 if (ret < 0)
139 goto err; 138 goto err;
diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
index 279e91d570a7..936b83bb02de 100644
--- a/net/batman-adv/soft-interface.c
+++ b/net/batman-adv/soft-interface.c
@@ -393,6 +393,166 @@ out:
393 return; 393 return;
394} 394}
395 395
396/**
397 * batadv_softif_vlan_free_ref - decrease the vlan object refcounter and
398 * possibly free it
399 * @softif_vlan: the vlan object to release
400 */
401static void batadv_softif_vlan_free_ref(struct batadv_softif_vlan *softif_vlan)
402{
403 if (atomic_dec_and_test(&softif_vlan->refcount))
404 kfree_rcu(softif_vlan, rcu);
405}
406
407/**
408 * batadv_softif_vlan_get - get the vlan object for a specific vid
409 * @bat_priv: the bat priv with all the soft interface information
410 * @vid: the identifier of the vlan object to retrieve
411 *
412 * Returns the private data of the vlan matching the vid passed as argument or
413 * NULL otherwise. The refcounter of the returned object is incremented by 1.
414 */
415static struct batadv_softif_vlan *
416batadv_softif_vlan_get(struct batadv_priv *bat_priv, unsigned short vid)
417{
418 struct batadv_softif_vlan *vlan_tmp, *vlan = NULL;
419
420 rcu_read_lock();
421 hlist_for_each_entry_rcu(vlan_tmp, &bat_priv->softif_vlan_list, list) {
422 if (vlan_tmp->vid != vid)
423 continue;
424
425 if (!atomic_inc_not_zero(&vlan_tmp->refcount))
426 continue;
427
428 vlan = vlan_tmp;
429 break;
430 }
431 rcu_read_unlock();
432
433 return vlan;
434}
435
436/**
437 * batadv_create_vlan - allocate the needed resources for a new vlan
438 * @bat_priv: the bat priv with all the soft interface information
439 * @vid: the VLAN identifier
440 *
441 * Returns 0 on success, a negative error otherwise.
442 */
443int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid)
444{
445 struct batadv_softif_vlan *vlan;
446
447 vlan = batadv_softif_vlan_get(bat_priv, vid);
448 if (vlan) {
449 batadv_softif_vlan_free_ref(vlan);
450 return -EEXIST;
451 }
452
453 vlan = kzalloc(sizeof(*vlan), GFP_ATOMIC);
454 if (!vlan)
455 return -ENOMEM;
456
457 vlan->vid = vid;
458 atomic_set(&vlan->refcount, 1);
459
460 /* add a new TT local entry. This one will be marked with the NOPURGE
461 * flag
462 */
463 batadv_tt_local_add(bat_priv->soft_iface,
464 bat_priv->soft_iface->dev_addr, vid,
465 BATADV_NULL_IFINDEX);
466
467 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
468 hlist_add_head_rcu(&vlan->list, &bat_priv->softif_vlan_list);
469 spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
470
471 return 0;
472}
473
474/**
475 * batadv_softif_destroy_vlan - remove and destroy a softif_vlan object
476 * @bat_priv: the bat priv with all the soft interface information
477 * @vlan: the object to remove
478 */
479static void batadv_softif_destroy_vlan(struct batadv_priv *bat_priv,
480 struct batadv_softif_vlan *vlan)
481{
482 spin_lock_bh(&bat_priv->softif_vlan_list_lock);
483 hlist_del_rcu(&vlan->list);
484 spin_unlock_bh(&bat_priv->softif_vlan_list_lock);
485
486 /* explicitly remove the associated TT local entry because it is marked
487 * with the NOPURGE flag
488 */
489 batadv_tt_local_remove(bat_priv, bat_priv->soft_iface->dev_addr,
490 vlan->vid, "vlan interface destroyed", false);
491
492 batadv_softif_vlan_free_ref(vlan);
493}
494
495/**
496 * batadv_interface_add_vid - ndo_add_vid API implementation
497 * @dev: the netdev of the mesh interface
498 * @vid: identifier of the new vlan
499 *
500 * Set up all the internal structures for handling the new vlan on top of the
501 * mesh interface
502 *
503 * Returns 0 on success or a negative error code in case of failure.
504 */
505static int batadv_interface_add_vid(struct net_device *dev, __be16 proto,
506 unsigned short vid)
507{
508 struct batadv_priv *bat_priv = netdev_priv(dev);
509
510 /* only 802.1Q vlans are supported.
511 * batman-adv does not know how to handle other types
512 */
513 if (proto != htons(ETH_P_8021Q))
514 return -EINVAL;
515
516 vid |= BATADV_VLAN_HAS_TAG;
517
518 return batadv_softif_create_vlan(bat_priv, vid);
519}
520
521/**
522 * batadv_interface_kill_vid - ndo_kill_vid API implementation
523 * @dev: the netdev of the mesh interface
524 * @vid: identifier of the deleted vlan
525 *
526 * Destroy all the internal structures used to handle the vlan identified by vid
527 * on top of the mesh interface
528 *
529 * Returns 0 on success, -EINVAL if the specified prototype is not ETH_P_8021Q
530 * or -ENOENT if the specified vlan id wasn't registered.
531 */
532static int batadv_interface_kill_vid(struct net_device *dev, __be16 proto,
533 unsigned short vid)
534{
535 struct batadv_priv *bat_priv = netdev_priv(dev);
536 struct batadv_softif_vlan *vlan;
537
538 /* only 802.1Q vlans are supported. batman-adv does not know how to
539 * handle other types
540 */
541 if (proto != htons(ETH_P_8021Q))
542 return -EINVAL;
543
544 vlan = batadv_softif_vlan_get(bat_priv, vid | BATADV_VLAN_HAS_TAG);
545 if (!vlan)
546 return -ENOENT;
547
548 batadv_softif_destroy_vlan(bat_priv, vlan);
549
550 /* finally free the vlan object */
551 batadv_softif_vlan_free_ref(vlan);
552
553 return 0;
554}
555
396/* batman-adv network devices have devices nesting below it and are a special 556/* batman-adv network devices have devices nesting below it and are a special
397 * "super class" of normal network devices; split their locks off into a 557 * "super class" of normal network devices; split their locks off into a
398 * separate class since they always nest. 558 * separate class since they always nest.
@@ -432,6 +592,7 @@ static void batadv_set_lockdep_class(struct net_device *dev)
432 */ 592 */
433static void batadv_softif_destroy_finish(struct work_struct *work) 593static void batadv_softif_destroy_finish(struct work_struct *work)
434{ 594{
595 struct batadv_softif_vlan *vlan;
435 struct batadv_priv *bat_priv; 596 struct batadv_priv *bat_priv;
436 struct net_device *soft_iface; 597 struct net_device *soft_iface;
437 598
@@ -439,6 +600,13 @@ static void batadv_softif_destroy_finish(struct work_struct *work)
439 cleanup_work); 600 cleanup_work);
440 soft_iface = bat_priv->soft_iface; 601 soft_iface = bat_priv->soft_iface;
441 602
603 /* destroy the "untagged" VLAN */
604 vlan = batadv_softif_vlan_get(bat_priv, BATADV_NO_FLAGS);
605 if (vlan) {
606 batadv_softif_destroy_vlan(bat_priv, vlan);
607 batadv_softif_vlan_free_ref(vlan);
608 }
609
442 batadv_sysfs_del_meshif(soft_iface); 610 batadv_sysfs_del_meshif(soft_iface);
443 611
444 rtnl_lock(); 612 rtnl_lock();
@@ -594,6 +762,8 @@ static const struct net_device_ops batadv_netdev_ops = {
594 .ndo_open = batadv_interface_open, 762 .ndo_open = batadv_interface_open,
595 .ndo_stop = batadv_interface_release, 763 .ndo_stop = batadv_interface_release,
596 .ndo_get_stats = batadv_interface_stats, 764 .ndo_get_stats = batadv_interface_stats,
765 .ndo_vlan_rx_add_vid = batadv_interface_add_vid,
766 .ndo_vlan_rx_kill_vid = batadv_interface_kill_vid,
597 .ndo_set_mac_address = batadv_interface_set_mac_addr, 767 .ndo_set_mac_address = batadv_interface_set_mac_addr,
598 .ndo_change_mtu = batadv_interface_change_mtu, 768 .ndo_change_mtu = batadv_interface_change_mtu,
599 .ndo_set_rx_mode = batadv_interface_set_rx_mode, 769 .ndo_set_rx_mode = batadv_interface_set_rx_mode,
@@ -633,6 +803,7 @@ static void batadv_softif_init_early(struct net_device *dev)
633 803
634 dev->netdev_ops = &batadv_netdev_ops; 804 dev->netdev_ops = &batadv_netdev_ops;
635 dev->destructor = batadv_softif_free; 805 dev->destructor = batadv_softif_free;
806 dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER;
636 dev->tx_queue_len = 0; 807 dev->tx_queue_len = 0;
637 808
638 /* can't call min_mtu, because the needed variables 809 /* can't call min_mtu, because the needed variables
diff --git a/net/batman-adv/soft-interface.h b/net/batman-adv/soft-interface.h
index 2f2472c2ea0d..16d9be6df647 100644
--- a/net/batman-adv/soft-interface.h
+++ b/net/batman-adv/soft-interface.h
@@ -28,5 +28,6 @@ struct net_device *batadv_softif_create(const char *name);
28void batadv_softif_destroy_sysfs(struct net_device *soft_iface); 28void batadv_softif_destroy_sysfs(struct net_device *soft_iface);
29int batadv_softif_is_valid(const struct net_device *net_dev); 29int batadv_softif_is_valid(const struct net_device *net_dev);
30extern struct rtnl_link_ops batadv_link_ops; 30extern struct rtnl_link_ops batadv_link_ops;
31int batadv_softif_create_vlan(struct batadv_priv *bat_priv, unsigned short vid);
31 32
32#endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */ 33#endif /* _NET_BATMAN_ADV_SOFT_INTERFACE_H_ */
diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
index 6954a5d5a9e9..e5fecd4add64 100644
--- a/net/batman-adv/types.h
+++ b/net/batman-adv/types.h
@@ -531,6 +531,22 @@ struct batadv_priv_nc {
531}; 531};
532 532
533/** 533/**
534 * struct batadv_softif_vlan - per VLAN attributes set
535 * @vid: VLAN identifier
536 * @kobj: kobject for sysfs vlan subdirectory
537 * @list: list node for bat_priv::softif_vlan_list
538 * @refcount: number of context where this object is currently in use
539 * @rcu: struct used for freeing in a RCU-safe manner
540 */
541struct batadv_softif_vlan {
542 unsigned short vid;
543 struct kobject *kobj;
544 struct hlist_node list;
545 atomic_t refcount;
546 struct rcu_head rcu;
547};
548
549/**
534 * struct batadv_priv - per mesh interface data 550 * struct batadv_priv - per mesh interface data
535 * @mesh_state: current status of the mesh (inactive/active/deactivating) 551 * @mesh_state: current status of the mesh (inactive/active/deactivating)
536 * @soft_iface: net device which holds this struct as private data 552 * @soft_iface: net device which holds this struct as private data
@@ -566,6 +582,9 @@ struct batadv_priv_nc {
566 * @primary_if: one of the hard interfaces assigned to this mesh interface 582 * @primary_if: one of the hard interfaces assigned to this mesh interface
567 * becomes the primary interface 583 * becomes the primary interface
568 * @bat_algo_ops: routing algorithm used by this mesh interface 584 * @bat_algo_ops: routing algorithm used by this mesh interface
585 * @softif_vlan_list: a list of softif_vlan structs, one per VLAN created on top
586 * of the mesh interface represented by this object
587 * @softif_vlan_list_lock: lock protecting softif_vlan_list
569 * @bla: bridge loope avoidance data 588 * @bla: bridge loope avoidance data
570 * @debug_log: holding debug logging relevant data 589 * @debug_log: holding debug logging relevant data
571 * @gw: gateway data 590 * @gw: gateway data
@@ -613,6 +632,8 @@ struct batadv_priv {
613 struct work_struct cleanup_work; 632 struct work_struct cleanup_work;
614 struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */ 633 struct batadv_hard_iface __rcu *primary_if; /* rcu protected pointer */
615 struct batadv_algo_ops *bat_algo_ops; 634 struct batadv_algo_ops *bat_algo_ops;
635 struct hlist_head softif_vlan_list;
636 spinlock_t softif_vlan_list_lock; /* protects softif_vlan_list */
616#ifdef CONFIG_BATMAN_ADV_BLA 637#ifdef CONFIG_BATMAN_ADV_BLA
617 struct batadv_priv_bla bla; 638 struct batadv_priv_bla bla;
618#endif 639#endif