From 13896bde30bf340ca15d2cc9092569e1bbbfd5f2 Mon Sep 17 00:00:00 2001 From: Eugene Bogomazov Date: Wed, 22 Jun 2022 16:12:28 +0300 Subject: [PATCH] bgpd: simplify code fragment for RFC 9234 Roles cannot be applied to iBGP sessions, so we can move this check to the top of the role configuration method. Thus, we simplify the internal logic of branching. Signed-off-by: Eugene Bogomazov --- bgpd/bgpd.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 91843160ed..4e90b02f56 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -4920,6 +4920,9 @@ int peer_ebgp_multihop_unset(struct peer *peer) /* Set Open Policy Role and check its correctness */ int peer_role_set(struct peer *peer, uint8_t role, bool strict_mode) { + if (peer->sort != BGP_PEER_EBGP) + return BGP_ERR_INVALID_INTERNAL_ROLE; + if (peer->local_role == role) { if (CHECK_FLAG(peer->flags, PEER_FLAG_STRICT_MODE) && !strict_mode) @@ -4934,8 +4937,6 @@ int peer_role_set(struct peer *peer, uint8_t role, bool strict_mode) bgp_session_reset(peer); } } else { - if (peer->sort != BGP_PEER_EBGP) - return BGP_ERR_INVALID_INTERNAL_ROLE; peer->local_role = role; if (strict_mode) SET_FLAG(peer->flags, PEER_FLAG_STRICT_MODE); -- 2.39.5