1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) B.A.T.M.A.N. contributors:
4 * Simon Wunderlich, Marek Lindner
10 #include <linux/bitmap.h>
14 /* shift the packet array by n places. */
15 static void batadv_bitmap_shift_left(unsigned long *seq_bits, s32 n)
17 if (n <= 0 || n >= BATADV_TQ_LOCAL_WINDOW_SIZE)
20 bitmap_shift_left(seq_bits, seq_bits, n, BATADV_TQ_LOCAL_WINDOW_SIZE);
24 * batadv_bit_get_packet() - receive and process one packet within the sequence
26 * @priv: the bat priv with all the soft interface information
27 * @seq_bits: pointer to the sequence number receive packet
28 * @seq_num_diff: difference between the current/received sequence number and
29 * the last sequence number
30 * @set_mark: whether this packet should be marked in seq_bits
32 * Return: true if the window was moved (either new or very old),
33 * false if the window was not moved/shifted.
35 bool batadv_bit_get_packet(void *priv, unsigned long *seq_bits,
36 s32 seq_num_diff, int set_mark)
38 struct batadv_priv *bat_priv = priv;
40 /* sequence number is slightly older. We already got a sequence number
41 * higher than this one, so we just mark it.
43 if (seq_num_diff <= 0 && seq_num_diff > -BATADV_TQ_LOCAL_WINDOW_SIZE) {
45 batadv_set_bit(seq_bits, -seq_num_diff);
49 /* sequence number is slightly newer, so we shift the window and
50 * set the mark if required
52 if (seq_num_diff > 0 && seq_num_diff < BATADV_TQ_LOCAL_WINDOW_SIZE) {
53 batadv_bitmap_shift_left(seq_bits, seq_num_diff);
56 batadv_set_bit(seq_bits, 0);
60 /* sequence number is much newer, probably missed a lot of packets */
61 if (seq_num_diff >= BATADV_TQ_LOCAL_WINDOW_SIZE &&
62 seq_num_diff < BATADV_EXPECTED_SEQNO_RANGE) {
63 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
64 "We missed a lot of packets (%i) !\n",
66 bitmap_zero(seq_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
68 batadv_set_bit(seq_bits, 0);
72 /* received a much older packet. The other host either restarted
73 * or the old packet got delayed somewhere in the network. The
74 * packet should be dropped without calling this function if the
75 * seqno window is protected.
77 * seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE
79 * seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE
81 batadv_dbg(BATADV_DBG_BATMAN, bat_priv,
82 "Other host probably restarted!\n");
84 bitmap_zero(seq_bits, BATADV_TQ_LOCAL_WINDOW_SIZE);
86 batadv_set_bit(seq_bits, 0);