Skip to content

Commit

Permalink
Staging: batman-adv: Fixing wrap-around bug in vis
Browse files Browse the repository at this point in the history
When the seqno for a vis packet had a wrap around from i.e. 255 to 0,
add_packet() would falsely claim the older packet with the seqno 255 as
newer as the one with the seqno of 0 and would therefore ignore the new
packet. This happens with all following vis packets until the old vis
packet expires after 180 seconds timeout. This patch fixes this issue
and gets rid of these highly undesired 3min. breaks for the vis-server.

Signed-off-by: Linus Lüssing <linus.luessing@web.de>
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Cc: stable <stable@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Linus Lüssing authored and Greg Kroah-Hartman committed May 11, 2010
1 parent f6497e3 commit ea4ceb1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion drivers/staging/batman-adv/vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,22 @@
#include "hard-interface.h"
#include "hash.h"

/* Returns the smallest signed integer in two's complement with the sizeof x */
#define smallest_signed_int(x) (1u << (7u + 8u * (sizeof(x) - 1u)))

/* Checks if a sequence number x is a predecessor/successor of y.
they handle overflows/underflows and can correctly check for a
predecessor/successor unless the variable sequence number has grown by
more then 2**(bitwidth(x)-1)-1.
This means that for a uint8_t with the maximum value 255, it would think:
* when adding nothing - it is neither a predecessor nor a successor
* before adding more than 127 to the starting value - it is a predecessor,
* when adding 128 - it is neither a predecessor nor a successor,
* after adding more than 127 to the starting value - it is a successor */
#define seq_before(x, y) ({typeof(x) _dummy = (x - y); \
_dummy > smallest_signed_int(_dummy); })
#define seq_after(x, y) seq_before(y, x)

struct hashtable_t *vis_hash;
DEFINE_SPINLOCK(vis_hash_lock);
static DEFINE_SPINLOCK(recv_list_lock);
Expand Down Expand Up @@ -212,7 +228,7 @@ static struct vis_info *add_packet(struct vis_packet *vis_packet,
old_info = hash_find(vis_hash, &search_elem);

if (old_info != NULL) {
if (vis_packet->seqno - old_info->packet.seqno <= 0) {
if (!seq_after(vis_packet->seqno, old_info->packet.seqno)) {
if (old_info->packet.seqno == vis_packet->seqno) {
recv_list_add(&old_info->recv_list,
vis_packet->sender_orig);
Expand Down

0 comments on commit ea4ceb1

Please sign in to comment.