Skip to content

Commit

Permalink
bgpd: bmp, buffer size conf avoid calling bgp_bmp_get()
Browse files Browse the repository at this point in the history
The bgp_bmp_get() call is not necessary if the buffer
size limit of bmp is the default value. Reversely, the
no form of the config command should not allocate an
unnecessary bgpbmp structure.

Fix this by controlling the passed value before doing the
allocation.

Signed-off-by: Philippe Guibert <[email protected]>
  • Loading branch information
pguibert6WIND committed Oct 30, 2024
1 parent d5fe649 commit 533edb8
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions bgpd/bgp_bmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,17 @@ static void bmp_stats(struct event *thread)
}
}

static void bmp_mirror_limit_set_default(struct bgp *bgp)
{
struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp);

if (bmpbgp == NULL)
return;
if (bmpbgp->mirror_qsizelimit == ~0UL)
return;
bmpbgp->mirror_qsizelimit = ~0UL;
}

/* read from the BMP socket to detect session termination */
static void bmp_read(struct event *t)
{
Expand Down Expand Up @@ -2763,9 +2774,15 @@ DEFPY(bmp_mirror_limit_cfg,
"Limit in bytes\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
struct bmp_bgp *bmpbgp;
struct bmp_bgp *bmpbgp = bmp_bgp_find(bgp);

if (buffer_limit == 0 && bmpbgp == NULL)
return CMD_SUCCESS;
if (bmpbgp && bmpbgp->mirror_qsizelimit == (size_t)buffer_limit)
return CMD_SUCCESS;
if (bmpbgp == NULL)
bmpbgp = bmp_bgp_get(bgp);

bmpbgp = bmp_bgp_get(bgp);
bmpbgp->mirror_qsizelimit = buffer_limit;

return CMD_SUCCESS;
Expand All @@ -2781,11 +2798,8 @@ DEFPY(no_bmp_mirror_limit_cfg,
"Limit in bytes\n")
{
VTY_DECLVAR_CONTEXT(bgp, bgp);
struct bmp_bgp *bmpbgp;

bmpbgp = bmp_bgp_get(bgp);
bmpbgp->mirror_qsizelimit = ~0UL;

bmp_mirror_limit_set_default(bgp);
return CMD_SUCCESS;
}

Expand Down

0 comments on commit 533edb8

Please sign in to comment.