mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-06 23:29:36 +00:00
Merge pull request #8581 from qlyoung/bgp-fix-last-reset-buffer-size
bgpd: rework BGP_MAX_PACKET_SIZE & friends
This commit is contained in:
commit
03d39784e7
@ -389,7 +389,8 @@ bgp_dump_route_node_record(int afi, struct bgp_dest *dest,
|
|||||||
bgp_dump_routes_attr(obuf, path->attr, p);
|
bgp_dump_routes_attr(obuf, path->attr, p);
|
||||||
|
|
||||||
cur_endp = stream_get_endp(obuf);
|
cur_endp = stream_get_endp(obuf);
|
||||||
if (cur_endp > BGP_MAX_PACKET_SIZE + BGP_DUMP_MSG_HEADER
|
if (cur_endp > BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE
|
||||||
|
+ BGP_DUMP_MSG_HEADER
|
||||||
+ BGP_DUMP_HEADER_SIZE) {
|
+ BGP_DUMP_HEADER_SIZE) {
|
||||||
stream_set_endp(obuf, endp);
|
stream_set_endp(obuf, endp);
|
||||||
break;
|
break;
|
||||||
@ -868,8 +869,8 @@ void bgp_dump_init(void)
|
|||||||
memset(&bgp_dump_routes, 0, sizeof(struct bgp_dump));
|
memset(&bgp_dump_routes, 0, sizeof(struct bgp_dump));
|
||||||
|
|
||||||
bgp_dump_obuf =
|
bgp_dump_obuf =
|
||||||
stream_new((BGP_MAX_PACKET_SIZE << 1) + BGP_DUMP_MSG_HEADER
|
stream_new((BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE * 2)
|
||||||
+ BGP_DUMP_HEADER_SIZE);
|
+ BGP_DUMP_MSG_HEADER + BGP_DUMP_HEADER_SIZE);
|
||||||
|
|
||||||
install_node(&bgp_dump_node);
|
install_node(&bgp_dump_node);
|
||||||
|
|
||||||
|
@ -1122,7 +1122,7 @@ int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability)
|
|||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
uint8_t *error;
|
uint8_t *error;
|
||||||
uint8_t error_data[BGP_MAX_PACKET_SIZE];
|
uint8_t error_data[BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE];
|
||||||
struct stream *s = BGP_INPUT(peer);
|
struct stream *s = BGP_INPUT(peer);
|
||||||
size_t end = stream_get_getp(s) + length;
|
size_t end = stream_get_getp(s) + length;
|
||||||
|
|
||||||
@ -1217,8 +1217,8 @@ int bgp_open_option_parse(struct peer *peer, uint8_t length, int *mp_capability)
|
|||||||
/* Extended Message Support */
|
/* Extended Message Support */
|
||||||
peer->max_packet_size =
|
peer->max_packet_size =
|
||||||
CHECK_FLAG(peer->cap, PEER_CAP_EXTENDED_MESSAGE_RCV)
|
CHECK_FLAG(peer->cap, PEER_CAP_EXTENDED_MESSAGE_RCV)
|
||||||
? BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE
|
? BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE
|
||||||
: BGP_MAX_PACKET_SIZE;
|
: BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE;
|
||||||
|
|
||||||
/* Check there are no common AFI/SAFIs and send Unsupported Capability
|
/* Check there are no common AFI/SAFIs and send Unsupported Capability
|
||||||
error. */
|
error. */
|
||||||
|
@ -545,7 +545,7 @@ void bgp_keepalive_send(struct peer *peer)
|
|||||||
{
|
{
|
||||||
struct stream *s;
|
struct stream *s;
|
||||||
|
|
||||||
s = stream_new(BGP_MAX_PACKET_SIZE);
|
s = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);
|
||||||
|
|
||||||
/* Make keepalive packet. */
|
/* Make keepalive packet. */
|
||||||
bgp_packet_set_marker(s, BGP_MSG_KEEPALIVE);
|
bgp_packet_set_marker(s, BGP_MSG_KEEPALIVE);
|
||||||
@ -586,7 +586,7 @@ void bgp_open_send(struct peer *peer)
|
|||||||
else
|
else
|
||||||
local_as = peer->local_as;
|
local_as = peer->local_as;
|
||||||
|
|
||||||
s = stream_new(BGP_MAX_PACKET_SIZE);
|
s = stream_new(BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE);
|
||||||
|
|
||||||
/* Make open packet. */
|
/* Make open packet. */
|
||||||
bgp_packet_set_marker(s, BGP_MSG_OPEN);
|
bgp_packet_set_marker(s, BGP_MSG_OPEN);
|
||||||
@ -752,7 +752,7 @@ void bgp_notify_send_with_data(struct peer *peer, uint8_t code,
|
|||||||
*/
|
*/
|
||||||
if (peer->curr) {
|
if (peer->curr) {
|
||||||
size_t packetsize = stream_get_endp(peer->curr);
|
size_t packetsize = stream_get_endp(peer->curr);
|
||||||
assert(packetsize <= sizeof(peer->last_reset_cause));
|
assert(packetsize <= peer->max_packet_size);
|
||||||
memcpy(peer->last_reset_cause, peer->curr->data, packetsize);
|
memcpy(peer->last_reset_cause, peer->curr->data, packetsize);
|
||||||
peer->last_reset_cause_size = packetsize;
|
peer->last_reset_cause_size = packetsize;
|
||||||
}
|
}
|
||||||
|
14
bgpd/bgpd.c
14
bgpd/bgpd.c
@ -1349,7 +1349,7 @@ struct peer *peer_new(struct bgp *bgp)
|
|||||||
peer->bgp = bgp_lock(bgp);
|
peer->bgp = bgp_lock(bgp);
|
||||||
peer = peer_lock(peer); /* initial reference */
|
peer = peer_lock(peer); /* initial reference */
|
||||||
peer->password = NULL;
|
peer->password = NULL;
|
||||||
peer->max_packet_size = BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE;
|
peer->max_packet_size = BGP_MAX_PACKET_SIZE;
|
||||||
|
|
||||||
/* Set default flags. */
|
/* Set default flags. */
|
||||||
FOREACH_AFI_SAFI (afi, safi) {
|
FOREACH_AFI_SAFI (afi, safi) {
|
||||||
@ -1384,7 +1384,7 @@ struct peer *peer_new(struct bgp *bgp)
|
|||||||
|
|
||||||
/* We use a larger buffer for peer->obuf_work in the event that:
|
/* We use a larger buffer for peer->obuf_work in the event that:
|
||||||
* - We RX a BGP_UPDATE where the attributes alone are just
|
* - We RX a BGP_UPDATE where the attributes alone are just
|
||||||
* under BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE.
|
* under BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE.
|
||||||
* - The user configures an outbound route-map that does many as-path
|
* - The user configures an outbound route-map that does many as-path
|
||||||
* prepends or adds many communities. At most they can have
|
* prepends or adds many communities. At most they can have
|
||||||
* CMD_ARGC_MAX args in a route-map so there is a finite limit on how
|
* CMD_ARGC_MAX args in a route-map so there is a finite limit on how
|
||||||
@ -1394,12 +1394,12 @@ struct peer *peer_new(struct bgp *bgp)
|
|||||||
* bounds checking for every single attribute as we construct an
|
* bounds checking for every single attribute as we construct an
|
||||||
* UPDATE.
|
* UPDATE.
|
||||||
*/
|
*/
|
||||||
peer->obuf_work = stream_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE
|
peer->obuf_work =
|
||||||
+ BGP_MAX_PACKET_SIZE_OVERFLOW);
|
stream_new(BGP_MAX_PACKET_SIZE + BGP_MAX_PACKET_SIZE_OVERFLOW);
|
||||||
peer->ibuf_work = ringbuf_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE
|
peer->ibuf_work =
|
||||||
* BGP_READ_PACKET_MAX);
|
ringbuf_new(BGP_MAX_PACKET_SIZE * BGP_READ_PACKET_MAX);
|
||||||
|
|
||||||
peer->scratch = stream_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE);
|
peer->scratch = stream_new(BGP_MAX_PACKET_SIZE);
|
||||||
|
|
||||||
bgp_sync_init(peer);
|
bgp_sync_init(peer);
|
||||||
|
|
||||||
|
@ -866,8 +866,9 @@ typedef enum {
|
|||||||
/* BGP message header and packet size. */
|
/* BGP message header and packet size. */
|
||||||
#define BGP_MARKER_SIZE 16
|
#define BGP_MARKER_SIZE 16
|
||||||
#define BGP_HEADER_SIZE 19
|
#define BGP_HEADER_SIZE 19
|
||||||
#define BGP_MAX_PACKET_SIZE 4096
|
#define BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE 4096
|
||||||
#define BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE 65535
|
#define BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE 65535
|
||||||
|
#define BGP_MAX_PACKET_SIZE BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE
|
||||||
#define BGP_MAX_PACKET_SIZE_OVERFLOW 1024
|
#define BGP_MAX_PACKET_SIZE_OVERFLOW 1024
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1049,7 +1050,7 @@ struct peer {
|
|||||||
struct stream_fifo *obuf; // packets waiting to be written
|
struct stream_fifo *obuf; // packets waiting to be written
|
||||||
|
|
||||||
/* used as a block to deposit raw wire data to */
|
/* used as a block to deposit raw wire data to */
|
||||||
uint8_t ibuf_scratch[BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE
|
uint8_t ibuf_scratch[BGP_EXTENDED_MESSAGE_MAX_PACKET_SIZE
|
||||||
* BGP_READ_PACKET_MAX];
|
* BGP_READ_PACKET_MAX];
|
||||||
struct ringbuf *ibuf_work; // WiP buffer used by bgp_read() only
|
struct ringbuf *ibuf_work; // WiP buffer used by bgp_read() only
|
||||||
struct stream *obuf_work; // WiP buffer used to construct packets
|
struct stream *obuf_work; // WiP buffer used to construct packets
|
||||||
|
@ -892,7 +892,7 @@ static int validate(struct aspath *as, const struct test_spec *sp)
|
|||||||
|
|
||||||
/* Excercise AS4 parsing a bit, with a dogfood test */
|
/* Excercise AS4 parsing a bit, with a dogfood test */
|
||||||
if (!s)
|
if (!s)
|
||||||
s = stream_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE);
|
s = stream_new(BGP_MAX_PACKET_SIZE);
|
||||||
bytes4 = aspath_put(s, as, 1);
|
bytes4 = aspath_put(s, as, 1);
|
||||||
as4 = make_aspath(STREAM_DATA(s), bytes4, 1);
|
as4 = make_aspath(STREAM_DATA(s), bytes4, 1);
|
||||||
|
|
||||||
@ -1201,13 +1201,13 @@ static int handle_attr_test(struct aspath_tests *t)
|
|||||||
|
|
||||||
asp = make_aspath(t->segment->asdata, t->segment->len, 0);
|
asp = make_aspath(t->segment->asdata, t->segment->len, 0);
|
||||||
|
|
||||||
peer.curr = stream_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE);
|
peer.curr = stream_new(BGP_MAX_PACKET_SIZE);
|
||||||
peer.obuf = stream_fifo_new();
|
peer.obuf = stream_fifo_new();
|
||||||
peer.bgp = &bgp;
|
peer.bgp = &bgp;
|
||||||
peer.host = (char *)"none";
|
peer.host = (char *)"none";
|
||||||
peer.fd = -1;
|
peer.fd = -1;
|
||||||
peer.cap = t->cap;
|
peer.cap = t->cap;
|
||||||
peer.max_packet_size = BGP_MAX_PACKET_SIZE;
|
peer.max_packet_size = BGP_STANDARD_MESSAGE_MAX_PACKET_SIZE;
|
||||||
|
|
||||||
stream_write(peer.curr, t->attrheader, t->len);
|
stream_write(peer.curr, t->attrheader, t->len);
|
||||||
datalen = aspath_put(peer.curr, asp, t->as4 == AS4_DATA);
|
datalen = aspath_put(peer.curr, asp, t->as4 == AS4_DATA);
|
||||||
|
@ -935,7 +935,7 @@ int main(void)
|
|||||||
peer->afc_adv[i][j] = 1;
|
peer->afc_adv[i][j] = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
peer->curr = stream_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE);
|
peer->curr = stream_new(BGP_MAX_PACKET_SIZE);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (mp_segments[i].name)
|
while (mp_segments[i].name)
|
||||||
|
@ -1100,7 +1100,7 @@ int main(void)
|
|||||||
peer = peer_create_accept(bgp);
|
peer = peer_create_accept(bgp);
|
||||||
peer->host = (char *)"foo";
|
peer->host = (char *)"foo";
|
||||||
peer->status = Established;
|
peer->status = Established;
|
||||||
peer->curr = stream_new(BGP_MAX_EXTENDED_MESSAGE_PACKET_SIZE);
|
peer->curr = stream_new(BGP_MAX_PACKET_SIZE);
|
||||||
|
|
||||||
ifp.ifindex = 0;
|
ifp.ifindex = 0;
|
||||||
peer->nexthop.ifp = &ifp;
|
peer->nexthop.ifp = &ifp;
|
||||||
|
Loading…
Reference in New Issue
Block a user