aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/bridge_loop_avoidance.c
diff options
context:
space:
mode:
Diffstat (limited to 'net/batman-adv/bridge_loop_avoidance.c')
-rw-r--r--net/batman-adv/bridge_loop_avoidance.c329
1 files changed, 230 insertions, 99 deletions
diff --git a/net/batman-adv/bridge_loop_avoidance.c b/net/batman-adv/bridge_loop_avoidance.c
index c24c481b666f..0a6c8b824a00 100644
--- a/net/batman-adv/bridge_loop_avoidance.c
+++ b/net/batman-adv/bridge_loop_avoidance.c
@@ -1,4 +1,4 @@
1/* Copyright (C) 2011-2015 B.A.T.M.A.N. contributors: 1/* Copyright (C) 2011-2016 B.A.T.M.A.N. contributors:
2 * 2 *
3 * Simon Wunderlich 3 * Simon Wunderlich
4 * 4 *
@@ -31,6 +31,7 @@
31#include <linux/jhash.h> 31#include <linux/jhash.h>
32#include <linux/jiffies.h> 32#include <linux/jiffies.h>
33#include <linux/kernel.h> 33#include <linux/kernel.h>
34#include <linux/kref.h>
34#include <linux/list.h> 35#include <linux/list.h>
35#include <linux/lockdep.h> 36#include <linux/lockdep.h>
36#include <linux/netdevice.h> 37#include <linux/netdevice.h>
@@ -58,7 +59,13 @@ static void
58batadv_bla_send_announce(struct batadv_priv *bat_priv, 59batadv_bla_send_announce(struct batadv_priv *bat_priv,
59 struct batadv_bla_backbone_gw *backbone_gw); 60 struct batadv_bla_backbone_gw *backbone_gw);
60 61
61/* return the index of the claim */ 62/**
63 * batadv_choose_claim - choose the right bucket for a claim.
64 * @data: data to hash
65 * @size: size of the hash table
66 *
67 * Return: the hash index of the claim
68 */
62static inline u32 batadv_choose_claim(const void *data, u32 size) 69static inline u32 batadv_choose_claim(const void *data, u32 size)
63{ 70{
64 struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data; 71 struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data;
@@ -70,7 +77,13 @@ static inline u32 batadv_choose_claim(const void *data, u32 size)
70 return hash % size; 77 return hash % size;
71} 78}
72 79
73/* return the index of the backbone gateway */ 80/**
81 * batadv_choose_backbone_gw - choose the right bucket for a backbone gateway.
82 * @data: data to hash
83 * @size: size of the hash table
84 *
85 * Return: the hash index of the backbone gateway
86 */
74static inline u32 batadv_choose_backbone_gw(const void *data, u32 size) 87static inline u32 batadv_choose_backbone_gw(const void *data, u32 size)
75{ 88{
76 const struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data; 89 const struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data;
@@ -82,7 +95,13 @@ static inline u32 batadv_choose_backbone_gw(const void *data, u32 size)
82 return hash % size; 95 return hash % size;
83} 96}
84 97
85/* compares address and vid of two backbone gws */ 98/**
99 * batadv_compare_backbone_gw - compare address and vid of two backbone gws
100 * @node: list node of the first entry to compare
101 * @data2: pointer to the second backbone gateway
102 *
103 * Return: 1 if the backbones have the same data, 0 otherwise
104 */
86static int batadv_compare_backbone_gw(const struct hlist_node *node, 105static int batadv_compare_backbone_gw(const struct hlist_node *node,
87 const void *data2) 106 const void *data2)
88{ 107{
@@ -100,7 +119,13 @@ static int batadv_compare_backbone_gw(const struct hlist_node *node,
100 return 1; 119 return 1;
101} 120}
102 121
103/* compares address and vid of two claims */ 122/**
123 * batadv_compare_backbone_gw - compare address and vid of two claims
124 * @node: list node of the first entry to compare
125 * @data2: pointer to the second claims
126 *
127 * Return: 1 if the claim have the same data, 0 otherwise
128 */
104static int batadv_compare_claim(const struct hlist_node *node, 129static int batadv_compare_claim(const struct hlist_node *node,
105 const void *data2) 130 const void *data2)
106{ 131{
@@ -118,35 +143,62 @@ static int batadv_compare_claim(const struct hlist_node *node,
118 return 1; 143 return 1;
119} 144}
120 145
121/* free a backbone gw */ 146/**
122static void 147 * batadv_backbone_gw_release - release backbone gw from lists and queue for
123batadv_backbone_gw_free_ref(struct batadv_bla_backbone_gw *backbone_gw) 148 * free after rcu grace period
149 * @ref: kref pointer of the backbone gw
150 */
151static void batadv_backbone_gw_release(struct kref *ref)
124{ 152{
125 if (atomic_dec_and_test(&backbone_gw->refcount)) 153 struct batadv_bla_backbone_gw *backbone_gw;
126 kfree_rcu(backbone_gw, rcu); 154
155 backbone_gw = container_of(ref, struct batadv_bla_backbone_gw,
156 refcount);
157
158 kfree_rcu(backbone_gw, rcu);
127} 159}
128 160
129/* finally deinitialize the claim */ 161/**
130static void batadv_claim_release(struct batadv_bla_claim *claim) 162 * batadv_backbone_gw_put - decrement the backbone gw refcounter and possibly
163 * release it
164 * @backbone_gw: backbone gateway to be free'd
165 */
166static void batadv_backbone_gw_put(struct batadv_bla_backbone_gw *backbone_gw)
131{ 167{
132 batadv_backbone_gw_free_ref(claim->backbone_gw); 168 kref_put(&backbone_gw->refcount, batadv_backbone_gw_release);
169}
170
171/**
172 * batadv_claim_release - release claim from lists and queue for free after rcu
173 * grace period
174 * @ref: kref pointer of the claim
175 */
176static void batadv_claim_release(struct kref *ref)
177{
178 struct batadv_bla_claim *claim;
179
180 claim = container_of(ref, struct batadv_bla_claim, refcount);
181
182 batadv_backbone_gw_put(claim->backbone_gw);
133 kfree_rcu(claim, rcu); 183 kfree_rcu(claim, rcu);
134} 184}
135 185
136/* free a claim, call claim_free_rcu if its the last reference */ 186/**
137static void batadv_claim_free_ref(struct batadv_bla_claim *claim) 187 * batadv_claim_put - decrement the claim refcounter and possibly
188 * release it
189 * @claim: claim to be free'd
190 */
191static void batadv_claim_put(struct batadv_bla_claim *claim)
138{ 192{
139 if (atomic_dec_and_test(&claim->refcount)) 193 kref_put(&claim->refcount, batadv_claim_release);
140 batadv_claim_release(claim);
141} 194}
142 195
143/** 196/**
144 * batadv_claim_hash_find 197 * batadv_claim_hash_find - looks for a claim in the claim hash
145 * @bat_priv: the bat priv with all the soft interface information 198 * @bat_priv: the bat priv with all the soft interface information
146 * @data: search data (may be local/static data) 199 * @data: search data (may be local/static data)
147 * 200 *
148 * looks for a claim in the hash, and returns it if found 201 * Return: claim if found or NULL otherwise.
149 * or NULL otherwise.
150 */ 202 */
151static struct batadv_bla_claim 203static struct batadv_bla_claim
152*batadv_claim_hash_find(struct batadv_priv *bat_priv, 204*batadv_claim_hash_find(struct batadv_priv *bat_priv,
@@ -169,7 +221,7 @@ static struct batadv_bla_claim
169 if (!batadv_compare_claim(&claim->hash_entry, data)) 221 if (!batadv_compare_claim(&claim->hash_entry, data))
170 continue; 222 continue;
171 223
172 if (!atomic_inc_not_zero(&claim->refcount)) 224 if (!kref_get_unless_zero(&claim->refcount))
173 continue; 225 continue;
174 226
175 claim_tmp = claim; 227 claim_tmp = claim;
@@ -181,12 +233,12 @@ static struct batadv_bla_claim
181} 233}
182 234
183/** 235/**
184 * batadv_backbone_hash_find - looks for a claim in the hash 236 * batadv_backbone_hash_find - looks for a backbone gateway in the hash
185 * @bat_priv: the bat priv with all the soft interface information 237 * @bat_priv: the bat priv with all the soft interface information
186 * @addr: the address of the originator 238 * @addr: the address of the originator
187 * @vid: the VLAN ID 239 * @vid: the VLAN ID
188 * 240 *
189 * Returns claim if found or NULL otherwise. 241 * Return: backbone gateway if found or NULL otherwise
190 */ 242 */
191static struct batadv_bla_backbone_gw * 243static struct batadv_bla_backbone_gw *
192batadv_backbone_hash_find(struct batadv_priv *bat_priv, u8 *addr, 244batadv_backbone_hash_find(struct batadv_priv *bat_priv, u8 *addr,
@@ -213,7 +265,7 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, u8 *addr,
213 &search_entry)) 265 &search_entry))
214 continue; 266 continue;
215 267
216 if (!atomic_inc_not_zero(&backbone_gw->refcount)) 268 if (!kref_get_unless_zero(&backbone_gw->refcount))
217 continue; 269 continue;
218 270
219 backbone_gw_tmp = backbone_gw; 271 backbone_gw_tmp = backbone_gw;
@@ -224,7 +276,10 @@ batadv_backbone_hash_find(struct batadv_priv *bat_priv, u8 *addr,
224 return backbone_gw_tmp; 276 return backbone_gw_tmp;
225} 277}
226 278
227/* delete all claims for a backbone */ 279/**
280 * batadv_bla_del_backbone_claims - delete all claims for a backbone
281 * @backbone_gw: backbone gateway where the claims should be removed
282 */
228static void 283static void
229batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw) 284batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)
230{ 285{
@@ -249,7 +304,7 @@ batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)
249 if (claim->backbone_gw != backbone_gw) 304 if (claim->backbone_gw != backbone_gw)
250 continue; 305 continue;
251 306
252 batadv_claim_free_ref(claim); 307 batadv_claim_put(claim);
253 hlist_del_rcu(&claim->hash_entry); 308 hlist_del_rcu(&claim->hash_entry);
254 } 309 }
255 spin_unlock_bh(list_lock); 310 spin_unlock_bh(list_lock);
@@ -368,18 +423,17 @@ static void batadv_bla_send_claim(struct batadv_priv *bat_priv, u8 *mac,
368 netif_rx(skb); 423 netif_rx(skb);
369out: 424out:
370 if (primary_if) 425 if (primary_if)
371 batadv_hardif_free_ref(primary_if); 426 batadv_hardif_put(primary_if);
372} 427}
373 428
374/** 429/**
375 * batadv_bla_get_backbone_gw 430 * batadv_bla_get_backbone_gw - finds or creates a backbone gateway
376 * @bat_priv: the bat priv with all the soft interface information 431 * @bat_priv: the bat priv with all the soft interface information
377 * @orig: the mac address of the originator 432 * @orig: the mac address of the originator
378 * @vid: the VLAN ID 433 * @vid: the VLAN ID
379 * @own_backbone: set if the requested backbone is local 434 * @own_backbone: set if the requested backbone is local
380 * 435 *
381 * searches for the backbone gw or creates a new one if it could not 436 * Return: the (possibly created) backbone gateway or NULL on error
382 * be found.
383 */ 437 */
384static struct batadv_bla_backbone_gw * 438static struct batadv_bla_backbone_gw *
385batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig, 439batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
@@ -412,7 +466,8 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
412 ether_addr_copy(entry->orig, orig); 466 ether_addr_copy(entry->orig, orig);
413 467
414 /* one for the hash, one for returning */ 468 /* one for the hash, one for returning */
415 atomic_set(&entry->refcount, 2); 469 kref_init(&entry->refcount);
470 kref_get(&entry->refcount);
416 471
417 hash_added = batadv_hash_add(bat_priv->bla.backbone_hash, 472 hash_added = batadv_hash_add(bat_priv->bla.backbone_hash,
418 batadv_compare_backbone_gw, 473 batadv_compare_backbone_gw,
@@ -430,7 +485,7 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
430 if (orig_node) { 485 if (orig_node) {
431 batadv_tt_global_del_orig(bat_priv, orig_node, vid, 486 batadv_tt_global_del_orig(bat_priv, orig_node, vid,
432 "became a backbone gateway"); 487 "became a backbone gateway");
433 batadv_orig_node_free_ref(orig_node); 488 batadv_orig_node_put(orig_node);
434 } 489 }
435 490
436 if (own_backbone) { 491 if (own_backbone) {
@@ -445,7 +500,13 @@ batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, u8 *orig,
445 return entry; 500 return entry;
446} 501}
447 502
448/* update or add the own backbone gw to make sure we announce 503/**
504 * batadv_bla_update_own_backbone_gw - updates the own backbone gw for a VLAN
505 * @bat_priv: the bat priv with all the soft interface information
506 * @primary_if: the selected primary interface
507 * @vid: VLAN identifier
508 *
509 * update or add the own backbone gw to make sure we announce
449 * where we receive other backbone gws 510 * where we receive other backbone gws
450 */ 511 */
451static void 512static void
@@ -462,7 +523,7 @@ batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv,
462 return; 523 return;
463 524
464 backbone_gw->lasttime = jiffies; 525 backbone_gw->lasttime = jiffies;
465 batadv_backbone_gw_free_ref(backbone_gw); 526 batadv_backbone_gw_put(backbone_gw);
466} 527}
467 528
468/** 529/**
@@ -511,7 +572,7 @@ static void batadv_bla_answer_request(struct batadv_priv *bat_priv,
511 572
512 /* finally, send an announcement frame */ 573 /* finally, send an announcement frame */
513 batadv_bla_send_announce(bat_priv, backbone_gw); 574 batadv_bla_send_announce(bat_priv, backbone_gw);
514 batadv_backbone_gw_free_ref(backbone_gw); 575 batadv_backbone_gw_put(backbone_gw);
515} 576}
516 577
517/** 578/**
@@ -542,12 +603,9 @@ static void batadv_bla_send_request(struct batadv_bla_backbone_gw *backbone_gw)
542} 603}
543 604
544/** 605/**
545 * batadv_bla_send_announce 606 * batadv_bla_send_announce - Send an announcement frame
546 * @bat_priv: the bat priv with all the soft interface information 607 * @bat_priv: the bat priv with all the soft interface information
547 * @backbone_gw: our backbone gateway which should be announced 608 * @backbone_gw: our backbone gateway which should be announced
548 *
549 * This function sends an announcement. It is called from multiple
550 * places.
551 */ 609 */
552static void batadv_bla_send_announce(struct batadv_priv *bat_priv, 610static void batadv_bla_send_announce(struct batadv_priv *bat_priv,
553 struct batadv_bla_backbone_gw *backbone_gw) 611 struct batadv_bla_backbone_gw *backbone_gw)
@@ -595,7 +653,8 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
595 claim->lasttime = jiffies; 653 claim->lasttime = jiffies;
596 claim->backbone_gw = backbone_gw; 654 claim->backbone_gw = backbone_gw;
597 655
598 atomic_set(&claim->refcount, 2); 656 kref_init(&claim->refcount);
657 kref_get(&claim->refcount);
599 batadv_dbg(BATADV_DBG_BLA, bat_priv, 658 batadv_dbg(BATADV_DBG_BLA, bat_priv,
600 "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n", 659 "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n",
601 mac, BATADV_PRINT_VID(vid)); 660 mac, BATADV_PRINT_VID(vid));
@@ -622,10 +681,10 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
622 spin_lock_bh(&claim->backbone_gw->crc_lock); 681 spin_lock_bh(&claim->backbone_gw->crc_lock);
623 claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); 682 claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
624 spin_unlock_bh(&claim->backbone_gw->crc_lock); 683 spin_unlock_bh(&claim->backbone_gw->crc_lock);
625 batadv_backbone_gw_free_ref(claim->backbone_gw); 684 batadv_backbone_gw_put(claim->backbone_gw);
626 } 685 }
627 /* set (new) backbone gw */ 686 /* set (new) backbone gw */
628 atomic_inc(&backbone_gw->refcount); 687 kref_get(&backbone_gw->refcount);
629 claim->backbone_gw = backbone_gw; 688 claim->backbone_gw = backbone_gw;
630 689
631 spin_lock_bh(&backbone_gw->crc_lock); 690 spin_lock_bh(&backbone_gw->crc_lock);
@@ -634,11 +693,14 @@ static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
634 backbone_gw->lasttime = jiffies; 693 backbone_gw->lasttime = jiffies;
635 694
636claim_free_ref: 695claim_free_ref:
637 batadv_claim_free_ref(claim); 696 batadv_claim_put(claim);
638} 697}
639 698
640/* Delete a claim from the claim hash which has the 699/**
641 * given mac address and vid. 700 * batadv_bla_del_claim - delete a claim from the claim hash
701 * @bat_priv: the bat priv with all the soft interface information
702 * @mac: mac address of the claim to be removed
703 * @vid: VLAN id for the claim to be removed
642 */ 704 */
643static void batadv_bla_del_claim(struct batadv_priv *bat_priv, 705static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
644 const u8 *mac, const unsigned short vid) 706 const u8 *mac, const unsigned short vid)
@@ -656,17 +718,25 @@ static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
656 718
657 batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim, 719 batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim,
658 batadv_choose_claim, claim); 720 batadv_choose_claim, claim);
659 batadv_claim_free_ref(claim); /* reference from the hash is gone */ 721 batadv_claim_put(claim); /* reference from the hash is gone */
660 722
661 spin_lock_bh(&claim->backbone_gw->crc_lock); 723 spin_lock_bh(&claim->backbone_gw->crc_lock);
662 claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN); 724 claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
663 spin_unlock_bh(&claim->backbone_gw->crc_lock); 725 spin_unlock_bh(&claim->backbone_gw->crc_lock);
664 726
665 /* don't need the reference from hash_find() anymore */ 727 /* don't need the reference from hash_find() anymore */
666 batadv_claim_free_ref(claim); 728 batadv_claim_put(claim);
667} 729}
668 730
669/* check for ANNOUNCE frame, return 1 if handled */ 731/**
732 * batadv_handle_announce - check for ANNOUNCE frame
733 * @bat_priv: the bat priv with all the soft interface information
734 * @an_addr: announcement mac address (ARP Sender HW address)
735 * @backbone_addr: originator address of the sender (Ethernet source MAC)
736 * @vid: the VLAN ID of the frame
737 *
738 * Return: 1 if handled
739 */
670static int batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr, 740static int batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
671 u8 *backbone_addr, unsigned short vid) 741 u8 *backbone_addr, unsigned short vid)
672{ 742{
@@ -712,11 +782,20 @@ static int batadv_handle_announce(struct batadv_priv *bat_priv, u8 *an_addr,
712 } 782 }
713 } 783 }
714 784
715 batadv_backbone_gw_free_ref(backbone_gw); 785 batadv_backbone_gw_put(backbone_gw);
716 return 1; 786 return 1;
717} 787}
718 788
719/* check for REQUEST frame, return 1 if handled */ 789/**
790 * batadv_handle_request - check for REQUEST frame
791 * @bat_priv: the bat priv with all the soft interface information
792 * @primary_if: the primary hard interface of this batman soft interface
793 * @backbone_addr: backbone address to be requested (ARP sender HW MAC)
794 * @ethhdr: ethernet header of a packet
795 * @vid: the VLAN ID of the frame
796 *
797 * Return: 1 if handled
798 */
720static int batadv_handle_request(struct batadv_priv *bat_priv, 799static int batadv_handle_request(struct batadv_priv *bat_priv,
721 struct batadv_hard_iface *primary_if, 800 struct batadv_hard_iface *primary_if,
722 u8 *backbone_addr, struct ethhdr *ethhdr, 801 u8 *backbone_addr, struct ethhdr *ethhdr,
@@ -740,7 +819,16 @@ static int batadv_handle_request(struct batadv_priv *bat_priv,
740 return 1; 819 return 1;
741} 820}
742 821
743/* check for UNCLAIM frame, return 1 if handled */ 822/**
823 * batadv_handle_unclaim - check for UNCLAIM frame
824 * @bat_priv: the bat priv with all the soft interface information
825 * @primary_if: the primary hard interface of this batman soft interface
826 * @backbone_addr: originator address of the backbone (Ethernet source)
827 * @claim_addr: Client to be unclaimed (ARP sender HW MAC)
828 * @vid: the VLAN ID of the frame
829 *
830 * Return: 1 if handled
831 */
744static int batadv_handle_unclaim(struct batadv_priv *bat_priv, 832static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
745 struct batadv_hard_iface *primary_if, 833 struct batadv_hard_iface *primary_if,
746 u8 *backbone_addr, u8 *claim_addr, 834 u8 *backbone_addr, u8 *claim_addr,
@@ -765,11 +853,20 @@ static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
765 claim_addr, BATADV_PRINT_VID(vid), backbone_gw->orig); 853 claim_addr, BATADV_PRINT_VID(vid), backbone_gw->orig);
766 854
767 batadv_bla_del_claim(bat_priv, claim_addr, vid); 855 batadv_bla_del_claim(bat_priv, claim_addr, vid);
768 batadv_backbone_gw_free_ref(backbone_gw); 856 batadv_backbone_gw_put(backbone_gw);
769 return 1; 857 return 1;
770} 858}
771 859
772/* check for CLAIM frame, return 1 if handled */ 860/**
861 * batadv_handle_claim - check for CLAIM frame
862 * @bat_priv: the bat priv with all the soft interface information
863 * @primary_if: the primary hard interface of this batman soft interface
864 * @backbone_addr: originator address of the backbone (Ethernet Source)
865 * @claim_addr: client mac address to be claimed (ARP sender HW MAC)
866 * @vid: the VLAN ID of the frame
867 *
868 * Return: 1 if handled
869 */
773static int batadv_handle_claim(struct batadv_priv *bat_priv, 870static int batadv_handle_claim(struct batadv_priv *bat_priv,
774 struct batadv_hard_iface *primary_if, 871 struct batadv_hard_iface *primary_if,
775 u8 *backbone_addr, u8 *claim_addr, 872 u8 *backbone_addr, u8 *claim_addr,
@@ -793,12 +890,12 @@ static int batadv_handle_claim(struct batadv_priv *bat_priv,
793 890
794 /* TODO: we could call something like tt_local_del() here. */ 891 /* TODO: we could call something like tt_local_del() here. */
795 892
796 batadv_backbone_gw_free_ref(backbone_gw); 893 batadv_backbone_gw_put(backbone_gw);
797 return 1; 894 return 1;
798} 895}
799 896
800/** 897/**
801 * batadv_check_claim_group 898 * batadv_check_claim_group - check for claim group membership
802 * @bat_priv: the bat priv with all the soft interface information 899 * @bat_priv: the bat priv with all the soft interface information
803 * @primary_if: the primary interface of this batman interface 900 * @primary_if: the primary interface of this batman interface
804 * @hw_src: the Hardware source in the ARP Header 901 * @hw_src: the Hardware source in the ARP Header
@@ -809,7 +906,7 @@ static int batadv_handle_claim(struct batadv_priv *bat_priv,
809 * This function also applies the group ID of the sender 906 * This function also applies the group ID of the sender
810 * if it is in the same mesh. 907 * if it is in the same mesh.
811 * 908 *
812 * returns: 909 * Return:
813 * 2 - if it is a claim packet and on the same group 910 * 2 - if it is a claim packet and on the same group
814 * 1 - if is a claim packet from another group 911 * 1 - if is a claim packet from another group
815 * 0 - if it is not a claim packet 912 * 0 - if it is not a claim packet
@@ -867,20 +964,18 @@ static int batadv_check_claim_group(struct batadv_priv *bat_priv,
867 bla_dst_own->group = bla_dst->group; 964 bla_dst_own->group = bla_dst->group;
868 } 965 }
869 966
870 batadv_orig_node_free_ref(orig_node); 967 batadv_orig_node_put(orig_node);
871 968
872 return 2; 969 return 2;
873} 970}
874 971
875/** 972/**
876 * batadv_bla_process_claim 973 * batadv_bla_process_claim - Check if this is a claim frame, and process it
877 * @bat_priv: the bat priv with all the soft interface information 974 * @bat_priv: the bat priv with all the soft interface information
878 * @primary_if: the primary hard interface of this batman soft interface 975 * @primary_if: the primary hard interface of this batman soft interface
879 * @skb: the frame to be checked 976 * @skb: the frame to be checked
880 * 977 *
881 * Check if this is a claim frame, and process it accordingly. 978 * Return: 1 if it was a claim frame, otherwise return 0 to
882 *
883 * returns 1 if it was a claim frame, otherwise return 0 to
884 * tell the callee that it can use the frame on its own. 979 * tell the callee that it can use the frame on its own.
885 */ 980 */
886static int batadv_bla_process_claim(struct batadv_priv *bat_priv, 981static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
@@ -1011,7 +1106,13 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
1011 return 1; 1106 return 1;
1012} 1107}
1013 1108
1014/* Check when we last heard from other nodes, and remove them in case of 1109/**
1110 * batadv_bla_purge_backbone_gw - Remove backbone gateways after a timeout or
1111 * immediately
1112 * @bat_priv: the bat priv with all the soft interface information
1113 * @now: whether the whole hash shall be wiped now
1114 *
1115 * Check when we last heard from other nodes, and remove them in case of
1015 * a time out, or clean all backbone gws if now is set. 1116 * a time out, or clean all backbone gws if now is set.
1016 */ 1117 */
1017static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now) 1118static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now)
@@ -1052,14 +1153,14 @@ purge_now:
1052 batadv_bla_del_backbone_claims(backbone_gw); 1153 batadv_bla_del_backbone_claims(backbone_gw);
1053 1154
1054 hlist_del_rcu(&backbone_gw->hash_entry); 1155 hlist_del_rcu(&backbone_gw->hash_entry);
1055 batadv_backbone_gw_free_ref(backbone_gw); 1156 batadv_backbone_gw_put(backbone_gw);
1056 } 1157 }
1057 spin_unlock_bh(list_lock); 1158 spin_unlock_bh(list_lock);
1058 } 1159 }
1059} 1160}
1060 1161
1061/** 1162/**
1062 * batadv_bla_purge_claims 1163 * batadv_bla_purge_claims - Remove claims after a timeout or immediately
1063 * @bat_priv: the bat priv with all the soft interface information 1164 * @bat_priv: the bat priv with all the soft interface information
1064 * @primary_if: the selected primary interface, may be NULL if now is set 1165 * @primary_if: the selected primary interface, may be NULL if now is set
1065 * @now: whether the whole hash shall be wiped now 1166 * @now: whether the whole hash shall be wiped now
@@ -1108,12 +1209,11 @@ purge_now:
1108} 1209}
1109 1210
1110/** 1211/**
1111 * batadv_bla_update_orig_address 1212 * batadv_bla_update_orig_address - Update the backbone gateways when the own
1213 * originator address changes
1112 * @bat_priv: the bat priv with all the soft interface information 1214 * @bat_priv: the bat priv with all the soft interface information
1113 * @primary_if: the new selected primary_if 1215 * @primary_if: the new selected primary_if
1114 * @oldif: the old primary interface, may be NULL 1216 * @oldif: the old primary interface, may be NULL
1115 *
1116 * Update the backbone gateways when the own orig address changes.
1117 */ 1217 */
1118void batadv_bla_update_orig_address(struct batadv_priv *bat_priv, 1218void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
1119 struct batadv_hard_iface *primary_if, 1219 struct batadv_hard_iface *primary_if,
@@ -1181,10 +1281,14 @@ void batadv_bla_status_update(struct net_device *net_dev)
1181 * so just call that one. 1281 * so just call that one.
1182 */ 1282 */
1183 batadv_bla_update_orig_address(bat_priv, primary_if, primary_if); 1283 batadv_bla_update_orig_address(bat_priv, primary_if, primary_if);
1184 batadv_hardif_free_ref(primary_if); 1284 batadv_hardif_put(primary_if);
1185} 1285}
1186 1286
1187/* periodic work to do: 1287/**
1288 * batadv_bla_periodic_work - performs periodic bla work
1289 * @work: kernel work struct
1290 *
1291 * periodic work to do:
1188 * * purge structures when they are too old 1292 * * purge structures when they are too old
1189 * * send announcements 1293 * * send announcements
1190 */ 1294 */
@@ -1251,7 +1355,7 @@ static void batadv_bla_periodic_work(struct work_struct *work)
1251 } 1355 }
1252out: 1356out:
1253 if (primary_if) 1357 if (primary_if)
1254 batadv_hardif_free_ref(primary_if); 1358 batadv_hardif_put(primary_if);
1255 1359
1256 queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work, 1360 queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work,
1257 msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH)); 1361 msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH));
@@ -1265,7 +1369,12 @@ out:
1265static struct lock_class_key batadv_claim_hash_lock_class_key; 1369static struct lock_class_key batadv_claim_hash_lock_class_key;
1266static struct lock_class_key batadv_backbone_hash_lock_class_key; 1370static struct lock_class_key batadv_backbone_hash_lock_class_key;
1267 1371
1268/* initialize all bla structures */ 1372/**
1373 * batadv_bla_init - initialize all bla structures
1374 * @bat_priv: the bat priv with all the soft interface information
1375 *
1376 * Return: 0 on success, < 0 on error.
1377 */
1269int batadv_bla_init(struct batadv_priv *bat_priv) 1378int batadv_bla_init(struct batadv_priv *bat_priv)
1270{ 1379{
1271 int i; 1380 int i;
@@ -1285,7 +1394,7 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
1285 if (primary_if) { 1394 if (primary_if) {
1286 crc = crc16(0, primary_if->net_dev->dev_addr, ETH_ALEN); 1395 crc = crc16(0, primary_if->net_dev->dev_addr, ETH_ALEN);
1287 bat_priv->bla.claim_dest.group = htons(crc); 1396 bat_priv->bla.claim_dest.group = htons(crc);
1288 batadv_hardif_free_ref(primary_if); 1397 batadv_hardif_put(primary_if);
1289 } else { 1398 } else {
1290 bat_priv->bla.claim_dest.group = 0; /* will be set later */ 1399 bat_priv->bla.claim_dest.group = 0; /* will be set later */
1291 } 1400 }
@@ -1320,7 +1429,7 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
1320} 1429}
1321 1430
1322/** 1431/**
1323 * batadv_bla_check_bcast_duplist 1432 * batadv_bla_check_bcast_duplist - Check if a frame is in the broadcast dup.
1324 * @bat_priv: the bat priv with all the soft interface information 1433 * @bat_priv: the bat priv with all the soft interface information
1325 * @skb: contains the bcast_packet to be checked 1434 * @skb: contains the bcast_packet to be checked
1326 * 1435 *
@@ -1332,6 +1441,8 @@ int batadv_bla_init(struct batadv_priv *bat_priv)
1332 * with a good chance that it is the same packet. If it is furthermore 1441 * with a good chance that it is the same packet. If it is furthermore
1333 * sent by another host, drop it. We allow equal packets from 1442 * sent by another host, drop it. We allow equal packets from
1334 * the same host however as this might be intended. 1443 * the same host however as this might be intended.
1444 *
1445 * Return: 1 if a packet is in the duplicate list, 0 otherwise.
1335 */ 1446 */
1336int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv, 1447int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
1337 struct sk_buff *skb) 1448 struct sk_buff *skb)
@@ -1390,14 +1501,13 @@ out:
1390} 1501}
1391 1502
1392/** 1503/**
1393 * batadv_bla_is_backbone_gw_orig 1504 * batadv_bla_is_backbone_gw_orig - Check if the originator is a gateway for
1505 * the VLAN identified by vid.
1394 * @bat_priv: the bat priv with all the soft interface information 1506 * @bat_priv: the bat priv with all the soft interface information
1395 * @orig: originator mac address 1507 * @orig: originator mac address
1396 * @vid: VLAN identifier 1508 * @vid: VLAN identifier
1397 * 1509 *
1398 * Check if the originator is a gateway for the VLAN identified by vid. 1510 * Return: true if orig is a backbone for this vid, false otherwise.
1399 *
1400 * Returns true if orig is a backbone for this vid, false otherwise.
1401 */ 1511 */
1402bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig, 1512bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,
1403 unsigned short vid) 1513 unsigned short vid)
@@ -1431,14 +1541,13 @@ bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, u8 *orig,
1431} 1541}
1432 1542
1433/** 1543/**
1434 * batadv_bla_is_backbone_gw 1544 * batadv_bla_is_backbone_gw - check if originator is a backbone gw for a VLAN.
1435 * @skb: the frame to be checked 1545 * @skb: the frame to be checked
1436 * @orig_node: the orig_node of the frame 1546 * @orig_node: the orig_node of the frame
1437 * @hdr_size: maximum length of the frame 1547 * @hdr_size: maximum length of the frame
1438 * 1548 *
1439 * bla_is_backbone_gw inspects the skb for the VLAN ID and returns 1 1549 * Return: 1 if the orig_node is also a gateway on the soft interface, otherwise
1440 * if the orig_node is also a gateway on the soft interface, otherwise it 1550 * it returns 0.
1441 * returns 0.
1442 */ 1551 */
1443int batadv_bla_is_backbone_gw(struct sk_buff *skb, 1552int batadv_bla_is_backbone_gw(struct sk_buff *skb,
1444 struct batadv_orig_node *orig_node, int hdr_size) 1553 struct batadv_orig_node *orig_node, int hdr_size)
@@ -1461,11 +1570,16 @@ int batadv_bla_is_backbone_gw(struct sk_buff *skb,
1461 if (!backbone_gw) 1570 if (!backbone_gw)
1462 return 0; 1571 return 0;
1463 1572
1464 batadv_backbone_gw_free_ref(backbone_gw); 1573 batadv_backbone_gw_put(backbone_gw);
1465 return 1; 1574 return 1;
1466} 1575}
1467 1576
1468/* free all bla structures (for softinterface free or module unload) */ 1577/**
1578 * batadv_bla_init - free all bla structures
1579 * @bat_priv: the bat priv with all the soft interface information
1580 *
1581 * for softinterface free or module unload
1582 */
1469void batadv_bla_free(struct batadv_priv *bat_priv) 1583void batadv_bla_free(struct batadv_priv *bat_priv)
1470{ 1584{
1471 struct batadv_hard_iface *primary_if; 1585 struct batadv_hard_iface *primary_if;
@@ -1484,22 +1598,23 @@ void batadv_bla_free(struct batadv_priv *bat_priv)
1484 bat_priv->bla.backbone_hash = NULL; 1598 bat_priv->bla.backbone_hash = NULL;
1485 } 1599 }
1486 if (primary_if) 1600 if (primary_if)
1487 batadv_hardif_free_ref(primary_if); 1601 batadv_hardif_put(primary_if);
1488} 1602}
1489 1603
1490/** 1604/**
1491 * batadv_bla_rx 1605 * batadv_bla_rx - check packets coming from the mesh.
1492 * @bat_priv: the bat priv with all the soft interface information 1606 * @bat_priv: the bat priv with all the soft interface information
1493 * @skb: the frame to be checked 1607 * @skb: the frame to be checked
1494 * @vid: the VLAN ID of the frame 1608 * @vid: the VLAN ID of the frame
1495 * @is_bcast: the packet came in a broadcast packet type. 1609 * @is_bcast: the packet came in a broadcast packet type.
1496 * 1610 *
1497 * bla_rx avoidance checks if: 1611 * batadv_bla_rx avoidance checks if:
1498 * * we have to race for a claim 1612 * * we have to race for a claim
1499 * * if the frame is allowed on the LAN 1613 * * if the frame is allowed on the LAN
1500 * 1614 *
1501 * in these cases, the skb is further handled by this function and 1615 * in these cases, the skb is further handled by this function
1502 * returns 1, otherwise it returns 0 and the caller shall further 1616 *
1617 * Return: 1 if handled, otherwise it returns 0 and the caller shall further
1503 * process the skb. 1618 * process the skb.
1504 */ 1619 */
1505int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, 1620int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
@@ -1576,27 +1691,28 @@ handled:
1576 1691
1577out: 1692out:
1578 if (primary_if) 1693 if (primary_if)
1579 batadv_hardif_free_ref(primary_if); 1694 batadv_hardif_put(primary_if);
1580 if (claim) 1695 if (claim)
1581 batadv_claim_free_ref(claim); 1696 batadv_claim_put(claim);
1582 return ret; 1697 return ret;
1583} 1698}
1584 1699
1585/** 1700/**
1586 * batadv_bla_tx 1701 * batadv_bla_tx - check packets going into the mesh
1587 * @bat_priv: the bat priv with all the soft interface information 1702 * @bat_priv: the bat priv with all the soft interface information
1588 * @skb: the frame to be checked 1703 * @skb: the frame to be checked
1589 * @vid: the VLAN ID of the frame 1704 * @vid: the VLAN ID of the frame
1590 * 1705 *
1591 * bla_tx checks if: 1706 * batadv_bla_tx checks if:
1592 * * a claim was received which has to be processed 1707 * * a claim was received which has to be processed
1593 * * the frame is allowed on the mesh 1708 * * the frame is allowed on the mesh
1594 * 1709 *
1595 * in these cases, the skb is further handled by this function and 1710 * in these cases, the skb is further handled by this function.
1596 * returns 1, otherwise it returns 0 and the caller shall further
1597 * process the skb.
1598 * 1711 *
1599 * This call might reallocate skb data. 1712 * This call might reallocate skb data.
1713 *
1714 * Return: 1 if handled, otherwise it returns 0 and the caller shall further
1715 * process the skb.
1600 */ 1716 */
1601int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, 1717int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
1602 unsigned short vid) 1718 unsigned short vid)
@@ -1664,12 +1780,19 @@ handled:
1664 ret = 1; 1780 ret = 1;
1665out: 1781out:
1666 if (primary_if) 1782 if (primary_if)
1667 batadv_hardif_free_ref(primary_if); 1783 batadv_hardif_put(primary_if);
1668 if (claim) 1784 if (claim)
1669 batadv_claim_free_ref(claim); 1785 batadv_claim_put(claim);
1670 return ret; 1786 return ret;
1671} 1787}
1672 1788
1789/**
1790 * batadv_bla_claim_table_seq_print_text - print the claim table in a seq file
1791 * @seq: seq file to print on
1792 * @offset: not used
1793 *
1794 * Return: always 0
1795 */
1673int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset) 1796int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
1674{ 1797{
1675 struct net_device *net_dev = (struct net_device *)seq->private; 1798 struct net_device *net_dev = (struct net_device *)seq->private;
@@ -1715,10 +1838,18 @@ int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
1715 } 1838 }
1716out: 1839out:
1717 if (primary_if) 1840 if (primary_if)
1718 batadv_hardif_free_ref(primary_if); 1841 batadv_hardif_put(primary_if);
1719 return 0; 1842 return 0;
1720} 1843}
1721 1844
1845/**
1846 * batadv_bla_backbone_table_seq_print_text - print the backbone table in a seq
1847 * file
1848 * @seq: seq file to print on
1849 * @offset: not used
1850 *
1851 * Return: always 0
1852 */
1722int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset) 1853int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
1723{ 1854{
1724 struct net_device *net_dev = (struct net_device *)seq->private; 1855 struct net_device *net_dev = (struct net_device *)seq->private;
@@ -1772,6 +1903,6 @@ int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
1772 } 1903 }
1773out: 1904out:
1774 if (primary_if) 1905 if (primary_if)
1775 batadv_hardif_free_ref(primary_if); 1906 batadv_hardif_put(primary_if);
1776 return 0; 1907 return 0;
1777} 1908}