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) 2006-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)  * Simon Wunderlich, Marek Lindner
^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 "bitarray.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/bitmap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include "log.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) /* shift the packet array by n places. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) 	if (n <= 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) 	bitmap_shift_left(seq_bits, seq_bits, n, BATADV_TQ_LOCAL_WINDOW_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)  * batadv_bit_get_packet() - receive and process one packet within the sequence
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)  *  number window
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)  * @priv: the bat priv with all the soft interface information
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)  * @seq_bits: pointer to the sequence number receive packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)  * @seq_num_diff: difference between the current/received sequence number and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)  *  the last sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)  * @set_mark: whether this packet should be marked in seq_bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32)  * Return: true if the window was moved (either new or very old),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)  *  false if the window was not moved/shifted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) bool batadv_bit_get_packet(void *priv, unsigned long *seq_bits,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 			   s32 seq_num_diff, int set_mark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	struct batadv_priv *bat_priv = priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 	/* sequence number is slightly older. We already got a sequence number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	 * higher than this one, so we just mark it.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 	if (seq_num_diff <= 0 && seq_num_diff > -BATADV_TQ_LOCAL_WINDOW_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 		if (set_mark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) 			batadv_set_bit(seq_bits, -seq_num_diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) 		return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) 	/* sequence number is slightly newer, so we shift the window and
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) 	 * set the mark if required
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) 	if (seq_num_diff > 0 && seq_num_diff < BATADV_TQ_LOCAL_WINDOW_SIZE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) 		batadv_bitmap_shift_left(seq_bits, seq_num_diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) 		if (set_mark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) 			batadv_set_bit(seq_bits, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) 	/* sequence number is much newer, probably missed a lot of packets */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) 	if (seq_num_diff >= BATADV_TQ_LOCAL_WINDOW_SIZE &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) 	    seq_num_diff < BATADV_EXPECTED_SEQNO_RANGE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) 		batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) 			   "We missed a lot of packets (%i) !\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) 			   seq_num_diff - 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) 		bitmap_zero(seq_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) 		if (set_mark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) 			batadv_set_bit(seq_bits, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) 		return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) 	/* received a much older packet. The other host either restarted
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) 	 * or the old packet got delayed somewhere in the network. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) 	 * packet should be dropped without calling this function if the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) 	 * seqno window is protected.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) 	 *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) 	 * seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) 	 * or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) 	 * seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) 	batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) 		   "Other host probably restarted!\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) 	bitmap_zero(seq_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) 	if (set_mark)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) 		batadv_set_bit(seq_bits, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) 	return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }