Skip to content

Commit 9132313

Browse files
bgpd: Limit size of sent NLRIs to flowspec peers (issue 18557)
See issue 18557 for detailed description of the problem. When announcing flowspec routes, frr currently sends NLRIs up to max_packet_size. However, flowspec NLRIs cannot exceed FLOWSPEC_NLRI_SIZELIMIT (or FLOWSPEC_NLRI_SIZELIMIT_EXTENDED). The proposed change reduces the size of the stream in that particular case to ensure no invalid messages are sent. Signed-off-by: Stephane Poignant <[email protected]>
1 parent 9f8027b commit 9132313

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

bgpd/bgp_updgrp.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#include "bgpd/bgp_route.h"
4242
#include "bgpd/bgp_filter.h"
4343
#include "bgpd/bgp_io.h"
44+
#include "bgpd/bgp_flowspec_private.h"
4445

4546
/********************
4647
* PRIVATE FUNCTIONS
@@ -69,6 +70,8 @@ static void sync_init(struct update_subgroup *subgrp,
6970
struct update_group *updgrp)
7071
{
7172
struct peer *peer = UPDGRP_PEER(updgrp);
73+
safi_t safi = UPDGRP_SAFI(updgrp);
74+
size_t nlri_max_length;
7275

7376
subgrp->sync =
7477
XCALLOC(MTYPE_BGP_SYNCHRONISE, sizeof(struct bgp_synchronize));
@@ -95,7 +98,20 @@ static void sync_init(struct update_subgroup *subgrp,
9598
*/
9699
subgrp->work = stream_new(peer->max_packet_size
97100
+ BGP_MAX_PACKET_SIZE_OVERFLOW);
98-
subgrp->scratch = stream_new(peer->max_packet_size);
101+
if (safi == SAFI_FLOWSPEC) {
102+
/* Issue 18557: for flowspec, need to make sure we never send
103+
* SAFIs larger than FLOWSPEC_NLRI_SIZELIMIT_EXTENDED or
104+
* FLOWSPEC_NLRI_SIZELIMIT, as those would be rejected
105+
*/
106+
nlri_max_length = (CHECK_FLAG(peer->cap, PEER_CAP_EXTENDED_MESSAGE_RCV))
107+
? FLOWSPEC_NLRI_SIZELIMIT_EXTENDED
108+
: FLOWSPEC_NLRI_SIZELIMIT;
109+
subgrp->scratch = stream_new((peer->max_packet_size <= nlri_max_length)
110+
? peer->max_packet_size
111+
: nlri_max_length);
112+
} else {
113+
subgrp->scratch = stream_new(peer->max_packet_size);
114+
}
99115
}
100116

101117
static void sync_delete(struct update_subgroup *subgrp)

0 commit comments

Comments
 (0)