1 /* Copyright (C) 2008-2012 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, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22 #include "translation-table.h"
24 #include "soft-interface.h"
25 #include "hard-interface.h"
27 #include "originator.h"
29 #define MAX_VIS_PACKET_SIZE 1000
31 static void start_vis_timer(struct bat_priv *bat_priv);
34 static void free_info(struct kref *ref)
36 struct vis_info *info = container_of(ref, struct vis_info, refcount);
37 struct bat_priv *bat_priv = info->bat_priv;
38 struct recvlist_node *entry, *tmp;
40 list_del_init(&info->send_list);
41 spin_lock_bh(&bat_priv->vis_list_lock);
42 list_for_each_entry_safe(entry, tmp, &info->recv_list, list) {
43 list_del(&entry->list);
47 spin_unlock_bh(&bat_priv->vis_list_lock);
48 kfree_skb(info->skb_packet);
52 /* Compare two vis packets, used by the hashing algorithm */
53 static int vis_info_cmp(const struct hlist_node *node, const void *data2)
55 const struct vis_info *d1, *d2;
56 const struct vis_packet *p1, *p2;
58 d1 = container_of(node, struct vis_info, hash_entry);
60 p1 = (struct vis_packet *)d1->skb_packet->data;
61 p2 = (struct vis_packet *)d2->skb_packet->data;
62 return compare_eth(p1->vis_orig, p2->vis_orig);
65 /* hash function to choose an entry in a hash table of given size
66 * hash algorithm from http://en.wikipedia.org/wiki/Hash_table
68 static uint32_t vis_info_choose(const void *data, uint32_t size)
70 const struct vis_info *vis_info = data;
71 const struct vis_packet *packet;
72 const unsigned char *key;
76 packet = (struct vis_packet *)vis_info->skb_packet->data;
77 key = packet->vis_orig;
78 for (i = 0; i < ETH_ALEN; i++) {
91 static struct vis_info *vis_hash_find(struct bat_priv *bat_priv,
94 struct hashtable_t *hash = bat_priv->vis_hash;
95 struct hlist_head *head;
96 struct hlist_node *node;
97 struct vis_info *vis_info, *vis_info_tmp = NULL;
103 index = vis_info_choose(data, hash->size);
104 head = &hash->table[index];
107 hlist_for_each_entry_rcu(vis_info, node, head, hash_entry) {
108 if (!vis_info_cmp(node, data))
111 vis_info_tmp = vis_info;
119 /* insert interface to the list of interfaces of one originator, if it
120 * does not already exist in the list
122 static void vis_data_insert_interface(const uint8_t *interface,
123 struct hlist_head *if_list,
126 struct if_list_entry *entry;
127 struct hlist_node *pos;
129 hlist_for_each_entry(entry, pos, if_list, list) {
130 if (compare_eth(entry->addr, interface))
134 /* it's a new address, add it to the list */
135 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
138 memcpy(entry->addr, interface, ETH_ALEN);
139 entry->primary = primary;
140 hlist_add_head(&entry->list, if_list);
143 static ssize_t vis_data_read_prim_sec(char *buff,
144 const struct hlist_head *if_list)
146 struct if_list_entry *entry;
147 struct hlist_node *pos;
150 hlist_for_each_entry(entry, pos, if_list, list) {
152 len += sprintf(buff + len, "PRIMARY, ");
154 len += sprintf(buff + len, "SEC %pM, ", entry->addr);
160 static size_t vis_data_count_prim_sec(struct hlist_head *if_list)
162 struct if_list_entry *entry;
163 struct hlist_node *pos;
166 hlist_for_each_entry(entry, pos, if_list, list) {
177 static ssize_t vis_data_read_entry(char *buff,
178 const struct vis_info_entry *entry,
179 const uint8_t *src, bool primary)
181 /* maximal length: max(4+17+2, 3+17+1+3+2) == 26 */
182 if (primary && entry->quality == 0)
183 return sprintf(buff, "TT %pM, ", entry->dest);
184 else if (compare_eth(entry->src, src))
185 return sprintf(buff, "TQ %pM %d, ", entry->dest,
191 int batadv_vis_seq_print_text(struct seq_file *seq, void *offset)
193 struct hard_iface *primary_if;
194 struct hlist_node *node;
195 struct hlist_head *head;
196 struct vis_info *info;
197 struct vis_packet *packet;
198 struct vis_info_entry *entries;
199 struct net_device *net_dev = (struct net_device *)seq->private;
200 struct bat_priv *bat_priv = netdev_priv(net_dev);
201 struct hashtable_t *hash = bat_priv->vis_hash;
202 HLIST_HEAD(vis_if_list);
203 struct if_list_entry *entry;
204 struct hlist_node *pos, *n;
207 int vis_server = atomic_read(&bat_priv->vis_mode);
208 size_t buff_pos, buf_size;
211 primary_if = batadv_primary_if_get_selected(bat_priv);
215 if (vis_server == VIS_TYPE_CLIENT_UPDATE)
219 /* Estimate length */
220 spin_lock_bh(&bat_priv->vis_hash_lock);
221 for (i = 0; i < hash->size; i++) {
222 head = &hash->table[i];
225 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
226 packet = (struct vis_packet *)info->skb_packet->data;
227 entries = (struct vis_info_entry *)
228 ((char *)packet + sizeof(*packet));
230 vis_data_insert_interface(packet->vis_orig,
233 for (j = 0; j < packet->entries; j++) {
234 if (entries[j].quality == 0)
236 if (compare_eth(entries[j].src,
239 vis_data_insert_interface(entries[j].src,
244 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
245 buf_size += 18 + 26 * packet->entries;
247 /* add primary/secondary records */
248 if (compare_eth(entry->addr, packet->vis_orig))
250 vis_data_count_prim_sec(&vis_if_list);
255 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
257 hlist_del(&entry->list);
264 buff = kmalloc(buf_size, GFP_ATOMIC);
266 spin_unlock_bh(&bat_priv->vis_hash_lock);
273 for (i = 0; i < hash->size; i++) {
274 head = &hash->table[i];
277 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
278 packet = (struct vis_packet *)info->skb_packet->data;
279 entries = (struct vis_info_entry *)
280 ((char *)packet + sizeof(*packet));
282 vis_data_insert_interface(packet->vis_orig,
285 for (j = 0; j < packet->entries; j++) {
286 if (entries[j].quality == 0)
288 if (compare_eth(entries[j].src,
291 vis_data_insert_interface(entries[j].src,
296 hlist_for_each_entry(entry, pos, &vis_if_list, list) {
297 buff_pos += sprintf(buff + buff_pos, "%pM,",
300 for (j = 0; j < packet->entries; j++)
301 buff_pos += vis_data_read_entry(
307 /* add primary/secondary records */
308 if (compare_eth(entry->addr, packet->vis_orig))
310 vis_data_read_prim_sec(buff + buff_pos,
313 buff_pos += sprintf(buff + buff_pos, "\n");
316 hlist_for_each_entry_safe(entry, pos, n, &vis_if_list,
318 hlist_del(&entry->list);
325 spin_unlock_bh(&bat_priv->vis_hash_lock);
327 seq_printf(seq, "%s", buff);
332 batadv_hardif_free_ref(primary_if);
336 /* add the info packet to the send list, if it was not
339 static void send_list_add(struct bat_priv *bat_priv, struct vis_info *info)
341 if (list_empty(&info->send_list)) {
342 kref_get(&info->refcount);
343 list_add_tail(&info->send_list, &bat_priv->vis_send_list);
347 /* delete the info packet from the send list, if it was
350 static void send_list_del(struct vis_info *info)
352 if (!list_empty(&info->send_list)) {
353 list_del_init(&info->send_list);
354 kref_put(&info->refcount, free_info);
358 /* tries to add one entry to the receive list. */
359 static void recv_list_add(struct bat_priv *bat_priv,
360 struct list_head *recv_list, const char *mac)
362 struct recvlist_node *entry;
364 entry = kmalloc(sizeof(*entry), GFP_ATOMIC);
368 memcpy(entry->mac, mac, ETH_ALEN);
369 spin_lock_bh(&bat_priv->vis_list_lock);
370 list_add_tail(&entry->list, recv_list);
371 spin_unlock_bh(&bat_priv->vis_list_lock);
374 /* returns 1 if this mac is in the recv_list */
375 static int recv_list_is_in(struct bat_priv *bat_priv,
376 const struct list_head *recv_list, const char *mac)
378 const struct recvlist_node *entry;
380 spin_lock_bh(&bat_priv->vis_list_lock);
381 list_for_each_entry(entry, recv_list, list) {
382 if (compare_eth(entry->mac, mac)) {
383 spin_unlock_bh(&bat_priv->vis_list_lock);
387 spin_unlock_bh(&bat_priv->vis_list_lock);
391 /* try to add the packet to the vis_hash. return NULL if invalid (e.g. too old,
392 * broken.. ). vis hash must be locked outside. is_new is set when the packet
393 * is newer than old entries in the hash.
395 static struct vis_info *add_packet(struct bat_priv *bat_priv,
396 struct vis_packet *vis_packet,
397 int vis_info_len, int *is_new,
400 struct vis_info *info, *old_info;
401 struct vis_packet *search_packet, *old_packet;
402 struct vis_info search_elem;
403 struct vis_packet *packet;
408 if (!bat_priv->vis_hash)
411 /* see if the packet is already in vis_hash */
412 search_elem.skb_packet = dev_alloc_skb(sizeof(*search_packet));
413 if (!search_elem.skb_packet)
415 search_packet = (struct vis_packet *)skb_put(search_elem.skb_packet,
416 sizeof(*search_packet));
418 memcpy(search_packet->vis_orig, vis_packet->vis_orig, ETH_ALEN);
419 old_info = vis_hash_find(bat_priv, &search_elem);
420 kfree_skb(search_elem.skb_packet);
423 old_packet = (struct vis_packet *)old_info->skb_packet->data;
424 if (!seq_after(ntohl(vis_packet->seqno),
425 ntohl(old_packet->seqno))) {
426 if (old_packet->seqno == vis_packet->seqno) {
427 recv_list_add(bat_priv, &old_info->recv_list,
428 vis_packet->sender_orig);
431 /* newer packet is already in hash. */
435 /* remove old entry */
436 batadv_hash_remove(bat_priv->vis_hash, vis_info_cmp,
437 vis_info_choose, old_info);
438 send_list_del(old_info);
439 kref_put(&old_info->refcount, free_info);
442 info = kmalloc(sizeof(*info), GFP_ATOMIC);
446 info->skb_packet = dev_alloc_skb(sizeof(*packet) + vis_info_len +
448 if (!info->skb_packet) {
452 skb_reserve(info->skb_packet, ETH_HLEN);
453 packet = (struct vis_packet *)skb_put(info->skb_packet, sizeof(*packet)
456 kref_init(&info->refcount);
457 INIT_LIST_HEAD(&info->send_list);
458 INIT_LIST_HEAD(&info->recv_list);
459 info->first_seen = jiffies;
460 info->bat_priv = bat_priv;
461 memcpy(packet, vis_packet, sizeof(*packet) + vis_info_len);
463 /* initialize and add new packet. */
466 /* Make it a broadcast packet, if required */
468 memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN);
470 /* repair if entries is longer than packet. */
471 if (packet->entries * sizeof(struct vis_info_entry) > vis_info_len)
472 packet->entries = vis_info_len / sizeof(struct vis_info_entry);
474 recv_list_add(bat_priv, &info->recv_list, packet->sender_orig);
477 hash_added = batadv_hash_add(bat_priv->vis_hash, vis_info_cmp,
478 vis_info_choose, info, &info->hash_entry);
479 if (hash_added != 0) {
480 /* did not work (for some reason) */
481 kref_put(&info->refcount, free_info);
488 /* handle the server sync packet, forward if needed. */
489 void batadv_receive_server_sync_packet(struct bat_priv *bat_priv,
490 struct vis_packet *vis_packet,
493 struct vis_info *info;
494 int is_new, make_broadcast;
495 int vis_server = atomic_read(&bat_priv->vis_mode);
497 make_broadcast = (vis_server == VIS_TYPE_SERVER_SYNC);
499 spin_lock_bh(&bat_priv->vis_hash_lock);
500 info = add_packet(bat_priv, vis_packet, vis_info_len,
501 &is_new, make_broadcast);
505 /* only if we are server ourselves and packet is newer than the one in
508 if (vis_server == VIS_TYPE_SERVER_SYNC && is_new)
509 send_list_add(bat_priv, info);
511 spin_unlock_bh(&bat_priv->vis_hash_lock);
514 /* handle an incoming client update packet and schedule forward if needed. */
515 void batadv_receive_client_update_packet(struct bat_priv *bat_priv,
516 struct vis_packet *vis_packet,
519 struct vis_info *info;
520 struct vis_packet *packet;
522 int vis_server = atomic_read(&bat_priv->vis_mode);
525 /* clients shall not broadcast. */
526 if (is_broadcast_ether_addr(vis_packet->target_orig))
529 /* Are we the target for this VIS packet? */
530 if (vis_server == VIS_TYPE_SERVER_SYNC &&
531 batadv_is_my_mac(vis_packet->target_orig))
534 spin_lock_bh(&bat_priv->vis_hash_lock);
535 info = add_packet(bat_priv, vis_packet, vis_info_len,
536 &is_new, are_target);
540 /* note that outdated packets will be dropped at this point. */
542 packet = (struct vis_packet *)info->skb_packet->data;
544 /* send only if we're the target server or ... */
545 if (are_target && is_new) {
546 packet->vis_type = VIS_TYPE_SERVER_SYNC; /* upgrade! */
547 send_list_add(bat_priv, info);
549 /* ... we're not the recipient (and thus need to forward). */
550 } else if (!batadv_is_my_mac(packet->target_orig)) {
551 send_list_add(bat_priv, info);
555 spin_unlock_bh(&bat_priv->vis_hash_lock);
558 /* Walk the originators and find the VIS server with the best tq. Set the packet
559 * address to its address and return the best_tq.
561 * Must be called with the originator hash locked
563 static int find_best_vis_server(struct bat_priv *bat_priv,
564 struct vis_info *info)
566 struct hashtable_t *hash = bat_priv->orig_hash;
567 struct neigh_node *router;
568 struct hlist_node *node;
569 struct hlist_head *head;
570 struct orig_node *orig_node;
571 struct vis_packet *packet;
575 packet = (struct vis_packet *)info->skb_packet->data;
577 for (i = 0; i < hash->size; i++) {
578 head = &hash->table[i];
581 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
582 router = batadv_orig_node_get_router(orig_node);
586 if ((orig_node->flags & VIS_SERVER) &&
587 (router->tq_avg > best_tq)) {
588 best_tq = router->tq_avg;
589 memcpy(packet->target_orig, orig_node->orig,
592 batadv_neigh_node_free_ref(router);
600 /* Return true if the vis packet is full. */
601 static bool vis_packet_full(const struct vis_info *info)
603 const struct vis_packet *packet;
604 packet = (struct vis_packet *)info->skb_packet->data;
606 if (MAX_VIS_PACKET_SIZE / sizeof(struct vis_info_entry)
607 < packet->entries + 1)
612 /* generates a packet of own vis data,
613 * returns 0 on success, -1 if no packet could be generated
615 static int generate_vis_packet(struct bat_priv *bat_priv)
617 struct hashtable_t *hash = bat_priv->orig_hash;
618 struct hlist_node *node;
619 struct hlist_head *head;
620 struct orig_node *orig_node;
621 struct neigh_node *router;
622 struct vis_info *info = bat_priv->my_vis_info;
623 struct vis_packet *packet = (struct vis_packet *)info->skb_packet->data;
624 struct vis_info_entry *entry;
625 struct tt_common_entry *tt_common_entry;
629 info->first_seen = jiffies;
630 packet->vis_type = atomic_read(&bat_priv->vis_mode);
632 memcpy(packet->target_orig, batadv_broadcast_addr, ETH_ALEN);
633 packet->header.ttl = TTL;
634 packet->seqno = htonl(ntohl(packet->seqno) + 1);
636 skb_trim(info->skb_packet, sizeof(*packet));
638 if (packet->vis_type == VIS_TYPE_CLIENT_UPDATE) {
639 best_tq = find_best_vis_server(bat_priv, info);
645 for (i = 0; i < hash->size; i++) {
646 head = &hash->table[i];
649 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
650 router = batadv_orig_node_get_router(orig_node);
654 if (!compare_eth(router->addr, orig_node->orig))
657 if (router->if_incoming->if_status != IF_ACTIVE)
660 if (router->tq_avg < 1)
663 /* fill one entry into buffer. */
664 entry = (struct vis_info_entry *)
665 skb_put(info->skb_packet, sizeof(*entry));
667 router->if_incoming->net_dev->dev_addr,
669 memcpy(entry->dest, orig_node->orig, ETH_ALEN);
670 entry->quality = router->tq_avg;
674 batadv_neigh_node_free_ref(router);
676 if (vis_packet_full(info))
682 hash = bat_priv->tt_local_hash;
684 for (i = 0; i < hash->size; i++) {
685 head = &hash->table[i];
688 hlist_for_each_entry_rcu(tt_common_entry, node, head,
690 entry = (struct vis_info_entry *)
691 skb_put(info->skb_packet,
693 memset(entry->src, 0, ETH_ALEN);
694 memcpy(entry->dest, tt_common_entry->addr, ETH_ALEN);
695 entry->quality = 0; /* 0 means TT */
698 if (vis_packet_full(info))
711 /* free old vis packets. Must be called with this vis_hash_lock
714 static void purge_vis_packets(struct bat_priv *bat_priv)
717 struct hashtable_t *hash = bat_priv->vis_hash;
718 struct hlist_node *node, *node_tmp;
719 struct hlist_head *head;
720 struct vis_info *info;
722 for (i = 0; i < hash->size; i++) {
723 head = &hash->table[i];
725 hlist_for_each_entry_safe(info, node, node_tmp,
727 /* never purge own data. */
728 if (info == bat_priv->my_vis_info)
731 if (has_timed_out(info->first_seen, VIS_TIMEOUT)) {
734 kref_put(&info->refcount, free_info);
740 static void broadcast_vis_packet(struct bat_priv *bat_priv,
741 struct vis_info *info)
743 struct neigh_node *router;
744 struct hashtable_t *hash = bat_priv->orig_hash;
745 struct hlist_node *node;
746 struct hlist_head *head;
747 struct orig_node *orig_node;
748 struct vis_packet *packet;
750 struct hard_iface *hard_iface;
751 uint8_t dstaddr[ETH_ALEN];
755 packet = (struct vis_packet *)info->skb_packet->data;
757 /* send to all routers in range. */
758 for (i = 0; i < hash->size; i++) {
759 head = &hash->table[i];
762 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
763 /* if it's a vis server and reachable, send it. */
764 if (!(orig_node->flags & VIS_SERVER))
767 router = batadv_orig_node_get_router(orig_node);
771 /* don't send it if we already received the packet from
774 if (recv_list_is_in(bat_priv, &info->recv_list,
776 batadv_neigh_node_free_ref(router);
780 memcpy(packet->target_orig, orig_node->orig, ETH_ALEN);
781 hard_iface = router->if_incoming;
782 memcpy(dstaddr, router->addr, ETH_ALEN);
784 batadv_neigh_node_free_ref(router);
786 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
788 batadv_send_skb_packet(skb, hard_iface,
796 static void unicast_vis_packet(struct bat_priv *bat_priv,
797 struct vis_info *info)
799 struct orig_node *orig_node;
800 struct neigh_node *router = NULL;
802 struct vis_packet *packet;
804 packet = (struct vis_packet *)info->skb_packet->data;
806 orig_node = orig_hash_find(bat_priv, packet->target_orig);
810 router = batadv_orig_node_get_router(orig_node);
814 skb = skb_clone(info->skb_packet, GFP_ATOMIC);
816 batadv_send_skb_packet(skb, router->if_incoming, router->addr);
820 batadv_neigh_node_free_ref(router);
822 batadv_orig_node_free_ref(orig_node);
825 /* only send one vis packet. called from send_vis_packets() */
826 static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
828 struct hard_iface *primary_if;
829 struct vis_packet *packet;
831 primary_if = batadv_primary_if_get_selected(bat_priv);
835 packet = (struct vis_packet *)info->skb_packet->data;
836 if (packet->header.ttl < 2) {
837 pr_debug("Error - can't send vis packet: ttl exceeded\n");
841 memcpy(packet->sender_orig, primary_if->net_dev->dev_addr, ETH_ALEN);
842 packet->header.ttl--;
844 if (is_broadcast_ether_addr(packet->target_orig))
845 broadcast_vis_packet(bat_priv, info);
847 unicast_vis_packet(bat_priv, info);
848 packet->header.ttl++; /* restore TTL */
852 batadv_hardif_free_ref(primary_if);
855 /* called from timer; send (and maybe generate) vis packet. */
856 static void send_vis_packets(struct work_struct *work)
858 struct delayed_work *delayed_work =
859 container_of(work, struct delayed_work, work);
860 struct bat_priv *bat_priv =
861 container_of(delayed_work, struct bat_priv, vis_work);
862 struct vis_info *info;
864 spin_lock_bh(&bat_priv->vis_hash_lock);
865 purge_vis_packets(bat_priv);
867 if (generate_vis_packet(bat_priv) == 0) {
868 /* schedule if generation was successful */
869 send_list_add(bat_priv, bat_priv->my_vis_info);
872 while (!list_empty(&bat_priv->vis_send_list)) {
873 info = list_first_entry(&bat_priv->vis_send_list,
874 typeof(*info), send_list);
876 kref_get(&info->refcount);
877 spin_unlock_bh(&bat_priv->vis_hash_lock);
879 send_vis_packet(bat_priv, info);
881 spin_lock_bh(&bat_priv->vis_hash_lock);
883 kref_put(&info->refcount, free_info);
885 spin_unlock_bh(&bat_priv->vis_hash_lock);
886 start_vis_timer(bat_priv);
889 /* init the vis server. this may only be called when if_list is already
890 * initialized (e.g. bat0 is initialized, interfaces have been added)
892 int batadv_vis_init(struct bat_priv *bat_priv)
894 struct vis_packet *packet;
897 if (bat_priv->vis_hash)
900 spin_lock_bh(&bat_priv->vis_hash_lock);
902 bat_priv->vis_hash = batadv_hash_new(256);
903 if (!bat_priv->vis_hash) {
904 pr_err("Can't initialize vis_hash\n");
908 bat_priv->my_vis_info = kmalloc(MAX_VIS_PACKET_SIZE, GFP_ATOMIC);
909 if (!bat_priv->my_vis_info)
912 bat_priv->my_vis_info->skb_packet = dev_alloc_skb(sizeof(*packet) +
913 MAX_VIS_PACKET_SIZE +
915 if (!bat_priv->my_vis_info->skb_packet)
918 skb_reserve(bat_priv->my_vis_info->skb_packet, ETH_HLEN);
919 packet = (struct vis_packet *)skb_put(bat_priv->my_vis_info->skb_packet,
922 /* prefill the vis info */
923 bat_priv->my_vis_info->first_seen = jiffies -
924 msecs_to_jiffies(VIS_INTERVAL);
925 INIT_LIST_HEAD(&bat_priv->my_vis_info->recv_list);
926 INIT_LIST_HEAD(&bat_priv->my_vis_info->send_list);
927 kref_init(&bat_priv->my_vis_info->refcount);
928 bat_priv->my_vis_info->bat_priv = bat_priv;
929 packet->header.version = COMPAT_VERSION;
930 packet->header.packet_type = BAT_VIS;
931 packet->header.ttl = TTL;
935 INIT_LIST_HEAD(&bat_priv->vis_send_list);
937 hash_added = batadv_hash_add(bat_priv->vis_hash, vis_info_cmp,
938 vis_info_choose, bat_priv->my_vis_info,
939 &bat_priv->my_vis_info->hash_entry);
940 if (hash_added != 0) {
941 pr_err("Can't add own vis packet into hash\n");
942 /* not in hash, need to remove it manually. */
943 kref_put(&bat_priv->my_vis_info->refcount, free_info);
947 spin_unlock_bh(&bat_priv->vis_hash_lock);
948 start_vis_timer(bat_priv);
952 kfree(bat_priv->my_vis_info);
953 bat_priv->my_vis_info = NULL;
955 spin_unlock_bh(&bat_priv->vis_hash_lock);
956 batadv_vis_quit(bat_priv);
960 /* Decrease the reference count on a hash item info */
961 static void free_info_ref(struct hlist_node *node, void *arg)
963 struct vis_info *info;
965 info = container_of(node, struct vis_info, hash_entry);
967 kref_put(&info->refcount, free_info);
970 /* shutdown vis-server */
971 void batadv_vis_quit(struct bat_priv *bat_priv)
973 if (!bat_priv->vis_hash)
976 cancel_delayed_work_sync(&bat_priv->vis_work);
978 spin_lock_bh(&bat_priv->vis_hash_lock);
979 /* properly remove, kill timers ... */
980 batadv_hash_delete(bat_priv->vis_hash, free_info_ref, NULL);
981 bat_priv->vis_hash = NULL;
982 bat_priv->my_vis_info = NULL;
983 spin_unlock_bh(&bat_priv->vis_hash_lock);
986 /* schedule packets for (re)transmission */
987 static void start_vis_timer(struct bat_priv *bat_priv)
989 INIT_DELAYED_WORK(&bat_priv->vis_work, send_vis_packets);
990 queue_delayed_work(batadv_event_workqueue, &bat_priv->vis_work,
991 msecs_to_jiffies(VIS_INTERVAL));