Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    1) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    2) /* Copyright (C) 2012-2020  B.A.T.M.A.N. contributors:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    4)  * Edo Monticelli, Antonio Quartulli
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    5)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    6) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    7) #include "tp_meter.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    8) #include "main.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300    9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   10) #include <linux/atomic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   11) #include <linux/build_bug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   12) #include <linux/byteorder/generic.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   13) #include <linux/cache.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   14) #include <linux/compiler.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   15) #include <linux/err.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   16) #include <linux/etherdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   17) #include <linux/gfp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   18) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   19) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   20) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   21) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   22) #include <linux/kref.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   23) #include <linux/kthread.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   24) #include <linux/limits.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   25) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   26) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   27) #include <linux/param.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   28) #include <linux/printk.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   29) #include <linux/random.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   30) #include <linux/rculist.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   31) #include <linux/rcupdate.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   32) #include <linux/sched.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   33) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   34) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   35) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   36) #include <linux/stddef.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   37) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   38) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   39) #include <linux/wait.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   40) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   41) #include <uapi/linux/batadv_packet.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   42) #include <uapi/linux/batman_adv.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   44) #include "hard-interface.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   45) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   46) #include "netlink.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   47) #include "originator.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   48) #include "send.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   50) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   51)  * BATADV_TP_DEF_TEST_LENGTH - Default test length if not specified by the user
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   52)  *  in milliseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   53)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   54) #define BATADV_TP_DEF_TEST_LENGTH 10000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   56) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   57)  * BATADV_TP_AWND - Advertised window by the receiver (in bytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   58)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   59) #define BATADV_TP_AWND 0x20000000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   61) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   62)  * BATADV_TP_RECV_TIMEOUT - Receiver activity timeout. If the receiver does not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   63)  *  get anything for such amount of milliseconds, the connection is killed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   64)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   65) #define BATADV_TP_RECV_TIMEOUT 1000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   66) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   67) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   68)  * BATADV_TP_MAX_RTO - Maximum sender timeout. If the sender RTO gets beyond
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   69)  * such amount of milliseconds, the receiver is considered unreachable and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   70)  * connection is killed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   71)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   72) #define BATADV_TP_MAX_RTO 30000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   74) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   75)  * BATADV_TP_FIRST_SEQ - First seqno of each session. The number is rather high
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   76)  *  in order to immediately trigger a wrap around (test purposes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   77)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   78) #define BATADV_TP_FIRST_SEQ ((u32)-1 - 2000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   80) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   81)  * BATADV_TP_PLEN - length of the payload (data after the batadv_unicast header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   82)  *  to simulate
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   83)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   84) #define BATADV_TP_PLEN (BATADV_TP_PACKET_LEN - ETH_HLEN - \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   85) 			sizeof(struct batadv_unicast_packet))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   87) static u8 batadv_tp_prerandom[4096] __read_mostly;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   89) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   90)  * batadv_tp_session_cookie() - generate session cookie based on session ids
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   91)  * @session: TP session identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   92)  * @icmp_uid: icmp pseudo uid of the tp session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   93)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   94)  * Return: 32 bit tp_meter session cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   96) static u32 batadv_tp_session_cookie(const u8 session[2], u8 icmp_uid)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   97) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   98) 	u32 cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  100) 	cookie = icmp_uid << 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  101) 	cookie |= session[0] << 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  102) 	cookie |= session[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  104) 	return cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  105) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  107) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  108)  * batadv_tp_cwnd() - compute the new cwnd size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  109)  * @base: base cwnd size value
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  110)  * @increment: the value to add to base to get the new size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  111)  * @min: minimum cwnd value (usually MSS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  112)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  113)  * Return the new cwnd size and ensure it does not exceed the Advertised
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  114)  * Receiver Window size. It is wrapped around safely.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  115)  * For details refer to Section 3.1 of RFC5681
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  116)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  117)  * Return: new congestion window size in bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  118)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  119) static u32 batadv_tp_cwnd(u32 base, u32 increment, u32 min)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  120) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  121) 	u32 new_size = base + increment;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  123) 	/* check for wrap-around */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  124) 	if (new_size < base)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  125) 		new_size = (u32)ULONG_MAX;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  126) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  127) 	new_size = min_t(u32, new_size, BATADV_TP_AWND);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  129) 	return max_t(u32, new_size, min);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  132) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  133)  * batadv_tp_updated_cwnd() - update the Congestion Windows
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  134)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  135)  * @mss: maximum segment size of transmission
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  136)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  137)  * 1) if the session is in Slow Start, the CWND has to be increased by 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  138)  * MSS every unique received ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  139)  * 2) if the session is in Congestion Avoidance, the CWND has to be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  140)  * increased by MSS * MSS / CWND for every unique received ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  141)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  142) static void batadv_tp_update_cwnd(struct batadv_tp_vars *tp_vars, u32 mss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  143) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  144) 	spin_lock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  146) 	/* slow start... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  147) 	if (tp_vars->cwnd <= tp_vars->ss_threshold) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  148) 		tp_vars->dec_cwnd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  149) 		tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  150) 		spin_unlock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  151) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  152) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  154) 	/* increment CWND at least of 1 (section 3.1 of RFC5681) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  155) 	tp_vars->dec_cwnd += max_t(u32, 1U << 3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  156) 				   ((mss * mss) << 6) / (tp_vars->cwnd << 3));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  157) 	if (tp_vars->dec_cwnd < (mss << 3)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  158) 		spin_unlock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  159) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  160) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  161) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  162) 	tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd, mss, mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  163) 	tp_vars->dec_cwnd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  164) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  165) 	spin_unlock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  168) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  169)  * batadv_tp_update_rto() - calculate new retransmission timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  170)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  171)  * @new_rtt: new roundtrip time in msec
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  172)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  173) static void batadv_tp_update_rto(struct batadv_tp_vars *tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  174) 				 u32 new_rtt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  175) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  176) 	long m = new_rtt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  178) 	/* RTT update
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  179) 	 * Details in Section 2.2 and 2.3 of RFC6298
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  180) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  181) 	 * It's tricky to understand. Don't lose hair please.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  182) 	 * Inspired by tcp_rtt_estimator() tcp_input.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  183) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  184) 	if (tp_vars->srtt != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  185) 		m -= (tp_vars->srtt >> 3); /* m is now error in rtt est */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  186) 		tp_vars->srtt += m; /* rtt = 7/8 srtt + 1/8 new */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  187) 		if (m < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  188) 			m = -m;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  190) 		m -= (tp_vars->rttvar >> 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  191) 		tp_vars->rttvar += m; /* mdev ~= 3/4 rttvar + 1/4 new */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  192) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  193) 		/* first measure getting in */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  194) 		tp_vars->srtt = m << 3;	/* take the measured time to be srtt */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  195) 		tp_vars->rttvar = m << 1; /* new_rtt / 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  196) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  198) 	/* rto = srtt + 4 * rttvar.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  199) 	 * rttvar is scaled by 4, therefore doesn't need to be multiplied
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  200) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  201) 	tp_vars->rto = (tp_vars->srtt >> 3) + tp_vars->rttvar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  202) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  204) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  205)  * batadv_tp_batctl_notify() - send client status result to client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  206)  * @reason: reason for tp meter session stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  207)  * @dst: destination of tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  208)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  209)  * @start_time: start of transmission in jiffies
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  210)  * @total_sent: bytes acked to the receiver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  211)  * @cookie: cookie of tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  212)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  213) static void batadv_tp_batctl_notify(enum batadv_tp_meter_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  214) 				    const u8 *dst, struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  215) 				    unsigned long start_time, u64 total_sent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  216) 				    u32 cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  218) 	u32 test_time;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  219) 	u8 result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  220) 	u32 total_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  221) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  222) 	if (!batadv_tp_is_error(reason)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  223) 		result = BATADV_TP_REASON_COMPLETE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  224) 		test_time = jiffies_to_msecs(jiffies - start_time);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  225) 		total_bytes = total_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  226) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  227) 		result = reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  228) 		test_time = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  229) 		total_bytes = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  230) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  231) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  232) 	batadv_netlink_tpmeter_notify(bat_priv, dst, result, test_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  233) 				      total_bytes, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  234) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  235) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  236) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  237)  * batadv_tp_batctl_error_notify() - send client error result to client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  238)  * @reason: reason for tp meter session stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  239)  * @dst: destination of tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  240)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  241)  * @cookie: cookie of tp_meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  242)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  243) static void batadv_tp_batctl_error_notify(enum batadv_tp_meter_reason reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  244) 					  const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  245) 					  struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  246) 					  u32 cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  248) 	batadv_tp_batctl_notify(reason, dst, bat_priv, 0, 0, cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  249) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  251) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  252)  * batadv_tp_list_find() - find a tp_vars object in the global list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  253)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  254)  * @dst: the other endpoint MAC address to look for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  255)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  256)  * Look for a tp_vars object matching dst as end_point and return it after
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  257)  * having increment the refcounter. Return NULL is not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  258)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  259)  * Return: matching tp_vars or NULL when no tp_vars with @dst was found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  260)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  261) static struct batadv_tp_vars *batadv_tp_list_find(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  262) 						  const u8 *dst)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  263) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  264) 	struct batadv_tp_vars *pos, *tp_vars = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  266) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  267) 	hlist_for_each_entry_rcu(pos, &bat_priv->tp_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  268) 		if (!batadv_compare_eth(pos->other_end, dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  269) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  271) 		/* most of the time this function is invoked during the normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  272) 		 * process..it makes sens to pay more when the session is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  273) 		 * finished and to speed the process up during the measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  274) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  275) 		if (unlikely(!kref_get_unless_zero(&pos->refcount)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  276) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  277) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  278) 		tp_vars = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  279) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  281) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  283) 	return tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  284) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  286) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  287)  * batadv_tp_list_find_session() - find tp_vars session object in the global
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  288)  *  list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  289)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  290)  * @dst: the other endpoint MAC address to look for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  291)  * @session: session identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  292)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  293)  * Look for a tp_vars object matching dst as end_point, session as tp meter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  294)  * session and return it after having increment the refcounter. Return NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  295)  * is not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  296)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  297)  * Return: matching tp_vars or NULL when no tp_vars was found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  298)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  299) static struct batadv_tp_vars *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  300) batadv_tp_list_find_session(struct batadv_priv *bat_priv, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  301) 			    const u8 *session)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  302) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  303) 	struct batadv_tp_vars *pos, *tp_vars = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  304) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  305) 	rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  306) 	hlist_for_each_entry_rcu(pos, &bat_priv->tp_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  307) 		if (!batadv_compare_eth(pos->other_end, dst))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  308) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  310) 		if (memcmp(pos->session, session, sizeof(pos->session)) != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  311) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  313) 		/* most of the time this function is invoked during the normal
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  314) 		 * process..it makes sense to pay more when the session is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  315) 		 * finished and to speed the process up during the measurement
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  316) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  317) 		if (unlikely(!kref_get_unless_zero(&pos->refcount)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  318) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  319) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  320) 		tp_vars = pos;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  321) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  322) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  323) 	rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  324) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  325) 	return tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  326) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  327) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  328) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  329)  * batadv_tp_vars_release() - release batadv_tp_vars from lists and queue for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  330)  *  free after rcu grace period
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  331)  * @ref: kref pointer of the batadv_tp_vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  332)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  333) static void batadv_tp_vars_release(struct kref *ref)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  334) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  335) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  336) 	struct batadv_tp_unacked *un, *safe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  337) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  338) 	tp_vars = container_of(ref, struct batadv_tp_vars, refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  340) 	/* lock should not be needed because this object is now out of any
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  341) 	 * context!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  342) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  343) 	spin_lock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  344) 	list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  345) 		list_del(&un->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  346) 		kfree(un);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  347) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  348) 	spin_unlock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  350) 	kfree_rcu(tp_vars, rcu);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  351) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  352) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  353) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  354)  * batadv_tp_vars_put() - decrement the batadv_tp_vars refcounter and possibly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  355)  *  release it
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  356)  * @tp_vars: the private data of the current TP meter session to be free'd
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  357)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  358) static void batadv_tp_vars_put(struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  359) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  360) 	if (!tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  361) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  363) 	kref_put(&tp_vars->refcount, batadv_tp_vars_release);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  364) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  366) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  367)  * batadv_tp_sender_cleanup() - cleanup sender data and drop and timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  368)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  369)  * @tp_vars: the private data of the current TP meter session to cleanup
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  370)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  371) static void batadv_tp_sender_cleanup(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  372) 				     struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  373) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  374) 	cancel_delayed_work(&tp_vars->finish_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  375) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  376) 	spin_lock_bh(&tp_vars->bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  377) 	hlist_del_rcu(&tp_vars->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  378) 	spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  380) 	/* drop list reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  381) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  382) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  383) 	atomic_dec(&tp_vars->bat_priv->tp_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  384) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  385) 	/* kill the timer and remove its reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  386) 	del_timer_sync(&tp_vars->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  387) 	/* the worker might have rearmed itself therefore we kill it again. Note
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  388) 	 * that if the worker should run again before invoking the following
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  389) 	 * del_timer(), it would not re-arm itself once again because the status
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  390) 	 * is OFF now
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  391) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  392) 	del_timer(&tp_vars->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  393) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  394) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  395) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  396) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  397)  * batadv_tp_sender_end() - print info about ended session and inform client
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  398)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  399)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  400)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  401) static void batadv_tp_sender_end(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  402) 				 struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  403) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  404) 	u32 session_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  405) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  406) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  407) 		   "Test towards %pM finished..shutting down (reason=%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  408) 		   tp_vars->other_end, tp_vars->reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  409) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  410) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  411) 		   "Last timing stats: SRTT=%ums RTTVAR=%ums RTO=%ums\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  412) 		   tp_vars->srtt >> 3, tp_vars->rttvar >> 2, tp_vars->rto);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  414) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  415) 		   "Final values: cwnd=%u ss_threshold=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  416) 		   tp_vars->cwnd, tp_vars->ss_threshold);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  417) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  418) 	session_cookie = batadv_tp_session_cookie(tp_vars->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  419) 						  tp_vars->icmp_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  420) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  421) 	batadv_tp_batctl_notify(tp_vars->reason,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  422) 				tp_vars->other_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  423) 				bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  424) 				tp_vars->start_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  425) 				atomic64_read(&tp_vars->tot_sent),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  426) 				session_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  427) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  429) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  430)  * batadv_tp_sender_shutdown() - let sender thread/timer stop gracefully
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  431)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  432)  * @reason: reason for tp meter session stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  433)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  434) static void batadv_tp_sender_shutdown(struct batadv_tp_vars *tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  435) 				      enum batadv_tp_meter_reason reason)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  436) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  437) 	if (!atomic_dec_and_test(&tp_vars->sending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  438) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  439) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  440) 	tp_vars->reason = reason;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  441) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  442) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  443) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  444)  * batadv_tp_sender_finish() - stop sender session after test_length was reached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  445)  * @work: delayed work reference of the related tp_vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  446)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  447) static void batadv_tp_sender_finish(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  448) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  449) 	struct delayed_work *delayed_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  450) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  451) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  452) 	delayed_work = to_delayed_work(work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  453) 	tp_vars = container_of(delayed_work, struct batadv_tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  454) 			       finish_work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  455) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  456) 	batadv_tp_sender_shutdown(tp_vars, BATADV_TP_REASON_COMPLETE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  458) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  459) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  460)  * batadv_tp_reset_sender_timer() - reschedule the sender timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  461)  * @tp_vars: the private TP meter data for this session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  462)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  463)  * Reschedule the timer using tp_vars->rto as delay
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  464)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  465) static void batadv_tp_reset_sender_timer(struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  466) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  467) 	/* most of the time this function is invoked while normal packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  468) 	 * reception...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  469) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  470) 	if (unlikely(atomic_read(&tp_vars->sending) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  471) 		/* timer ref will be dropped in batadv_tp_sender_cleanup */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  472) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  474) 	mod_timer(&tp_vars->timer, jiffies + msecs_to_jiffies(tp_vars->rto));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  477) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  478)  * batadv_tp_sender_timeout() - timer that fires in case of packet loss
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  479)  * @t: address to timer_list inside tp_vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  480)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  481)  * If fired it means that there was packet loss.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  482)  * Switch to Slow Start, set the ss_threshold to half of the current cwnd and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  483)  * reset the cwnd to 3*MSS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  484)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  485) static void batadv_tp_sender_timeout(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  486) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  487) 	struct batadv_tp_vars *tp_vars = from_timer(tp_vars, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  488) 	struct batadv_priv *bat_priv = tp_vars->bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  489) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  490) 	if (atomic_read(&tp_vars->sending) == 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  491) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  492) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  493) 	/* if the user waited long enough...shutdown the test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  494) 	if (unlikely(tp_vars->rto >= BATADV_TP_MAX_RTO)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  495) 		batadv_tp_sender_shutdown(tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  496) 					  BATADV_TP_REASON_DST_UNREACHABLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  497) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  498) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  499) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  500) 	/* RTO exponential backoff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  501) 	 * Details in Section 5.5 of RFC6298
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  502) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  503) 	tp_vars->rto <<= 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  504) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  505) 	spin_lock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  506) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  507) 	tp_vars->ss_threshold = tp_vars->cwnd >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  508) 	if (tp_vars->ss_threshold < BATADV_TP_PLEN * 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  509) 		tp_vars->ss_threshold = BATADV_TP_PLEN * 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  510) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  511) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  512) 		   "Meter: RTO fired during test towards %pM! cwnd=%u new ss_thr=%u, resetting last_sent to %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  513) 		   tp_vars->other_end, tp_vars->cwnd, tp_vars->ss_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  514) 		   atomic_read(&tp_vars->last_acked));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  516) 	tp_vars->cwnd = BATADV_TP_PLEN * 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  517) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  518) 	spin_unlock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  519) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  520) 	/* resend the non-ACKed packets.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  521) 	tp_vars->last_sent = atomic_read(&tp_vars->last_acked);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  522) 	wake_up(&tp_vars->more_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  523) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  524) 	batadv_tp_reset_sender_timer(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  525) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  526) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  527) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  528)  * batadv_tp_fill_prerandom() - Fill buffer with prefetched random bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  529)  * @tp_vars: the private TP meter data for this session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  530)  * @buf: Buffer to fill with bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  531)  * @nbytes: amount of pseudorandom bytes
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  532)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  533) static void batadv_tp_fill_prerandom(struct batadv_tp_vars *tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  534) 				     u8 *buf, size_t nbytes)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  535) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  536) 	u32 local_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  537) 	size_t bytes_inbuf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  538) 	size_t to_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  539) 	size_t pos = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  540) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  541) 	spin_lock_bh(&tp_vars->prerandom_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  542) 	local_offset = tp_vars->prerandom_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  543) 	tp_vars->prerandom_offset += nbytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  544) 	tp_vars->prerandom_offset %= sizeof(batadv_tp_prerandom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  545) 	spin_unlock_bh(&tp_vars->prerandom_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  546) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  547) 	while (nbytes) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  548) 		local_offset %= sizeof(batadv_tp_prerandom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  549) 		bytes_inbuf = sizeof(batadv_tp_prerandom) - local_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  550) 		to_copy = min(nbytes, bytes_inbuf);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  551) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  552) 		memcpy(&buf[pos], &batadv_tp_prerandom[local_offset], to_copy);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  553) 		pos += to_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  554) 		nbytes -= to_copy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  555) 		local_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  556) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  557) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  558) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  559) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  560)  * batadv_tp_send_msg() - send a single message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  561)  * @tp_vars: the private TP meter data for this session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  562)  * @src: source mac address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  563)  * @orig_node: the originator of the destination
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  564)  * @seqno: sequence number of this packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  565)  * @len: length of the entire packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  566)  * @session: session identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  567)  * @uid: local ICMP "socket" index
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  568)  * @timestamp: timestamp in jiffies which is replied in ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  569)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  570)  * Create and send a single TP Meter message.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  571)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  572)  * Return: 0 on success, BATADV_TP_REASON_DST_UNREACHABLE if the destination is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  573)  * not reachable, BATADV_TP_REASON_MEMORY_ERROR if the packet couldn't be
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  574)  * allocated
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  575)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  576) static int batadv_tp_send_msg(struct batadv_tp_vars *tp_vars, const u8 *src,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  577) 			      struct batadv_orig_node *orig_node,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  578) 			      u32 seqno, size_t len, const u8 *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  579) 			      int uid, u32 timestamp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  580) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  581) 	struct batadv_icmp_tp_packet *icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  582) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  583) 	int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  584) 	u8 *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  585) 	size_t data_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  586) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  587) 	skb = netdev_alloc_skb_ip_align(NULL, len + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  588) 	if (unlikely(!skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  589) 		return BATADV_TP_REASON_MEMORY_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  590) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  591) 	skb_reserve(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  592) 	icmp = skb_put(skb, sizeof(*icmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  593) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  594) 	/* fill the icmp header */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  595) 	ether_addr_copy(icmp->dst, orig_node->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  596) 	ether_addr_copy(icmp->orig, src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  597) 	icmp->version = BATADV_COMPAT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  598) 	icmp->packet_type = BATADV_ICMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  599) 	icmp->ttl = BATADV_TTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  600) 	icmp->msg_type = BATADV_TP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  601) 	icmp->uid = uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  602) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  603) 	icmp->subtype = BATADV_TP_MSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  604) 	memcpy(icmp->session, session, sizeof(icmp->session));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  605) 	icmp->seqno = htonl(seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  606) 	icmp->timestamp = htonl(timestamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  607) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  608) 	data_len = len - sizeof(*icmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  609) 	data = skb_put(skb, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  610) 	batadv_tp_fill_prerandom(tp_vars, data, data_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  611) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  612) 	r = batadv_send_skb_to_orig(skb, orig_node, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  613) 	if (r == NET_XMIT_SUCCESS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  614) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  615) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  616) 	return BATADV_TP_REASON_CANT_SEND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  617) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  618) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  619) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  620)  * batadv_tp_recv_ack() - ACK receiving function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  621)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  622)  * @skb: the buffer containing the received packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  623)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  624)  * Process a received TP ACK packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  625)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  626) static void batadv_tp_recv_ack(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  627) 			       const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  628) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  629) 	struct batadv_hard_iface *primary_if = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  630) 	struct batadv_orig_node *orig_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  631) 	const struct batadv_icmp_tp_packet *icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  632) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  633) 	size_t packet_len, mss;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  634) 	u32 rtt, recv_ack, cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  635) 	unsigned char *dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  636) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  637) 	packet_len = BATADV_TP_PLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  638) 	mss = BATADV_TP_PLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  639) 	packet_len += sizeof(struct batadv_unicast_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  640) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  641) 	icmp = (struct batadv_icmp_tp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  642) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  643) 	/* find the tp_vars */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  644) 	tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  645) 					      icmp->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  646) 	if (unlikely(!tp_vars))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  647) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  648) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  649) 	if (unlikely(atomic_read(&tp_vars->sending) == 0))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  650) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  651) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  652) 	/* old ACK? silently drop it.. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  653) 	if (batadv_seq_before(ntohl(icmp->seqno),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  654) 			      (u32)atomic_read(&tp_vars->last_acked)))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  655) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  656) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  657) 	primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  658) 	if (unlikely(!primary_if))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  659) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  660) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  661) 	orig_node = batadv_orig_hash_find(bat_priv, icmp->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  662) 	if (unlikely(!orig_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  663) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  664) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  665) 	/* update RTO with the new sampled RTT, if any */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  666) 	rtt = jiffies_to_msecs(jiffies) - ntohl(icmp->timestamp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  667) 	if (icmp->timestamp && rtt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  668) 		batadv_tp_update_rto(tp_vars, rtt);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  669) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  670) 	/* ACK for new data... reset the timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  671) 	batadv_tp_reset_sender_timer(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  672) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  673) 	recv_ack = ntohl(icmp->seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  674) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  675) 	/* check if this ACK is a duplicate */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  676) 	if (atomic_read(&tp_vars->last_acked) == recv_ack) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  677) 		atomic_inc(&tp_vars->dup_acks);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  678) 		if (atomic_read(&tp_vars->dup_acks) != 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  679) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  680) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  681) 		if (recv_ack >= tp_vars->recover)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  682) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  683) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  684) 		/* if this is the third duplicate ACK do Fast Retransmit */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  685) 		batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  686) 				   orig_node, recv_ack, packet_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  687) 				   icmp->session, icmp->uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  688) 				   jiffies_to_msecs(jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  689) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  690) 		spin_lock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  691) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  692) 		/* Fast Recovery */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  693) 		tp_vars->fast_recovery = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  694) 		/* Set recover to the last outstanding seqno when Fast Recovery
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  695) 		 * is entered. RFC6582, Section 3.2, step 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  696) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  697) 		tp_vars->recover = tp_vars->last_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  698) 		tp_vars->ss_threshold = tp_vars->cwnd >> 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  699) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  700) 			   "Meter: Fast Recovery, (cur cwnd=%u) ss_thr=%u last_sent=%u recv_ack=%u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  701) 			   tp_vars->cwnd, tp_vars->ss_threshold,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  702) 			   tp_vars->last_sent, recv_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  703) 		tp_vars->cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 3 * mss,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  704) 					       mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  705) 		tp_vars->dec_cwnd = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  706) 		tp_vars->last_sent = recv_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  707) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  708) 		spin_unlock_bh(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  709) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  710) 		/* count the acked data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  711) 		atomic64_add(recv_ack - atomic_read(&tp_vars->last_acked),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  712) 			     &tp_vars->tot_sent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  713) 		/* reset the duplicate ACKs counter */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  714) 		atomic_set(&tp_vars->dup_acks, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  715) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  716) 		if (tp_vars->fast_recovery) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  717) 			/* partial ACK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  718) 			if (batadv_seq_before(recv_ack, tp_vars->recover)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  719) 				/* this is another hole in the window. React
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  720) 				 * immediately as specified by NewReno (see
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  721) 				 * Section 3.2 of RFC6582 for details)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  722) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  723) 				dev_addr = primary_if->net_dev->dev_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  724) 				batadv_tp_send_msg(tp_vars, dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  725) 						   orig_node, recv_ack,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  726) 						   packet_len, icmp->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  727) 						   icmp->uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  728) 						   jiffies_to_msecs(jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  729) 				tp_vars->cwnd = batadv_tp_cwnd(tp_vars->cwnd,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  730) 							       mss, mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  731) 			} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  732) 				tp_vars->fast_recovery = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  733) 				/* set cwnd to the value of ss_threshold at the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  734) 				 * moment that Fast Recovery was entered.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  735) 				 * RFC6582, Section 3.2, step 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  736) 				 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  737) 				cwnd = batadv_tp_cwnd(tp_vars->ss_threshold, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  738) 						      mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  739) 				tp_vars->cwnd = cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  740) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  741) 			goto move_twnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  742) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  743) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  744) 		if (recv_ack - atomic_read(&tp_vars->last_acked) >= mss)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  745) 			batadv_tp_update_cwnd(tp_vars, mss);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  746) move_twnd:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  747) 		/* move the Transmit Window */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  748) 		atomic_set(&tp_vars->last_acked, recv_ack);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  749) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  750) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  751) 	wake_up(&tp_vars->more_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  752) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  753) 	if (likely(primary_if))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  754) 		batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  755) 	if (likely(orig_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  756) 		batadv_orig_node_put(orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  757) 	if (likely(tp_vars))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  758) 		batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  759) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  760) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  761) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  762)  * batadv_tp_avail() - check if congestion window is not full
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  763)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  764)  * @payload_len: size of the payload of a single message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  765)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  766)  * Return: true when congestion window is not full, false otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  767)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  768) static bool batadv_tp_avail(struct batadv_tp_vars *tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  769) 			    size_t payload_len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  771) 	u32 win_left, win_limit;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  772) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  773) 	win_limit = atomic_read(&tp_vars->last_acked) + tp_vars->cwnd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  774) 	win_left = win_limit - tp_vars->last_sent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  775) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  776) 	return win_left >= payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  777) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  778) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  779) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  780)  * batadv_tp_wait_available() - wait until congestion window becomes free or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  781)  *  timeout is reached
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  782)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  783)  * @plen: size of the payload of a single message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  784)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  785)  * Return: 0 if the condition evaluated to false after the timeout elapsed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  786)  *  1 if the condition evaluated to true after the timeout elapsed, the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  787)  *  remaining jiffies (at least 1) if the condition evaluated to true before
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  788)  *  the timeout elapsed, or -ERESTARTSYS if it was interrupted by a signal.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  789)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  790) static int batadv_tp_wait_available(struct batadv_tp_vars *tp_vars, size_t plen)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  791) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  792) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  793) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  794) 	ret = wait_event_interruptible_timeout(tp_vars->more_bytes,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  795) 					       batadv_tp_avail(tp_vars, plen),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  796) 					       HZ / 10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  797) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  798) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  799) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  800) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  801) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  802)  * batadv_tp_send() - main sending thread of a tp meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  803)  * @arg: address of the related tp_vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  804)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  805)  * Return: nothing, this function never returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  806)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  807) static int batadv_tp_send(void *arg)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  808) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  809) 	struct batadv_tp_vars *tp_vars = arg;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  810) 	struct batadv_priv *bat_priv = tp_vars->bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  811) 	struct batadv_hard_iface *primary_if = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  812) 	struct batadv_orig_node *orig_node = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  813) 	size_t payload_len, packet_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  814) 	int err = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  815) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  816) 	if (unlikely(tp_vars->role != BATADV_TP_SENDER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  817) 		err = BATADV_TP_REASON_DST_UNREACHABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  818) 		tp_vars->reason = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  819) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  820) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  821) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  822) 	orig_node = batadv_orig_hash_find(bat_priv, tp_vars->other_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  823) 	if (unlikely(!orig_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  824) 		err = BATADV_TP_REASON_DST_UNREACHABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  825) 		tp_vars->reason = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  826) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  827) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  828) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  829) 	primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  830) 	if (unlikely(!primary_if)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  831) 		err = BATADV_TP_REASON_DST_UNREACHABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  832) 		tp_vars->reason = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  833) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  834) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  835) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  836) 	/* assume that all the hard_interfaces have a correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  837) 	 * configured MTU, so use the soft_iface MTU as MSS.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  838) 	 * This might not be true and in that case the fragmentation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  839) 	 * should be used.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  840) 	 * Now, try to send the packet as it is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  841) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  842) 	payload_len = BATADV_TP_PLEN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  843) 	BUILD_BUG_ON(sizeof(struct batadv_icmp_tp_packet) > BATADV_TP_PLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  844) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  845) 	batadv_tp_reset_sender_timer(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  846) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  847) 	/* queue the worker in charge of terminating the test */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  848) 	queue_delayed_work(batadv_event_workqueue, &tp_vars->finish_work,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  849) 			   msecs_to_jiffies(tp_vars->test_length));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  850) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  851) 	while (atomic_read(&tp_vars->sending) != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  852) 		if (unlikely(!batadv_tp_avail(tp_vars, payload_len))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  853) 			batadv_tp_wait_available(tp_vars, payload_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  854) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  855) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  856) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  857) 		/* to emulate normal unicast traffic, add to the payload len
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  858) 		 * the size of the unicast header
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  859) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  860) 		packet_len = payload_len + sizeof(struct batadv_unicast_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  861) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  862) 		err = batadv_tp_send_msg(tp_vars, primary_if->net_dev->dev_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  863) 					 orig_node, tp_vars->last_sent,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  864) 					 packet_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  865) 					 tp_vars->session, tp_vars->icmp_uid,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  866) 					 jiffies_to_msecs(jiffies));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  867) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  868) 		/* something went wrong during the preparation/transmission */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  869) 		if (unlikely(err && err != BATADV_TP_REASON_CANT_SEND)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  870) 			batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  871) 				   "Meter: %s() cannot send packets (%d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  872) 				   __func__, err);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  873) 			/* ensure nobody else tries to stop the thread now */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  874) 			if (atomic_dec_and_test(&tp_vars->sending))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  875) 				tp_vars->reason = err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  876) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  877) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  878) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  879) 		/* right-shift the TWND */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  880) 		if (!err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  881) 			tp_vars->last_sent += payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  882) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  883) 		cond_resched();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  884) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  885) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  886) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  887) 	if (likely(primary_if))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  888) 		batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  889) 	if (likely(orig_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  890) 		batadv_orig_node_put(orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  891) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  892) 	batadv_tp_sender_end(bat_priv, tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  893) 	batadv_tp_sender_cleanup(bat_priv, tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  894) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  895) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  896) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  897) 	do_exit(0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  898) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  899) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  900) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  901)  * batadv_tp_start_kthread() - start new thread which manages the tp meter
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  902)  *  sender
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  903)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  904)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  905) static void batadv_tp_start_kthread(struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  906) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  907) 	struct task_struct *kthread;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  908) 	struct batadv_priv *bat_priv = tp_vars->bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  909) 	u32 session_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  910) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  911) 	kref_get(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  912) 	kthread = kthread_create(batadv_tp_send, tp_vars, "kbatadv_tp_meter");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  913) 	if (IS_ERR(kthread)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  914) 		session_cookie = batadv_tp_session_cookie(tp_vars->session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  915) 							  tp_vars->icmp_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  916) 		pr_err("batadv: cannot create tp meter kthread\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  917) 		batadv_tp_batctl_error_notify(BATADV_TP_REASON_MEMORY_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  918) 					      tp_vars->other_end,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  919) 					      bat_priv, session_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  920) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  921) 		/* drop reserved reference for kthread */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  922) 		batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  923) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  924) 		/* cleanup of failed tp meter variables */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  925) 		batadv_tp_sender_cleanup(bat_priv, tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  926) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  927) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  928) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  929) 	wake_up_process(kthread);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  930) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  931) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  932) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  933)  * batadv_tp_start() - start a new tp meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  934)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  935)  * @dst: the receiver MAC address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  936)  * @test_length: test length in milliseconds
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  937)  * @cookie: session cookie
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  938)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  939) void batadv_tp_start(struct batadv_priv *bat_priv, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  940) 		     u32 test_length, u32 *cookie)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  941) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  942) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  943) 	u8 session_id[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  944) 	u8 icmp_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  945) 	u32 session_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  946) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  947) 	get_random_bytes(session_id, sizeof(session_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  948) 	get_random_bytes(&icmp_uid, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  949) 	session_cookie = batadv_tp_session_cookie(session_id, icmp_uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  950) 	*cookie = session_cookie;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  951) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  952) 	/* look for an already existing test towards this node */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  953) 	spin_lock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  954) 	tp_vars = batadv_tp_list_find(bat_priv, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  955) 	if (tp_vars) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  956) 		spin_unlock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  957) 		batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  958) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  959) 			   "Meter: test to or from the same node already ongoing, aborting\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  960) 		batadv_tp_batctl_error_notify(BATADV_TP_REASON_ALREADY_ONGOING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  961) 					      dst, bat_priv, session_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  962) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  963) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  964) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  965) 	if (!atomic_add_unless(&bat_priv->tp_num, 1, BATADV_TP_MAX_NUM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  966) 		spin_unlock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  967) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  968) 			   "Meter: too many ongoing sessions, aborting (SEND)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  969) 		batadv_tp_batctl_error_notify(BATADV_TP_REASON_TOO_MANY, dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  970) 					      bat_priv, session_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  971) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  972) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  973) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  974) 	tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  975) 	if (!tp_vars) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  976) 		spin_unlock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  977) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  978) 			   "Meter: %s cannot allocate list elements\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  979) 			   __func__);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  980) 		batadv_tp_batctl_error_notify(BATADV_TP_REASON_MEMORY_ERROR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  981) 					      dst, bat_priv, session_cookie);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  982) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  983) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  984) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  985) 	/* initialize tp_vars */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  986) 	ether_addr_copy(tp_vars->other_end, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  987) 	kref_init(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  988) 	tp_vars->role = BATADV_TP_SENDER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  989) 	atomic_set(&tp_vars->sending, 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  990) 	memcpy(tp_vars->session, session_id, sizeof(session_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  991) 	tp_vars->icmp_uid = icmp_uid;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  992) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  993) 	tp_vars->last_sent = BATADV_TP_FIRST_SEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  994) 	atomic_set(&tp_vars->last_acked, BATADV_TP_FIRST_SEQ);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  995) 	tp_vars->fast_recovery = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  996) 	tp_vars->recover = BATADV_TP_FIRST_SEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  997) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  998) 	/* initialise the CWND to 3*MSS (Section 3.1 in RFC5681).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  999) 	 * For batman-adv the MSS is the size of the payload received by the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1000) 	 * soft_interface, hence its MTU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1001) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1002) 	tp_vars->cwnd = BATADV_TP_PLEN * 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1003) 	/* at the beginning initialise the SS threshold to the biggest possible
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1004) 	 * window size, hence the AWND size
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1005) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1006) 	tp_vars->ss_threshold = BATADV_TP_AWND;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1007) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1008) 	/* RTO initial value is 3 seconds.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1009) 	 * Details in Section 2.1 of RFC6298
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1010) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1011) 	tp_vars->rto = 1000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1012) 	tp_vars->srtt = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1013) 	tp_vars->rttvar = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1014) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1015) 	atomic64_set(&tp_vars->tot_sent, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1016) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1017) 	kref_get(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1018) 	timer_setup(&tp_vars->timer, batadv_tp_sender_timeout, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1019) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1020) 	tp_vars->bat_priv = bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1021) 	tp_vars->start_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1022) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1023) 	init_waitqueue_head(&tp_vars->more_bytes);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1024) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1025) 	spin_lock_init(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1026) 	INIT_LIST_HEAD(&tp_vars->unacked_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1027) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1028) 	spin_lock_init(&tp_vars->cwnd_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1029) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1030) 	tp_vars->prerandom_offset = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1031) 	spin_lock_init(&tp_vars->prerandom_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1032) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1033) 	kref_get(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1034) 	hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1035) 	spin_unlock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1036) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1037) 	tp_vars->test_length = test_length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1038) 	if (!tp_vars->test_length)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1039) 		tp_vars->test_length = BATADV_TP_DEF_TEST_LENGTH;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1040) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1041) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1042) 		   "Meter: starting throughput meter towards %pM (length=%ums)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1043) 		   dst, test_length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1044) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1045) 	/* init work item for finished tp tests */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1046) 	INIT_DELAYED_WORK(&tp_vars->finish_work, batadv_tp_sender_finish);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1047) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1048) 	/* start tp kthread. This way the write() call issued from userspace can
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1049) 	 * happily return and avoid to block
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1050) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1051) 	batadv_tp_start_kthread(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1052) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1053) 	/* don't return reference to new tp_vars */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1054) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1055) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1056) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1057) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1058)  * batadv_tp_stop() - stop currently running tp meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1059)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1060)  * @dst: the receiver MAC address
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1061)  * @return_value: reason for tp meter session stop
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1062)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1063) void batadv_tp_stop(struct batadv_priv *bat_priv, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1064) 		    u8 return_value)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1065) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1066) 	struct batadv_orig_node *orig_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1067) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1068) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1069) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1070) 		   "Meter: stopping test towards %pM\n", dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1071) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1072) 	orig_node = batadv_orig_hash_find(bat_priv, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1073) 	if (!orig_node)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1074) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1075) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1076) 	tp_vars = batadv_tp_list_find(bat_priv, orig_node->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1077) 	if (!tp_vars) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1078) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1079) 			   "Meter: trying to interrupt an already over connection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1080) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1081) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1082) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1083) 	batadv_tp_sender_shutdown(tp_vars, return_value);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1084) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1085) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1086) 	batadv_orig_node_put(orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1087) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1088) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1089) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1090)  * batadv_tp_reset_receiver_timer() - reset the receiver shutdown timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1091)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1092)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1093)  * start the receiver shutdown timer or reset it if already started
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1094)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1095) static void batadv_tp_reset_receiver_timer(struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1096) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1097) 	mod_timer(&tp_vars->timer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1098) 		  jiffies + msecs_to_jiffies(BATADV_TP_RECV_TIMEOUT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1099) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1101) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1102)  * batadv_tp_receiver_shutdown() - stop a tp meter receiver when timeout is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1103)  *  reached without received ack
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1104)  * @t: address to timer_list inside tp_vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1105)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1106) static void batadv_tp_receiver_shutdown(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1108) 	struct batadv_tp_vars *tp_vars = from_timer(tp_vars, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1109) 	struct batadv_tp_unacked *un, *safe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1110) 	struct batadv_priv *bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1112) 	bat_priv = tp_vars->bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1114) 	/* if there is recent activity rearm the timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1115) 	if (!batadv_has_timed_out(tp_vars->last_recv_time,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1116) 				  BATADV_TP_RECV_TIMEOUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1117) 		/* reset the receiver shutdown timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1118) 		batadv_tp_reset_receiver_timer(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1119) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1120) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1122) 	batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1123) 		   "Shutting down for inactivity (more than %dms) from %pM\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1124) 		   BATADV_TP_RECV_TIMEOUT, tp_vars->other_end);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1125) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1126) 	spin_lock_bh(&tp_vars->bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1127) 	hlist_del_rcu(&tp_vars->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1128) 	spin_unlock_bh(&tp_vars->bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1130) 	/* drop list reference */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1131) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1133) 	atomic_dec(&bat_priv->tp_num);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1135) 	spin_lock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1136) 	list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1137) 		list_del(&un->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1138) 		kfree(un);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1139) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1140) 	spin_unlock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1142) 	/* drop reference of timer */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1143) 	batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1146) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1147)  * batadv_tp_send_ack() - send an ACK packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1148)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1149)  * @dst: the mac address of the destination originator
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1150)  * @seq: the sequence number to ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1151)  * @timestamp: the timestamp to echo back in the ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1152)  * @session: session identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1153)  * @socket_index: local ICMP socket identifier
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1154)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1155)  * Return: 0 on success, a positive integer representing the reason of the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1156)  * failure otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1158) static int batadv_tp_send_ack(struct batadv_priv *bat_priv, const u8 *dst,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1159) 			      u32 seq, __be32 timestamp, const u8 *session,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1160) 			      int socket_index)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1162) 	struct batadv_hard_iface *primary_if = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1163) 	struct batadv_orig_node *orig_node;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1164) 	struct batadv_icmp_tp_packet *icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1165) 	struct sk_buff *skb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1166) 	int r, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1168) 	orig_node = batadv_orig_hash_find(bat_priv, dst);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1169) 	if (unlikely(!orig_node)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1170) 		ret = BATADV_TP_REASON_DST_UNREACHABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1171) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1174) 	primary_if = batadv_primary_if_get_selected(bat_priv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1175) 	if (unlikely(!primary_if)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1176) 		ret = BATADV_TP_REASON_DST_UNREACHABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1177) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1178) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1179) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1180) 	skb = netdev_alloc_skb_ip_align(NULL, sizeof(*icmp) + ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1181) 	if (unlikely(!skb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1182) 		ret = BATADV_TP_REASON_MEMORY_ERROR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1183) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1184) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1185) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1186) 	skb_reserve(skb, ETH_HLEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1187) 	icmp = skb_put(skb, sizeof(*icmp));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1188) 	icmp->packet_type = BATADV_ICMP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1189) 	icmp->version = BATADV_COMPAT_VERSION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1190) 	icmp->ttl = BATADV_TTL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1191) 	icmp->msg_type = BATADV_TP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1192) 	ether_addr_copy(icmp->dst, orig_node->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1193) 	ether_addr_copy(icmp->orig, primary_if->net_dev->dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1194) 	icmp->uid = socket_index;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1196) 	icmp->subtype = BATADV_TP_ACK;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1197) 	memcpy(icmp->session, session, sizeof(icmp->session));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1198) 	icmp->seqno = htonl(seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1199) 	icmp->timestamp = timestamp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1200) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1201) 	/* send the ack */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1202) 	r = batadv_send_skb_to_orig(skb, orig_node, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1203) 	if (unlikely(r < 0) || r == NET_XMIT_DROP) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1204) 		ret = BATADV_TP_REASON_DST_UNREACHABLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1205) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1206) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1207) 	ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1209) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1210) 	if (likely(orig_node))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1211) 		batadv_orig_node_put(orig_node);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1212) 	if (likely(primary_if))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1213) 		batadv_hardif_put(primary_if);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1215) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1216) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1217) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1218) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1219)  * batadv_tp_handle_out_of_order() - store an out of order packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1220)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1221)  * @skb: the buffer containing the received packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1222)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1223)  * Store the out of order packet in the unacked list for late processing. This
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1224)  * packets are kept in this list so that they can be ACKed at once as soon as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1225)  * all the previous packets have been received
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1226)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1227)  * Return: true if the packed has been successfully processed, false otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1228)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1229) static bool batadv_tp_handle_out_of_order(struct batadv_tp_vars *tp_vars,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1230) 					  const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1231) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1232) 	const struct batadv_icmp_tp_packet *icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1233) 	struct batadv_tp_unacked *un, *new;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1234) 	u32 payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1235) 	bool added = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1237) 	new = kmalloc(sizeof(*new), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1238) 	if (unlikely(!new))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1239) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1241) 	icmp = (struct batadv_icmp_tp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1243) 	new->seqno = ntohl(icmp->seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1244) 	payload_len = skb->len - sizeof(struct batadv_unicast_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1245) 	new->len = payload_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1246) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1247) 	spin_lock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1248) 	/* if the list is empty immediately attach this new object */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1249) 	if (list_empty(&tp_vars->unacked_list)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1250) 		list_add(&new->list, &tp_vars->unacked_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1251) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1252) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1253) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1254) 	/* otherwise loop over the list and either drop the packet because this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1255) 	 * is a duplicate or store it at the right position.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1256) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1257) 	 * The iteration is done in the reverse way because it is likely that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1258) 	 * the last received packet (the one being processed now) has a bigger
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1259) 	 * seqno than all the others already stored.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1260) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1261) 	list_for_each_entry_reverse(un, &tp_vars->unacked_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1262) 		/* check for duplicates */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1263) 		if (new->seqno == un->seqno) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1264) 			if (new->len > un->len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1265) 				un->len = new->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1266) 			kfree(new);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1267) 			added = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1268) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1271) 		/* look for the right position */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1272) 		if (batadv_seq_before(new->seqno, un->seqno))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1273) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1275) 		/* as soon as an entry having a bigger seqno is found, the new
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1276) 		 * one is attached _after_ it. In this way the list is kept in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1277) 		 * ascending order
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1278) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1279) 		list_add_tail(&new->list, &un->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1280) 		added = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1281) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1282) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1284) 	/* received packet with smallest seqno out of order; add it to front */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1285) 	if (!added)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1286) 		list_add(&new->list, &tp_vars->unacked_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1288) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1289) 	spin_unlock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1290) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1291) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1292) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1294) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1295)  * batadv_tp_ack_unordered() - update number received bytes in current stream
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1296)  *  without gaps
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1297)  * @tp_vars: the private data of the current TP meter session
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1298)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1299) static void batadv_tp_ack_unordered(struct batadv_tp_vars *tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1300) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1301) 	struct batadv_tp_unacked *un, *safe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1302) 	u32 to_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1304) 	/* go through the unacked packet list and possibly ACK them as
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1305) 	 * well
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1306) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1307) 	spin_lock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1308) 	list_for_each_entry_safe(un, safe, &tp_vars->unacked_list, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1309) 		/* the list is ordered, therefore it is possible to stop as soon
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1310) 		 * there is a gap between the last acked seqno and the seqno of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1311) 		 * the packet under inspection
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1312) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1313) 		if (batadv_seq_before(tp_vars->last_recv, un->seqno))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1314) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1316) 		to_ack = un->seqno + un->len - tp_vars->last_recv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1317) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1318) 		if (batadv_seq_before(tp_vars->last_recv, un->seqno + un->len))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1319) 			tp_vars->last_recv += to_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1321) 		list_del(&un->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1322) 		kfree(un);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1323) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1324) 	spin_unlock_bh(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1325) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1327) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1328)  * batadv_tp_init_recv() - return matching or create new receiver tp_vars
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1329)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1330)  * @icmp: received icmp tp msg
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1331)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1332)  * Return: corresponding tp_vars or NULL on errors
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1333)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1334) static struct batadv_tp_vars *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1335) batadv_tp_init_recv(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1336) 		    const struct batadv_icmp_tp_packet *icmp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1338) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1340) 	spin_lock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1341) 	tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1342) 					      icmp->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1343) 	if (tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1344) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1345) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1346) 	if (!atomic_add_unless(&bat_priv->tp_num, 1, BATADV_TP_MAX_NUM)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1347) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1348) 			   "Meter: too many ongoing sessions, aborting (RECV)\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1349) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1350) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1351) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1352) 	tp_vars = kmalloc(sizeof(*tp_vars), GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1353) 	if (!tp_vars)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1354) 		goto out_unlock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1355) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1356) 	ether_addr_copy(tp_vars->other_end, icmp->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1357) 	tp_vars->role = BATADV_TP_RECEIVER;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1358) 	memcpy(tp_vars->session, icmp->session, sizeof(tp_vars->session));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1359) 	tp_vars->last_recv = BATADV_TP_FIRST_SEQ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1360) 	tp_vars->bat_priv = bat_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1361) 	kref_init(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1362) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1363) 	spin_lock_init(&tp_vars->unacked_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1364) 	INIT_LIST_HEAD(&tp_vars->unacked_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1365) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1366) 	kref_get(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1367) 	hlist_add_head_rcu(&tp_vars->list, &bat_priv->tp_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1369) 	kref_get(&tp_vars->refcount);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1370) 	timer_setup(&tp_vars->timer, batadv_tp_receiver_shutdown, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1371) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1372) 	batadv_tp_reset_receiver_timer(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1373) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1374) out_unlock:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1375) 	spin_unlock_bh(&bat_priv->tp_list_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1377) 	return tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1378) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1379) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1380) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1381)  * batadv_tp_recv_msg() - process a single data message
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1382)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1383)  * @skb: the buffer containing the received packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1384)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1385)  * Process a received TP MSG packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1386)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1387) static void batadv_tp_recv_msg(struct batadv_priv *bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1388) 			       const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1389) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1390) 	const struct batadv_icmp_tp_packet *icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1391) 	struct batadv_tp_vars *tp_vars;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1392) 	size_t packet_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1393) 	u32 seqno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1394) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1395) 	icmp = (struct batadv_icmp_tp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1396) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1397) 	seqno = ntohl(icmp->seqno);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1398) 	/* check if this is the first seqno. This means that if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1399) 	 * first packet is lost, the tp meter does not work anymore!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1400) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1401) 	if (seqno == BATADV_TP_FIRST_SEQ) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1402) 		tp_vars = batadv_tp_init_recv(bat_priv, icmp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1403) 		if (!tp_vars) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1404) 			batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1405) 				   "Meter: seqno != BATADV_TP_FIRST_SEQ cannot initiate connection\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1406) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1407) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1408) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1409) 		tp_vars = batadv_tp_list_find_session(bat_priv, icmp->orig,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1410) 						      icmp->session);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1411) 		if (!tp_vars) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1412) 			batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1413) 				   "Unexpected packet from %pM!\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1414) 				   icmp->orig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1415) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1416) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1417) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1418) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1419) 	if (unlikely(tp_vars->role != BATADV_TP_RECEIVER)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1420) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1421) 			   "Meter: dropping packet: not expected (role=%u)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1422) 			   tp_vars->role);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1423) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1424) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1425) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1426) 	tp_vars->last_recv_time = jiffies;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1427) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1428) 	/* if the packet is a duplicate, it may be the case that an ACK has been
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1429) 	 * lost. Resend the ACK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1430) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1431) 	if (batadv_seq_before(seqno, tp_vars->last_recv))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1432) 		goto send_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1433) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1434) 	/* if the packet is out of order enqueue it */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1435) 	if (ntohl(icmp->seqno) != tp_vars->last_recv) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1436) 		/* exit immediately (and do not send any ACK) if the packet has
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1437) 		 * not been enqueued correctly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1438) 		 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1439) 		if (!batadv_tp_handle_out_of_order(tp_vars, skb))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1440) 			goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1441) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1442) 		/* send a duplicate ACK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1443) 		goto send_ack;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1444) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1445) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1446) 	/* if everything was fine count the ACKed bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1447) 	packet_size = skb->len - sizeof(struct batadv_unicast_packet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1448) 	tp_vars->last_recv += packet_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1449) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1450) 	/* check if this ordered message filled a gap.... */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1451) 	batadv_tp_ack_unordered(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1452) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1453) send_ack:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1454) 	/* send the ACK. If the received packet was out of order, the ACK that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1455) 	 * is going to be sent is a duplicate (the sender will count them and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1456) 	 * possibly enter Fast Retransmit as soon as it has reached 3)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1457) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1458) 	batadv_tp_send_ack(bat_priv, icmp->orig, tp_vars->last_recv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1459) 			   icmp->timestamp, icmp->session, icmp->uid);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1460) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1461) 	if (likely(tp_vars))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1462) 		batadv_tp_vars_put(tp_vars);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1463) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1464) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1465) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1466)  * batadv_tp_meter_recv() - main TP Meter receiving function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1467)  * @bat_priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1468)  * @skb: the buffer containing the received packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1469)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1470) void batadv_tp_meter_recv(struct batadv_priv *bat_priv, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1471) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1472) 	struct batadv_icmp_tp_packet *icmp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1473) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1474) 	icmp = (struct batadv_icmp_tp_packet *)skb->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1475) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1476) 	switch (icmp->subtype) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1477) 	case BATADV_TP_MSG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1478) 		batadv_tp_recv_msg(bat_priv, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1479) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1480) 	case BATADV_TP_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1481) 		batadv_tp_recv_ack(bat_priv, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1482) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1483) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1484) 		batadv_dbg(BATADV_DBG_TP_METER, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1485) 			   "Received unknown TP Metric packet type %u\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1486) 			   icmp->subtype);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1487) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1488) 	consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1489) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1490) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1491) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1492)  * batadv_tp_meter_init() - initialize global tp_meter structures
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1493)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1494) void __init batadv_tp_meter_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1495) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1496) 	get_random_bytes(batadv_tp_prerandom, sizeof(batadv_tp_prerandom));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1497) }