From 533edb8a770c5e930087a7535199d1b1f257ee02 Mon Sep 17 00:00:00 2001 From: Philippe Guibert Date: Tue, 29 Oct 2024 22:30:55 +0100 Subject: [PATCH] bgpd: bmp, buffer size conf avoid calling bgp_bmp_get() 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 --- bgpd/bgp_bmp.c | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index cb949b6dd2bf..0c8306eb493e 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -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) { @@ -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; @@ -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; }