Skip to content

Commit 7ba8895

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, the maximum size of flowspec NLRIs is limited to a much lower value here. Because of this, past as certain amount of flowspec routes, the peer will drop the session. The proposed change reduces the size of the buffer for the NLRI to the maximum value between nlri_max_length and either FLOWSPEC_NLRI_SIZELIMIT_EXTENDED (if the peer advertised support for extended messages) or FLOWSPEC_NLRI_SIZELIMIT (if it did not). Signed-off-by: Stephane Poignant <[email protected]>
1 parent 9f8027b commit 7ba8895

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Diff for: bgpd/bgp_updgrp.c

+17-1
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)