summaryrefslogtreecommitdiff
path: root/bgpd/bgp_open.c
diff options
context:
space:
mode:
authorDonatas Abraitis <donatas@opensourcerouting.org>2024-01-16 14:37:51 +0200
committerDonatas Abraitis <donatas@opensourcerouting.org>2024-01-16 14:37:51 +0200
commit722195d4eca0279093140727fe4b5d3143a827b7 (patch)
tree735d40f9c25ead2099f91ae178cbb5a07938bda4 /bgpd/bgp_open.c
parent0c74220c6e841a3ca0c8534b34a138d5d05a1ebb (diff)
bgpd: Set role capability received flag only if parsed correctly
If we receive a malformed packet, we might end-up with a bad state. Signed-off-by: Donatas Abraitis <donatas@opensourcerouting.org>
Diffstat (limited to 'bgpd/bgp_open.c')
-rw-r--r--bgpd/bgp_open.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index cb13801745..ac7fbc215b 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -887,14 +887,16 @@ static int bgp_capability_hostname(struct peer *peer,
static int bgp_capability_role(struct peer *peer, struct capability_header *hdr)
{
- SET_FLAG(peer->cap, PEER_CAP_ROLE_RCV);
if (hdr->length != CAPABILITY_CODE_ROLE_LEN) {
flog_warn(EC_BGP_CAPABILITY_INVALID_LENGTH,
"Role: Received invalid length %d", hdr->length);
return -1;
}
+
uint8_t role = stream_getc(BGP_INPUT(peer));
+ SET_FLAG(peer->cap, PEER_CAP_ROLE_RCV);
+
peer->remote_role = role;
return 0;
}