From: Rafael Zalamena Date: Fri, 1 Feb 2019 11:50:06 +0000 (-0200) Subject: bfdd: generate random session identificators X-Git-Tag: 7.1_pulled~230^2~6 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=843b324ddd620e5b70bf0ac1f5d02e697e986e3d;p=matthieu%2Ffrr.git bfdd: generate random session identificators This also avoids returning `session_id == 0` which should not happen. Signed-off-by: Rafael Zalamena --- diff --git a/bfdd/bfd.c b/bfdd/bfd.c index c092b672d3..aa09d0be4a 100644 --- a/bfdd/bfd.c +++ b/bfdd/bfd.c @@ -100,9 +100,18 @@ struct bfd_session *bs_peer_find(struct bfd_peer_cfg *bpc) static uint32_t ptm_bfd_gen_ID(void) { - static uint32_t sessionID = 1; + uint32_t session_id; - return (sessionID++); + /* + * RFC 5880, Section 6.8.1. recommends that we should generate + * random session identification numbers. + */ + do { + session_id = ((random() << 16) & 0xFFFF0000) + | (random() & 0x0000FFFF); + } while (session_id == 0 || bfd_id_lookup(session_id) != NULL); + + return session_id; } void ptm_bfd_start_xmt_timer(struct bfd_session *bfd, bool is_echo)