1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2006-2018 B.A.T.M.A.N. contributors:
4 * Simon Wunderlich, Marek Lindner
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, see <http://www.gnu.org/licenses/>.
22 #include <linux/bitmap.h>
26 /* shift the packet array by n places. */
27 static void batadv_bitmap_shift_left(unsigned long *seq_bits
, s32 n
)
29 if (n
<= 0 || n
>= BATADV_TQ_LOCAL_WINDOW_SIZE
)
32 bitmap_shift_left(seq_bits
, seq_bits
, n
, BATADV_TQ_LOCAL_WINDOW_SIZE
);
36 * batadv_bit_get_packet() - receive and process one packet within the sequence
38 * @priv: the bat priv with all the soft interface information
39 * @seq_bits: pointer to the sequence number receive packet
40 * @seq_num_diff: difference between the current/received sequence number and
41 * the last sequence number
42 * @set_mark: whether this packet should be marked in seq_bits
44 * Return: true if the window was moved (either new or very old),
45 * false if the window was not moved/shifted.
47 bool batadv_bit_get_packet(void *priv
, unsigned long *seq_bits
,
48 s32 seq_num_diff
, int set_mark
)
50 struct batadv_priv
*bat_priv
= priv
;
52 /* sequence number is slightly older. We already got a sequence number
53 * higher than this one, so we just mark it.
55 if (seq_num_diff
<= 0 && seq_num_diff
> -BATADV_TQ_LOCAL_WINDOW_SIZE
) {
57 batadv_set_bit(seq_bits
, -seq_num_diff
);
61 /* sequence number is slightly newer, so we shift the window and
62 * set the mark if required
64 if (seq_num_diff
> 0 && seq_num_diff
< BATADV_TQ_LOCAL_WINDOW_SIZE
) {
65 batadv_bitmap_shift_left(seq_bits
, seq_num_diff
);
68 batadv_set_bit(seq_bits
, 0);
72 /* sequence number is much newer, probably missed a lot of packets */
73 if (seq_num_diff
>= BATADV_TQ_LOCAL_WINDOW_SIZE
&&
74 seq_num_diff
< BATADV_EXPECTED_SEQNO_RANGE
) {
75 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
76 "We missed a lot of packets (%i) !\n",
78 bitmap_zero(seq_bits
, BATADV_TQ_LOCAL_WINDOW_SIZE
);
80 batadv_set_bit(seq_bits
, 0);
84 /* received a much older packet. The other host either restarted
85 * or the old packet got delayed somewhere in the network. The
86 * packet should be dropped without calling this function if the
87 * seqno window is protected.
89 * seq_num_diff <= -BATADV_TQ_LOCAL_WINDOW_SIZE
91 * seq_num_diff >= BATADV_EXPECTED_SEQNO_RANGE
93 batadv_dbg(BATADV_DBG_BATMAN
, bat_priv
,
94 "Other host probably restarted!\n");
96 bitmap_zero(seq_bits
, BATADV_TQ_LOCAL_WINDOW_SIZE
);
98 batadv_set_bit(seq_bits
, 0);