Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cf2d72ec authored by Simon Wunderlich's avatar Simon Wunderlich Committed by Greg Kroah-Hartman
Browse files

Staging: batman-adv: 32bit sequence number and TTL for broadcasts



This patch changes the sequence number range from 8 or 16 bit to 32 bit.
This should avoid problems with the sequence number sliding window algorithm
which we had seen in the past for broadcast floods or malicious packet
injections. We can not assure 100% security with this patch, but it is quite
an improvement over the old 16 bit sequence numbers:

 * expected window size can be increased (4096 -> 65536)
 * 64k packets in the right order would now be needed to cause a loop,
   which seems practically impossible.

Furthermore, a TTL field has been added to the broadcast packet type, just to
make sure.

These changes required to increase the compatibility level once again.

Signed-off-by: default avatarSimon Wunderlich <siwu@hrz.tu-chemnitz.de>
[sven.eckelmann@gmx.de: Change atomic64_* back to atomic_*, Rework on
top of current version]
Signed-off-by: default avatarSven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 6856ba1f
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -252,9 +252,9 @@ void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
	while (aggregated_packet(buff_pos, packet_len,
				 batman_packet->num_hna)) {

		/* network to host order for our 16bit seqno, and the
		/* network to host order for our 32bit seqno, and the
		   orig_interval. */
		batman_packet->seqno = ntohs(batman_packet->seqno);
		batman_packet->seqno = ntohl(batman_packet->seqno);

		hna_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
		receive_bat_packet(ethhdr, batman_packet,
+4 −4
Original line number Diff line number Diff line
@@ -24,10 +24,10 @@

/* returns true if the corresponding bit in the given seq_bits indicates true
 * and curr_seqno is within range of last_seqno */
uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint16_t last_seqno,
		       uint16_t curr_seqno)
uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno,
		       uint32_t curr_seqno)
{
	int16_t diff, word_offset, word_num;
	int32_t diff, word_offset, word_num;

	diff = last_seqno - curr_seqno;
	if (diff < 0 || diff >= TQ_LOCAL_WINDOW_SIZE) {
@@ -125,7 +125,7 @@ static void bit_reset_window(TYPE_OF_WORD *seq_bits)
 *  1 if the window was moved (either new or very old)
 *  0 if the window was not moved/shifted.
 */
char bit_get_packet(TYPE_OF_WORD *seq_bits, int16_t seq_num_diff,
char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
		    int8_t set_mark)
{
	/* sequence number is slightly older. We already got a sequence number
+3 −3
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@

/* returns true if the corresponding bit in the given seq_bits indicates true
 * and curr_seqno is within range of last_seqno */
uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint16_t last_seqno,
					   uint16_t curr_seqno);
uint8_t get_bit_status(TYPE_OF_WORD *seq_bits, uint32_t last_seqno,
					   uint32_t curr_seqno);

/* turn corresponding bit on, so we can remember that we got the packet */
void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n);
@@ -35,7 +35,7 @@ void bit_mark(TYPE_OF_WORD *seq_bits, int32_t n);

/* receive and process one packet, returns 1 if received seq_num is considered
 * new, 0 if old  */
char bit_get_packet(TYPE_OF_WORD *seq_bits, int16_t seq_num_diff,
char bit_get_packet(TYPE_OF_WORD *seq_bits, int32_t seq_num_diff,
					int8_t set_mark);

/* count the hamming weight, how many good packets did we receive? */
+1 −1
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@
#define MAX_AGGREGATION_MS 100

#define RESET_PROTECTION_MS 30000
#define EXPECTED_SEQNO_RANGE	4096
#define EXPECTED_SEQNO_RANGE	65536
/* don't reset again within 30 seconds */

#define MODULE_INACTIVE 0
+5 −4
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@
#define BAT_VIS       0x05

/* this file is included by batctl which needs these defines */
#define COMPAT_VERSION 8
#define COMPAT_VERSION 11
#define DIRECTLINK 0x40
#define VIS_SERVER 0x20

@@ -48,7 +48,7 @@ struct batman_packet {
	uint8_t  version;  /* batman version field */
	uint8_t  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
	uint8_t  tq;
	uint16_t seqno;
	uint32_t seqno;
	uint8_t  orig[6];
	uint8_t  prev_sender[6];
	uint8_t  ttl;
@@ -79,15 +79,16 @@ struct bcast_packet {
	uint8_t  packet_type;
	uint8_t  version;  /* batman version field */
	uint8_t  orig[6];
	uint16_t seqno;
	uint8_t  ttl;
	uint32_t seqno;
} __attribute__((packed));

struct vis_packet {
	uint8_t  packet_type;
	uint8_t  version;        /* batman version field */
	uint8_t  vis_type;	 /* which type of vis-participant sent this? */
	uint8_t  seqno;		 /* sequence number */
	uint8_t  entries;	 /* number of entries behind this struct */
	uint32_t seqno;		 /* sequence number */
	uint8_t  ttl;		 /* TTL */
	uint8_t  vis_orig[6];	 /* originator that informs about its
				  * neighbors */
Loading