0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

BGP: Print warnings when the allocated memory is larger than given acceptable maximum.

This commit is contained in:
Katerina Kubecova 2024-12-16 11:37:10 +01:00 committed by Maria Matejka
parent c6b778794e
commit 1f6ecd7e19
5 changed files with 19 additions and 1 deletions

View File

@ -3419,6 +3419,11 @@ using the following configuration parameters:
otherwise the session will not be established. This behavior is defined otherwise the session will not be established. This behavior is defined
in <rfc id="9234"> as "strict mode" and is used to enforce corresponding in <rfc id="9234"> as "strict mode" and is used to enforce corresponding
configuration at your conterpart side. Default: disabled. configuration at your conterpart side. Default: disabled.
<tag><label id="bgp-tx_size_warning">tx size warning <m/number/</tag>
If this option is set, the bgp protocol prints warning when it consumes at least
given size of memory. This includes also the memory consumed
by any export table. Zero means disabled. Default: disabled.
</descrip> </descrip>
<sect1>Channel configuration <sect1>Channel configuration

View File

@ -2413,6 +2413,13 @@ bgp_rt_notify(struct proto *P, struct channel *C, const net_addr *n, rte *new, c
/* And queue the notification */ /* And queue the notification */
if (bgp_update_prefix(c, bgp_get_prefix(c, NET_TO_INDEX(n), path, bc->add_path_tx), buck)) if (bgp_update_prefix(c, bgp_get_prefix(c, NET_TO_INDEX(n), path, bc->add_path_tx), buck))
bgp_schedule_packet(p->conn, bc, PKT_UPDATE); bgp_schedule_packet(p->conn, bc, PKT_UPDATE);
if ((p->cf->tx_size_warning > 0) )
{
struct resmem mem = rmemsize(P->pool);
if (mem.effective + mem.overhead >= p->cf->tx_size_warning)
log_rl(&p->tbf_mem, L_WARN "%s: Used %lu memory", P->name, mem.effective + mem.overhead);
}
} }

View File

@ -2019,6 +2019,8 @@ bgp_init(struct proto_config *CF)
ea_set_attr(&pes, EA_LITERAL_EMBEDDED(&ea_bgp_rem_as, 0, cf->remote_as)); ea_set_attr(&pes, EA_LITERAL_EMBEDDED(&ea_bgp_rem_as, 0, cf->remote_as));
proto_announce_state_later(&p->p, pes); proto_announce_state_later(&p->p, pes);
p->tbf_mem = (struct tbf) TBF_DEFAULT_LOG_LIMITS;
return P; return P;
} }

View File

@ -146,6 +146,7 @@ struct bgp_config {
int require_hostname; /* Require remote support for hostname [draft] */ int require_hostname; /* Require remote support for hostname [draft] */
int require_gr; /* Require remote support for graceful restart [RFC 4724] */ int require_gr; /* Require remote support for graceful restart [RFC 4724] */
int require_llgr; /* Require remote support for long-lived graceful restart [draft] */ int require_llgr; /* Require remote support for long-lived graceful restart [draft] */
uint tx_size_warning; /* The maximum amount of memory which is not logged as warning */
struct bfd_options *bfd; /* Use BFD for liveness detection */ struct bfd_options *bfd; /* Use BFD for liveness detection */
}; };
@ -392,6 +393,7 @@ struct bgp_proto {
u8 last_error_class; /* Error class of last error */ u8 last_error_class; /* Error class of last error */
u32 last_error_code; /* Error code of last error. BGP protocol errors u32 last_error_code; /* Error code of last error. BGP protocol errors
are encoded as (bgp_err_code << 16 | bgp_err_subcode) */ are encoded as (bgp_err_code << 16 | bgp_err_subcode) */
struct tbf tbf_mem; /* For logging memory allocation */
}; };
#define bgp_ea_state(p) _Generic((p), \ #define bgp_ea_state(p) _Generic((p), \

View File

@ -31,7 +31,7 @@ CF_KEYWORDS(BGP, LOCAL, NEIGHBOR, AS, HOLD, TIME, CONNECT, RETRY, KEEPALIVE,
LIVED, STALE, IMPORT, IBGP, EBGP, MANDATORY, INTERNAL, EXTERNAL, SETS, LIVED, STALE, IMPORT, IBGP, EBGP, MANDATORY, INTERNAL, EXTERNAL, SETS,
DYNAMIC, RANGE, NAME, DIGITS, AIGP, ORIGINATE, COST, ENFORCE, DYNAMIC, RANGE, NAME, DIGITS, AIGP, ORIGINATE, COST, ENFORCE,
FIRST, FREE, VALIDATE, BASE, ROLE, ROLES, PEER, PROVIDER, CUSTOMER, FIRST, FREE, VALIDATE, BASE, ROLE, ROLES, PEER, PROVIDER, CUSTOMER,
RS_SERVER, RS_CLIENT, REQUIRE, BGP_OTC, GLOBAL, SEND) RS_SERVER, RS_CLIENT, REQUIRE, BGP_OTC, GLOBAL, SEND, TX, SIZE, WARNING)
CF_ENUM(T_ENUM_BGP_ORIGIN, ORIGIN_, IGP, EGP, INCOMPLETE) CF_ENUM(T_ENUM_BGP_ORIGIN, ORIGIN_, IGP, EGP, INCOMPLETE)
@ -80,6 +80,7 @@ bgp_proto_start: proto_start BGP {
BGP_CFG->dynamic_name = "dynbgp"; BGP_CFG->dynamic_name = "dynbgp";
BGP_CFG->check_link = -1; BGP_CFG->check_link = -1;
BGP_CFG->send_hold_time = -1; BGP_CFG->send_hold_time = -1;
BGP_CFG->tx_size_warning = 0;
} }
; ;
@ -227,6 +228,7 @@ bgp_proto:
| bgp_proto LOCAL ROLE bgp_role_name ';' { BGP_CFG->local_role = $4; } | bgp_proto LOCAL ROLE bgp_role_name ';' { BGP_CFG->local_role = $4; }
| bgp_proto REQUIRE ROLES bool ';' { BGP_CFG->require_roles = $4; } | bgp_proto REQUIRE ROLES bool ';' { BGP_CFG->require_roles = $4; }
| bgp_proto DISABLE RX bool ';' { BGP_CFG->disable_rx = $4; } | bgp_proto DISABLE RX bool ';' { BGP_CFG->disable_rx = $4; }
| bgp_proto TX SIZE WARNING expr ';' { BGP_CFG->tx_size_warning = $5; }
; ;
bgp_afi: bgp_afi: