Lines Matching +full:buffered +full:- +full:negative

1 // SPDX-License-Identifier: GPL-2.0
4 * Martin Hundebøll, Jeppe Ledet-Pedersen
7 #include "network-coding.h"
55 * batadv_nc_init() - one-time initialization for network coding
57 * Return: 0 on success or negative error number in case of failure
71 * batadv_nc_start_timer() - initialise the nc periodic worker
76 queue_delayed_work(batadv_event_workqueue, &bat_priv->nc.work, in batadv_nc_start_timer()
81 * batadv_nc_tvlv_container_update() - update the network coding tvlv container
89 nc_mode = atomic_read(&bat_priv->network_coding); in batadv_nc_tvlv_container_update()
103 * batadv_nc_status_update() - update the network coding tvlv container after
115 * batadv_nc_tvlv_ogm_handler_v1() - process incoming nc tvlv container
128 clear_bit(BATADV_ORIG_CAPA_HAS_NC, &orig->capabilities); in batadv_nc_tvlv_ogm_handler_v1()
130 set_bit(BATADV_ORIG_CAPA_HAS_NC, &orig->capabilities); in batadv_nc_tvlv_ogm_handler_v1()
134 * batadv_nc_mesh_init() - initialise coding hash table and start housekeeping
137 * Return: 0 on success or negative error number in case of failure
141 bat_priv->nc.timestamp_fwd_flush = jiffies; in batadv_nc_mesh_init()
142 bat_priv->nc.timestamp_sniffed_purge = jiffies; in batadv_nc_mesh_init()
144 if (bat_priv->nc.coding_hash || bat_priv->nc.decoding_hash) in batadv_nc_mesh_init()
147 bat_priv->nc.coding_hash = batadv_hash_new(128); in batadv_nc_mesh_init()
148 if (!bat_priv->nc.coding_hash) in batadv_nc_mesh_init()
151 batadv_hash_set_lock_class(bat_priv->nc.coding_hash, in batadv_nc_mesh_init()
154 bat_priv->nc.decoding_hash = batadv_hash_new(128); in batadv_nc_mesh_init()
155 if (!bat_priv->nc.decoding_hash) { in batadv_nc_mesh_init()
156 batadv_hash_destroy(bat_priv->nc.coding_hash); in batadv_nc_mesh_init()
160 batadv_hash_set_lock_class(bat_priv->nc.decoding_hash, in batadv_nc_mesh_init()
163 INIT_DELAYED_WORK(&bat_priv->nc.work, batadv_nc_worker); in batadv_nc_mesh_init()
173 return -ENOMEM; in batadv_nc_mesh_init()
177 * batadv_nc_init_bat_priv() - initialise the nc specific bat_priv variables
182 atomic_set(&bat_priv->network_coding, 0); in batadv_nc_init_bat_priv()
183 bat_priv->nc.min_tq = 200; in batadv_nc_init_bat_priv()
184 bat_priv->nc.max_fwd_delay = 10; in batadv_nc_init_bat_priv()
185 bat_priv->nc.max_buffer_time = 200; in batadv_nc_init_bat_priv()
189 * batadv_nc_init_orig() - initialise the nc fields of an orig_node
194 INIT_LIST_HEAD(&orig_node->in_coding_list); in batadv_nc_init_orig()
195 INIT_LIST_HEAD(&orig_node->out_coding_list); in batadv_nc_init_orig()
196 spin_lock_init(&orig_node->in_coding_list_lock); in batadv_nc_init_orig()
197 spin_lock_init(&orig_node->out_coding_list_lock); in batadv_nc_init_orig()
201 * batadv_nc_node_release() - release nc_node from lists and queue for free
211 batadv_orig_node_put(nc_node->orig_node); in batadv_nc_node_release()
216 * 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
252 kref_put(&nc_path->refcount, batadv_nc_path_release); in batadv_nc_path_put()
256 * batadv_nc_packet_free() - frees nc packet
264 kfree_skb(nc_packet->skb); in batadv_nc_packet_free()
266 consume_skb(nc_packet->skb); in batadv_nc_packet_free()
268 batadv_nc_path_put(nc_packet->nc_path); in batadv_nc_packet_free()
273 * batadv_nc_to_purge_nc_node() - checks whether an nc node has to be purged
282 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) in batadv_nc_to_purge_nc_node()
285 return batadv_has_timed_out(nc_node->last_seen, BATADV_NC_NODE_TIMEOUT); in batadv_nc_to_purge_nc_node()
289 * batadv_nc_to_purge_nc_path_coding() - checks whether an nc path has timed out
298 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) in batadv_nc_to_purge_nc_path_coding()
304 return batadv_has_timed_out(nc_path->last_valid, in batadv_nc_to_purge_nc_path_coding()
305 bat_priv->nc.max_fwd_delay * 10); in batadv_nc_to_purge_nc_path_coding()
309 * batadv_nc_to_purge_nc_path_decoding() - checks whether an nc path has timed
319 if (atomic_read(&bat_priv->mesh_state) != BATADV_MESH_ACTIVE) in batadv_nc_to_purge_nc_path_decoding()
325 return batadv_has_timed_out(nc_path->last_valid, in batadv_nc_to_purge_nc_path_decoding()
326 bat_priv->nc.max_buffer_time * 10); in batadv_nc_to_purge_nc_path_decoding()
330 * batadv_nc_purge_orig_nc_nodes() - go through list of nc nodes and purge stale
359 "Removing nc_node %pM -> %pM\n", in batadv_nc_purge_orig_nc_nodes()
360 nc_node->addr, nc_node->orig_node->orig); in batadv_nc_purge_orig_nc_nodes()
361 list_del_rcu(&nc_node->list); in batadv_nc_purge_orig_nc_nodes()
368 * batadv_nc_purge_orig() - purges all nc node data attached of the given
383 batadv_nc_purge_orig_nc_nodes(bat_priv, &orig_node->in_coding_list, in batadv_nc_purge_orig()
384 &orig_node->in_coding_list_lock, in batadv_nc_purge_orig()
388 batadv_nc_purge_orig_nc_nodes(bat_priv, &orig_node->out_coding_list, in batadv_nc_purge_orig()
389 &orig_node->out_coding_list_lock, in batadv_nc_purge_orig()
394 * batadv_nc_purge_orig_hash() - traverse entire originator hash to check if
400 struct batadv_hashtable *hash = bat_priv->orig_hash; in batadv_nc_purge_orig_hash()
409 for (i = 0; i < hash->size; i++) { in batadv_nc_purge_orig_hash()
410 head = &hash->table[i]; in batadv_nc_purge_orig_hash()
421 * batadv_nc_purge_paths() - traverse all nc paths part of the hash and remove
441 for (i = 0; i < hash->size; i++) { in batadv_nc_purge_paths()
442 head = &hash->table[i]; in batadv_nc_purge_paths()
443 lock = &hash->list_locks[i]; in batadv_nc_purge_paths()
454 /* purging an non-empty nc_path should never happen, but in batadv_nc_purge_paths()
459 if (!unlikely(list_empty(&nc_path->packet_list))) { in batadv_nc_purge_paths()
462 "Skipping free of non-empty nc_path (%pM -> %pM)!\n", in batadv_nc_purge_paths()
463 nc_path->prev_hop, in batadv_nc_purge_paths()
464 nc_path->next_hop); in batadv_nc_purge_paths()
470 "Remove nc_path %pM -> %pM\n", in batadv_nc_purge_paths()
471 nc_path->prev_hop, nc_path->next_hop); in batadv_nc_purge_paths()
472 hlist_del_rcu(&nc_path->hash_entry); in batadv_nc_purge_paths()
480 * batadv_nc_hash_key_gen() - computes the nc_path hash key
488 memcpy(key->prev_hop, src, sizeof(key->prev_hop)); in batadv_nc_hash_key_gen()
489 memcpy(key->next_hop, dst, sizeof(key->next_hop)); in batadv_nc_hash_key_gen()
493 * batadv_nc_hash_choose() - compute the hash value for an nc path
504 hash = jhash(&nc_path->prev_hop, sizeof(nc_path->prev_hop), hash); in batadv_nc_hash_choose()
505 hash = jhash(&nc_path->next_hop, sizeof(nc_path->next_hop), hash); in batadv_nc_hash_choose()
511 * batadv_nc_hash_compare() - comparing function used in the network coding hash
527 if (!batadv_compare_eth(nc_path1->prev_hop, nc_path2->prev_hop)) in batadv_nc_hash_compare()
530 if (!batadv_compare_eth(nc_path1->next_hop, nc_path2->next_hop)) in batadv_nc_hash_compare()
537 * batadv_nc_hash_find() - search for an existing nc path and return it
554 index = batadv_nc_hash_choose(data, hash->size); in batadv_nc_hash_find()
555 head = &hash->table[index]; in batadv_nc_hash_find()
559 if (!batadv_nc_hash_compare(&nc_path->hash_entry, data)) in batadv_nc_hash_find()
562 if (!kref_get_unless_zero(&nc_path->refcount)) in batadv_nc_hash_find()
574 * batadv_nc_send_packet() - send non-coded packet and free nc_packet struct
579 batadv_send_unicast_skb(nc_packet->skb, nc_packet->neigh_node); in batadv_nc_send_packet()
580 nc_packet->skb = NULL; in batadv_nc_send_packet()
585 * batadv_nc_sniffed_purge() - Checks timestamp of given sniffed nc_packet.
601 unsigned long timeout = bat_priv->nc.max_buffer_time; in batadv_nc_sniffed_purge()
604 lockdep_assert_held(&nc_path->packet_list_lock); in batadv_nc_sniffed_purge()
609 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE && in batadv_nc_sniffed_purge()
610 !batadv_has_timed_out(nc_packet->timestamp, timeout)) in batadv_nc_sniffed_purge()
614 list_del(&nc_packet->list); in batadv_nc_sniffed_purge()
624 * batadv_nc_fwd_flush() - Checks the timestamp of the given nc packet.
640 unsigned long timeout = bat_priv->nc.max_fwd_delay; in batadv_nc_fwd_flush()
642 lockdep_assert_held(&nc_path->packet_list_lock); in batadv_nc_fwd_flush()
647 if (atomic_read(&bat_priv->mesh_state) == BATADV_MESH_ACTIVE && in batadv_nc_fwd_flush()
648 !batadv_has_timed_out(nc_packet->timestamp, timeout)) in batadv_nc_fwd_flush()
654 nc_packet->skb->len + ETH_HLEN); in batadv_nc_fwd_flush()
655 list_del(&nc_packet->list); in batadv_nc_fwd_flush()
662 * batadv_nc_process_nc_paths() - traverse given nc packet pool and free timed
687 for (i = 0; i < hash->size; i++) { in batadv_nc_process_nc_paths()
688 head = &hash->table[i]; in batadv_nc_process_nc_paths()
694 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_process_nc_paths()
696 &nc_path->packet_list, list) { in batadv_nc_process_nc_paths()
701 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_process_nc_paths()
708 * batadv_nc_worker() - periodic task for housekeeping related to network
724 batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, in batadv_nc_worker()
726 batadv_nc_purge_paths(bat_priv, bat_priv->nc.decoding_hash, in batadv_nc_worker()
729 timeout = bat_priv->nc.max_fwd_delay; in batadv_nc_worker()
731 if (batadv_has_timed_out(bat_priv->nc.timestamp_fwd_flush, timeout)) { in batadv_nc_worker()
732 batadv_nc_process_nc_paths(bat_priv, bat_priv->nc.coding_hash, in batadv_nc_worker()
734 bat_priv->nc.timestamp_fwd_flush = jiffies; in batadv_nc_worker()
737 if (batadv_has_timed_out(bat_priv->nc.timestamp_sniffed_purge, in batadv_nc_worker()
738 bat_priv->nc.max_buffer_time)) { in batadv_nc_worker()
739 batadv_nc_process_nc_paths(bat_priv, bat_priv->nc.decoding_hash, in batadv_nc_worker()
741 bat_priv->nc.timestamp_sniffed_purge = jiffies; in batadv_nc_worker()
749 * batadv_can_nc_with_orig() - checks whether the given orig node is suitable
759 * 4) The TQ value of the OGM must be above bat_priv->nc.min_tq.
773 last_ttl = orig_ifinfo->last_ttl; in batadv_can_nc_with_orig()
774 last_real_seqno = orig_ifinfo->last_real_seqno; in batadv_can_nc_with_orig()
777 if (last_real_seqno != ntohl(ogm_packet->seqno)) in batadv_can_nc_with_orig()
779 if (last_ttl != ogm_packet->ttl + 1) in batadv_can_nc_with_orig()
781 if (!batadv_compare_eth(ogm_packet->orig, ogm_packet->prev_sender)) in batadv_can_nc_with_orig()
783 if (ogm_packet->tq < bat_priv->nc.min_tq) in batadv_can_nc_with_orig()
790 * batadv_nc_find_nc_node() - search for an existing nc node and return it
807 list = &orig_neigh_node->in_coding_list; in batadv_nc_find_nc_node()
809 list = &orig_neigh_node->out_coding_list; in batadv_nc_find_nc_node()
814 if (!batadv_compare_eth(nc_node->addr, orig_node->orig)) in batadv_nc_find_nc_node()
817 if (!kref_get_unless_zero(&nc_node->refcount)) in batadv_nc_find_nc_node()
830 * batadv_nc_get_nc_node() - retrieves an nc node or creates the entry if it was
852 lock = &orig_neigh_node->in_coding_list_lock; in batadv_nc_get_nc_node()
853 list = &orig_neigh_node->in_coding_list; in batadv_nc_get_nc_node()
855 lock = &orig_neigh_node->out_coding_list_lock; in batadv_nc_get_nc_node()
856 list = &orig_neigh_node->out_coding_list; in batadv_nc_get_nc_node()
873 INIT_LIST_HEAD(&nc_node->list); in batadv_nc_get_nc_node()
874 kref_init(&nc_node->refcount); in batadv_nc_get_nc_node()
875 ether_addr_copy(nc_node->addr, orig_node->orig); in batadv_nc_get_nc_node()
876 kref_get(&orig_neigh_node->refcount); in batadv_nc_get_nc_node()
877 nc_node->orig_node = orig_neigh_node; in batadv_nc_get_nc_node()
879 batadv_dbg(BATADV_DBG_NC, bat_priv, "Adding nc_node %pM -> %pM\n", in batadv_nc_get_nc_node()
880 nc_node->addr, nc_node->orig_node->orig); in batadv_nc_get_nc_node()
883 kref_get(&nc_node->refcount); in batadv_nc_get_nc_node()
884 list_add_tail_rcu(&nc_node->list, list); in batadv_nc_get_nc_node()
893 * batadv_nc_update_nc_node() - updates stored incoming and outgoing nc node
912 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_update_nc_node()
916 if (!test_bit(BATADV_ORIG_CAPA_HAS_NC, &orig_node->capabilities)) in batadv_nc_update_nc_node()
930 in_nc_node->last_seen = jiffies; in batadv_nc_update_nc_node()
938 out_nc_node->last_seen = jiffies; in batadv_nc_update_nc_node()
946 * batadv_nc_get_path() - get existing nc_path or allocate a new one
949 * @src: ethernet source address - first half of the nc path search key
950 * @dst: ethernet destination address - second half of the nc path search key
970 nc_path->last_valid = jiffies; in batadv_nc_get_path()
981 INIT_LIST_HEAD(&nc_path->packet_list); in batadv_nc_get_path()
982 spin_lock_init(&nc_path->packet_list_lock); in batadv_nc_get_path()
983 kref_init(&nc_path->refcount); in batadv_nc_get_path()
984 nc_path->last_valid = jiffies; in batadv_nc_get_path()
985 ether_addr_copy(nc_path->next_hop, dst); in batadv_nc_get_path()
986 ether_addr_copy(nc_path->prev_hop, src); in batadv_nc_get_path()
988 batadv_dbg(BATADV_DBG_NC, bat_priv, "Adding nc_path %pM -> %pM\n", in batadv_nc_get_path()
989 nc_path->prev_hop, in batadv_nc_get_path()
990 nc_path->next_hop); in batadv_nc_get_path()
993 kref_get(&nc_path->refcount); in batadv_nc_get_path()
996 &nc_path->hash_entry); in batadv_nc_get_path()
1007 * batadv_nc_random_weight_tq() - scale the receivers TQ-value to avoid unfair
1015 /* randomize the estimated packet loss (max TQ - estimated TQ) */ in batadv_nc_random_weight_tq()
1016 u8 rand_tq = prandom_u32_max(BATADV_TQ_MAX_VALUE + 1 - tq); in batadv_nc_random_weight_tq()
1019 return BATADV_TQ_MAX_VALUE - rand_tq; in batadv_nc_random_weight_tq()
1023 * batadv_nc_memxor() - XOR destination with source
1037 * batadv_nc_code_packets() - code a received unicast_packet with an nc packet
1069 int header_add = coded_size - unicast_size; in batadv_nc_code_packets()
1074 router_neigh = batadv_orig_router_get(neigh_node->orig_node, in batadv_nc_code_packets()
1084 neigh_tmp = nc_packet->neigh_node; in batadv_nc_code_packets()
1085 router_coding = batadv_orig_router_get(neigh_tmp->orig_node, in batadv_nc_code_packets()
1095 tq_tmp = router_neigh_ifinfo->bat_iv.tq_avg; in batadv_nc_code_packets()
1097 tq_tmp = router_coding_ifinfo->bat_iv.tq_avg; in batadv_nc_code_packets()
1100 /* Select one destination for the MAC-header dst-field based on in batadv_nc_code_packets()
1101 * weighted TQ-values. in batadv_nc_code_packets()
1104 /* Destination from nc_packet is selected for MAC-header */ in batadv_nc_code_packets()
1105 first_dest = nc_packet->neigh_node; in batadv_nc_code_packets()
1106 first_source = nc_packet->nc_path->prev_hop; in batadv_nc_code_packets()
1108 second_source = ethhdr->h_source; in batadv_nc_code_packets()
1109 packet1 = (struct batadv_unicast_packet *)nc_packet->skb->data; in batadv_nc_code_packets()
1110 packet2 = (struct batadv_unicast_packet *)skb->data; in batadv_nc_code_packets()
1111 packet_id1 = nc_packet->packet_id; in batadv_nc_code_packets()
1113 skb->data + sizeof(*packet2)); in batadv_nc_code_packets()
1115 /* Destination for skb is selected for MAC-header */ in batadv_nc_code_packets()
1117 first_source = ethhdr->h_source; in batadv_nc_code_packets()
1118 second_dest = nc_packet->neigh_node; in batadv_nc_code_packets()
1119 second_source = nc_packet->nc_path->prev_hop; in batadv_nc_code_packets()
1120 packet1 = (struct batadv_unicast_packet *)skb->data; in batadv_nc_code_packets()
1121 packet2 = (struct batadv_unicast_packet *)nc_packet->skb->data; in batadv_nc_code_packets()
1123 skb->data + sizeof(*packet1)); in batadv_nc_code_packets()
1124 packet_id2 = nc_packet->packet_id; in batadv_nc_code_packets()
1130 if (skb->len <= nc_packet->skb->len) { in batadv_nc_code_packets()
1131 skb_dest = nc_packet->skb; in batadv_nc_code_packets()
1135 skb_src = nc_packet->skb; in batadv_nc_code_packets()
1139 coding_len = skb_src->len - unicast_size; in batadv_nc_code_packets()
1146 coded_packet = (struct batadv_coded_packet *)skb_dest->data; in batadv_nc_code_packets()
1149 coded_packet->packet_type = BATADV_CODED; in batadv_nc_code_packets()
1150 coded_packet->version = BATADV_COMPAT_VERSION; in batadv_nc_code_packets()
1151 coded_packet->ttl = packet1->ttl; in batadv_nc_code_packets()
1154 ether_addr_copy(coded_packet->first_source, first_source); in batadv_nc_code_packets()
1155 ether_addr_copy(coded_packet->first_orig_dest, packet1->dest); in batadv_nc_code_packets()
1156 coded_packet->first_crc = packet_id1; in batadv_nc_code_packets()
1157 coded_packet->first_ttvn = packet1->ttvn; in batadv_nc_code_packets()
1160 ether_addr_copy(coded_packet->second_dest, second_dest->addr); in batadv_nc_code_packets()
1161 ether_addr_copy(coded_packet->second_source, second_source); in batadv_nc_code_packets()
1162 ether_addr_copy(coded_packet->second_orig_dest, packet2->dest); in batadv_nc_code_packets()
1163 coded_packet->second_crc = packet_id2; in batadv_nc_code_packets()
1164 coded_packet->second_ttl = packet2->ttl; in batadv_nc_code_packets()
1165 coded_packet->second_ttvn = packet2->ttvn; in batadv_nc_code_packets()
1166 coded_packet->coded_len = htons(coding_len); in batadv_nc_code_packets()
1169 batadv_nc_memxor(skb_dest->data + coded_size, in batadv_nc_code_packets()
1170 skb_src->data + unicast_size, coding_len); in batadv_nc_code_packets()
1173 if (BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1174 BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1176 count = skb_src->len + ETH_HLEN; in batadv_nc_code_packets()
1177 count += skb_dest->len + ETH_HLEN; in batadv_nc_code_packets()
1180 } else if (!BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1181 !BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1183 count = skb_src->len + ETH_HLEN; in batadv_nc_code_packets()
1184 count += skb_dest->len + ETH_HLEN; in batadv_nc_code_packets()
1187 } else if (BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1188 !BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1192 skb_src->len + ETH_HLEN); in batadv_nc_code_packets()
1195 skb_dest->len + ETH_HLEN); in batadv_nc_code_packets()
1196 } else if (!BATADV_SKB_CB(skb_src)->decoded && in batadv_nc_code_packets()
1197 BATADV_SKB_CB(skb_dest)->decoded) { in batadv_nc_code_packets()
1201 skb_src->len + ETH_HLEN); in batadv_nc_code_packets()
1204 skb_dest->len + ETH_HLEN); in batadv_nc_code_packets()
1211 nc_packet->skb = NULL; in batadv_nc_code_packets()
1226 * batadv_nc_skb_coding_possible() - true if a decoded skb is available at dst.
1236 * re-code the packet if the source of the previous encoded packet is involved.
1244 if (BATADV_SKB_CB(skb)->decoded && !batadv_compare_eth(dst, src)) in batadv_nc_skb_coding_possible()
1250 * batadv_nc_path_search() - Find the coding path matching in_nc_node and
1251 * out_nc_node to retrieve a buffered packet that can be used for coding.
1270 struct batadv_hashtable *hash = bat_priv->nc.coding_hash; in batadv_nc_path_search()
1277 batadv_nc_hash_key_gen(&nc_path_key, in_nc_node->addr, in batadv_nc_path_search()
1278 out_nc_node->addr); in batadv_nc_path_search()
1279 idx = batadv_nc_hash_choose(&nc_path_key, hash->size); in batadv_nc_path_search()
1283 hlist_for_each_entry_rcu(nc_path, &hash->table[idx], hash_entry) { in batadv_nc_path_search()
1284 if (!batadv_compare_eth(nc_path->prev_hop, in_nc_node->addr)) in batadv_nc_path_search()
1287 if (!batadv_compare_eth(nc_path->next_hop, out_nc_node->addr)) in batadv_nc_path_search()
1290 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_path_search()
1291 if (list_empty(&nc_path->packet_list)) { in batadv_nc_path_search()
1292 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_path_search()
1297 &nc_path->packet_list, list) { in batadv_nc_path_search()
1298 if (!batadv_nc_skb_coding_possible(nc_packet->skb, in batadv_nc_path_search()
1300 in_nc_node->addr)) in batadv_nc_path_search()
1304 list_del(&nc_packet->list); in batadv_nc_path_search()
1309 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_path_search()
1318 * batadv_nc_skb_src_search() - Loops through the list of neighboring nodes of
1345 &orig_node->out_coding_list, list) { in batadv_nc_skb_src_search()
1348 out_nc_node->addr, eth_src)) in batadv_nc_skb_src_search()
1364 * batadv_nc_skb_store_before_coding() - set the ethernet src and dst of the
1383 ether_addr_copy(ethhdr->h_source, ethhdr->h_dest); in batadv_nc_skb_store_before_coding()
1384 ether_addr_copy(ethhdr->h_dest, eth_dst_new); in batadv_nc_skb_store_before_coding()
1399 * batadv_nc_skb_dst_search() - Loops through list of neighboring nodes to dst.
1415 struct net_device *netdev = neigh_node->if_incoming->soft_iface; in batadv_nc_skb_dst_search()
1417 struct batadv_orig_node *orig_node = neigh_node->orig_node; in batadv_nc_skb_dst_search()
1422 list_for_each_entry_rcu(nc_node, &orig_node->in_coding_list, list) { in batadv_nc_skb_dst_search()
1425 neigh_node->addr, in batadv_nc_skb_dst_search()
1426 ethhdr->h_source, nc_node); in batadv_nc_skb_dst_search()
1439 neigh_node->addr); in batadv_nc_skb_dst_search()
1440 batadv_nc_skb_store_before_coding(bat_priv, nc_packet->skb, in batadv_nc_skb_dst_search()
1441 nc_packet->neigh_node->addr); in batadv_nc_skb_dst_search()
1448 /* out of mem ? Coding failed - we have to free the buffered packet in batadv_nc_skb_dst_search()
1457 * batadv_nc_skb_add_to_path() - buffer skb for later encoding / decoding
1463 * Return: true if the packet was buffered or false in case of an error.
1477 nc_packet->timestamp = jiffies; in batadv_nc_skb_add_to_path()
1478 nc_packet->packet_id = packet_id; in batadv_nc_skb_add_to_path()
1479 nc_packet->skb = skb; in batadv_nc_skb_add_to_path()
1480 nc_packet->neigh_node = neigh_node; in batadv_nc_skb_add_to_path()
1481 nc_packet->nc_path = nc_path; in batadv_nc_skb_add_to_path()
1484 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_skb_add_to_path()
1485 list_add_tail(&nc_packet->list, &nc_path->packet_list); in batadv_nc_skb_add_to_path()
1486 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_skb_add_to_path()
1492 * batadv_nc_skb_forward() - try to code a packet or add it to the coding packet
1502 const struct net_device *netdev = neigh_node->if_incoming->soft_iface; in batadv_nc_skb_forward()
1511 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_skb_forward()
1517 if (packet->packet_type != BATADV_UNICAST) in batadv_nc_skb_forward()
1524 /* Find or create a nc_path for this src-dst pair */ in batadv_nc_skb_forward()
1526 bat_priv->nc.coding_hash, in batadv_nc_skb_forward()
1527 ethhdr->h_source, in batadv_nc_skb_forward()
1528 neigh_node->addr); in batadv_nc_skb_forward()
1549 * batadv_nc_skb_store_for_decoding() - save a clone of the skb which can be
1564 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_skb_store_for_decoding()
1570 if (packet->packet_type != BATADV_UNICAST) in batadv_nc_skb_store_for_decoding()
1575 bat_priv->nc.decoding_hash, in batadv_nc_skb_store_for_decoding()
1576 ethhdr->h_source, in batadv_nc_skb_store_for_decoding()
1577 ethhdr->h_dest); in batadv_nc_skb_store_for_decoding()
1582 /* Clone skb and adjust skb->data to point at batman header */ in batadv_nc_skb_store_for_decoding()
1610 * batadv_nc_skb_store_sniffed_unicast() - check if a received unicast packet
1620 if (batadv_is_my_mac(bat_priv, ethhdr->h_dest)) in batadv_nc_skb_store_sniffed_unicast()
1630 * batadv_nc_skb_decode_packet() - decode given skb using the decode data stored
1644 const int h_diff = sizeof(struct batadv_coded_packet) - h_size; in batadv_nc_skb_decode_packet()
1653 memcpy(&coded_packet_tmp, skb->data, sizeof(coded_packet_tmp)); in batadv_nc_skb_decode_packet()
1665 skb_set_mac_header(skb, -ETH_HLEN); in batadv_nc_skb_decode_packet()
1680 ether_addr_copy(ethhdr->h_dest, coded_packet_tmp.second_dest); in batadv_nc_skb_decode_packet()
1681 skb->pkt_type = PACKET_HOST; in batadv_nc_skb_decode_packet()
1694 if (coding_len > skb->len) in batadv_nc_skb_decode_packet()
1700 batadv_nc_memxor(skb->data + h_size, in batadv_nc_skb_decode_packet()
1701 nc_packet->skb->data + h_size, in batadv_nc_skb_decode_packet()
1705 if (nc_packet->skb->len > coding_len + h_size) { in batadv_nc_skb_decode_packet()
1712 unicast_packet = (struct batadv_unicast_packet *)skb->data; in batadv_nc_skb_decode_packet()
1713 unicast_packet->packet_type = BATADV_UNICAST; in batadv_nc_skb_decode_packet()
1714 unicast_packet->version = BATADV_COMPAT_VERSION; in batadv_nc_skb_decode_packet()
1715 unicast_packet->ttl = ttl; in batadv_nc_skb_decode_packet()
1716 ether_addr_copy(unicast_packet->dest, orig_dest); in batadv_nc_skb_decode_packet()
1717 unicast_packet->ttvn = ttvn; in batadv_nc_skb_decode_packet()
1724 * batadv_nc_find_decoding_packet() - search through buffered decoding data to
1737 struct batadv_hashtable *hash = bat_priv->nc.decoding_hash; in batadv_nc_find_decoding_packet()
1747 /* Select the correct packet id based on the location of our mac-addr */ in batadv_nc_find_decoding_packet()
1748 dest = ethhdr->h_source; in batadv_nc_find_decoding_packet()
1749 if (!batadv_is_my_mac(bat_priv, coded->second_dest)) { in batadv_nc_find_decoding_packet()
1750 source = coded->second_source; in batadv_nc_find_decoding_packet()
1751 packet_id = coded->second_crc; in batadv_nc_find_decoding_packet()
1753 source = coded->first_source; in batadv_nc_find_decoding_packet()
1754 packet_id = coded->first_crc; in batadv_nc_find_decoding_packet()
1758 index = batadv_nc_hash_choose(&nc_path_key, hash->size); in batadv_nc_find_decoding_packet()
1762 hlist_for_each_entry_rcu(nc_path, &hash->table[index], hash_entry) { in batadv_nc_find_decoding_packet()
1764 spin_lock_bh(&nc_path->packet_list_lock); in batadv_nc_find_decoding_packet()
1766 &nc_path->packet_list, list) { in batadv_nc_find_decoding_packet()
1767 if (packet_id == tmp_nc_packet->packet_id) { in batadv_nc_find_decoding_packet()
1768 list_del(&tmp_nc_packet->list); in batadv_nc_find_decoding_packet()
1774 spin_unlock_bh(&nc_path->packet_list_lock); in batadv_nc_find_decoding_packet()
1789 * batadv_nc_recv_coded_packet() - try to decode coded packet and enqueue the
1800 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); in batadv_nc_recv_coded_packet()
1808 if (!atomic_read(&bat_priv->network_coding)) in batadv_nc_recv_coded_packet()
1815 coded_packet = (struct batadv_coded_packet *)skb->data; in batadv_nc_recv_coded_packet()
1819 if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest) && in batadv_nc_recv_coded_packet()
1820 !batadv_is_my_mac(bat_priv, coded_packet->second_dest)) in batadv_nc_recv_coded_packet()
1824 if (batadv_is_my_mac(bat_priv, coded_packet->second_dest)) in batadv_nc_recv_coded_packet()
1838 if (skb_linearize(nc_packet->skb) < 0) in batadv_nc_recv_coded_packet()
1849 BATADV_SKB_CB(skb)->decoded = true; in batadv_nc_recv_coded_packet()
1852 skb->len + ETH_HLEN); in batadv_nc_recv_coded_packet()
1864 * batadv_nc_mesh_free() - clean up network coding memory
1871 cancel_delayed_work_sync(&bat_priv->nc.work); in batadv_nc_mesh_free()
1873 batadv_nc_purge_paths(bat_priv, bat_priv->nc.coding_hash, NULL); in batadv_nc_mesh_free()
1874 batadv_hash_destroy(bat_priv->nc.coding_hash); in batadv_nc_mesh_free()
1875 batadv_nc_purge_paths(bat_priv, bat_priv->nc.decoding_hash, NULL); in batadv_nc_mesh_free()
1876 batadv_hash_destroy(bat_priv->nc.decoding_hash); in batadv_nc_mesh_free()