Lines Matching +full:buffered +full:- +full:negative
1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2012-2020 B.A.T.M.A.N. contributors:
4 * Martin Hundebøll, Jeppe Ledet-Pedersen
7 #include "network-coding.h"
42 #include "hard-interface.h"
58 * batadv_nc_init() - one-time initialization for network coding
60 * Return: 0 on success or negative error number in case of failure
74 * batadv_nc_start_timer() - initialise the nc periodic worker
79 queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work, in batadv_nc_start_timer()
84 * batadv_nc_tvlv_container_update() - update the network coding tvlv container
92 nc_mode = atomic_read(&bat_priv->network_coding); in batadv_nc_tvlv_container_update()
106 * batadv_nc_status_update() - update the network coding tvlv container after
118 * batadv_nc_tvlv_ogm_handler_v1() - process incoming nc tvlv container
131 clear_bit(BATADV_ORIG_CAPA_HAS_NC, &orig->capabilities); in batadv_nc_tvlv_ogm_handler_v1()
133 set_bit(BATADV_ORIG_CAPA_HAS_NC, &orig->capabilities); in batadv_nc_tvlv_ogm_handler_v1()
137 * batadv_nc_mesh_init() - initialise coding hash table and start housekeeping
140 * Return: 0 on success or negative error number in case of failure
144 bat_priv->nc.timestamp_fwd_flush = jiffies; in batadv_nc_mesh_init()
145 bat_priv->nc.timestamp_sniffed_purge = jiffies; in batadv_nc_mesh_init()
147 if (bat_priv->nc.coding_hash || bat_priv->nc.decoding_hash) in batadv_nc_mesh_init()
150 bat_priv->nc.coding_hash = batadv_hash_new(128); in batadv_nc_mesh_init()
151 if (!bat_priv->nc.coding_hash) in batadv_nc_mesh_init()
154 batadv_hash_set_lock_class(bat_priv->nc.coding_hash, in batadv_nc_mesh_init()
157 bat_priv->nc.decoding_hash = batadv_hash_new(128); in batadv_nc_mesh_init()
158 if (!bat_priv->nc.decoding_hash) { in batadv_nc_mesh_init()
159 batadv_hash_destroy(bat_priv->nc.coding_hash); in batadv_nc_mesh_init()
163 batadv_hash_set_lock_class(bat_priv->nc.decoding_hash, in batadv_nc_mesh_init()
166 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker); in batadv_nc_mesh_init()
176 return -ENOMEM; in batadv_nc_mesh_init()
180 * batadv_nc_init_bat_priv() - initialise the nc specific bat_priv variables
185 atomic_set(&bat_priv->network_coding, 0); in batadv_nc_init_bat_priv()
186 bat_priv->nc.min_tq = 200; in batadv_nc_init_bat_priv()
187 bat_priv->nc.max_fwd_delay = 10; in batadv_nc_init_bat_priv()
188 bat_priv->nc.max_buffer_time = 200; in batadv_nc_init_bat_priv()
192 * batadv_nc_init_orig() - initialise the nc fields of an orig_node
197 INIT_LIST_HEAD(&orig_node->in_coding_list); in batadv_nc_init_orig()
198 INIT_LIST_HEAD(&orig_node->out_coding_list); in batadv_nc_init_orig()
199 spin_lock_init(&orig_node->in_coding_list_lock); in batadv_nc_init_orig()
200 spin_lock_init(&orig_node->out_coding_list_lock); in batadv_nc_init_orig()
204 * batadv_nc_node_release() - release nc_node from lists and queue for free
214 batadv_orig_node_put(nc_node->orig_node); in batadv_nc_node_release()
219 * batadv_nc_node_put() - decrement the nc_node refcounter and possibly
225 kref_put(&nc_node->refcount, batadv_nc_node_release); in batadv_nc_node_put()
229 * batadv_nc_path_release() - release nc_path from lists and queue for free
243 * batadv_nc_path_put() - decrement the nc_path refcounter and possibly
249 kref_put(&nc_path->refcount, batadv_nc_path_release); in batadv_nc_path_put()
253 * batadv_nc_packet_free() - frees nc packet
261 kfree_skb(nc_packet->skb); in batadv_nc_packet_free()
263 consume_skb(nc_packet->skb); in batadv_nc_packet_free()
265 batadv_nc_path_put(nc_packet->nc_path); in batadv_nc_packet_free()
270 * batadv_nc_to_purge_nc_node() - checks whether an nc node has to be purged
279 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) in batadv_nc_to_purge_nc_node()
282 return batadv_has_timed_out(nc_node->last_seen, BATADV_NC_NODE_TIMEOUT); in batadv_nc_to_purge_nc_node()
286 * batadv_nc_to_purge_nc_path_coding() - checks whether an nc path has timed out
295 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) in batadv_nc_to_purge_nc_path_coding()
301 return batadv_has_timed_out(nc_path->last_valid, in batadv_nc_to_purge_nc_path_coding()
302 bat_priv->nc.max_fwd_delay * 10); in batadv_nc_to_purge_nc_path_coding()
306 * batadv_nc_to_purge_nc_path_decoding() - checks whether an nc path has timed
316 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) in batadv_nc_to_purge_nc_path_decoding()
322 return batadv_has_timed_out(nc_path->last_valid, in batadv_nc_to_purge_nc_path_decoding()
323 bat_priv->nc.max_buffer_time * 10); in batadv_nc_to_purge_nc_path_decoding()
327 * batadv_nc_purge_orig_nc_nodes() - go through list of nc nodes and purge stale
356 "Removing nc_node %pM -> %pM\n", in batadv_nc_purge_orig_nc_nodes()
357 nc_node->addr, nc_node->orig_node->orig); in batadv_nc_purge_orig_nc_nodes()
358 list_del_rcu(&nc_node->list); in batadv_nc_purge_orig_nc_nodes()
365 * batadv_nc_purge_orig() - purges all nc node data attached of the given
380 batadv_nc_purge_orig_nc_nodes(bat_priv, &orig_node->in_coding_list, in batadv_nc_purge_orig()
381 &orig_node->in_coding_list_lock, in batadv_nc_purge_orig()
385 batadv_nc_purge_orig_nc_nodes(bat_priv, &orig_node->out_coding_list, in batadv_nc_purge_orig()
386 &orig_node->out_coding_list_lock, in batadv_nc_purge_orig()
391 * batadv_nc_purge_orig_hash() - traverse entire originator hash to check if
397 struct batadv_hashtable *hash = bat_priv->orig_hash; in batadv_nc_purge_orig_hash()
406 for (i = 0; i < hash->size; i++) { in batadv_nc_purge_orig_hash()
407 head = &hash->table[i]; in batadv_nc_purge_orig_hash()
418 * batadv_nc_purge_paths() - traverse all nc paths part of the hash and remove
438 for (i = 0; i < hash->size; i++) { in batadv_nc_purge_paths()
439 head = &hash->table[i]; in batadv_nc_purge_paths()
440 lock = &hash->list_locks[i]; in batadv_nc_purge_paths()
451 /* purging an non-empty nc_path should never happen, but in batadv_nc_purge_paths()
456 if (!unlikely(list_empty(&nc_path->packet_list))) { in batadv_nc_purge_paths()
459 "Skipping free of non-empty nc_path (%pM -> %pM)!\n", in batadv_nc_purge_paths()
460 nc_path->prev_hop, in batadv_nc_purge_paths()
461 nc_path->next_hop); in batadv_nc_purge_paths()
467 "Remove nc_path %pM -> %pM\n", in batadv_nc_purge_paths()
468 nc_path->prev_hop, nc_path->next_hop); in batadv_nc_purge_paths()
469 hlist_del_rcu(&nc_path->hash_entry); in batadv_nc_purge_paths()
477 * batadv_nc_hash_key_gen() - computes the nc_path hash key
485 memcpy(key->prev_hop, src, sizeof(key->prev_hop)); in batadv_nc_hash_key_gen()
486 memcpy(key->next_hop, dst, sizeof(key->next_hop)); in batadv_nc_hash_key_gen()
490 * batadv_nc_hash_choose() - compute the hash value for an nc path
501 hash = jhash(&nc_path->prev_hop, sizeof(nc_path->prev_hop), hash); in batadv_nc_hash_choose()
502 hash = jhash(&nc_path->next_hop, sizeof(nc_path->next_hop), hash); in batadv_nc_hash_choose()
508 * batadv_nc_hash_compare() - comparing function used in the network coding hash
524 if (!batadv_compare_eth(nc_path1->prev_hop, nc_path2->prev_hop)) in batadv_nc_hash_compare()
527 if (!batadv_compare_eth(nc_path1->next_hop, nc_path2->next_hop)) in batadv_nc_hash_compare()
534 * batadv_nc_hash_find() - search for an existing nc path and return it
551 index = batadv_nc_hash_choose(data, hash->size); in batadv_nc_hash_find()
552 head = &hash->table[index]; in batadv_nc_hash_find()
556 if (!batadv_nc_hash_compare(&nc_path->hash_entry, data)) in batadv_nc_hash_find()
559 if (!kref_get_unless_zero(&nc_path->refcount)) in batadv_nc_hash_find()
571 * batadv_nc_send_packet() - send non-coded packet and free nc_packet struct
576 batadv_send_unicast_skb(nc_packet->skb, nc_packet->neigh_node); in batadv_nc_send_packet()
577 nc_packet->skb = NULL; in batadv_nc_send_packet()
582 * batadv_nc_sniffed_purge() - Checks timestamp of given sniffed nc_packet.
598 unsigned long timeout = bat_priv->nc.max_buffer_time; in batadv_nc_sniffed_purge()
601 lockdep_assert_held(&nc_path->packet_list_lock); in batadv_nc_sniffed_purge()
606 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE && in batadv_nc_sniffed_purge()
607 !batadv_has_timed_out(nc_packet->timestamp, timeout)) in batadv_nc_sniffed_purge()
611 list_del(&nc_packet->list); in batadv_nc_sniffed_purge()
621 * batadv_nc_fwd_flush() - Checks the timestamp of the given nc packet.
637 unsigned long timeout = bat_priv->nc.max_fwd_delay; in batadv_nc_fwd_flush()
639 lockdep_assert_held(&nc_path->packet_list_lock); in batadv_nc_fwd_flush()
644 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE && in batadv_nc_fwd_flush()
645 !batadv_has_timed_out(nc_packet->timestamp, timeout)) in batadv_nc_fwd_flush()
651 nc_packet->skb->len + ETH_HLEN); in batadv_nc_fwd_flush()
652 list_del(&nc_packet->list); in batadv_nc_fwd_flush()
659 * batadv_nc_process_nc_paths() - traverse given nc packet pool and free timed
684 for (i = 0; i < hash->size; i++) { in batadv_nc_process_nc_paths()
685 head = &hash->table[i]; in batadv_nc_process_nc_paths()
691 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_process_nc_paths()
693 &nc_path->packet_list, list) { in batadv_nc_process_nc_paths()
698 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_process_nc_paths()
705 * batadv_nc_worker() - periodic task for housekeeping related to network
721 batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, in batadv_nc_worker()
723 batadv_nc_purge_paths(bat_priv, bat_priv->nc.decoding_hash, in batadv_nc_worker()
726 timeout = bat_priv->nc.max_fwd_delay; in batadv_nc_worker()
728 if (batadv_has_timed_out(bat_priv->nc.timestamp_fwd_flush, timeout)) { in batadv_nc_worker()
729 batadv_nc_process_nc_paths(bat_priv, bat_priv->nc.coding_hash, in batadv_nc_worker()
731 bat_priv->nc.timestamp_fwd_flush = jiffies; in batadv_nc_worker()
734 if (batadv_has_timed_out(bat_priv->nc.timestamp_sniffed_purge, in batadv_nc_worker()
735 bat_priv->nc.max_buffer_time)) { in batadv_nc_worker()
736 batadv_nc_process_nc_paths(bat_priv, bat_priv->nc.decoding_hash, in batadv_nc_worker()
738 bat_priv->nc.timestamp_sniffed_purge = jiffies; in batadv_nc_worker()
746 * batadv_can_nc_with_orig() - checks whether the given orig node is suitable
756 * 4) The TQ value of the OGM must be above bat_priv->nc.min_tq.
770 last_ttl = orig_ifinfo->last_ttl; in batadv_can_nc_with_orig()
771 last_real_seqno = orig_ifinfo->last_real_seqno; in batadv_can_nc_with_orig()
774 if (last_real_seqno != ntohl(ogm_packet->seqno)) in batadv_can_nc_with_orig()
776 if (last_ttl != ogm_packet->ttl + 1) in batadv_can_nc_with_orig()
778 if (!batadv_compare_eth(ogm_packet->orig, ogm_packet->prev_sender)) in batadv_can_nc_with_orig()
780 if (ogm_packet->tq < bat_priv->nc.min_tq) in batadv_can_nc_with_orig()
787 * batadv_nc_find_nc_node() - search for an existing nc node and return it
804 list = &orig_neigh_node->in_coding_list; in batadv_nc_find_nc_node()
806 list = &orig_neigh_node->out_coding_list; in batadv_nc_find_nc_node()
811 if (!batadv_compare_eth(nc_node->addr, orig_node->orig)) in batadv_nc_find_nc_node()
814 if (!kref_get_unless_zero(&nc_node->refcount)) in batadv_nc_find_nc_node()
827 * batadv_nc_get_nc_node() - retrieves an nc node or creates the entry if it was
849 lock = &orig_neigh_node->in_coding_list_lock; in batadv_nc_get_nc_node()
850 list = &orig_neigh_node->in_coding_list; in batadv_nc_get_nc_node()
852 lock = &orig_neigh_node->out_coding_list_lock; in batadv_nc_get_nc_node()
853 list = &orig_neigh_node->out_coding_list; in batadv_nc_get_nc_node()
870 INIT_LIST_HEAD(&nc_node->list); in batadv_nc_get_nc_node()
871 kref_init(&nc_node->refcount); in batadv_nc_get_nc_node()
872 ether_addr_copy(nc_node->addr, orig_node->orig); in batadv_nc_get_nc_node()
873 kref_get(&orig_neigh_node->refcount); in batadv_nc_get_nc_node()
874 nc_node->orig_node = orig_neigh_node; in batadv_nc_get_nc_node()
876 batadv_dbg(BATADV_DBG_NC, bat_priv, "Adding nc_node %pM -> %pM\n", in batadv_nc_get_nc_node()
877 nc_node->addr, nc_node->orig_node->orig); in batadv_nc_get_nc_node()
880 kref_get(&nc_node->refcount); in batadv_nc_get_nc_node()
881 list_add_tail_rcu(&nc_node->list, list); in batadv_nc_get_nc_node()
890 * batadv_nc_update_nc_node() - updates stored incoming and outgoing nc node
909 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_update_nc_node()
913 if (!test_bit(BATADV_ORIG_CAPA_HAS_NC, &orig_node->capabilities)) in batadv_nc_update_nc_node()
927 in_nc_node->last_seen = jiffies; in batadv_nc_update_nc_node()
935 out_nc_node->last_seen = jiffies; in batadv_nc_update_nc_node()
945 * batadv_nc_get_path() - get existing nc_path or allocate a new one
948 * @src: ethernet source address - first half of the nc path search key
949 * @dst: ethernet destination address - second half of the nc path search key
969 nc_path->last_valid = jiffies; in batadv_nc_get_path()
980 INIT_LIST_HEAD(&nc_path->packet_list); in batadv_nc_get_path()
981 spin_lock_init(&nc_path->packet_list_lock); in batadv_nc_get_path()
982 kref_init(&nc_path->refcount); in batadv_nc_get_path()
983 nc_path->last_valid = jiffies; in batadv_nc_get_path()
984 ether_addr_copy(nc_path->next_hop, dst); in batadv_nc_get_path()
985 ether_addr_copy(nc_path->prev_hop, src); in batadv_nc_get_path()
987 batadv_dbg(BATADV_DBG_NC, bat_priv, "Adding nc_path %pM -> %pM\n", in batadv_nc_get_path()
988 nc_path->prev_hop, in batadv_nc_get_path()
989 nc_path->next_hop); in batadv_nc_get_path()
992 kref_get(&nc_path->refcount); in batadv_nc_get_path()
995 &nc_path->hash_entry); in batadv_nc_get_path()
1006 * batadv_nc_random_weight_tq() - scale the receivers TQ-value to avoid unfair
1014 /* randomize the estimated packet loss (max TQ - estimated TQ) */ in batadv_nc_random_weight_tq()
1015 u8 rand_tq = prandom_u32_max(BATADV_TQ_MAX_VALUE + 1 - tq); in batadv_nc_random_weight_tq()
1018 return BATADV_TQ_MAX_VALUE - rand_tq; in batadv_nc_random_weight_tq()
1022 * batadv_nc_memxor() - XOR destination with source
1036 * batadv_nc_code_packets() - code a received unicast_packet with an nc packet
1068 int header_add = coded_size - unicast_size; in batadv_nc_code_packets()
1073 router_neigh = batadv_orig_router_get(neigh_node->orig_node, in batadv_nc_code_packets()
1083 neigh_tmp = nc_packet->neigh_node; in batadv_nc_code_packets()
1084 router_coding = batadv_orig_router_get(neigh_tmp->orig_node, in batadv_nc_code_packets()
1094 tq_tmp = router_neigh_ifinfo->bat_iv.tq_avg; in batadv_nc_code_packets()
1096 tq_tmp = router_coding_ifinfo->bat_iv.tq_avg; in batadv_nc_code_packets()
1099 /* Select one destination for the MAC-header dst-field based on in batadv_nc_code_packets()
1100 * weighted TQ-values. in batadv_nc_code_packets()
1103 /* Destination from nc_packet is selected for MAC-header */ in batadv_nc_code_packets()
1104 first_dest = nc_packet->neigh_node; in batadv_nc_code_packets()
1105 first_source = nc_packet->nc_path->prev_hop; in batadv_nc_code_packets()
1107 second_source = ethhdr->h_source; in batadv_nc_code_packets()
1108 packet1 = (struct batadv_unicast_packet *)nc_packet->skb->data; in batadv_nc_code_packets()
1109 packet2 = (struct batadv_unicast_packet *)skb->data; in batadv_nc_code_packets()
1110 packet_id1 = nc_packet->packet_id; in batadv_nc_code_packets()
1112 skb->data + sizeof(*packet2)); in batadv_nc_code_packets()
1114 /* Destination for skb is selected for MAC-header */ in batadv_nc_code_packets()
1116 first_source = ethhdr->h_source; in batadv_nc_code_packets()
1117 second_dest = nc_packet->neigh_node; in batadv_nc_code_packets()
1118 second_source = nc_packet->nc_path->prev_hop; in batadv_nc_code_packets()
1119 packet1 = (struct batadv_unicast_packet *)skb->data; in batadv_nc_code_packets()
1120 packet2 = (struct batadv_unicast_packet *)nc_packet->skb->data; in batadv_nc_code_packets()
1122 skb->data + sizeof(*packet1)); in batadv_nc_code_packets()
1123 packet_id2 = nc_packet->packet_id; in batadv_nc_code_packets()
1129 if (skb->len <= nc_packet->skb->len) { in batadv_nc_code_packets()
1130 skb_dest = nc_packet->skb; in batadv_nc_code_packets()
1134 skb_src = nc_packet->skb; in batadv_nc_code_packets()
1138 coding_len = skb_src->len - unicast_size; in batadv_nc_code_packets()
1145 coded_packet = (struct batadv_coded_packet *)skb_dest->data; in batadv_nc_code_packets()
1148 coded_packet->packet_type = BATADV_CODED; in batadv_nc_code_packets()
1149 coded_packet->version = BATADV_COMPAT_VERSION; in batadv_nc_code_packets()
1150 coded_packet->ttl = packet1->ttl; in batadv_nc_code_packets()
1153 ether_addr_copy(coded_packet->first_source, first_source); in batadv_nc_code_packets()
1154 ether_addr_copy(coded_packet->first_orig_dest, packet1->dest); in batadv_nc_code_packets()
1155 coded_packet->first_crc = packet_id1; in batadv_nc_code_packets()
1156 coded_packet->first_ttvn = packet1->ttvn; in batadv_nc_code_packets()
1159 ether_addr_copy(coded_packet->second_dest, second_dest->addr); in batadv_nc_code_packets()
1160 ether_addr_copy(coded_packet->second_source, second_source); in batadv_nc_code_packets()
1161 ether_addr_copy(coded_packet->second_orig_dest, packet2->dest); in batadv_nc_code_packets()
1162 coded_packet->second_crc = packet_id2; in batadv_nc_code_packets()
1163 coded_packet->second_ttl = packet2->ttl; in batadv_nc_code_packets()
1164 coded_packet->second_ttvn = packet2->ttvn; in batadv_nc_code_packets()
1165 coded_packet->coded_len = htons(coding_len); in batadv_nc_code_packets()
1168 batadv_nc_memxor(skb_dest->data + coded_size, in batadv_nc_code_packets()
1169 skb_src->data + unicast_size, coding_len); in batadv_nc_code_packets()
1172 if (BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1173 BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1175 count = skb_src->len + ETH_HLEN; in batadv_nc_code_packets()
1176 count += skb_dest->len + ETH_HLEN; in batadv_nc_code_packets()
1179 } else if (!BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1180 !BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1182 count = skb_src->len + ETH_HLEN; in batadv_nc_code_packets()
1183 count += skb_dest->len + ETH_HLEN; in batadv_nc_code_packets()
1186 } else if (BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1187 !BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1191 skb_src->len + ETH_HLEN); in batadv_nc_code_packets()
1194 skb_dest->len + ETH_HLEN); in batadv_nc_code_packets()
1195 } else if (!BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1196 BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1200 skb_src->len + ETH_HLEN); in batadv_nc_code_packets()
1203 skb_dest->len + ETH_HLEN); in batadv_nc_code_packets()
1210 nc_packet->skb = NULL; in batadv_nc_code_packets()
1229 * batadv_nc_skb_coding_possible() - true if a decoded skb is available at dst.
1239 * re-code the packet if the source of the previous encoded packet is involved.
1247 if (BATADV_SKB_CB(skb)->decoded && !batadv_compare_eth(dst, src)) in batadv_nc_skb_coding_possible()
1253 * batadv_nc_path_search() - Find the coding path matching in_nc_node and
1254 * out_nc_node to retrieve a buffered packet that can be used for coding.
1273 struct batadv_hashtable *hash = bat_priv->nc.coding_hash; in batadv_nc_path_search()
1280 batadv_nc_hash_key_gen(&nc_path_key, in_nc_node->addr, in batadv_nc_path_search()
1281 out_nc_node->addr); in batadv_nc_path_search()
1282 idx = batadv_nc_hash_choose(&nc_path_key, hash->size); in batadv_nc_path_search()
1286 hlist_for_each_entry_rcu(nc_path, &hash->table[idx], hash_entry) { in batadv_nc_path_search()
1287 if (!batadv_compare_eth(nc_path->prev_hop, in_nc_node->addr)) in batadv_nc_path_search()
1290 if (!batadv_compare_eth(nc_path->next_hop, out_nc_node->addr)) in batadv_nc_path_search()
1293 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_path_search()
1294 if (list_empty(&nc_path->packet_list)) { in batadv_nc_path_search()
1295 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_path_search()
1300 &nc_path->packet_list, list) { in batadv_nc_path_search()
1301 if (!batadv_nc_skb_coding_possible(nc_packet->skb, in batadv_nc_path_search()
1303 in_nc_node->addr)) in batadv_nc_path_search()
1307 list_del(&nc_packet->list); in batadv_nc_path_search()
1312 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_path_search()
1321 * batadv_nc_skb_src_search() - Loops through the list of neighboring nodes of
1348 &orig_node->out_coding_list, list) { in batadv_nc_skb_src_search()
1351 out_nc_node->addr, eth_src)) in batadv_nc_skb_src_search()
1367 * batadv_nc_skb_store_before_coding() - set the ethernet src and dst of the
1386 ether_addr_copy(ethhdr->h_source, ethhdr->h_dest); in batadv_nc_skb_store_before_coding()
1387 ether_addr_copy(ethhdr->h_dest, eth_dst_new); in batadv_nc_skb_store_before_coding()
1402 * batadv_nc_skb_dst_search() - Loops through list of neighboring nodes to dst.
1418 struct net_device *netdev = neigh_node->if_incoming->soft_iface; in batadv_nc_skb_dst_search()
1420 struct batadv_orig_node *orig_node = neigh_node->orig_node; in batadv_nc_skb_dst_search()
1425 list_for_each_entry_rcu(nc_node, &orig_node->in_coding_list, list) { in batadv_nc_skb_dst_search()
1428 neigh_node->addr, in batadv_nc_skb_dst_search()
1429 ethhdr->h_source, nc_node); in batadv_nc_skb_dst_search()
1442 neigh_node->addr); in batadv_nc_skb_dst_search()
1443 batadv_nc_skb_store_before_coding(bat_priv, nc_packet->skb, in batadv_nc_skb_dst_search()
1444 nc_packet->neigh_node->addr); in batadv_nc_skb_dst_search()
1451 /* out of mem ? Coding failed - we have to free the buffered packet in batadv_nc_skb_dst_search()
1460 * batadv_nc_skb_add_to_path() - buffer skb for later encoding / decoding
1466 * Return: true if the packet was buffered or false in case of an error.
1480 nc_packet->timestamp = jiffies; in batadv_nc_skb_add_to_path()
1481 nc_packet->packet_id = packet_id; in batadv_nc_skb_add_to_path()
1482 nc_packet->skb = skb; in batadv_nc_skb_add_to_path()
1483 nc_packet->neigh_node = neigh_node; in batadv_nc_skb_add_to_path()
1484 nc_packet->nc_path = nc_path; in batadv_nc_skb_add_to_path()
1487 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_skb_add_to_path()
1488 list_add_tail(&nc_packet->list, &nc_path->packet_list); in batadv_nc_skb_add_to_path()
1489 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_skb_add_to_path()
1495 * batadv_nc_skb_forward() - try to code a packet or add it to the coding packet
1505 const struct net_device *netdev = neigh_node->if_incoming->soft_iface; in batadv_nc_skb_forward()
1514 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_skb_forward()
1520 if (packet->packet_type != BATADV_UNICAST) in batadv_nc_skb_forward()
1527 /* Find or create a nc_path for this src-dst pair */ in batadv_nc_skb_forward()
1529 bat_priv->nc.coding_hash, in batadv_nc_skb_forward()
1530 ethhdr->h_source, in batadv_nc_skb_forward()
1531 neigh_node->addr); in batadv_nc_skb_forward()
1552 * batadv_nc_skb_store_for_decoding() - save a clone of the skb which can be
1567 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_skb_store_for_decoding()
1573 if (packet->packet_type != BATADV_UNICAST) in batadv_nc_skb_store_for_decoding()
1578 bat_priv->nc.decoding_hash, in batadv_nc_skb_store_for_decoding()
1579 ethhdr->h_source, in batadv_nc_skb_store_for_decoding()
1580 ethhdr->h_dest); in batadv_nc_skb_store_for_decoding()
1585 /* Clone skb and adjust skb->data to point at batman header */ in batadv_nc_skb_store_for_decoding()
1613 * batadv_nc_skb_store_sniffed_unicast() - check if a received unicast packet
1623 if (batadv_is_my_mac(bat_priv, ethhdr->h_dest)) in batadv_nc_skb_store_sniffed_unicast()
1633 * batadv_nc_skb_decode_packet() - decode given skb using the decode data stored
1647 const int h_diff = sizeof(struct batadv_coded_packet) - h_size; in batadv_nc_skb_decode_packet()
1656 memcpy(&coded_packet_tmp, skb->data, sizeof(coded_packet_tmp)); in batadv_nc_skb_decode_packet()
1668 skb_set_mac_header(skb, -ETH_HLEN); in batadv_nc_skb_decode_packet()
1683 ether_addr_copy(ethhdr->h_dest, coded_packet_tmp.second_dest); in batadv_nc_skb_decode_packet()
1684 skb->pkt_type = PACKET_HOST; in batadv_nc_skb_decode_packet()
1697 if (coding_len > skb->len) in batadv_nc_skb_decode_packet()
1703 batadv_nc_memxor(skb->data + h_size, in batadv_nc_skb_decode_packet()
1704 nc_packet->skb->data + h_size, in batadv_nc_skb_decode_packet()
1708 if (nc_packet->skb->len > coding_len + h_size) { in batadv_nc_skb_decode_packet()
1715 unicast_packet = (struct batadv_unicast_packet *)skb->data; in batadv_nc_skb_decode_packet()
1716 unicast_packet->packet_type = BATADV_UNICAST; in batadv_nc_skb_decode_packet()
1717 unicast_packet->version = BATADV_COMPAT_VERSION; in batadv_nc_skb_decode_packet()
1718 unicast_packet->ttl = ttl; in batadv_nc_skb_decode_packet()
1719 ether_addr_copy(unicast_packet->dest, orig_dest); in batadv_nc_skb_decode_packet()
1720 unicast_packet->ttvn = ttvn; in batadv_nc_skb_decode_packet()
1727 * batadv_nc_find_decoding_packet() - search through buffered decoding data to
1740 struct batadv_hashtable *hash = bat_priv->nc.decoding_hash; in batadv_nc_find_decoding_packet()
1750 /* Select the correct packet id based on the location of our mac-addr */ in batadv_nc_find_decoding_packet()
1751 dest = ethhdr->h_source; in batadv_nc_find_decoding_packet()
1752 if (!batadv_is_my_mac(bat_priv, coded->second_dest)) { in batadv_nc_find_decoding_packet()
1753 source = coded->second_source; in batadv_nc_find_decoding_packet()
1754 packet_id = coded->second_crc; in batadv_nc_find_decoding_packet()
1756 source = coded->first_source; in batadv_nc_find_decoding_packet()
1757 packet_id = coded->first_crc; in batadv_nc_find_decoding_packet()
1761 index = batadv_nc_hash_choose(&nc_path_key, hash->size); in batadv_nc_find_decoding_packet()
1765 hlist_for_each_entry_rcu(nc_path, &hash->table[index], hash_entry) { in batadv_nc_find_decoding_packet()
1767 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_find_decoding_packet()
1769 &nc_path->packet_list, list) { in batadv_nc_find_decoding_packet()
1770 if (packet_id == tmp_nc_packet->packet_id) { in batadv_nc_find_decoding_packet()
1771 list_del(&tmp_nc_packet->list); in batadv_nc_find_decoding_packet()
1777 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_find_decoding_packet()
1792 * batadv_nc_recv_coded_packet() - try to decode coded packet and enqueue the
1803 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); in batadv_nc_recv_coded_packet()
1811 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_recv_coded_packet()
1818 coded_packet = (struct batadv_coded_packet *)skb->data; in batadv_nc_recv_coded_packet()
1822 if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest) && in batadv_nc_recv_coded_packet()
1823 !batadv_is_my_mac(bat_priv, coded_packet->second_dest)) in batadv_nc_recv_coded_packet()
1827 if (batadv_is_my_mac(bat_priv, coded_packet->second_dest)) in batadv_nc_recv_coded_packet()
1841 if (skb_linearize(nc_packet->skb) < 0) in batadv_nc_recv_coded_packet()
1852 BATADV_SKB_CB(skb)->decoded = true; in batadv_nc_recv_coded_packet()
1855 skb->len + ETH_HLEN); in batadv_nc_recv_coded_packet()
1867 * batadv_nc_mesh_free() - clean up network coding memory
1874 cancel_delayed_work_sync(&bat_priv->nc.work); in batadv_nc_mesh_free()
1876 batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, NULL); in batadv_nc_mesh_free()
1877 batadv_hash_destroy(bat_priv->nc.coding_hash); in batadv_nc_mesh_free()
1878 batadv_nc_purge_paths(bat_priv, bat_priv->nc.decoding_hash, NULL); in batadv_nc_mesh_free()
1879 batadv_hash_destroy(bat_priv->nc.decoding_hash); in batadv_nc_mesh_free()
1884 * batadv_nc_nodes_seq_print_text() - print the nc node information
1892 struct net_device *net_dev = (struct net_device *)seq->private; in batadv_nc_nodes_seq_print_text()
1894 struct batadv_hashtable *hash = bat_priv->orig_hash; in batadv_nc_nodes_seq_print_text()
1906 for (i = 0; i < hash->size; i++) { in batadv_nc_nodes_seq_print_text()
1907 head = &hash->table[i]; in batadv_nc_nodes_seq_print_text()
1915 if (list_empty(&orig_node->in_coding_list) && in batadv_nc_nodes_seq_print_text()
1916 list_empty(&orig_node->out_coding_list)) in batadv_nc_nodes_seq_print_text()
1919 seq_printf(seq, "Node: %pM\n", orig_node->orig); in batadv_nc_nodes_seq_print_text()
1924 &orig_node->in_coding_list, in batadv_nc_nodes_seq_print_text()
1927 nc_node->addr); in batadv_nc_nodes_seq_print_text()
1931 &orig_node->out_coding_list, in batadv_nc_nodes_seq_print_text()
1934 nc_node->addr); in batadv_nc_nodes_seq_print_text()
1947 * batadv_nc_init_debugfs() - create nc folder and related files in debugfs
1954 nc_dir = debugfs_create_dir("nc", bat_priv->debug_dir); in batadv_nc_init_debugfs()
1956 debugfs_create_u8("min_tq", 0644, nc_dir, &bat_priv->nc.min_tq); in batadv_nc_init_debugfs()
1959 &bat_priv->nc.max_fwd_delay); in batadv_nc_init_debugfs()
1962 &bat_priv->nc.max_buffer_time); in batadv_nc_init_debugfs()