Lines Matching +full:buffered +full:- +full:negative
1 // SPDX-License-Identifier: GPL-2.0
26 #include "hard-interface.h"
32 * batadv_frag_clear_chain() - delete entries in the fragment buffer chain
44 hlist_del(&entry->list); in batadv_frag_clear_chain()
47 kfree_skb(entry->skb); in batadv_frag_clear_chain()
49 consume_skb(entry->skb); in batadv_frag_clear_chain()
56 * batadv_frag_purge_orig() - free fragments associated to an orig
67 chain = &orig_node->fragments[i]; in batadv_frag_purge_orig()
68 spin_lock_bh(&chain->lock); in batadv_frag_purge_orig()
71 batadv_frag_clear_chain(&chain->fragment_list, true); in batadv_frag_purge_orig()
72 chain->size = 0; in batadv_frag_purge_orig()
75 spin_unlock_bh(&chain->lock); in batadv_frag_purge_orig()
80 * batadv_frag_size_limit() - maximum possible size of packet to be fragmented
88 limit -= sizeof(struct batadv_frag_packet); in batadv_frag_size_limit()
95 * batadv_frag_init_chain() - check and prepare fragment chain for new fragment
102 * Caller must hold chain->lock.
110 lockdep_assert_held(&chain->lock); in batadv_frag_init_chain()
112 if (chain->seqno == seqno) in batadv_frag_init_chain()
115 if (!hlist_empty(&chain->fragment_list)) in batadv_frag_init_chain()
116 batadv_frag_clear_chain(&chain->fragment_list, true); in batadv_frag_init_chain()
118 chain->size = 0; in batadv_frag_init_chain()
119 chain->seqno = seqno; in batadv_frag_init_chain()
125 * batadv_frag_insert_packet() - insert a fragment into a fragment chain
133 * Return: true if skb is buffered, false on error. If the chain has all the
150 * the later merge. Non-linear merge should be added to remove this in batadv_frag_insert_packet()
156 frag_packet = (struct batadv_frag_packet *)skb->data; in batadv_frag_insert_packet()
157 seqno = ntohs(frag_packet->seqno); in batadv_frag_insert_packet()
164 frag_entry_new->skb = skb; in batadv_frag_insert_packet()
165 frag_entry_new->no = frag_packet->no; in batadv_frag_insert_packet()
171 chain = &orig_node->fragments[bucket]; in batadv_frag_insert_packet()
172 spin_lock_bh(&chain->lock); in batadv_frag_insert_packet()
174 hlist_add_head(&frag_entry_new->list, &chain->fragment_list); in batadv_frag_insert_packet()
175 chain->size = skb->len - hdr_size; in batadv_frag_insert_packet()
176 chain->timestamp = jiffies; in batadv_frag_insert_packet()
177 chain->total_size = ntohs(frag_packet->total_size); in batadv_frag_insert_packet()
183 hlist_for_each_entry(frag_entry_curr, &chain->fragment_list, list) { in batadv_frag_insert_packet()
185 if (frag_entry_curr->no == frag_entry_new->no) in batadv_frag_insert_packet()
189 if (frag_entry_curr->no < frag_entry_new->no) { in batadv_frag_insert_packet()
190 hlist_add_before(&frag_entry_new->list, in batadv_frag_insert_packet()
191 &frag_entry_curr->list); in batadv_frag_insert_packet()
192 chain->size += skb->len - hdr_size; in batadv_frag_insert_packet()
193 chain->timestamp = jiffies; in batadv_frag_insert_packet()
204 hlist_add_behind(&frag_entry_new->list, &frag_entry_last->list); in batadv_frag_insert_packet()
205 chain->size += skb->len - hdr_size; in batadv_frag_insert_packet()
206 chain->timestamp = jiffies; in batadv_frag_insert_packet()
211 if (chain->size > batadv_frag_size_limit() || in batadv_frag_insert_packet()
212 chain->total_size != ntohs(frag_packet->total_size) || in batadv_frag_insert_packet()
213 chain->total_size > batadv_frag_size_limit()) { in batadv_frag_insert_packet()
218 batadv_frag_clear_chain(&chain->fragment_list, true); in batadv_frag_insert_packet()
219 chain->size = 0; in batadv_frag_insert_packet()
220 } else if (ntohs(frag_packet->total_size) == chain->size) { in batadv_frag_insert_packet()
222 hlist_move_list(&chain->fragment_list, chain_out); in batadv_frag_insert_packet()
223 chain->size = 0; in batadv_frag_insert_packet()
227 spin_unlock_bh(&chain->lock); in batadv_frag_insert_packet()
239 * batadv_frag_merge_packets() - merge a chain of fragments
259 entry = hlist_entry(chain->first, struct batadv_frag_list_entry, list); in batadv_frag_merge_packets()
260 hlist_del(&entry->list); in batadv_frag_merge_packets()
261 skb_out = entry->skb; in batadv_frag_merge_packets()
264 packet = (struct batadv_frag_packet *)skb_out->data; in batadv_frag_merge_packets()
265 size = ntohs(packet->total_size) + hdr_size; in batadv_frag_merge_packets()
268 if (pskb_expand_head(skb_out, 0, size - skb_out->len, GFP_ATOMIC) < 0) { in batadv_frag_merge_packets()
279 skb_out->ip_summed = CHECKSUM_NONE; in batadv_frag_merge_packets()
280 memmove(skb_out->data - ETH_HLEN, skb_mac_header(skb_out), ETH_HLEN); in batadv_frag_merge_packets()
281 skb_set_mac_header(skb_out, -ETH_HLEN); in batadv_frag_merge_packets()
287 size = entry->skb->len - hdr_size; in batadv_frag_merge_packets()
288 skb_put_data(skb_out, entry->skb->data + hdr_size, size); in batadv_frag_merge_packets()
298 * batadv_frag_skb_buffer() - buffer fragment for later merge
305 * set *skb to merged packet; 2) Packet is buffered: Return true and set *skb
308 * Return: true when the packet is merged or buffered, false when skb is not
338 * batadv_frag_skb_fwd() - forward fragments that would exceed MTU when merged
343 * Look up the next-hop of the fragments payload and check if the merged packet
344 * will exceed the MTU towards the next-hop. If so, the fragment is forwarded
353 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); in batadv_frag_skb_fwd()
360 packet = (struct batadv_frag_packet *)skb->data; in batadv_frag_skb_fwd()
361 orig_node_dst = batadv_orig_hash_find(bat_priv, packet->dest); in batadv_frag_skb_fwd()
372 total_size = ntohs(packet->total_size); in batadv_frag_skb_fwd()
373 if (total_size > neigh_node->if_incoming->net_dev->mtu) { in batadv_frag_skb_fwd()
376 skb->len + ETH_HLEN); in batadv_frag_skb_fwd()
378 packet->ttl--; in batadv_frag_skb_fwd()
390 * batadv_frag_create() - create a fragment from skb
408 unsigned int tailroom = net_dev->needed_tailroom; in batadv_frag_create()
417 skb_fragment->priority = skb->priority; in batadv_frag_create()
419 /* Eat the last mtu-bytes of the skb */ in batadv_frag_create()
421 skb_split(skb, skb_fragment, skb->len - fragment_size); in batadv_frag_create()
425 memcpy(skb_fragment->data, frag_head, header_size); in batadv_frag_create()
432 * batadv_frag_send_packet() - create up to 16 fragments from the passed skb
435 * @neigh_node: next-hop of the created fragments
437 * Return: the netdev tx status or a negative errno code on a failure
443 struct net_device *net_dev = neigh_node->if_incoming->net_dev; in batadv_frag_send_packet()
448 unsigned int mtu = net_dev->mtu; in batadv_frag_send_packet()
453 /* To avoid merge and refragmentation at next-hops we never send in batadv_frag_send_packet()
457 max_fragment_size = mtu - header_size; in batadv_frag_send_packet()
459 if (skb->len == 0 || max_fragment_size == 0) in batadv_frag_send_packet()
460 return -EINVAL; in batadv_frag_send_packet()
462 num_fragments = (skb->len - 1) / max_fragment_size + 1; in batadv_frag_send_packet()
463 max_fragment_size = (skb->len - 1) / num_fragments + 1; in batadv_frag_send_packet()
467 ret = -EAGAIN; in batadv_frag_send_packet()
471 bat_priv = orig_node->bat_priv; in batadv_frag_send_packet()
474 ret = -EINVAL; in batadv_frag_send_packet()
481 * batman-adv fragments were created and submitted to the in batadv_frag_send_packet()
482 * hard-interface in batadv_frag_send_packet()
485 ret = -ENOMEM; in batadv_frag_send_packet()
493 frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno)); in batadv_frag_send_packet()
496 frag_header.total_size = htons(skb->len); in batadv_frag_send_packet()
498 /* skb->priority values from 256->263 are magic values to in batadv_frag_send_packet()
503 if (skb->priority >= 256 && skb->priority <= 263) in batadv_frag_send_packet()
504 frag_header.priority = skb->priority - 256; in batadv_frag_send_packet()
508 ether_addr_copy(frag_header.orig, primary_if->net_dev->dev_addr); in batadv_frag_send_packet()
509 ether_addr_copy(frag_header.dest, orig_node->orig); in batadv_frag_send_packet()
512 while (skb->len > max_fragment_size) { in batadv_frag_send_packet()
514 if (unlikely(frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1)) { in batadv_frag_send_packet()
515 ret = -EINVAL; in batadv_frag_send_packet()
522 ret = -ENOMEM; in batadv_frag_send_packet()
528 skb_fragment->len + ETH_HLEN); in batadv_frag_send_packet()
546 memcpy(skb->data, &frag_header, header_size); in batadv_frag_send_packet()
551 skb->len + ETH_HLEN); in batadv_frag_send_packet()