29 #define BATADV_MAX_VIS_PACKET_SIZE 1000
31 static void batadv_start_vis_timer(
struct batadv_priv *bat_priv);
34 static void batadv_free_info(
struct kref *ref)
44 spin_lock_bh(&bat_priv->
vis.list_lock);
50 spin_unlock_bh(&bat_priv->
vis.list_lock);
75 const unsigned char *
key;
106 index = batadv_vis_info_choose(data, hash->
size);
110 hlist_for_each_entry_rcu(vis_info, node, head,
hash_entry) {
111 if (!batadv_vis_info_cmp(node, data))
114 vis_info_tmp = vis_info;
133 if (batadv_compare_eth(entry->
addr, interface))
143 hlist_add_head(&entry->
list, if_list);
146 static void batadv_vis_data_read_prim_sec(
struct seq_file *seq,
162 batadv_vis_data_read_entry(
struct seq_file *seq,
166 if (primary && entry->
quality == 0)
168 else if (batadv_compare_eth(entry->
src, src))
182 for (i = 0; i < packet->
entries; i++) {
183 if (entries[i].quality == 0)
186 if (batadv_compare_eth(entries[i].src, packet->
vis_orig))
189 batadv_vis_data_insert_interface(entries[i].src, list,
false);
193 static void batadv_vis_data_read_entries(
struct seq_file *seq,
205 for (i = 0; i < packet->
entries; i++)
206 batadv_vis_data_read_entry(seq, &entries[i],
211 batadv_vis_data_read_prim_sec(seq, list);
217 static void batadv_vis_seq_print_text_bucket(
struct seq_file *seq,
230 hlist_for_each_entry_rcu(info, node, head, hash_entry) {
232 entries_pos = (
uint8_t *)packet +
sizeof(*packet);
235 batadv_vis_data_insert_interface(packet->vis_orig, &vis_if_list,
237 batadv_vis_data_insert_interfaces(&vis_if_list, packet,
239 batadv_vis_data_read_entries(seq, &vis_if_list, packet,
243 hlist_del(&entry->
list);
254 struct batadv_priv *bat_priv = netdev_priv(net_dev);
260 primary_if = batadv_primary_if_get_selected(bat_priv);
267 spin_lock_bh(&bat_priv->
vis.hash_lock);
268 for (i = 0; i < hash->
size; i++) {
270 batadv_vis_seq_print_text_bucket(seq, head);
272 spin_unlock_bh(&bat_priv->
vis.hash_lock);
276 batadv_hardif_free_ref(primary_if);
283 static void batadv_send_list_add(
struct batadv_priv *bat_priv,
299 kref_put(&info->
refcount, batadv_free_info);
304 static void batadv_recv_list_add(
struct batadv_priv *bat_priv,
314 spin_lock_bh(&bat_priv->
vis.list_lock);
316 spin_unlock_bh(&bat_priv->
vis.list_lock);
320 static int batadv_recv_list_is_in(
struct batadv_priv *bat_priv,
326 spin_lock_bh(&bat_priv->
vis.list_lock);
328 if (batadv_compare_eth(entry->
mac, mac)) {
329 spin_unlock_bh(&bat_priv->
vis.list_lock);
333 spin_unlock_bh(&bat_priv->
vis.list_lock);
344 int *is_new,
int make_broadcast)
357 if (!bat_priv->
vis.hash)
361 search_elem.skb_packet = dev_alloc_skb(
sizeof(*search_packet));
362 if (!search_elem.skb_packet)
364 len =
sizeof(*search_packet);
365 tmp_skb = search_elem.skb_packet;
369 old_info = batadv_vis_hash_find(bat_priv, &search_elem);
378 batadv_recv_list_add(bat_priv,
388 batadv_hash_remove(bat_priv->
vis.hash, batadv_vis_info_cmp,
389 batadv_vis_info_choose, old_info);
390 batadv_send_list_del(old_info);
391 kref_put(&old_info->
refcount, batadv_free_info);
398 len =
sizeof(*packet) + vis_info_len;
412 memcpy(packet, vis_packet, len);
423 if (packet->
entries > max_entries)
429 hash_added = batadv_hash_add(bat_priv->
vis.hash, batadv_vis_info_cmp,
430 batadv_vis_info_choose, info,
432 if (hash_added != 0) {
434 kref_put(&info->
refcount, batadv_free_info);
447 int is_new, make_broadcast;
452 spin_lock_bh(&bat_priv->
vis.hash_lock);
453 info = batadv_add_packet(bat_priv, vis_packet, vis_info_len,
454 &is_new, make_broadcast);
462 batadv_send_list_add(bat_priv, info);
464 spin_unlock_bh(&bat_priv->
vis.hash_lock);
479 if (is_broadcast_ether_addr(vis_packet->
target_orig))
487 spin_lock_bh(&bat_priv->
vis.hash_lock);
488 info = batadv_add_packet(bat_priv, vis_packet, vis_info_len,
489 &is_new, are_target);
498 if (are_target && is_new) {
500 batadv_send_list_add(bat_priv, info);
504 batadv_send_list_add(bat_priv, info);
508 spin_unlock_bh(&bat_priv->
vis.hash_lock);
516 static int batadv_find_best_vis_server(
struct batadv_priv *bat_priv,
530 for (i = 0; i < hash->
size; i++) {
534 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
540 (router->
tq_avg > best_tq)) {
562 if (num < packet->entries + 1)
570 static int batadv_generate_vis_packet(
struct batadv_priv *bat_priv)
597 best_tq = batadv_find_best_vis_server(bat_priv, info);
603 for (i = 0; i < hash->
size; i++) {
607 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
612 if (!batadv_compare_eth(router->
addr, orig_node->
orig))
634 if (batadv_vis_packet_full(info))
640 hash = bat_priv->
tt.local_hash;
642 for (i = 0; i < hash->
size; i++) {
646 hlist_for_each_entry_rcu(tt_common_entry, node, head,
655 if (batadv_vis_packet_full(info))
671 static void batadv_purge_vis_packets(
struct batadv_priv *bat_priv)
679 for (i = 0; i < hash->
size; i++) {
685 if (info == bat_priv->
vis.my_info)
691 batadv_send_list_del(info);
692 kref_put(&info->
refcount, batadv_free_info);
698 static void batadv_broadcast_vis_packet(
struct batadv_priv *bat_priv,
716 for (i = 0; i < hash->
size; i++) {
720 hlist_for_each_entry_rcu(orig_node, node, head, hash_entry) {
732 if (batadv_recv_list_is_in(bat_priv, &info->
recv_list,
754 static void batadv_unicast_vis_packet(
struct batadv_priv *bat_priv,
764 orig_node = batadv_orig_hash_find(bat_priv, packet->
target_orig);
784 static void batadv_send_vis_packet(
struct batadv_priv *bat_priv,
790 primary_if = batadv_primary_if_get_selected(bat_priv);
796 pr_debug(
"Error - can't send vis packet: ttl exceeded\n");
804 batadv_broadcast_vis_packet(bat_priv, info);
806 batadv_unicast_vis_packet(bat_priv, info);
811 batadv_hardif_free_ref(primary_if);
822 delayed_work =
container_of(work,
struct delayed_work, work);
825 spin_lock_bh(&bat_priv->
vis.hash_lock);
826 batadv_purge_vis_packets(bat_priv);
828 if (batadv_generate_vis_packet(bat_priv) == 0) {
830 batadv_send_list_add(bat_priv, bat_priv->
vis.my_info);
833 while (!list_empty(&bat_priv->
vis.send_list)) {
838 spin_unlock_bh(&bat_priv->
vis.hash_lock);
840 batadv_send_vis_packet(bat_priv, info);
842 spin_lock_bh(&bat_priv->
vis.hash_lock);
843 batadv_send_list_del(info);
844 kref_put(&info->
refcount, batadv_free_info);
846 spin_unlock_bh(&bat_priv->
vis.hash_lock);
847 batadv_start_vis_timer(bat_priv);
858 unsigned long first_seen;
861 if (bat_priv->
vis.hash)
864 spin_lock_bh(&bat_priv->
vis.hash_lock);
867 if (!bat_priv->
vis.hash) {
868 pr_err(
"Can't initialize vis_hash\n");
873 if (!bat_priv->
vis.my_info)
877 bat_priv->
vis.my_info->skb_packet = dev_alloc_skb(len);
878 if (!bat_priv->
vis.my_info->skb_packet)
881 skb_reserve(bat_priv->
vis.my_info->skb_packet, ETH_HLEN);
882 tmp_skb = bat_priv->
vis.my_info->skb_packet;
887 bat_priv->
vis.my_info->first_seen = first_seen;
888 INIT_LIST_HEAD(&bat_priv->
vis.my_info->recv_list);
889 INIT_LIST_HEAD(&bat_priv->
vis.my_info->send_list);
890 kref_init(&bat_priv->
vis.my_info->refcount);
891 bat_priv->
vis.my_info->bat_priv = bat_priv;
899 INIT_LIST_HEAD(&bat_priv->
vis.send_list);
901 hash_added = batadv_hash_add(bat_priv->
vis.hash, batadv_vis_info_cmp,
902 batadv_vis_info_choose,
903 bat_priv->
vis.my_info,
904 &bat_priv->
vis.my_info->hash_entry);
905 if (hash_added != 0) {
906 pr_err(
"Can't add own vis packet into hash\n");
908 kref_put(&bat_priv->
vis.my_info->refcount, batadv_free_info);
912 spin_unlock_bh(&bat_priv->
vis.hash_lock);
913 batadv_start_vis_timer(bat_priv);
920 spin_unlock_bh(&bat_priv->
vis.hash_lock);
926 static void batadv_free_info_ref(
struct hlist_node *node,
void *
arg)
931 batadv_send_list_del(info);
932 kref_put(&info->
refcount, batadv_free_info);
938 if (!bat_priv->
vis.hash)
943 spin_lock_bh(&bat_priv->
vis.hash_lock);
945 batadv_hash_delete(bat_priv->
vis.hash, batadv_free_info_ref,
NULL);
948 spin_unlock_bh(&bat_priv->
vis.hash_lock);
952 static void batadv_start_vis_timer(
struct batadv_priv *bat_priv)