Lines Matching +full:buffered +full:- +full:negative
1 // SPDX-License-Identifier: GPL-2.0
26 #include "hard-interface.h"
31 * batadv_frag_clear_chain() - delete entries in the fragment buffer chain
43 hlist_del(&entry->list); in batadv_frag_clear_chain()
46 kfree_skb(entry->skb); in batadv_frag_clear_chain()
48 consume_skb(entry->skb); in batadv_frag_clear_chain()
55 * batadv_frag_purge_orig() - free fragments associated to an orig
66 chain = &orig_node->fragments[i]; in batadv_frag_purge_orig()
67 spin_lock_bh(&chain->lock); in batadv_frag_purge_orig()
70 batadv_frag_clear_chain(&chain->fragment_list, true); in batadv_frag_purge_orig()
71 chain->size = 0; in batadv_frag_purge_orig()
74 spin_unlock_bh(&chain->lock); in batadv_frag_purge_orig()
79 * batadv_frag_size_limit() - maximum possible size of packet to be fragmented
87 limit -= sizeof(struct batadv_frag_packet); in batadv_frag_size_limit()
94 * batadv_frag_init_chain() - check and prepare fragment chain for new fragment
101 * Caller must hold chain->lock.
109 lockdep_assert_held(&chain->lock); in batadv_frag_init_chain()
111 if (chain->seqno == seqno) in batadv_frag_init_chain()
114 if (!hlist_empty(&chain->fragment_list)) in batadv_frag_init_chain()
115 batadv_frag_clear_chain(&chain->fragment_list, true); in batadv_frag_init_chain()
117 chain->size = 0; in batadv_frag_init_chain()
118 chain->seqno = seqno; in batadv_frag_init_chain()
124 * batadv_frag_insert_packet() - insert a fragment into a fragment chain
132 * Return: true if skb is buffered, false on error. If the chain has all the
149 * the later merge. Non-linear merge should be added to remove this in batadv_frag_insert_packet()
155 frag_packet = (struct batadv_frag_packet *)skb->data; in batadv_frag_insert_packet()
156 seqno = ntohs(frag_packet->seqno); in batadv_frag_insert_packet()
163 frag_entry_new->skb = skb; in batadv_frag_insert_packet()
164 frag_entry_new->no = frag_packet->no; in batadv_frag_insert_packet()
170 chain = &orig_node->fragments[bucket]; in batadv_frag_insert_packet()
171 spin_lock_bh(&chain->lock); in batadv_frag_insert_packet()
173 hlist_add_head(&frag_entry_new->list, &chain->fragment_list); in batadv_frag_insert_packet()
174 chain->size = skb->len - hdr_size; in batadv_frag_insert_packet()
175 chain->timestamp = jiffies; in batadv_frag_insert_packet()
176 chain->total_size = ntohs(frag_packet->total_size); in batadv_frag_insert_packet()
182 hlist_for_each_entry(frag_entry_curr, &chain->fragment_list, list) { in batadv_frag_insert_packet()
184 if (frag_entry_curr->no == frag_entry_new->no) in batadv_frag_insert_packet()
188 if (frag_entry_curr->no < frag_entry_new->no) { in batadv_frag_insert_packet()
189 hlist_add_before(&frag_entry_new->list, in batadv_frag_insert_packet()
190 &frag_entry_curr->list); in batadv_frag_insert_packet()
191 chain->size += skb->len - hdr_size; in batadv_frag_insert_packet()
192 chain->timestamp = jiffies; in batadv_frag_insert_packet()
203 hlist_add_behind(&frag_entry_new->list, &frag_entry_last->list); in batadv_frag_insert_packet()
204 chain->size += skb->len - hdr_size; in batadv_frag_insert_packet()
205 chain->timestamp = jiffies; in batadv_frag_insert_packet()
210 if (chain->size > batadv_frag_size_limit() || in batadv_frag_insert_packet()
211 chain->total_size != ntohs(frag_packet->total_size) || in batadv_frag_insert_packet()
212 chain->total_size > batadv_frag_size_limit()) { in batadv_frag_insert_packet()
217 batadv_frag_clear_chain(&chain->fragment_list, true); in batadv_frag_insert_packet()
218 chain->size = 0; in batadv_frag_insert_packet()
219 } else if (ntohs(frag_packet->total_size) == chain->size) { in batadv_frag_insert_packet()
221 hlist_move_list(&chain->fragment_list, chain_out); in batadv_frag_insert_packet()
222 chain->size = 0; in batadv_frag_insert_packet()
226 spin_unlock_bh(&chain->lock); in batadv_frag_insert_packet()
238 * batadv_frag_merge_packets() - merge a chain of fragments
258 entry = hlist_entry(chain->first, struct batadv_frag_list_entry, list); in batadv_frag_merge_packets()
259 hlist_del(&entry->list); in batadv_frag_merge_packets()
260 skb_out = entry->skb; in batadv_frag_merge_packets()
263 packet = (struct batadv_frag_packet *)skb_out->data; in batadv_frag_merge_packets()
264 size = ntohs(packet->total_size) + hdr_size; in batadv_frag_merge_packets()
267 if (pskb_expand_head(skb_out, 0, size - skb_out->len, GFP_ATOMIC) < 0) { in batadv_frag_merge_packets()
278 skb_out->ip_summed = CHECKSUM_NONE; in batadv_frag_merge_packets()
279 memmove(skb_out->data - ETH_HLEN, skb_mac_header(skb_out), ETH_HLEN); in batadv_frag_merge_packets()
280 skb_set_mac_header(skb_out, -ETH_HLEN); in batadv_frag_merge_packets()
286 size = entry->skb->len - hdr_size; in batadv_frag_merge_packets()
287 skb_put_data(skb_out, entry->skb->data + hdr_size, size); in batadv_frag_merge_packets()
297 * batadv_frag_skb_buffer() - buffer fragment for later merge
304 * set *skb to merged packet; 2) Packet is buffered: Return true and set *skb
307 * Return: true when the packet is merged or buffered, false when skb is not
337 * batadv_frag_skb_fwd() - forward fragments that would exceed MTU when merged
342 * Look up the next-hop of the fragments payload and check if the merged packet
343 * will exceed the MTU towards the next-hop. If so, the fragment is forwarded
352 struct batadv_priv *bat_priv = netdev_priv(recv_if->soft_iface); in batadv_frag_skb_fwd()
358 packet = (struct batadv_frag_packet *)skb->data; in batadv_frag_skb_fwd()
360 neigh_node = batadv_orig_to_router(bat_priv, packet->dest, recv_if); in batadv_frag_skb_fwd()
367 total_size = ntohs(packet->total_size); in batadv_frag_skb_fwd()
368 if (total_size > neigh_node->if_incoming->net_dev->mtu) { in batadv_frag_skb_fwd()
371 skb->len + ETH_HLEN); in batadv_frag_skb_fwd()
373 packet->ttl--; in batadv_frag_skb_fwd()
384 * batadv_frag_create() - create a fragment from skb
402 unsigned int tailroom = net_dev->needed_tailroom; in batadv_frag_create()
411 skb_fragment->priority = skb->priority; in batadv_frag_create()
413 /* Eat the last mtu-bytes of the skb */ in batadv_frag_create()
415 skb_split(skb, skb_fragment, skb->len - fragment_size); in batadv_frag_create()
419 memcpy(skb_fragment->data, frag_head, header_size); in batadv_frag_create()
426 * batadv_frag_send_packet() - create up to 16 fragments from the passed skb
429 * @neigh_node: next-hop of the created fragments
431 * Return: the netdev tx status or a negative errno code on a failure
437 struct net_device *net_dev = neigh_node->if_incoming->net_dev; in batadv_frag_send_packet()
442 unsigned int mtu = net_dev->mtu; in batadv_frag_send_packet()
447 /* To avoid merge and refragmentation at next-hops we never send in batadv_frag_send_packet()
451 max_fragment_size = mtu - header_size; in batadv_frag_send_packet()
453 if (skb->len == 0 || max_fragment_size == 0) in batadv_frag_send_packet()
454 return -EINVAL; in batadv_frag_send_packet()
456 num_fragments = (skb->len - 1) / max_fragment_size + 1; in batadv_frag_send_packet()
457 max_fragment_size = (skb->len - 1) / num_fragments + 1; in batadv_frag_send_packet()
461 ret = -EAGAIN; in batadv_frag_send_packet()
465 bat_priv = orig_node->bat_priv; in batadv_frag_send_packet()
468 ret = -EINVAL; in batadv_frag_send_packet()
475 * batman-adv fragments were created and submitted to the in batadv_frag_send_packet()
476 * hard-interface in batadv_frag_send_packet()
479 ret = -ENOMEM; in batadv_frag_send_packet()
487 frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno)); in batadv_frag_send_packet()
490 frag_header.total_size = htons(skb->len); in batadv_frag_send_packet()
492 /* skb->priority values from 256->263 are magic values to in batadv_frag_send_packet()
497 if (skb->priority >= 256 && skb->priority <= 263) in batadv_frag_send_packet()
498 frag_header.priority = skb->priority - 256; in batadv_frag_send_packet()
502 ether_addr_copy(frag_header.orig, primary_if->net_dev->dev_addr); in batadv_frag_send_packet()
503 ether_addr_copy(frag_header.dest, orig_node->orig); in batadv_frag_send_packet()
506 while (skb->len > max_fragment_size) { in batadv_frag_send_packet()
508 if (unlikely(frag_header.no == BATADV_FRAG_MAX_FRAGMENTS - 1)) { in batadv_frag_send_packet()
509 ret = -EINVAL; in batadv_frag_send_packet()
516 ret = -ENOMEM; in batadv_frag_send_packet()
522 skb_fragment->len + ETH_HLEN); in batadv_frag_send_packet()
540 memcpy(skb->data, &frag_header, header_size); in batadv_frag_send_packet()
545 skb->len + ETH_HLEN); in batadv_frag_send_packet()