1 /* Copyright (C) 2011-2014 B.A.T.M.A.N. contributors:
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "hard-interface.h"
21 #include "originator.h"
22 #include "bridge_loop_avoidance.h"
23 #include "translation-table.h"
26 #include <linux/etherdevice.h>
27 #include <linux/crc16.h>
28 #include <linux/if_arp.h>
30 #include <linux/if_vlan.h>
32 static const uint8_t batadv_announce_mac[4] = {0x43, 0x05, 0x43, 0x05};
34 static void batadv_bla_periodic_work(struct work_struct *work);
36 batadv_bla_send_announce(struct batadv_priv *bat_priv,
37 struct batadv_bla_backbone_gw *backbone_gw);
39 /* return the index of the claim */
40 static inline uint32_t batadv_choose_claim(const void *data, uint32_t size)
42 struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data;
45 hash = batadv_hash_bytes(hash, &claim->addr, sizeof(claim->addr));
46 hash = batadv_hash_bytes(hash, &claim->vid, sizeof(claim->vid));
55 /* return the index of the backbone gateway */
56 static inline uint32_t batadv_choose_backbone_gw(const void *data,
59 const struct batadv_bla_claim *claim = (struct batadv_bla_claim *)data;
62 hash = batadv_hash_bytes(hash, &claim->addr, sizeof(claim->addr));
63 hash = batadv_hash_bytes(hash, &claim->vid, sizeof(claim->vid));
73 /* compares address and vid of two backbone gws */
74 static int batadv_compare_backbone_gw(const struct hlist_node *node,
77 const void *data1 = container_of(node, struct batadv_bla_backbone_gw,
79 const struct batadv_bla_backbone_gw *gw1 = data1, *gw2 = data2;
81 if (!batadv_compare_eth(gw1->orig, gw2->orig))
84 if (gw1->vid != gw2->vid)
90 /* compares address and vid of two claims */
91 static int batadv_compare_claim(const struct hlist_node *node,
94 const void *data1 = container_of(node, struct batadv_bla_claim,
96 const struct batadv_bla_claim *cl1 = data1, *cl2 = data2;
98 if (!batadv_compare_eth(cl1->addr, cl2->addr))
101 if (cl1->vid != cl2->vid)
107 /* free a backbone gw */
109 batadv_backbone_gw_free_ref(struct batadv_bla_backbone_gw *backbone_gw)
111 if (atomic_dec_and_test(&backbone_gw->refcount))
112 kfree_rcu(backbone_gw, rcu);
115 /* finally deinitialize the claim */
116 static void batadv_claim_free_rcu(struct rcu_head *rcu)
118 struct batadv_bla_claim *claim;
120 claim = container_of(rcu, struct batadv_bla_claim, rcu);
122 batadv_backbone_gw_free_ref(claim->backbone_gw);
126 /* free a claim, call claim_free_rcu if its the last reference */
127 static void batadv_claim_free_ref(struct batadv_bla_claim *claim)
129 if (atomic_dec_and_test(&claim->refcount))
130 call_rcu(&claim->rcu, batadv_claim_free_rcu);
133 /* @bat_priv: the bat priv with all the soft interface information
134 * @data: search data (may be local/static data)
136 * looks for a claim in the hash, and returns it if found
139 static struct batadv_bla_claim
140 *batadv_claim_hash_find(struct batadv_priv *bat_priv,
141 struct batadv_bla_claim *data)
143 struct batadv_hashtable *hash = bat_priv->bla.claim_hash;
144 struct hlist_head *head;
145 struct batadv_bla_claim *claim;
146 struct batadv_bla_claim *claim_tmp = NULL;
152 index = batadv_choose_claim(data, hash->size);
153 head = &hash->table[index];
156 hlist_for_each_entry_rcu(claim, head, hash_entry) {
157 if (!batadv_compare_claim(&claim->hash_entry, data))
160 if (!atomic_inc_not_zero(&claim->refcount))
172 * batadv_backbone_hash_find - looks for a claim in the hash
173 * @bat_priv: the bat priv with all the soft interface information
174 * @addr: the address of the originator
177 * Returns claim if found or NULL otherwise.
179 static struct batadv_bla_backbone_gw *
180 batadv_backbone_hash_find(struct batadv_priv *bat_priv,
181 uint8_t *addr, unsigned short vid)
183 struct batadv_hashtable *hash = bat_priv->bla.backbone_hash;
184 struct hlist_head *head;
185 struct batadv_bla_backbone_gw search_entry, *backbone_gw;
186 struct batadv_bla_backbone_gw *backbone_gw_tmp = NULL;
192 memcpy(search_entry.orig, addr, ETH_ALEN);
193 search_entry.vid = vid;
195 index = batadv_choose_backbone_gw(&search_entry, hash->size);
196 head = &hash->table[index];
199 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
200 if (!batadv_compare_backbone_gw(&backbone_gw->hash_entry,
204 if (!atomic_inc_not_zero(&backbone_gw->refcount))
207 backbone_gw_tmp = backbone_gw;
212 return backbone_gw_tmp;
215 /* delete all claims for a backbone */
217 batadv_bla_del_backbone_claims(struct batadv_bla_backbone_gw *backbone_gw)
219 struct batadv_hashtable *hash;
220 struct hlist_node *node_tmp;
221 struct hlist_head *head;
222 struct batadv_bla_claim *claim;
224 spinlock_t *list_lock; /* protects write access to the hash lists */
226 hash = backbone_gw->bat_priv->bla.claim_hash;
230 for (i = 0; i < hash->size; i++) {
231 head = &hash->table[i];
232 list_lock = &hash->list_locks[i];
234 spin_lock_bh(list_lock);
235 hlist_for_each_entry_safe(claim, node_tmp,
237 if (claim->backbone_gw != backbone_gw)
240 batadv_claim_free_ref(claim);
241 hlist_del_rcu(&claim->hash_entry);
243 spin_unlock_bh(list_lock);
246 /* all claims gone, intialize CRC */
247 backbone_gw->crc = BATADV_BLA_CRC_INIT;
251 * batadv_bla_send_claim - sends a claim frame according to the provided info
252 * @bat_priv: the bat priv with all the soft interface information
253 * @orig: the mac address to be announced within the claim
255 * @claimtype: the type of the claim (CLAIM, UNCLAIM, ANNOUNCE, ...)
257 static void batadv_bla_send_claim(struct batadv_priv *bat_priv, uint8_t *mac,
258 unsigned short vid, int claimtype)
261 struct ethhdr *ethhdr;
262 struct batadv_hard_iface *primary_if;
263 struct net_device *soft_iface;
265 struct batadv_bla_claim_dst local_claim_dest;
268 primary_if = batadv_primary_if_get_selected(bat_priv);
272 memcpy(&local_claim_dest, &bat_priv->bla.claim_dest,
273 sizeof(local_claim_dest));
274 local_claim_dest.type = claimtype;
276 soft_iface = primary_if->soft_iface;
278 skb = arp_create(ARPOP_REPLY, ETH_P_ARP,
279 /* IP DST: 0.0.0.0 */
281 primary_if->soft_iface,
282 /* IP SRC: 0.0.0.0 */
284 /* Ethernet DST: Broadcast */
286 /* Ethernet SRC/HW SRC: originator mac */
287 primary_if->net_dev->dev_addr,
288 /* HW DST: FF:43:05:XX:YY:YY
289 * with XX = claim type
290 * and YY:YY = group id
292 (uint8_t *)&local_claim_dest);
297 ethhdr = (struct ethhdr *)skb->data;
298 hw_src = (uint8_t *)ethhdr + ETH_HLEN + sizeof(struct arphdr);
300 /* now we pretend that the client would have sent this ... */
302 case BATADV_CLAIM_TYPE_CLAIM:
303 /* normal claim frame
304 * set Ethernet SRC to the clients mac
306 memcpy(ethhdr->h_source, mac, ETH_ALEN);
307 batadv_dbg(BATADV_DBG_BLA, bat_priv,
308 "bla_send_claim(): CLAIM %pM on vid %d\n", mac,
309 BATADV_PRINT_VID(vid));
311 case BATADV_CLAIM_TYPE_UNCLAIM:
313 * set HW SRC to the clients mac
315 memcpy(hw_src, mac, ETH_ALEN);
316 batadv_dbg(BATADV_DBG_BLA, bat_priv,
317 "bla_send_claim(): UNCLAIM %pM on vid %d\n", mac,
318 BATADV_PRINT_VID(vid));
320 case BATADV_CLAIM_TYPE_ANNOUNCE:
321 /* announcement frame
322 * set HW SRC to the special mac containg the crc
324 memcpy(hw_src, mac, ETH_ALEN);
325 batadv_dbg(BATADV_DBG_BLA, bat_priv,
326 "bla_send_claim(): ANNOUNCE of %pM on vid %d\n",
327 ethhdr->h_source, BATADV_PRINT_VID(vid));
329 case BATADV_CLAIM_TYPE_REQUEST:
331 * set HW SRC and header destination to the receiving backbone
334 memcpy(hw_src, mac, ETH_ALEN);
335 memcpy(ethhdr->h_dest, mac, ETH_ALEN);
336 batadv_dbg(BATADV_DBG_BLA, bat_priv,
337 "bla_send_claim(): REQUEST of %pM to %pM on vid %d\n",
338 ethhdr->h_source, ethhdr->h_dest,
339 BATADV_PRINT_VID(vid));
343 if (vid & BATADV_VLAN_HAS_TAG)
344 skb = vlan_insert_tag(skb, htons(ETH_P_8021Q),
345 vid & VLAN_VID_MASK);
347 skb_reset_mac_header(skb);
348 skb->protocol = eth_type_trans(skb, soft_iface);
349 batadv_inc_counter(bat_priv, BATADV_CNT_RX);
350 batadv_add_counter(bat_priv, BATADV_CNT_RX_BYTES,
351 skb->len + ETH_HLEN);
352 soft_iface->last_rx = jiffies;
357 batadv_hardif_free_ref(primary_if);
361 * batadv_bla_get_backbone_gw
362 * @bat_priv: the bat priv with all the soft interface information
363 * @orig: the mac address of the originator
366 * searches for the backbone gw or creates a new one if it could not
369 static struct batadv_bla_backbone_gw *
370 batadv_bla_get_backbone_gw(struct batadv_priv *bat_priv, uint8_t *orig,
371 unsigned short vid, bool own_backbone)
373 struct batadv_bla_backbone_gw *entry;
374 struct batadv_orig_node *orig_node;
377 entry = batadv_backbone_hash_find(bat_priv, orig, vid);
382 batadv_dbg(BATADV_DBG_BLA, bat_priv,
383 "bla_get_backbone_gw(): not found (%pM, %d), creating new entry\n",
384 orig, BATADV_PRINT_VID(vid));
386 entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
391 entry->lasttime = jiffies;
392 entry->crc = BATADV_BLA_CRC_INIT;
393 entry->bat_priv = bat_priv;
394 atomic_set(&entry->request_sent, 0);
395 atomic_set(&entry->wait_periods, 0);
396 memcpy(entry->orig, orig, ETH_ALEN);
398 /* one for the hash, one for returning */
399 atomic_set(&entry->refcount, 2);
401 hash_added = batadv_hash_add(bat_priv->bla.backbone_hash,
402 batadv_compare_backbone_gw,
403 batadv_choose_backbone_gw, entry,
406 if (unlikely(hash_added != 0)) {
407 /* hash failed, free the structure */
412 /* this is a gateway now, remove any TT entry on this VLAN */
413 orig_node = batadv_orig_hash_find(bat_priv, orig);
415 batadv_tt_global_del_orig(bat_priv, orig_node, vid,
416 "became a backbone gateway");
417 batadv_orig_node_free_ref(orig_node);
421 batadv_bla_send_announce(bat_priv, entry);
423 /* this will be decreased in the worker thread */
424 atomic_inc(&entry->request_sent);
425 atomic_set(&entry->wait_periods, BATADV_BLA_WAIT_PERIODS);
426 atomic_inc(&bat_priv->bla.num_requests);
432 /* update or add the own backbone gw to make sure we announce
433 * where we receive other backbone gws
436 batadv_bla_update_own_backbone_gw(struct batadv_priv *bat_priv,
437 struct batadv_hard_iface *primary_if,
440 struct batadv_bla_backbone_gw *backbone_gw;
442 backbone_gw = batadv_bla_get_backbone_gw(bat_priv,
443 primary_if->net_dev->dev_addr,
445 if (unlikely(!backbone_gw))
448 backbone_gw->lasttime = jiffies;
449 batadv_backbone_gw_free_ref(backbone_gw);
452 /* @bat_priv: the bat priv with all the soft interface information
453 * @vid: the vid where the request came on
455 * Repeat all of our own claims, and finally send an ANNOUNCE frame
456 * to allow the requester another check if the CRC is correct now.
458 static void batadv_bla_answer_request(struct batadv_priv *bat_priv,
459 struct batadv_hard_iface *primary_if,
462 struct hlist_head *head;
463 struct batadv_hashtable *hash;
464 struct batadv_bla_claim *claim;
465 struct batadv_bla_backbone_gw *backbone_gw;
468 batadv_dbg(BATADV_DBG_BLA, bat_priv,
469 "bla_answer_request(): received a claim request, send all of our own claims again\n");
471 backbone_gw = batadv_backbone_hash_find(bat_priv,
472 primary_if->net_dev->dev_addr,
477 hash = bat_priv->bla.claim_hash;
478 for (i = 0; i < hash->size; i++) {
479 head = &hash->table[i];
482 hlist_for_each_entry_rcu(claim, head, hash_entry) {
483 /* only own claims are interesting */
484 if (claim->backbone_gw != backbone_gw)
487 batadv_bla_send_claim(bat_priv, claim->addr, claim->vid,
488 BATADV_CLAIM_TYPE_CLAIM);
493 /* finally, send an announcement frame */
494 batadv_bla_send_announce(bat_priv, backbone_gw);
495 batadv_backbone_gw_free_ref(backbone_gw);
498 /* @backbone_gw: the backbone gateway from whom we are out of sync
500 * When the crc is wrong, ask the backbone gateway for a full table update.
501 * After the request, it will repeat all of his own claims and finally
502 * send an announcement claim with which we can check again.
504 static void batadv_bla_send_request(struct batadv_bla_backbone_gw *backbone_gw)
506 /* first, remove all old entries */
507 batadv_bla_del_backbone_claims(backbone_gw);
509 batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
510 "Sending REQUEST to %pM\n", backbone_gw->orig);
513 batadv_bla_send_claim(backbone_gw->bat_priv, backbone_gw->orig,
514 backbone_gw->vid, BATADV_CLAIM_TYPE_REQUEST);
516 /* no local broadcasts should be sent or received, for now. */
517 if (!atomic_read(&backbone_gw->request_sent)) {
518 atomic_inc(&backbone_gw->bat_priv->bla.num_requests);
519 atomic_set(&backbone_gw->request_sent, 1);
523 /* @bat_priv: the bat priv with all the soft interface information
524 * @backbone_gw: our backbone gateway which should be announced
526 * This function sends an announcement. It is called from multiple
529 static void batadv_bla_send_announce(struct batadv_priv *bat_priv,
530 struct batadv_bla_backbone_gw *backbone_gw)
532 uint8_t mac[ETH_ALEN];
535 memcpy(mac, batadv_announce_mac, 4);
536 crc = htons(backbone_gw->crc);
537 memcpy(&mac[4], &crc, 2);
539 batadv_bla_send_claim(bat_priv, mac, backbone_gw->vid,
540 BATADV_CLAIM_TYPE_ANNOUNCE);
544 * batadv_bla_add_claim - Adds a claim in the claim hash
545 * @bat_priv: the bat priv with all the soft interface information
546 * @mac: the mac address of the claim
547 * @vid: the VLAN ID of the frame
548 * @backbone_gw: the backbone gateway which claims it
550 static void batadv_bla_add_claim(struct batadv_priv *bat_priv,
551 const uint8_t *mac, const unsigned short vid,
552 struct batadv_bla_backbone_gw *backbone_gw)
554 struct batadv_bla_claim *claim;
555 struct batadv_bla_claim search_claim;
558 memcpy(search_claim.addr, mac, ETH_ALEN);
559 search_claim.vid = vid;
560 claim = batadv_claim_hash_find(bat_priv, &search_claim);
562 /* create a new claim entry if it does not exist yet. */
564 claim = kzalloc(sizeof(*claim), GFP_ATOMIC);
568 memcpy(claim->addr, mac, ETH_ALEN);
570 claim->lasttime = jiffies;
571 claim->backbone_gw = backbone_gw;
573 atomic_set(&claim->refcount, 2);
574 batadv_dbg(BATADV_DBG_BLA, bat_priv,
575 "bla_add_claim(): adding new entry %pM, vid %d to hash ...\n",
576 mac, BATADV_PRINT_VID(vid));
577 hash_added = batadv_hash_add(bat_priv->bla.claim_hash,
578 batadv_compare_claim,
579 batadv_choose_claim, claim,
582 if (unlikely(hash_added != 0)) {
583 /* only local changes happened. */
588 claim->lasttime = jiffies;
589 if (claim->backbone_gw == backbone_gw)
590 /* no need to register a new backbone */
593 batadv_dbg(BATADV_DBG_BLA, bat_priv,
594 "bla_add_claim(): changing ownership for %pM, vid %d\n",
595 mac, BATADV_PRINT_VID(vid));
597 claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
598 batadv_backbone_gw_free_ref(claim->backbone_gw);
600 /* set (new) backbone gw */
601 atomic_inc(&backbone_gw->refcount);
602 claim->backbone_gw = backbone_gw;
604 backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
605 backbone_gw->lasttime = jiffies;
608 batadv_claim_free_ref(claim);
611 /* Delete a claim from the claim hash which has the
612 * given mac address and vid.
614 static void batadv_bla_del_claim(struct batadv_priv *bat_priv,
615 const uint8_t *mac, const unsigned short vid)
617 struct batadv_bla_claim search_claim, *claim;
619 memcpy(search_claim.addr, mac, ETH_ALEN);
620 search_claim.vid = vid;
621 claim = batadv_claim_hash_find(bat_priv, &search_claim);
625 batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla_del_claim(): %pM, vid %d\n",
626 mac, BATADV_PRINT_VID(vid));
628 batadv_hash_remove(bat_priv->bla.claim_hash, batadv_compare_claim,
629 batadv_choose_claim, claim);
630 batadv_claim_free_ref(claim); /* reference from the hash is gone */
632 claim->backbone_gw->crc ^= crc16(0, claim->addr, ETH_ALEN);
634 /* don't need the reference from hash_find() anymore */
635 batadv_claim_free_ref(claim);
638 /* check for ANNOUNCE frame, return 1 if handled */
639 static int batadv_handle_announce(struct batadv_priv *bat_priv,
640 uint8_t *an_addr, uint8_t *backbone_addr,
643 struct batadv_bla_backbone_gw *backbone_gw;
646 if (memcmp(an_addr, batadv_announce_mac, 4) != 0)
649 backbone_gw = batadv_bla_get_backbone_gw(bat_priv, backbone_addr, vid,
652 if (unlikely(!backbone_gw))
656 /* handle as ANNOUNCE frame */
657 backbone_gw->lasttime = jiffies;
658 crc = ntohs(*((__be16 *)(&an_addr[4])));
660 batadv_dbg(BATADV_DBG_BLA, bat_priv,
661 "handle_announce(): ANNOUNCE vid %d (sent by %pM)... CRC = %#.4x\n",
662 BATADV_PRINT_VID(vid), backbone_gw->orig, crc);
664 if (backbone_gw->crc != crc) {
665 batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
666 "handle_announce(): CRC FAILED for %pM/%d (my = %#.4x, sent = %#.4x)\n",
668 BATADV_PRINT_VID(backbone_gw->vid),
669 backbone_gw->crc, crc);
671 batadv_bla_send_request(backbone_gw);
673 /* if we have sent a request and the crc was OK,
674 * we can allow traffic again.
676 if (atomic_read(&backbone_gw->request_sent)) {
677 atomic_dec(&backbone_gw->bat_priv->bla.num_requests);
678 atomic_set(&backbone_gw->request_sent, 0);
682 batadv_backbone_gw_free_ref(backbone_gw);
686 /* check for REQUEST frame, return 1 if handled */
687 static int batadv_handle_request(struct batadv_priv *bat_priv,
688 struct batadv_hard_iface *primary_if,
689 uint8_t *backbone_addr,
690 struct ethhdr *ethhdr, unsigned short vid)
692 /* check for REQUEST frame */
693 if (!batadv_compare_eth(backbone_addr, ethhdr->h_dest))
696 /* sanity check, this should not happen on a normal switch,
697 * we ignore it in this case.
699 if (!batadv_compare_eth(ethhdr->h_dest, primary_if->net_dev->dev_addr))
702 batadv_dbg(BATADV_DBG_BLA, bat_priv,
703 "handle_request(): REQUEST vid %d (sent by %pM)...\n",
704 BATADV_PRINT_VID(vid), ethhdr->h_source);
706 batadv_bla_answer_request(bat_priv, primary_if, vid);
710 /* check for UNCLAIM frame, return 1 if handled */
711 static int batadv_handle_unclaim(struct batadv_priv *bat_priv,
712 struct batadv_hard_iface *primary_if,
713 uint8_t *backbone_addr,
714 uint8_t *claim_addr, unsigned short vid)
716 struct batadv_bla_backbone_gw *backbone_gw;
718 /* unclaim in any case if it is our own */
719 if (primary_if && batadv_compare_eth(backbone_addr,
720 primary_if->net_dev->dev_addr))
721 batadv_bla_send_claim(bat_priv, claim_addr, vid,
722 BATADV_CLAIM_TYPE_UNCLAIM);
724 backbone_gw = batadv_backbone_hash_find(bat_priv, backbone_addr, vid);
729 /* this must be an UNCLAIM frame */
730 batadv_dbg(BATADV_DBG_BLA, bat_priv,
731 "handle_unclaim(): UNCLAIM %pM on vid %d (sent by %pM)...\n",
732 claim_addr, BATADV_PRINT_VID(vid), backbone_gw->orig);
734 batadv_bla_del_claim(bat_priv, claim_addr, vid);
735 batadv_backbone_gw_free_ref(backbone_gw);
739 /* check for CLAIM frame, return 1 if handled */
740 static int batadv_handle_claim(struct batadv_priv *bat_priv,
741 struct batadv_hard_iface *primary_if,
742 uint8_t *backbone_addr, uint8_t *claim_addr,
745 struct batadv_bla_backbone_gw *backbone_gw;
747 /* register the gateway if not yet available, and add the claim. */
749 backbone_gw = batadv_bla_get_backbone_gw(bat_priv, backbone_addr, vid,
752 if (unlikely(!backbone_gw))
755 /* this must be a CLAIM frame */
756 batadv_bla_add_claim(bat_priv, claim_addr, vid, backbone_gw);
757 if (batadv_compare_eth(backbone_addr, primary_if->net_dev->dev_addr))
758 batadv_bla_send_claim(bat_priv, claim_addr, vid,
759 BATADV_CLAIM_TYPE_CLAIM);
761 /* TODO: we could call something like tt_local_del() here. */
763 batadv_backbone_gw_free_ref(backbone_gw);
768 * batadv_check_claim_group
769 * @bat_priv: the bat priv with all the soft interface information
770 * @hw_src: the Hardware source in the ARP Header
771 * @hw_dst: the Hardware destination in the ARP Header
772 * @ethhdr: pointer to the Ethernet header of the claim frame
774 * checks if it is a claim packet and if its on the same group.
775 * This function also applies the group ID of the sender
776 * if it is in the same mesh.
779 * 2 - if it is a claim packet and on the same group
780 * 1 - if is a claim packet from another group
781 * 0 - if it is not a claim packet
783 static int batadv_check_claim_group(struct batadv_priv *bat_priv,
784 struct batadv_hard_iface *primary_if,
785 uint8_t *hw_src, uint8_t *hw_dst,
786 struct ethhdr *ethhdr)
788 uint8_t *backbone_addr;
789 struct batadv_orig_node *orig_node;
790 struct batadv_bla_claim_dst *bla_dst, *bla_dst_own;
792 bla_dst = (struct batadv_bla_claim_dst *)hw_dst;
793 bla_dst_own = &bat_priv->bla.claim_dest;
795 /* check if it is a claim packet in general */
796 if (memcmp(bla_dst->magic, bla_dst_own->magic,
797 sizeof(bla_dst->magic)) != 0)
800 /* if announcement packet, use the source,
801 * otherwise assume it is in the hw_src
803 switch (bla_dst->type) {
804 case BATADV_CLAIM_TYPE_CLAIM:
805 backbone_addr = hw_src;
807 case BATADV_CLAIM_TYPE_REQUEST:
808 case BATADV_CLAIM_TYPE_ANNOUNCE:
809 case BATADV_CLAIM_TYPE_UNCLAIM:
810 backbone_addr = ethhdr->h_source;
816 /* don't accept claim frames from ourselves */
817 if (batadv_compare_eth(backbone_addr, primary_if->net_dev->dev_addr))
820 /* if its already the same group, it is fine. */
821 if (bla_dst->group == bla_dst_own->group)
824 /* lets see if this originator is in our mesh */
825 orig_node = batadv_orig_hash_find(bat_priv, backbone_addr);
827 /* dont accept claims from gateways which are not in
828 * the same mesh or group.
833 /* if our mesh friends mac is bigger, use it for ourselves. */
834 if (ntohs(bla_dst->group) > ntohs(bla_dst_own->group)) {
835 batadv_dbg(BATADV_DBG_BLA, bat_priv,
836 "taking other backbones claim group: %#.4x\n",
837 ntohs(bla_dst->group));
838 bla_dst_own->group = bla_dst->group;
841 batadv_orig_node_free_ref(orig_node);
847 /* @bat_priv: the bat priv with all the soft interface information
848 * @skb: the frame to be checked
850 * Check if this is a claim frame, and process it accordingly.
852 * returns 1 if it was a claim frame, otherwise return 0 to
853 * tell the callee that it can use the frame on its own.
855 static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
856 struct batadv_hard_iface *primary_if,
859 struct batadv_bla_claim_dst *bla_dst;
860 uint8_t *hw_src, *hw_dst;
861 struct vlan_ethhdr *vhdr;
862 struct ethhdr *ethhdr;
863 struct arphdr *arphdr;
869 vid = batadv_get_vid(skb, 0);
870 ethhdr = eth_hdr(skb);
872 proto = ethhdr->h_proto;
874 if (vid & BATADV_VLAN_HAS_TAG) {
875 vhdr = (struct vlan_ethhdr *)ethhdr;
876 proto = vhdr->h_vlan_encapsulated_proto;
877 headlen += VLAN_HLEN;
880 if (proto != htons(ETH_P_ARP))
881 return 0; /* not a claim frame */
883 /* this must be a ARP frame. check if it is a claim. */
885 if (unlikely(!pskb_may_pull(skb, headlen + arp_hdr_len(skb->dev))))
888 /* pskb_may_pull() may have modified the pointers, get ethhdr again */
889 ethhdr = eth_hdr(skb);
890 arphdr = (struct arphdr *)((uint8_t *)ethhdr + headlen);
892 /* Check whether the ARP frame carries a valid
895 if (arphdr->ar_hrd != htons(ARPHRD_ETHER))
897 if (arphdr->ar_pro != htons(ETH_P_IP))
899 if (arphdr->ar_hln != ETH_ALEN)
901 if (arphdr->ar_pln != 4)
904 hw_src = (uint8_t *)arphdr + sizeof(struct arphdr);
905 hw_dst = hw_src + ETH_ALEN + 4;
906 bla_dst = (struct batadv_bla_claim_dst *)hw_dst;
908 /* check if it is a claim frame. */
909 ret = batadv_check_claim_group(bat_priv, primary_if, hw_src, hw_dst,
912 batadv_dbg(BATADV_DBG_BLA, bat_priv,
913 "bla_process_claim(): received a claim frame from another group. From: %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n",
914 ethhdr->h_source, BATADV_PRINT_VID(vid), hw_src,
920 /* become a backbone gw ourselves on this vlan if not happened yet */
921 batadv_bla_update_own_backbone_gw(bat_priv, primary_if, vid);
923 /* check for the different types of claim frames ... */
924 switch (bla_dst->type) {
925 case BATADV_CLAIM_TYPE_CLAIM:
926 if (batadv_handle_claim(bat_priv, primary_if, hw_src,
927 ethhdr->h_source, vid))
930 case BATADV_CLAIM_TYPE_UNCLAIM:
931 if (batadv_handle_unclaim(bat_priv, primary_if,
932 ethhdr->h_source, hw_src, vid))
936 case BATADV_CLAIM_TYPE_ANNOUNCE:
937 if (batadv_handle_announce(bat_priv, hw_src, ethhdr->h_source,
941 case BATADV_CLAIM_TYPE_REQUEST:
942 if (batadv_handle_request(bat_priv, primary_if, hw_src, ethhdr,
948 batadv_dbg(BATADV_DBG_BLA, bat_priv,
949 "bla_process_claim(): ERROR - this looks like a claim frame, but is useless. eth src %pM on vid %d ...(hw_src %pM, hw_dst %pM)\n",
950 ethhdr->h_source, BATADV_PRINT_VID(vid), hw_src, hw_dst);
954 /* Check when we last heard from other nodes, and remove them in case of
955 * a time out, or clean all backbone gws if now is set.
957 static void batadv_bla_purge_backbone_gw(struct batadv_priv *bat_priv, int now)
959 struct batadv_bla_backbone_gw *backbone_gw;
960 struct hlist_node *node_tmp;
961 struct hlist_head *head;
962 struct batadv_hashtable *hash;
963 spinlock_t *list_lock; /* protects write access to the hash lists */
966 hash = bat_priv->bla.backbone_hash;
970 for (i = 0; i < hash->size; i++) {
971 head = &hash->table[i];
972 list_lock = &hash->list_locks[i];
974 spin_lock_bh(list_lock);
975 hlist_for_each_entry_safe(backbone_gw, node_tmp,
979 if (!batadv_has_timed_out(backbone_gw->lasttime,
980 BATADV_BLA_BACKBONE_TIMEOUT))
983 batadv_dbg(BATADV_DBG_BLA, backbone_gw->bat_priv,
984 "bla_purge_backbone_gw(): backbone gw %pM timed out\n",
988 /* don't wait for the pending request anymore */
989 if (atomic_read(&backbone_gw->request_sent))
990 atomic_dec(&bat_priv->bla.num_requests);
992 batadv_bla_del_backbone_claims(backbone_gw);
994 hlist_del_rcu(&backbone_gw->hash_entry);
995 batadv_backbone_gw_free_ref(backbone_gw);
997 spin_unlock_bh(list_lock);
1002 * batadv_bla_purge_claims
1003 * @bat_priv: the bat priv with all the soft interface information
1004 * @primary_if: the selected primary interface, may be NULL if now is set
1005 * @now: whether the whole hash shall be wiped now
1007 * Check when we heard last time from our own claims, and remove them in case of
1008 * a time out, or clean all claims if now is set
1010 static void batadv_bla_purge_claims(struct batadv_priv *bat_priv,
1011 struct batadv_hard_iface *primary_if,
1014 struct batadv_bla_claim *claim;
1015 struct hlist_head *head;
1016 struct batadv_hashtable *hash;
1019 hash = bat_priv->bla.claim_hash;
1023 for (i = 0; i < hash->size; i++) {
1024 head = &hash->table[i];
1027 hlist_for_each_entry_rcu(claim, head, hash_entry) {
1030 if (!batadv_compare_eth(claim->backbone_gw->orig,
1031 primary_if->net_dev->dev_addr))
1033 if (!batadv_has_timed_out(claim->lasttime,
1034 BATADV_BLA_CLAIM_TIMEOUT))
1037 batadv_dbg(BATADV_DBG_BLA, bat_priv,
1038 "bla_purge_claims(): %pM, vid %d, time out\n",
1039 claim->addr, claim->vid);
1042 batadv_handle_unclaim(bat_priv, primary_if,
1043 claim->backbone_gw->orig,
1044 claim->addr, claim->vid);
1051 * batadv_bla_update_orig_address
1052 * @bat_priv: the bat priv with all the soft interface information
1053 * @primary_if: the new selected primary_if
1054 * @oldif: the old primary interface, may be NULL
1056 * Update the backbone gateways when the own orig address changes.
1058 void batadv_bla_update_orig_address(struct batadv_priv *bat_priv,
1059 struct batadv_hard_iface *primary_if,
1060 struct batadv_hard_iface *oldif)
1062 struct batadv_bla_backbone_gw *backbone_gw;
1063 struct hlist_head *head;
1064 struct batadv_hashtable *hash;
1068 /* reset bridge loop avoidance group id */
1069 group = htons(crc16(0, primary_if->net_dev->dev_addr, ETH_ALEN));
1070 bat_priv->bla.claim_dest.group = group;
1072 /* purge everything when bridge loop avoidance is turned off */
1073 if (!atomic_read(&bat_priv->bridge_loop_avoidance))
1077 batadv_bla_purge_claims(bat_priv, NULL, 1);
1078 batadv_bla_purge_backbone_gw(bat_priv, 1);
1082 hash = bat_priv->bla.backbone_hash;
1086 for (i = 0; i < hash->size; i++) {
1087 head = &hash->table[i];
1090 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
1091 /* own orig still holds the old value. */
1092 if (!batadv_compare_eth(backbone_gw->orig,
1093 oldif->net_dev->dev_addr))
1096 memcpy(backbone_gw->orig,
1097 primary_if->net_dev->dev_addr, ETH_ALEN);
1098 /* send an announce frame so others will ask for our
1099 * claims and update their tables.
1101 batadv_bla_send_announce(bat_priv, backbone_gw);
1107 /* periodic work to do:
1108 * * purge structures when they are too old
1109 * * send announcements
1111 static void batadv_bla_periodic_work(struct work_struct *work)
1113 struct delayed_work *delayed_work;
1114 struct batadv_priv *bat_priv;
1115 struct batadv_priv_bla *priv_bla;
1116 struct hlist_head *head;
1117 struct batadv_bla_backbone_gw *backbone_gw;
1118 struct batadv_hashtable *hash;
1119 struct batadv_hard_iface *primary_if;
1122 delayed_work = container_of(work, struct delayed_work, work);
1123 priv_bla = container_of(delayed_work, struct batadv_priv_bla, work);
1124 bat_priv = container_of(priv_bla, struct batadv_priv, bla);
1125 primary_if = batadv_primary_if_get_selected(bat_priv);
1129 batadv_bla_purge_claims(bat_priv, primary_if, 0);
1130 batadv_bla_purge_backbone_gw(bat_priv, 0);
1132 if (!atomic_read(&bat_priv->bridge_loop_avoidance))
1135 hash = bat_priv->bla.backbone_hash;
1139 for (i = 0; i < hash->size; i++) {
1140 head = &hash->table[i];
1143 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
1144 if (!batadv_compare_eth(backbone_gw->orig,
1145 primary_if->net_dev->dev_addr))
1148 backbone_gw->lasttime = jiffies;
1150 batadv_bla_send_announce(bat_priv, backbone_gw);
1152 /* request_sent is only set after creation to avoid
1153 * problems when we are not yet known as backbone gw
1156 * We can reset this now after we waited some periods
1157 * to give bridge forward delays and bla group forming
1161 if (atomic_read(&backbone_gw->request_sent) == 0)
1164 if (!atomic_dec_and_test(&backbone_gw->wait_periods))
1167 atomic_dec(&backbone_gw->bat_priv->bla.num_requests);
1168 atomic_set(&backbone_gw->request_sent, 0);
1174 batadv_hardif_free_ref(primary_if);
1176 queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work,
1177 msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH));
1180 /* The hash for claim and backbone hash receive the same key because they
1181 * are getting initialized by hash_new with the same key. Reinitializing
1182 * them with to different keys to allow nested locking without generating
1185 static struct lock_class_key batadv_claim_hash_lock_class_key;
1186 static struct lock_class_key batadv_backbone_hash_lock_class_key;
1188 /* initialize all bla structures */
1189 int batadv_bla_init(struct batadv_priv *bat_priv)
1192 uint8_t claim_dest[ETH_ALEN] = {0xff, 0x43, 0x05, 0x00, 0x00, 0x00};
1193 struct batadv_hard_iface *primary_if;
1195 unsigned long entrytime;
1197 spin_lock_init(&bat_priv->bla.bcast_duplist_lock);
1199 batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla hash registering\n");
1201 /* setting claim destination address */
1202 memcpy(&bat_priv->bla.claim_dest.magic, claim_dest, 3);
1203 bat_priv->bla.claim_dest.type = 0;
1204 primary_if = batadv_primary_if_get_selected(bat_priv);
1206 crc = crc16(0, primary_if->net_dev->dev_addr, ETH_ALEN);
1207 bat_priv->bla.claim_dest.group = htons(crc);
1208 batadv_hardif_free_ref(primary_if);
1210 bat_priv->bla.claim_dest.group = 0; /* will be set later */
1213 /* initialize the duplicate list */
1214 entrytime = jiffies - msecs_to_jiffies(BATADV_DUPLIST_TIMEOUT);
1215 for (i = 0; i < BATADV_DUPLIST_SIZE; i++)
1216 bat_priv->bla.bcast_duplist[i].entrytime = entrytime;
1217 bat_priv->bla.bcast_duplist_curr = 0;
1219 if (bat_priv->bla.claim_hash)
1222 bat_priv->bla.claim_hash = batadv_hash_new(128);
1223 bat_priv->bla.backbone_hash = batadv_hash_new(32);
1225 if (!bat_priv->bla.claim_hash || !bat_priv->bla.backbone_hash)
1228 batadv_hash_set_lock_class(bat_priv->bla.claim_hash,
1229 &batadv_claim_hash_lock_class_key);
1230 batadv_hash_set_lock_class(bat_priv->bla.backbone_hash,
1231 &batadv_backbone_hash_lock_class_key);
1233 batadv_dbg(BATADV_DBG_BLA, bat_priv, "bla hashes initialized\n");
1235 INIT_DELAYED_WORK(&bat_priv->bla.work, batadv_bla_periodic_work);
1237 queue_delayed_work(batadv_event_workqueue, &bat_priv->bla.work,
1238 msecs_to_jiffies(BATADV_BLA_PERIOD_LENGTH));
1243 * batadv_bla_check_bcast_duplist
1244 * @bat_priv: the bat priv with all the soft interface information
1245 * @skb: contains the bcast_packet to be checked
1247 * check if it is on our broadcast list. Another gateway might
1248 * have sent the same packet because it is connected to the same backbone,
1249 * so we have to remove this duplicate.
1251 * This is performed by checking the CRC, which will tell us
1252 * with a good chance that it is the same packet. If it is furthermore
1253 * sent by another host, drop it. We allow equal packets from
1254 * the same host however as this might be intended.
1256 int batadv_bla_check_bcast_duplist(struct batadv_priv *bat_priv,
1257 struct sk_buff *skb)
1259 int i, curr, ret = 0;
1261 struct batadv_bcast_packet *bcast_packet;
1262 struct batadv_bcast_duplist_entry *entry;
1264 bcast_packet = (struct batadv_bcast_packet *)skb->data;
1266 /* calculate the crc ... */
1267 crc = batadv_skb_crc32(skb, (u8 *)(bcast_packet + 1));
1269 spin_lock_bh(&bat_priv->bla.bcast_duplist_lock);
1271 for (i = 0; i < BATADV_DUPLIST_SIZE; i++) {
1272 curr = (bat_priv->bla.bcast_duplist_curr + i);
1273 curr %= BATADV_DUPLIST_SIZE;
1274 entry = &bat_priv->bla.bcast_duplist[curr];
1276 /* we can stop searching if the entry is too old ;
1277 * later entries will be even older
1279 if (batadv_has_timed_out(entry->entrytime,
1280 BATADV_DUPLIST_TIMEOUT))
1283 if (entry->crc != crc)
1286 if (batadv_compare_eth(entry->orig, bcast_packet->orig))
1289 /* this entry seems to match: same crc, not too old,
1290 * and from another gw. therefore return 1 to forbid it.
1295 /* not found, add a new entry (overwrite the oldest entry)
1296 * and allow it, its the first occurence.
1298 curr = (bat_priv->bla.bcast_duplist_curr + BATADV_DUPLIST_SIZE - 1);
1299 curr %= BATADV_DUPLIST_SIZE;
1300 entry = &bat_priv->bla.bcast_duplist[curr];
1302 entry->entrytime = jiffies;
1303 memcpy(entry->orig, bcast_packet->orig, ETH_ALEN);
1304 bat_priv->bla.bcast_duplist_curr = curr;
1307 spin_unlock_bh(&bat_priv->bla.bcast_duplist_lock);
1314 /* @bat_priv: the bat priv with all the soft interface information
1315 * @orig: originator mac address
1316 * @vid: VLAN identifier
1318 * Check if the originator is a gateway for the VLAN identified by vid.
1320 * Returns true if orig is a backbone for this vid, false otherwise.
1322 bool batadv_bla_is_backbone_gw_orig(struct batadv_priv *bat_priv, uint8_t *orig,
1325 struct batadv_hashtable *hash = bat_priv->bla.backbone_hash;
1326 struct hlist_head *head;
1327 struct batadv_bla_backbone_gw *backbone_gw;
1330 if (!atomic_read(&bat_priv->bridge_loop_avoidance))
1336 for (i = 0; i < hash->size; i++) {
1337 head = &hash->table[i];
1340 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
1341 if (batadv_compare_eth(backbone_gw->orig, orig) &&
1342 backbone_gw->vid == vid) {
1355 * batadv_bla_is_backbone_gw
1356 * @skb: the frame to be checked
1357 * @orig_node: the orig_node of the frame
1358 * @hdr_size: maximum length of the frame
1360 * bla_is_backbone_gw inspects the skb for the VLAN ID and returns 1
1361 * if the orig_node is also a gateway on the soft interface, otherwise it
1364 int batadv_bla_is_backbone_gw(struct sk_buff *skb,
1365 struct batadv_orig_node *orig_node, int hdr_size)
1367 struct batadv_bla_backbone_gw *backbone_gw;
1370 if (!atomic_read(&orig_node->bat_priv->bridge_loop_avoidance))
1373 /* first, find out the vid. */
1374 if (!pskb_may_pull(skb, hdr_size + ETH_HLEN))
1377 vid = batadv_get_vid(skb, hdr_size);
1379 /* see if this originator is a backbone gw for this VLAN */
1380 backbone_gw = batadv_backbone_hash_find(orig_node->bat_priv,
1381 orig_node->orig, vid);
1385 batadv_backbone_gw_free_ref(backbone_gw);
1389 /* free all bla structures (for softinterface free or module unload) */
1390 void batadv_bla_free(struct batadv_priv *bat_priv)
1392 struct batadv_hard_iface *primary_if;
1394 cancel_delayed_work_sync(&bat_priv->bla.work);
1395 primary_if = batadv_primary_if_get_selected(bat_priv);
1397 if (bat_priv->bla.claim_hash) {
1398 batadv_bla_purge_claims(bat_priv, primary_if, 1);
1399 batadv_hash_destroy(bat_priv->bla.claim_hash);
1400 bat_priv->bla.claim_hash = NULL;
1402 if (bat_priv->bla.backbone_hash) {
1403 batadv_bla_purge_backbone_gw(bat_priv, 1);
1404 batadv_hash_destroy(bat_priv->bla.backbone_hash);
1405 bat_priv->bla.backbone_hash = NULL;
1408 batadv_hardif_free_ref(primary_if);
1413 * @bat_priv: the bat priv with all the soft interface information
1414 * @skb: the frame to be checked
1415 * @vid: the VLAN ID of the frame
1416 * @is_bcast: the packet came in a broadcast packet type.
1418 * bla_rx avoidance checks if:
1419 * * we have to race for a claim
1420 * * if the frame is allowed on the LAN
1422 * in these cases, the skb is further handled by this function and
1423 * returns 1, otherwise it returns 0 and the caller shall further
1426 int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb,
1427 unsigned short vid, bool is_bcast)
1429 struct ethhdr *ethhdr;
1430 struct batadv_bla_claim search_claim, *claim = NULL;
1431 struct batadv_hard_iface *primary_if;
1434 ethhdr = eth_hdr(skb);
1436 primary_if = batadv_primary_if_get_selected(bat_priv);
1440 if (!atomic_read(&bat_priv->bridge_loop_avoidance))
1444 if (unlikely(atomic_read(&bat_priv->bla.num_requests)))
1445 /* don't allow broadcasts while requests are in flight */
1446 if (is_multicast_ether_addr(ethhdr->h_dest) && is_bcast)
1449 memcpy(search_claim.addr, ethhdr->h_source, ETH_ALEN);
1450 search_claim.vid = vid;
1451 claim = batadv_claim_hash_find(bat_priv, &search_claim);
1454 /* possible optimization: race for a claim */
1455 /* No claim exists yet, claim it for us!
1457 batadv_handle_claim(bat_priv, primary_if,
1458 primary_if->net_dev->dev_addr,
1459 ethhdr->h_source, vid);
1463 /* if it is our own claim ... */
1464 if (batadv_compare_eth(claim->backbone_gw->orig,
1465 primary_if->net_dev->dev_addr)) {
1466 /* ... allow it in any case */
1467 claim->lasttime = jiffies;
1471 /* if it is a broadcast ... */
1472 if (is_multicast_ether_addr(ethhdr->h_dest) && is_bcast) {
1473 /* ... drop it. the responsible gateway is in charge.
1475 * We need to check is_bcast because with the gateway
1476 * feature, broadcasts (like DHCP requests) may be sent
1477 * using a unicast packet type.
1481 /* seems the client considers us as its best gateway.
1482 * send a claim and update the claim table
1485 batadv_handle_claim(bat_priv, primary_if,
1486 primary_if->net_dev->dev_addr,
1487 ethhdr->h_source, vid);
1491 batadv_bla_update_own_backbone_gw(bat_priv, primary_if, vid);
1501 batadv_hardif_free_ref(primary_if);
1503 batadv_claim_free_ref(claim);
1509 * @bat_priv: the bat priv with all the soft interface information
1510 * @skb: the frame to be checked
1511 * @vid: the VLAN ID of the frame
1514 * * a claim was received which has to be processed
1515 * * the frame is allowed on the mesh
1517 * in these cases, the skb is further handled by this function and
1518 * returns 1, otherwise it returns 0 and the caller shall further
1521 * This call might reallocate skb data.
1523 int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
1526 struct ethhdr *ethhdr;
1527 struct batadv_bla_claim search_claim, *claim = NULL;
1528 struct batadv_hard_iface *primary_if;
1531 primary_if = batadv_primary_if_get_selected(bat_priv);
1535 if (!atomic_read(&bat_priv->bridge_loop_avoidance))
1538 /* in VLAN case, the mac header might not be set. */
1539 skb_reset_mac_header(skb);
1541 if (batadv_bla_process_claim(bat_priv, primary_if, skb))
1544 ethhdr = eth_hdr(skb);
1546 if (unlikely(atomic_read(&bat_priv->bla.num_requests)))
1547 /* don't allow broadcasts while requests are in flight */
1548 if (is_multicast_ether_addr(ethhdr->h_dest))
1551 memcpy(search_claim.addr, ethhdr->h_source, ETH_ALEN);
1552 search_claim.vid = vid;
1554 claim = batadv_claim_hash_find(bat_priv, &search_claim);
1556 /* if no claim exists, allow it. */
1560 /* check if we are responsible. */
1561 if (batadv_compare_eth(claim->backbone_gw->orig,
1562 primary_if->net_dev->dev_addr)) {
1563 /* if yes, the client has roamed and we have
1566 batadv_handle_unclaim(bat_priv, primary_if,
1567 primary_if->net_dev->dev_addr,
1568 ethhdr->h_source, vid);
1572 /* check if it is a multicast/broadcast frame */
1573 if (is_multicast_ether_addr(ethhdr->h_dest)) {
1574 /* drop it. the responsible gateway has forwarded it into
1575 * the backbone network.
1579 /* we must allow it. at least if we are
1580 * responsible for the DESTINATION.
1585 batadv_bla_update_own_backbone_gw(bat_priv, primary_if, vid);
1592 batadv_hardif_free_ref(primary_if);
1594 batadv_claim_free_ref(claim);
1598 int batadv_bla_claim_table_seq_print_text(struct seq_file *seq, void *offset)
1600 struct net_device *net_dev = (struct net_device *)seq->private;
1601 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1602 struct batadv_hashtable *hash = bat_priv->bla.claim_hash;
1603 struct batadv_bla_claim *claim;
1604 struct batadv_hard_iface *primary_if;
1605 struct hlist_head *head;
1608 uint8_t *primary_addr;
1610 primary_if = batadv_seq_print_text_primary_if_get(seq);
1614 primary_addr = primary_if->net_dev->dev_addr;
1616 "Claims announced for the mesh %s (orig %pM, group id %#.4x)\n",
1617 net_dev->name, primary_addr,
1618 ntohs(bat_priv->bla.claim_dest.group));
1619 seq_printf(seq, " %-17s %-5s %-17s [o] (%-6s)\n",
1620 "Client", "VID", "Originator", "CRC");
1621 for (i = 0; i < hash->size; i++) {
1622 head = &hash->table[i];
1625 hlist_for_each_entry_rcu(claim, head, hash_entry) {
1626 is_own = batadv_compare_eth(claim->backbone_gw->orig,
1628 seq_printf(seq, " * %pM on %5d by %pM [%c] (%#.4x)\n",
1629 claim->addr, BATADV_PRINT_VID(claim->vid),
1630 claim->backbone_gw->orig,
1631 (is_own ? 'x' : ' '),
1632 claim->backbone_gw->crc);
1638 batadv_hardif_free_ref(primary_if);
1642 int batadv_bla_backbone_table_seq_print_text(struct seq_file *seq, void *offset)
1644 struct net_device *net_dev = (struct net_device *)seq->private;
1645 struct batadv_priv *bat_priv = netdev_priv(net_dev);
1646 struct batadv_hashtable *hash = bat_priv->bla.backbone_hash;
1647 struct batadv_bla_backbone_gw *backbone_gw;
1648 struct batadv_hard_iface *primary_if;
1649 struct hlist_head *head;
1653 uint8_t *primary_addr;
1655 primary_if = batadv_seq_print_text_primary_if_get(seq);
1659 primary_addr = primary_if->net_dev->dev_addr;
1661 "Backbones announced for the mesh %s (orig %pM, group id %#.4x)\n",
1662 net_dev->name, primary_addr,
1663 ntohs(bat_priv->bla.claim_dest.group));
1664 seq_printf(seq, " %-17s %-5s %-9s (%-6s)\n",
1665 "Originator", "VID", "last seen", "CRC");
1666 for (i = 0; i < hash->size; i++) {
1667 head = &hash->table[i];
1670 hlist_for_each_entry_rcu(backbone_gw, head, hash_entry) {
1671 msecs = jiffies_to_msecs(jiffies -
1672 backbone_gw->lasttime);
1673 secs = msecs / 1000;
1674 msecs = msecs % 1000;
1676 is_own = batadv_compare_eth(backbone_gw->orig,
1681 seq_printf(seq, " * %pM on %5d %4i.%03is (%#.4x)\n",
1683 BATADV_PRINT_VID(backbone_gw->vid), secs,
1684 msecs, backbone_gw->crc);
1690 batadv_hardif_free_ref(primary_if);