Skip to content

Commit 81ece63

Browse files
committed
bgpd: Set TCP min MSS per listener
Set only if at least one peer is in passive mode. Signed-off-by: Donatas Abraitis <[email protected]>
1 parent 84e14c1 commit 81ece63

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

bgpd/bgp_network.c

+47
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,53 @@ static int bgp_get_instance_for_inc_conn(int sock, struct bgp **bgp_inst)
334334
#endif
335335
}
336336

337+
int bgp_tcp_mss_set(struct peer *peer)
338+
{
339+
struct listnode *node;
340+
int ret = 0;
341+
struct bgp_listener *listener;
342+
uint32_t min_mss = 0;
343+
struct peer *p;
344+
345+
for (ALL_LIST_ELEMENTS_RO(peer->bgp->peer, node, p)) {
346+
if (!CHECK_FLAG(p->flags, PEER_FLAG_TCP_MSS))
347+
continue;
348+
349+
if (!p->tcp_mss)
350+
continue;
351+
352+
if (!min_mss)
353+
min_mss = p->tcp_mss;
354+
355+
min_mss = MIN(min_mss, p->tcp_mss);
356+
}
357+
358+
frr_with_privs(&bgpd_privs) {
359+
for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener)) {
360+
if (listener->su.sa.sa_family !=
361+
peer->connection->su.sa.sa_family)
362+
continue;
363+
364+
if (!listener->bgp) {
365+
if (peer->bgp->vrf_id != VRF_DEFAULT)
366+
continue;
367+
} else if (listener->bgp != peer->bgp)
368+
continue;
369+
370+
/* Set TCP MSS per listener only if there is at least
371+
* one peer that is in passive mode. Otherwise, TCP MSS
372+
* is set per socket via bgp_connect().
373+
*/
374+
if (CHECK_FLAG(peer->flags, PEER_FLAG_PASSIVE))
375+
sockopt_tcp_mss_set(listener->fd, min_mss);
376+
377+
break;
378+
}
379+
}
380+
381+
return ret;
382+
}
383+
337384
static void bgp_socket_set_buffer_size(const int fd)
338385
{
339386
if (getsockopt_so_sendbuf(fd) < (int)bm->socket_buffer)

bgpd/bgp_network.h

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ extern int bgp_md5_unset_prefix(struct bgp *bgp, struct prefix *p);
3030
extern int bgp_md5_set(struct peer_connection *connection);
3131
extern int bgp_md5_unset(struct peer_connection *connection);
3232
extern int bgp_set_socket_ttl(struct peer_connection *connection);
33+
extern int bgp_tcp_mss_set(struct peer *peer);
3334
extern int bgp_update_address(struct interface *ifp, const union sockunion *dst,
3435
union sockunion *addr);
3536

bgpd/bgpd.c

+2
Original file line numberDiff line numberDiff line change
@@ -5779,6 +5779,7 @@ void peer_tcp_mss_set(struct peer *peer, uint32_t tcp_mss)
57795779
{
57805780
peer->tcp_mss = tcp_mss;
57815781
SET_FLAG(peer->flags, PEER_FLAG_TCP_MSS);
5782+
bgp_tcp_mss_set(peer);
57825783
}
57835784

57845785
/* Reset the TCP-MSS value in the peer structure,
@@ -5789,6 +5790,7 @@ void peer_tcp_mss_unset(struct peer *peer)
57895790
{
57905791
UNSET_FLAG(peer->flags, PEER_FLAG_TCP_MSS);
57915792
peer->tcp_mss = 0;
5793+
bgp_tcp_mss_set(peer);
57925794
}
57935795

57945796
/*

0 commit comments

Comments
 (0)