Skip to content

Commit

Permalink
zebra: Reduce memory usage of streams for encoding packets
Browse files Browse the repository at this point in the history
For those packets that we are not sending 16k of data, but something
far less than 256 bytes.  Reduce those stream sizes we allocate
to something much more reasonable.

Signed-off-by: Donald Sharp <[email protected]>
  • Loading branch information
donaldsharp committed Dec 7, 2024
1 parent 440d5ed commit b308f21
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 33 deletions.
2 changes: 1 addition & 1 deletion lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ typedef uint16_t zebra_size_t;

/* For input/output buffer to zebra. */
#define ZEBRA_MAX_PACKET_SIZ 16384U
#define ZEBRA_SMALL_PACKET_SIZE 200U
#define ZEBRA_SMALL_PACKET_SIZE 200U

/* Zebra header size. */
#define ZEBRA_HEADER_SIZE 10
Expand Down
34 changes: 16 additions & 18 deletions zebra/zapi_msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ int zsend_interface_address(int cmd, struct zserv *client,
{
int blen;
struct prefix *p;
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, ifp->vrf->vrf_id);
stream_putl(s, ifp->ifindex);
Expand Down Expand Up @@ -327,7 +327,7 @@ static int zsend_interface_nbr_address(int cmd, struct zserv *client,
struct nbr_connected *ifc)
{
int blen;
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
struct prefix *p;

zclient_create_header(s, cmd, ifp->vrf->vrf_id);
Expand Down Expand Up @@ -655,7 +655,7 @@ static int zsend_nexthop_lookup_mrib(struct zserv *client, struct ipaddr *addr,
struct nexthop *nexthop;

/* Get output stream. */
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
stream_reset(s);

/* Fill in result. */
Expand Down Expand Up @@ -710,7 +710,7 @@ int zsend_nhg_notify(uint16_t type, uint16_t instance, uint32_t session_id,
zlog_debug("%s: type %d, id %d, note %s",
__func__, type, id, zapi_nhg_notify_owner2str(note));

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
stream_reset(s);

zclient_create_header(s, ZEBRA_NHG_NOTIFY_OWNER, VRF_DEFAULT);
Expand Down Expand Up @@ -843,7 +843,7 @@ void zsend_rule_notify_owner(const struct zebra_dplane_ctx *ctx,
if (!client)
return;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_RULE_NOTIFY_OWNER,
dplane_ctx_rule_get_vrfid(ctx));
Expand Down Expand Up @@ -897,7 +897,7 @@ void zsend_iptable_notify_owner(const struct zebra_dplane_ctx *ctx,
if (!client)
return;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, VRF_DEFAULT);
stream_putw(s, note);
Expand Down Expand Up @@ -931,7 +931,7 @@ void zsend_ipset_notify_owner(const struct zebra_dplane_ctx *ctx,
if (!client)
return;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, VRF_DEFAULT);
stream_putw(s, note);
Expand Down Expand Up @@ -967,7 +967,7 @@ void zsend_ipset_entry_notify_owner(const struct zebra_dplane_ctx *ctx,
if (!client)
return;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, VRF_DEFAULT);
stream_putw(s, note);
Expand Down Expand Up @@ -1015,13 +1015,12 @@ int zsend_router_id_update(struct zserv *client, afi_t afi, struct prefix *p,
vrf_id_t vrf_id)
{
int blen;
struct stream *s;

/* Check this client need interface information. */
if (!vrf_bitmap_check(&client->ridinfo[afi], vrf_id))
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

/* Message type. */
zclient_create_header(s, ZEBRA_ROUTER_ID_UPDATE, vrf_id);
Expand All @@ -1043,7 +1042,7 @@ int zsend_router_id_update(struct zserv *client, afi_t afi, struct prefix *p,
*/
int zsend_pw_update(struct zserv *client, struct zebra_pw *pw)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_PW_STATUS_UPDATE, pw->vrf_id);
stream_write(s, pw->ifname, IFNAMSIZ);
Expand All @@ -1060,7 +1059,7 @@ int zsend_pw_update(struct zserv *client, struct zebra_pw *pw)
int zsend_assign_label_chunk_response(struct zserv *client, vrf_id_t vrf_id,
struct label_manager_chunk *lmc)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, vrf_id);
/* proto */
Expand All @@ -1086,7 +1085,7 @@ int zsend_assign_label_chunk_response(struct zserv *client, vrf_id_t vrf_id,
int zsend_label_manager_connect_response(struct zserv *client, vrf_id_t vrf_id,
unsigned short result)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_LABEL_MANAGER_CONNECT, vrf_id);

Expand All @@ -1110,7 +1109,7 @@ static int zsend_assign_table_chunk_response(struct zserv *client,
vrf_id_t vrf_id,
struct table_manager_chunk *tmc)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_GET_TABLE_CHUNK, vrf_id);

Expand All @@ -1130,7 +1129,7 @@ static int zsend_table_manager_connect_response(struct zserv *client,
vrf_id_t vrf_id,
uint16_t result)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_TABLE_MANAGER_CONNECT, vrf_id);

Expand Down Expand Up @@ -2359,7 +2358,7 @@ static void zread_router_id_delete(ZAPI_HANDLER_ARGS)

static void zsend_capabilities(struct zserv *client, struct zebra_vrf *zvrf)
{
struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_CAPABILITIES, zvrf->vrf->vrf_id);
stream_putl(s, vrf_get_backend());
Expand Down Expand Up @@ -3866,8 +3865,7 @@ static inline void zebra_gre_source_set(ZAPI_HANDLER_ARGS)
static void zsend_error_msg(struct zserv *client, enum zebra_error_types error,
struct zmsghdr *bad_hdr)
{

struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
struct stream *s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_ERROR, bad_hdr->vrf_id);

Expand Down
4 changes: 2 additions & 2 deletions zebra/zebra_csm.c
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ static void zebra_csm_maint_mode(struct event *t)

client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
if (client) {
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
zclient_create_header(s, ZEBRA_MAINTENANCE_MODE, VRF_DEFAULT);
stream_putc(s, enter);
/* Write packet size. */
Expand Down Expand Up @@ -275,7 +275,7 @@ static void zebra_csm_fast_restart(struct event *t)
zrouter.fast_shutdown = true;
client = zserv_find_client(ZEBRA_ROUTE_BGP, 0);
if (client) {
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
zclient_create_header(s, ZEBRA_FAST_SHUTDOWN, VRF_DEFAULT);
stream_putc(s, upgrade);
/* Write packet size. */
Expand Down
6 changes: 3 additions & 3 deletions zebra/zebra_evpn.c
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ static int ip_prefix_send_to_client(vrf_id_t vrf_id, struct prefix *p,
if (!client)
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, vrf_id);
stream_put(s, p, sizeof(struct prefix));
Expand Down Expand Up @@ -1182,7 +1182,7 @@ int zebra_evpn_send_add_to_client(struct zebra_evpn *zevpn)

svi_index = zevpn->svi_if ? zevpn->svi_if->ifindex : 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_VNI_ADD, zebra_vrf_get_evpn_id());
stream_putl(s, zevpn->vni);
Expand Down Expand Up @@ -1234,7 +1234,7 @@ int zebra_evpn_send_del_to_client(struct zebra_evpn *zevpn)
zebra_evpn_update_all_es(zevpn);
}

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
stream_reset(s);

zclient_create_header(s, ZEBRA_VNI_DEL, zebra_vrf_get_evpn_id());
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_evpn_mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -1004,7 +1004,7 @@ int zebra_evpn_macip_send_msg_to_client(vni_t vni,
if (!client)
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, zebra_vrf_get_evpn_id());
stream_putl(s, vni);
Expand Down
6 changes: 3 additions & 3 deletions zebra/zebra_evpn_mh.c
Original file line number Diff line number Diff line change
Expand Up @@ -2256,7 +2256,7 @@ static int zebra_evpn_es_send_add_to_client(struct zebra_evpn_es *es)
if (!client)
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_LOCAL_ES_ADD, zebra_vrf_get_evpn_id());
stream_put(s, &es->esi, sizeof(esi_t));
Expand Down Expand Up @@ -2292,7 +2292,7 @@ static int zebra_evpn_es_send_del_to_client(struct zebra_evpn_es *es)
if (!client)
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);
stream_reset(s);

zclient_create_header(s, ZEBRA_LOCAL_ES_DEL, zebra_vrf_get_evpn_id());
Expand Down Expand Up @@ -2975,7 +2975,7 @@ static int zebra_evpn_es_evi_send_to_client(struct zebra_evpn_es *es,
if (!client)
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s,
add ? ZEBRA_LOCAL_ES_EVI_ADD : ZEBRA_LOCAL_ES_EVI_DEL,
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_mpls.c
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ static int fec_send(struct zebra_fec *fec, struct zserv *client)
rn = fec->rn;

/* Get output stream. */
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_FEC_UPDATE, VRF_DEFAULT);

Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_mroute.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void zebra_ipmr_route_stats(ZAPI_HANDLER_ARGS)
suc = kernel_get_ipmr_sg_stats(zvrf, &mroute);

stream_failure:
s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

stream_reset(s);

Expand Down
6 changes: 3 additions & 3 deletions zebra/zebra_vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2248,7 +2248,7 @@ static int zl3vni_send_add_to_client(struct zebra_l3vni *zl3vni)
is_anycast_mac = false;
}

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

/* The message is used for both vni add and/or update like
* vrr mac is added for l3vni SVI.
Expand Down Expand Up @@ -2291,7 +2291,7 @@ static int zl3vni_send_del_to_client(struct zebra_l3vni *zl3vni)
if (!client)
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, ZEBRA_L3VNI_DEL, zl3vni_vrf_id(zl3vni));
stream_putl(s, zl3vni->vni);
Expand Down Expand Up @@ -5915,7 +5915,7 @@ static int zebra_vxlan_sg_send(struct zebra_vrf *zvrf,
if (!CHECK_FLAG(zvrf->flags, ZEBRA_PIM_SEND_VXLAN_SG))
return 0;

s = stream_new(ZEBRA_MAX_PACKET_SIZ);
s = stream_new(ZEBRA_SMALL_PACKET_SIZE);

zclient_create_header(s, cmd, VRF_DEFAULT);
stream_putl(s, IPV4_MAX_BYTELEN);
Expand Down

0 comments on commit b308f21

Please sign in to comment.