mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-05-28 12:10:24 +00:00
bgpd: Make buffer sizes automatically the correct size
In the bgp code to send routes to zebra we were spending a non trivial amount of time managing buffer sizes. We know a priori the multipath supported by our system so let's just use that value to appropriately size the buffers. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
parent
8ea37652c7
commit
d1e7e033fd
@ -232,12 +232,6 @@ bgp_exit (int status)
|
||||
vnc_zebra_destroy();
|
||||
#endif
|
||||
bgp_zebra_destroy();
|
||||
if (bgp_nexthop_buf)
|
||||
stream_free (bgp_nexthop_buf);
|
||||
if (bgp_ifindices_buf)
|
||||
stream_free (bgp_ifindices_buf);
|
||||
if (bgp_label_buf)
|
||||
stream_free (bgp_label_buf);
|
||||
|
||||
/* reverse bgp_master_init */
|
||||
if (bm->master)
|
||||
|
@ -1222,8 +1222,7 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info
|
||||
u_char distance;
|
||||
struct peer *peer;
|
||||
struct bgp_info *mpinfo;
|
||||
size_t oldsize, newsize;
|
||||
u_int32_t nhcount, metric;
|
||||
u_int32_t metric;
|
||||
struct bgp_info local_info;
|
||||
struct bgp_info *info_cp = &local_info;
|
||||
route_tag_t tag;
|
||||
@ -1270,8 +1269,6 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info
|
||||
|
||||
SET_FLAG (flags, ZEBRA_FLAG_INTERNAL);
|
||||
|
||||
nhcount = 1 + bgp_info_mpath_count (info);
|
||||
|
||||
if (p->family == AF_INET && !BGP_ATTR_NEXTHOP_AFI_IP6(info->attr))
|
||||
{
|
||||
struct zapi_ipv4 api;
|
||||
@ -1280,38 +1277,10 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info
|
||||
int valid_nh_count = 0;
|
||||
|
||||
/* resize nexthop buffer size if necessary */
|
||||
if ((oldsize = stream_get_size (bgp_nexthop_buf)) <
|
||||
(sizeof (struct in_addr *) * nhcount))
|
||||
{
|
||||
newsize = sizeof (struct in_addr *) * nhcount;
|
||||
newsize = stream_resize (bgp_nexthop_buf, newsize);
|
||||
if (newsize == oldsize)
|
||||
{
|
||||
zlog_err ("can't resize nexthop buffer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream_reset (bgp_nexthop_buf);
|
||||
nexthop = NULL;
|
||||
|
||||
/* For labeled unicast, each nexthop has a label too. Resize label
|
||||
* buffer, if required.
|
||||
*/
|
||||
if (safi == SAFI_LABELED_UNICAST)
|
||||
{
|
||||
if ((oldsize = stream_get_size (bgp_label_buf)) <
|
||||
(sizeof (unsigned int) * nhcount))
|
||||
{
|
||||
newsize = (sizeof (unsigned int) * nhcount);
|
||||
newsize = stream_resize (bgp_label_buf, newsize);
|
||||
if (newsize == oldsize)
|
||||
{
|
||||
zlog_err ("can't resize label buffer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream_reset (bgp_label_buf);
|
||||
}
|
||||
stream_reset (bgp_label_buf);
|
||||
|
||||
/* Metric is currently based on the best-path only. */
|
||||
metric = info->attr->med;
|
||||
@ -1464,52 +1433,9 @@ bgp_zebra_announce (struct bgp_node *rn, struct prefix *p, struct bgp_info *info
|
||||
int valid_nh_count = 0;
|
||||
char buf[2][INET6_ADDRSTRLEN];
|
||||
|
||||
/* resize nexthop buffer size if necessary */
|
||||
if ((oldsize = stream_get_size (bgp_nexthop_buf)) <
|
||||
(sizeof (struct in6_addr *) * nhcount))
|
||||
{
|
||||
newsize = (sizeof (struct in6_addr *) * nhcount);
|
||||
newsize = stream_resize (bgp_nexthop_buf, newsize);
|
||||
if (newsize == oldsize)
|
||||
{
|
||||
zlog_err ("can't resize nexthop buffer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream_reset (bgp_nexthop_buf);
|
||||
|
||||
/* resize ifindices buffer size if necessary */
|
||||
if ((oldsize = stream_get_size (bgp_ifindices_buf)) <
|
||||
(sizeof (unsigned int) * nhcount))
|
||||
{
|
||||
newsize = (sizeof (unsigned int) * nhcount);
|
||||
newsize = stream_resize (bgp_ifindices_buf, newsize);
|
||||
if (newsize == oldsize)
|
||||
{
|
||||
zlog_err ("can't resize nexthop buffer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream_reset (bgp_ifindices_buf);
|
||||
|
||||
/* For labeled unicast, each nexthop has a label too. Resize label
|
||||
* buffer, if required.
|
||||
*/
|
||||
if (safi == SAFI_LABELED_UNICAST)
|
||||
{
|
||||
if ((oldsize = stream_get_size (bgp_label_buf)) <
|
||||
(sizeof (unsigned int) * nhcount))
|
||||
{
|
||||
newsize = (sizeof (unsigned int) * nhcount);
|
||||
newsize = stream_resize (bgp_label_buf, newsize);
|
||||
if (newsize == oldsize)
|
||||
{
|
||||
zlog_err ("can't resize label buffer");
|
||||
return;
|
||||
}
|
||||
}
|
||||
stream_reset (bgp_label_buf);
|
||||
}
|
||||
stream_reset (bgp_label_buf);
|
||||
|
||||
ifindex = 0;
|
||||
nexthop = NULL;
|
||||
@ -2270,14 +2196,22 @@ bgp_zebra_init (struct thread_master *master)
|
||||
zclient->import_check_update = bgp_read_import_check_update;
|
||||
zclient->fec_update = bgp_read_fec_update;
|
||||
|
||||
bgp_nexthop_buf = stream_new(BGP_NEXTHOP_BUF_SIZE);
|
||||
bgp_ifindices_buf = stream_new(BGP_IFINDICES_BUF_SIZE);
|
||||
bgp_label_buf = stream_new(BGP_LABEL_BUF_SIZE);
|
||||
bgp_nexthop_buf = stream_new(multipath_num * sizeof (struct in6_addr));
|
||||
bgp_ifindices_buf = stream_new(multipath_num * sizeof (unsigned int));
|
||||
bgp_label_buf = stream_new(multipath_num * sizeof (unsigned int));
|
||||
}
|
||||
|
||||
void
|
||||
bgp_zebra_destroy(void)
|
||||
{
|
||||
|
||||
if (bgp_nexthop_buf)
|
||||
stream_free (bgp_nexthop_buf);
|
||||
if (bgp_ifindices_buf)
|
||||
stream_free (bgp_ifindices_buf);
|
||||
if (bgp_label_buf)
|
||||
stream_free (bgp_label_buf);
|
||||
|
||||
if (zclient == NULL)
|
||||
return;
|
||||
zclient_stop(zclient);
|
||||
|
@ -21,14 +21,6 @@
|
||||
#ifndef _QUAGGA_BGP_ZEBRA_H
|
||||
#define _QUAGGA_BGP_ZEBRA_H
|
||||
|
||||
#define BGP_NEXTHOP_BUF_SIZE (8 * sizeof (struct in_addr *))
|
||||
#define BGP_IFINDICES_BUF_SIZE (8 * sizeof (unsigned int))
|
||||
#define BGP_LABEL_BUF_SIZE (8 * sizeof (unsigned int))
|
||||
|
||||
extern struct stream *bgp_nexthop_buf;
|
||||
extern struct stream *bgp_ifindices_buf;
|
||||
extern struct stream *bgp_label_buf;
|
||||
|
||||
extern void bgp_zebra_init (struct thread_master *master);
|
||||
extern void bgp_zebra_destroy (void);
|
||||
extern int bgp_if_update_all (void);
|
||||
|
Loading…
Reference in New Issue
Block a user