Lines Matching +full:stop +full:- +full:ack
1 // SPDX-License-Identifier: GPL-2.0
45 #include "hard-interface.h"
52 * BATADV_TP_DEF_TEST_LENGTH - Default test length if not specified by the user
58 * BATADV_TP_AWND - Advertised window by the receiver (in bytes)
63 * BATADV_TP_RECV_TIMEOUT - Receiver activity timeout. If the receiver does not
69 * BATADV_TP_MAX_RTO - Maximum sender timeout. If the sender RTO gets beyond
76 * BATADV_TP_FIRST_SEQ - First seqno of each session. The number is rather high
79 #define BATADV_TP_FIRST_SEQ ((u32)-1 - 2000)
82 * BATADV_TP_PLEN - length of the payload (data after the batadv_unicast header)
85 #define BATADV_TP_PLEN (BATADV_TP_PACKET_LEN - ETH_HLEN - \
91 * batadv_tp_session_cookie() - generate session cookie based on session ids
109 * batadv_tp_cwnd() - compute the new cwnd size
124 /* check for wrap-around */ in batadv_tp_cwnd()
134 * batadv_tp_update_cwnd() - update the Congestion Windows
139 * MSS every unique received ACK
141 * increased by MSS * MSS / CWND for every unique received ACK
145 spin_lock_bh(&tp_vars->cwnd_lock); in batadv_tp_update_cwnd()
148 if (tp_vars->cwnd <= tp_vars->ss_threshold) { in batadv_tp_update_cwnd()
149 tp_vars->dec_cwnd = 0; in batadv_tp_update_cwnd()
150 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss); in batadv_tp_update_cwnd()
151 spin_unlock_bh(&tp_vars->cwnd_lock); in batadv_tp_update_cwnd()
156 tp_vars->dec_cwnd += max_t(u32, 1U << 3, in batadv_tp_update_cwnd()
157 ((mss * mss) << 6) / (tp_vars->cwnd << 3)); in batadv_tp_update_cwnd()
158 if (tp_vars->dec_cwnd < (mss << 3)) { in batadv_tp_update_cwnd()
159 spin_unlock_bh(&tp_vars->cwnd_lock); in batadv_tp_update_cwnd()
163 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss); in batadv_tp_update_cwnd()
164 tp_vars->dec_cwnd = 0; in batadv_tp_update_cwnd()
166 spin_unlock_bh(&tp_vars->cwnd_lock); in batadv_tp_update_cwnd()
170 * batadv_tp_update_rto() - calculate new retransmission timeout
185 if (tp_vars->srtt != 0) { in batadv_tp_update_rto()
186 m -= (tp_vars->srtt >> 3); /* m is now error in rtt est */ in batadv_tp_update_rto()
187 tp_vars->srtt += m; /* rtt = 7/8 srtt + 1/8 new */ in batadv_tp_update_rto()
189 m = -m; in batadv_tp_update_rto()
191 m -= (tp_vars->rttvar >> 2); in batadv_tp_update_rto()
192 tp_vars->rttvar += m; /* mdev ~= 3/4 rttvar + 1/4 new */ in batadv_tp_update_rto()
195 tp_vars->srtt = m << 3; /* take the measured time to be srtt */ in batadv_tp_update_rto()
196 tp_vars->rttvar = m << 1; /* new_rtt / 2 */ in batadv_tp_update_rto()
202 tp_vars->rto = (tp_vars->srtt >> 3) + tp_vars->rttvar; in batadv_tp_update_rto()
206 * batadv_tp_batctl_notify() - send client status result to client
207 * @reason: reason for tp meter session stop
225 test_time = jiffies_to_msecs(jiffies - start_time); in batadv_tp_batctl_notify()
238 * batadv_tp_batctl_error_notify() - send client error result to client
239 * @reason: reason for tp meter session stop
253 * batadv_tp_list_find() - find a tp_vars object in the global list
268 hlist_for_each_entry_rcu(pos, &bat_priv->tp_list, list) { in batadv_tp_list_find()
269 if (!batadv_compare_eth(pos->other_end, dst)) in batadv_tp_list_find()
276 if (unlikely(!kref_get_unless_zero(&pos->refcount))) in batadv_tp_list_find()
288 * batadv_tp_list_find_session() - find tp_vars session object in the global
307 hlist_for_each_entry_rcu(pos, &bat_priv->tp_list, list) { in batadv_tp_list_find_session()
308 if (!batadv_compare_eth(pos->other_end, dst)) in batadv_tp_list_find_session()
311 if (memcmp(pos->session, session, sizeof(pos->session)) != 0) in batadv_tp_list_find_session()
318 if (unlikely(!kref_get_unless_zero(&pos->refcount))) in batadv_tp_list_find_session()
330 * batadv_tp_vars_release() - release batadv_tp_vars from lists and queue for
344 spin_lock_bh(&tp_vars->unacked_lock); in batadv_tp_vars_release()
345 list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) { in batadv_tp_vars_release()
346 list_del(&un->list); in batadv_tp_vars_release()
349 spin_unlock_bh(&tp_vars->unacked_lock); in batadv_tp_vars_release()
355 * batadv_tp_vars_put() - decrement the batadv_tp_vars refcounter and possibly
364 kref_put(&tp_vars->refcount, batadv_tp_vars_release); in batadv_tp_vars_put()
368 * batadv_tp_sender_cleanup() - cleanup sender data and drop and timer
375 cancel_delayed_work(&tp_vars->finish_work); in batadv_tp_sender_cleanup()
377 spin_lock_bh(&tp_vars->bat_priv->tp_list_lock); in batadv_tp_sender_cleanup()
378 hlist_del_rcu(&tp_vars->list); in batadv_tp_sender_cleanup()
379 spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock); in batadv_tp_sender_cleanup()
384 atomic_dec(&tp_vars->bat_priv->tp_num); in batadv_tp_sender_cleanup()
387 del_timer_sync(&tp_vars->timer); in batadv_tp_sender_cleanup()
390 * del_timer(), it would not re-arm itself once again because the status in batadv_tp_sender_cleanup()
393 del_timer(&tp_vars->timer); in batadv_tp_sender_cleanup()
398 * batadv_tp_sender_end() - print info about ended session and inform client
409 tp_vars->other_end, tp_vars->reason); in batadv_tp_sender_end()
413 tp_vars->srtt >> 3, tp_vars->rttvar >> 2, tp_vars->rto); in batadv_tp_sender_end()
417 tp_vars->cwnd, tp_vars->ss_threshold); in batadv_tp_sender_end()
419 session_cookie = batadv_tp_session_cookie(tp_vars->session, in batadv_tp_sender_end()
420 tp_vars->icmp_uid); in batadv_tp_sender_end()
422 batadv_tp_batctl_notify(tp_vars->reason, in batadv_tp_sender_end()
423 tp_vars->other_end, in batadv_tp_sender_end()
425 tp_vars->start_time, in batadv_tp_sender_end()
426 atomic64_read(&tp_vars->tot_sent), in batadv_tp_sender_end()
431 * batadv_tp_sender_shutdown() - let sender thread/timer stop gracefully
433 * @reason: reason for tp meter session stop
438 if (!atomic_dec_and_test(&tp_vars->sending)) in batadv_tp_sender_shutdown()
441 tp_vars->reason = reason; in batadv_tp_sender_shutdown()
445 * batadv_tp_sender_finish() - stop sender session after test_length was reached
461 * batadv_tp_reset_sender_timer() - reschedule the sender timer
464 * Reschedule the timer using tp_vars->rto as delay
471 if (unlikely(atomic_read(&tp_vars->sending) == 0)) in batadv_tp_reset_sender_timer()
475 mod_timer(&tp_vars->timer, jiffies + msecs_to_jiffies(tp_vars->rto)); in batadv_tp_reset_sender_timer()
479 * batadv_tp_sender_timeout() - timer that fires in case of packet loss
489 struct batadv_priv *bat_priv = tp_vars->bat_priv; in batadv_tp_sender_timeout()
491 if (atomic_read(&tp_vars->sending) == 0) in batadv_tp_sender_timeout()
495 if (unlikely(tp_vars->rto >= BATADV_TP_MAX_RTO)) { in batadv_tp_sender_timeout()
504 tp_vars->rto <<= 1; in batadv_tp_sender_timeout()
506 spin_lock_bh(&tp_vars->cwnd_lock); in batadv_tp_sender_timeout()
508 tp_vars->ss_threshold = tp_vars->cwnd >> 1; in batadv_tp_sender_timeout()
509 if (tp_vars->ss_threshold < BATADV_TP_PLEN * 2) in batadv_tp_sender_timeout()
510 tp_vars->ss_threshold = BATADV_TP_PLEN * 2; in batadv_tp_sender_timeout()
514 tp_vars->other_end, tp_vars->cwnd, tp_vars->ss_threshold, in batadv_tp_sender_timeout()
515 atomic_read(&tp_vars->last_acked)); in batadv_tp_sender_timeout()
517 tp_vars->cwnd = BATADV_TP_PLEN * 3; in batadv_tp_sender_timeout()
519 spin_unlock_bh(&tp_vars->cwnd_lock); in batadv_tp_sender_timeout()
521 /* resend the non-ACKed packets.. */ in batadv_tp_sender_timeout()
522 tp_vars->last_sent = atomic_read(&tp_vars->last_acked); in batadv_tp_sender_timeout()
523 wake_up(&tp_vars->more_bytes); in batadv_tp_sender_timeout()
529 * batadv_tp_fill_prerandom() - Fill buffer with prefetched random bytes
542 spin_lock_bh(&tp_vars->prerandom_lock); in batadv_tp_fill_prerandom()
543 local_offset = tp_vars->prerandom_offset; in batadv_tp_fill_prerandom()
544 tp_vars->prerandom_offset += nbytes; in batadv_tp_fill_prerandom()
545 tp_vars->prerandom_offset %= sizeof(batadv_tp_prerandom); in batadv_tp_fill_prerandom()
546 spin_unlock_bh(&tp_vars->prerandom_lock); in batadv_tp_fill_prerandom()
550 bytes_inbuf = sizeof(batadv_tp_prerandom) - local_offset; in batadv_tp_fill_prerandom()
555 nbytes -= to_copy; in batadv_tp_fill_prerandom()
561 * batadv_tp_send_msg() - send a single message
569 * @timestamp: timestamp in jiffies which is replied in ack
596 ether_addr_copy(icmp->dst, orig_node->orig); in batadv_tp_send_msg()
597 ether_addr_copy(icmp->orig, src); in batadv_tp_send_msg()
598 icmp->version = BATADV_COMPAT_VERSION; in batadv_tp_send_msg()
599 icmp->packet_type = BATADV_ICMP; in batadv_tp_send_msg()
600 icmp->ttl = BATADV_TTL; in batadv_tp_send_msg()
601 icmp->msg_type = BATADV_TP; in batadv_tp_send_msg()
602 icmp->uid = uid; in batadv_tp_send_msg()
604 icmp->subtype = BATADV_TP_MSG; in batadv_tp_send_msg()
605 memcpy(icmp->session, session, sizeof(icmp->session)); in batadv_tp_send_msg()
606 icmp->seqno = htonl(seqno); in batadv_tp_send_msg()
607 icmp->timestamp = htonl(timestamp); in batadv_tp_send_msg()
609 data_len = len - sizeof(*icmp); in batadv_tp_send_msg()
621 * batadv_tp_recv_ack() - ACK receiving function
625 * Process a received TP ACK packet
642 icmp = (struct batadv_icmp_tp_packet *)skb->data; in batadv_tp_recv_ack()
645 tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig, in batadv_tp_recv_ack()
646 icmp->session); in batadv_tp_recv_ack()
650 if (unlikely(atomic_read(&tp_vars->sending) == 0)) in batadv_tp_recv_ack()
653 /* old ACK? silently drop it.. */ in batadv_tp_recv_ack()
654 if (batadv_seq_before(ntohl(icmp->seqno), in batadv_tp_recv_ack()
655 (u32)atomic_read(&tp_vars->last_acked))) in batadv_tp_recv_ack()
662 orig_node = batadv_orig_hash_find(bat_priv, icmp->orig); in batadv_tp_recv_ack()
667 rtt = jiffies_to_msecs(jiffies) - ntohl(icmp->timestamp); in batadv_tp_recv_ack()
668 if (icmp->timestamp && rtt) in batadv_tp_recv_ack()
671 /* ACK for new data... reset the timer */ in batadv_tp_recv_ack()
674 recv_ack = ntohl(icmp->seqno); in batadv_tp_recv_ack()
676 /* check if this ACK is a duplicate */ in batadv_tp_recv_ack()
677 if (atomic_read(&tp_vars->last_acked) == recv_ack) { in batadv_tp_recv_ack()
678 atomic_inc(&tp_vars->dup_acks); in batadv_tp_recv_ack()
679 if (atomic_read(&tp_vars->dup_acks) != 3) in batadv_tp_recv_ack()
682 if (recv_ack >= tp_vars->recover) in batadv_tp_recv_ack()
685 /* if this is the third duplicate ACK do Fast Retransmit */ in batadv_tp_recv_ack()
686 batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr, in batadv_tp_recv_ack()
688 icmp->session, icmp->uid, in batadv_tp_recv_ack()
691 spin_lock_bh(&tp_vars->cwnd_lock); in batadv_tp_recv_ack()
694 tp_vars->fast_recovery = true; in batadv_tp_recv_ack()
698 tp_vars->recover = tp_vars->last_sent; in batadv_tp_recv_ack()
699 tp_vars->ss_threshold = tp_vars->cwnd >> 1; in batadv_tp_recv_ack()
702 tp_vars->cwnd, tp_vars->ss_threshold, in batadv_tp_recv_ack()
703 tp_vars->last_sent, recv_ack); in batadv_tp_recv_ack()
704 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 3 * mss, in batadv_tp_recv_ack()
706 tp_vars->dec_cwnd = 0; in batadv_tp_recv_ack()
707 tp_vars->last_sent = recv_ack; in batadv_tp_recv_ack()
709 spin_unlock_bh(&tp_vars->cwnd_lock); in batadv_tp_recv_ack()
712 atomic64_add(recv_ack - atomic_read(&tp_vars->last_acked), in batadv_tp_recv_ack()
713 &tp_vars->tot_sent); in batadv_tp_recv_ack()
715 atomic_set(&tp_vars->dup_acks, 0); in batadv_tp_recv_ack()
717 if (tp_vars->fast_recovery) { in batadv_tp_recv_ack()
718 /* partial ACK */ in batadv_tp_recv_ack()
719 if (batadv_seq_before(recv_ack, tp_vars->recover)) { in batadv_tp_recv_ack()
724 dev_addr = primary_if->net_dev->dev_addr; in batadv_tp_recv_ack()
727 packet_len, icmp->session, in batadv_tp_recv_ack()
728 icmp->uid, in batadv_tp_recv_ack()
730 tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, in batadv_tp_recv_ack()
733 tp_vars->fast_recovery = false; in batadv_tp_recv_ack()
738 cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 0, in batadv_tp_recv_ack()
740 tp_vars->cwnd = cwnd; in batadv_tp_recv_ack()
745 if (recv_ack - atomic_read(&tp_vars->last_acked) >= mss) in batadv_tp_recv_ack()
749 atomic_set(&tp_vars->last_acked, recv_ack); in batadv_tp_recv_ack()
752 wake_up(&tp_vars->more_bytes); in batadv_tp_recv_ack()
760 * batadv_tp_avail() - check if congestion window is not full
771 win_limit = atomic_read(&tp_vars->last_acked) + tp_vars->cwnd; in batadv_tp_avail()
772 win_left = win_limit - tp_vars->last_sent; in batadv_tp_avail()
778 * batadv_tp_wait_available() - wait until congestion window becomes free or
786 * the timeout elapsed, or -ERESTARTSYS if it was interrupted by a signal.
792 ret = wait_event_interruptible_timeout(tp_vars->more_bytes, in batadv_tp_wait_available()
800 * batadv_tp_send() - main sending thread of a tp meter session
808 struct batadv_priv *bat_priv = tp_vars->bat_priv; in batadv_tp_send()
814 if (unlikely(tp_vars->role != BATADV_TP_SENDER)) { in batadv_tp_send()
816 tp_vars->reason = err; in batadv_tp_send()
820 orig_node = batadv_orig_hash_find(bat_priv, tp_vars->other_end); in batadv_tp_send()
823 tp_vars->reason = err; in batadv_tp_send()
830 tp_vars->reason = err; in batadv_tp_send()
846 queue_delayed_work(batadv_event_workqueue, &tp_vars->finish_work, in batadv_tp_send()
847 msecs_to_jiffies(tp_vars->test_length)); in batadv_tp_send()
849 while (atomic_read(&tp_vars->sending) != 0) { in batadv_tp_send()
860 err = batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr, in batadv_tp_send()
861 orig_node, tp_vars->last_sent, in batadv_tp_send()
863 tp_vars->session, tp_vars->icmp_uid, in batadv_tp_send()
871 /* ensure nobody else tries to stop the thread now */ in batadv_tp_send()
872 if (atomic_dec_and_test(&tp_vars->sending)) in batadv_tp_send()
873 tp_vars->reason = err; in batadv_tp_send()
877 /* right-shift the TWND */ in batadv_tp_send()
879 tp_vars->last_sent += payload_len; in batadv_tp_send()
897 * batadv_tp_start_kthread() - start new thread which manages the tp meter
904 struct batadv_priv *bat_priv = tp_vars->bat_priv; in batadv_tp_start_kthread()
907 kref_get(&tp_vars->refcount); in batadv_tp_start_kthread()
910 session_cookie = batadv_tp_session_cookie(tp_vars->session, in batadv_tp_start_kthread()
911 tp_vars->icmp_uid); in batadv_tp_start_kthread()
914 tp_vars->other_end, in batadv_tp_start_kthread()
929 * batadv_tp_start() - start a new tp meter session
949 spin_lock_bh(&bat_priv->tp_list_lock); in batadv_tp_start()
952 spin_unlock_bh(&bat_priv->tp_list_lock); in batadv_tp_start()
961 if (!atomic_add_unless(&bat_priv->tp_num, 1, BATADV_TP_MAX_NUM)) { in batadv_tp_start()
962 spin_unlock_bh(&bat_priv->tp_list_lock); in batadv_tp_start()
972 spin_unlock_bh(&bat_priv->tp_list_lock); in batadv_tp_start()
982 ether_addr_copy(tp_vars->other_end, dst); in batadv_tp_start()
983 kref_init(&tp_vars->refcount); in batadv_tp_start()
984 tp_vars->role = BATADV_TP_SENDER; in batadv_tp_start()
985 atomic_set(&tp_vars->sending, 1); in batadv_tp_start()
986 memcpy(tp_vars->session, session_id, sizeof(session_id)); in batadv_tp_start()
987 tp_vars->icmp_uid = icmp_uid; in batadv_tp_start()
989 tp_vars->last_sent = BATADV_TP_FIRST_SEQ; in batadv_tp_start()
990 atomic_set(&tp_vars->last_acked, BATADV_TP_FIRST_SEQ); in batadv_tp_start()
991 tp_vars->fast_recovery = false; in batadv_tp_start()
992 tp_vars->recover = BATADV_TP_FIRST_SEQ; in batadv_tp_start()
995 * For batman-adv the MSS is the size of the payload received by the in batadv_tp_start()
998 tp_vars->cwnd = BATADV_TP_PLEN * 3; in batadv_tp_start()
1002 tp_vars->ss_threshold = BATADV_TP_AWND; in batadv_tp_start()
1007 tp_vars->rto = 1000; in batadv_tp_start()
1008 tp_vars->srtt = 0; in batadv_tp_start()
1009 tp_vars->rttvar = 0; in batadv_tp_start()
1011 atomic64_set(&tp_vars->tot_sent, 0); in batadv_tp_start()
1013 kref_get(&tp_vars->refcount); in batadv_tp_start()
1014 timer_setup(&tp_vars->timer, batadv_tp_sender_timeout, 0); in batadv_tp_start()
1016 tp_vars->bat_priv = bat_priv; in batadv_tp_start()
1017 tp_vars->start_time = jiffies; in batadv_tp_start()
1019 init_waitqueue_head(&tp_vars->more_bytes); in batadv_tp_start()
1021 spin_lock_init(&tp_vars->unacked_lock); in batadv_tp_start()
1022 INIT_LIST_HEAD(&tp_vars->unacked_list); in batadv_tp_start()
1024 spin_lock_init(&tp_vars->cwnd_lock); in batadv_tp_start()
1026 tp_vars->prerandom_offset = 0; in batadv_tp_start()
1027 spin_lock_init(&tp_vars->prerandom_lock); in batadv_tp_start()
1029 kref_get(&tp_vars->refcount); in batadv_tp_start()
1030 hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list); in batadv_tp_start()
1031 spin_unlock_bh(&bat_priv->tp_list_lock); in batadv_tp_start()
1033 tp_vars->test_length = test_length; in batadv_tp_start()
1034 if (!tp_vars->test_length) in batadv_tp_start()
1035 tp_vars->test_length = BATADV_TP_DEF_TEST_LENGTH; in batadv_tp_start()
1042 INIT_DELAYED_WORK(&tp_vars->finish_work, batadv_tp_sender_finish); in batadv_tp_start()
1054 * batadv_tp_stop() - stop currently running tp meter session
1057 * @return_value: reason for tp meter session stop
1072 tp_vars = batadv_tp_list_find(bat_priv, orig_node->orig); in batadv_tp_stop()
1086 * batadv_tp_reset_receiver_timer() - reset the receiver shutdown timer
1093 mod_timer(&tp_vars->timer, in batadv_tp_reset_receiver_timer()
1098 * batadv_tp_receiver_shutdown() - stop a tp meter receiver when timeout is
1099 * reached without received ack
1108 bat_priv = tp_vars->bat_priv; in batadv_tp_receiver_shutdown()
1111 if (!batadv_has_timed_out(tp_vars->last_recv_time, in batadv_tp_receiver_shutdown()
1120 BATADV_TP_RECV_TIMEOUT, tp_vars->other_end); in batadv_tp_receiver_shutdown()
1122 spin_lock_bh(&tp_vars->bat_priv->tp_list_lock); in batadv_tp_receiver_shutdown()
1123 hlist_del_rcu(&tp_vars->list); in batadv_tp_receiver_shutdown()
1124 spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock); in batadv_tp_receiver_shutdown()
1129 atomic_dec(&bat_priv->tp_num); in batadv_tp_receiver_shutdown()
1131 spin_lock_bh(&tp_vars->unacked_lock); in batadv_tp_receiver_shutdown()
1132 list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) { in batadv_tp_receiver_shutdown()
1133 list_del(&un->list); in batadv_tp_receiver_shutdown()
1136 spin_unlock_bh(&tp_vars->unacked_lock); in batadv_tp_receiver_shutdown()
1143 * batadv_tp_send_ack() - send an ACK packet
1146 * @seq: the sequence number to ACK
1147 * @timestamp: the timestamp to echo back in the ACK
1184 icmp->packet_type = BATADV_ICMP; in batadv_tp_send_ack()
1185 icmp->version = BATADV_COMPAT_VERSION; in batadv_tp_send_ack()
1186 icmp->ttl = BATADV_TTL; in batadv_tp_send_ack()
1187 icmp->msg_type = BATADV_TP; in batadv_tp_send_ack()
1188 ether_addr_copy(icmp->dst, orig_node->orig); in batadv_tp_send_ack()
1189 ether_addr_copy(icmp->orig, primary_if->net_dev->dev_addr); in batadv_tp_send_ack()
1190 icmp->uid = socket_index; in batadv_tp_send_ack()
1192 icmp->subtype = BATADV_TP_ACK; in batadv_tp_send_ack()
1193 memcpy(icmp->session, session, sizeof(icmp->session)); in batadv_tp_send_ack()
1194 icmp->seqno = htonl(seq); in batadv_tp_send_ack()
1195 icmp->timestamp = timestamp; in batadv_tp_send_ack()
1197 /* send the ack */ in batadv_tp_send_ack()
1213 * batadv_tp_handle_out_of_order() - store an out of order packet
1235 icmp = (struct batadv_icmp_tp_packet *)skb->data; in batadv_tp_handle_out_of_order()
1237 new->seqno = ntohl(icmp->seqno); in batadv_tp_handle_out_of_order()
1238 payload_len = skb->len - sizeof(struct batadv_unicast_packet); in batadv_tp_handle_out_of_order()
1239 new->len = payload_len; in batadv_tp_handle_out_of_order()
1241 spin_lock_bh(&tp_vars->unacked_lock); in batadv_tp_handle_out_of_order()
1243 if (list_empty(&tp_vars->unacked_list)) { in batadv_tp_handle_out_of_order()
1244 list_add(&new->list, &tp_vars->unacked_list); in batadv_tp_handle_out_of_order()
1255 list_for_each_entry_reverse(un, &tp_vars->unacked_list, list) { in batadv_tp_handle_out_of_order()
1257 if (new->seqno == un->seqno) { in batadv_tp_handle_out_of_order()
1258 if (new->len > un->len) in batadv_tp_handle_out_of_order()
1259 un->len = new->len; in batadv_tp_handle_out_of_order()
1266 if (batadv_seq_before(new->seqno, un->seqno)) in batadv_tp_handle_out_of_order()
1273 list_add_tail(&new->list, &un->list); in batadv_tp_handle_out_of_order()
1280 list_add(&new->list, &tp_vars->unacked_list); in batadv_tp_handle_out_of_order()
1283 spin_unlock_bh(&tp_vars->unacked_lock); in batadv_tp_handle_out_of_order()
1289 * batadv_tp_ack_unordered() - update number received bytes in current stream
1298 /* go through the unacked packet list and possibly ACK them as in batadv_tp_ack_unordered()
1301 spin_lock_bh(&tp_vars->unacked_lock); in batadv_tp_ack_unordered()
1302 list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) { in batadv_tp_ack_unordered()
1303 /* the list is ordered, therefore it is possible to stop as soon in batadv_tp_ack_unordered()
1307 if (batadv_seq_before(tp_vars->last_recv, un->seqno)) in batadv_tp_ack_unordered()
1310 to_ack = un->seqno + un->len - tp_vars->last_recv; in batadv_tp_ack_unordered()
1312 if (batadv_seq_before(tp_vars->last_recv, un->seqno + un->len)) in batadv_tp_ack_unordered()
1313 tp_vars->last_recv += to_ack; in batadv_tp_ack_unordered()
1315 list_del(&un->list); in batadv_tp_ack_unordered()
1318 spin_unlock_bh(&tp_vars->unacked_lock); in batadv_tp_ack_unordered()
1322 * batadv_tp_init_recv() - return matching or create new receiver tp_vars
1334 spin_lock_bh(&bat_priv->tp_list_lock); in batadv_tp_init_recv()
1335 tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig, in batadv_tp_init_recv()
1336 icmp->session); in batadv_tp_init_recv()
1340 if (!atomic_add_unless(&bat_priv->tp_num, 1, BATADV_TP_MAX_NUM)) { in batadv_tp_init_recv()
1350 ether_addr_copy(tp_vars->other_end, icmp->orig); in batadv_tp_init_recv()
1351 tp_vars->role = BATADV_TP_RECEIVER; in batadv_tp_init_recv()
1352 memcpy(tp_vars->session, icmp->session, sizeof(tp_vars->session)); in batadv_tp_init_recv()
1353 tp_vars->last_recv = BATADV_TP_FIRST_SEQ; in batadv_tp_init_recv()
1354 tp_vars->bat_priv = bat_priv; in batadv_tp_init_recv()
1355 kref_init(&tp_vars->refcount); in batadv_tp_init_recv()
1357 spin_lock_init(&tp_vars->unacked_lock); in batadv_tp_init_recv()
1358 INIT_LIST_HEAD(&tp_vars->unacked_list); in batadv_tp_init_recv()
1360 kref_get(&tp_vars->refcount); in batadv_tp_init_recv()
1361 hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list); in batadv_tp_init_recv()
1363 kref_get(&tp_vars->refcount); in batadv_tp_init_recv()
1364 timer_setup(&tp_vars->timer, batadv_tp_receiver_shutdown, 0); in batadv_tp_init_recv()
1369 spin_unlock_bh(&bat_priv->tp_list_lock); in batadv_tp_init_recv()
1375 * batadv_tp_recv_msg() - process a single data message
1389 icmp = (struct batadv_icmp_tp_packet *)skb->data; in batadv_tp_recv_msg()
1391 seqno = ntohl(icmp->seqno); in batadv_tp_recv_msg()
1403 tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig, in batadv_tp_recv_msg()
1404 icmp->session); in batadv_tp_recv_msg()
1408 icmp->orig); in batadv_tp_recv_msg()
1413 if (unlikely(tp_vars->role != BATADV_TP_RECEIVER)) { in batadv_tp_recv_msg()
1416 tp_vars->role); in batadv_tp_recv_msg()
1420 tp_vars->last_recv_time = jiffies; in batadv_tp_recv_msg()
1422 /* if the packet is a duplicate, it may be the case that an ACK has been in batadv_tp_recv_msg()
1423 * lost. Resend the ACK in batadv_tp_recv_msg()
1425 if (batadv_seq_before(seqno, tp_vars->last_recv)) in batadv_tp_recv_msg()
1429 if (ntohl(icmp->seqno) != tp_vars->last_recv) { in batadv_tp_recv_msg()
1430 /* exit immediately (and do not send any ACK) if the packet has in batadv_tp_recv_msg()
1436 /* send a duplicate ACK */ in batadv_tp_recv_msg()
1441 packet_size = skb->len - sizeof(struct batadv_unicast_packet); in batadv_tp_recv_msg()
1442 tp_vars->last_recv += packet_size; in batadv_tp_recv_msg()
1448 /* send the ACK. If the received packet was out of order, the ACK that in batadv_tp_recv_msg()
1452 batadv_tp_send_ack(bat_priv, icmp->orig, tp_vars->last_recv, in batadv_tp_recv_msg()
1453 icmp->timestamp, icmp->session, icmp->uid); in batadv_tp_recv_msg()
1459 * batadv_tp_meter_recv() - main TP Meter receiving function
1467 icmp = (struct batadv_icmp_tp_packet *)skb->data; in batadv_tp_meter_recv()
1469 switch (icmp->subtype) { in batadv_tp_meter_recv()
1479 icmp->subtype); in batadv_tp_meter_recv()
1485 * batadv_tp_meter_init() - initialize global tp_meter structures