summaryrefslogtreecommitdiff
path: root/proto/babel
diff options
context:
space:
mode:
authorToke Høiland-Jørgensen <toke@toke.dk>2023-01-30 23:36:39 +0100
committerOndrej Zajicek <santiago@crfreenet.org>2023-01-30 23:36:39 +0100
commit3e7e4a71868bc519aacc0eb785471b46fc345a5c (patch)
treef6ae8ac0f57c6aad4b9ad53c47d71425cba3c82c /proto/babel
parent72230d3ca37d34cafa0442c23f83121ae1fc41be (diff)
Babel: Fix missing modulo comparison of seqnos
Juliusz noticed there were a couple of places we were doing straight inequality comparisons of seqnos in Babel. This is wrong because seqnos can wrap: so we need to use the modulo-64k comparison function for these cases as well. Introduce a strict-inequality version of the modulo-comparison for this purpose.
Diffstat (limited to 'proto/babel')
-rw-r--r--proto/babel/babel.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/proto/babel/babel.c b/proto/babel/babel.c
index ff8b6b52..a20bd724 100644
--- a/proto/babel/babel.c
+++ b/proto/babel/babel.c
@@ -49,6 +49,10 @@
static inline int ge_mod64k(uint a, uint b)
{ return (u16)(a - b) < 0x8000; }
+/* Strict inequality version of the above */
+static inline int gt_mod64k(uint a, uint b)
+{ return ge_mod64k(a, b) && a != b; }
+
static void babel_expire_requests(struct babel_proto *p, struct babel_entry *e);
static void babel_select_route(struct babel_proto *p, struct babel_entry *e, struct babel_route *mod);
static inline void babel_announce_retraction(struct babel_proto *p, struct babel_entry *e);
@@ -559,7 +563,7 @@ babel_is_feasible(struct babel_source *s, u16 seqno, u16 metric)
{
return !s ||
(metric == BABEL_INFINITY) ||
- (seqno > s->seqno) ||
+ gt_mod64k(seqno, s->seqno) ||
((seqno == s->seqno) && (metric < s->metric));
}
@@ -1013,7 +1017,7 @@ babel_send_update_(struct babel_iface *ifa, btime changed, struct fib *rtable)
struct babel_source *s = babel_get_source(p, e, e->router_id);
s->expires = current_time() + BABEL_GARBAGE_INTERVAL;
- if ((msg.update.seqno > s->seqno) ||
+ if (gt_mod64k(msg.update.seqno, s->seqno) ||
((msg.update.seqno == s->seqno) && (msg.update.metric < s->metric)))
{
s->seqno = msg.update.seqno;