]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
BGP: Print warnings when the allocated memory is larger than given acceptable maximum.
authorKaterina Kubecova <katerina.kubecova@nic.cz>
Mon, 16 Dec 2024 10:37:10 +0000 (11:37 +0100)
committerMaria Matejka <mq@ucw.cz>
Mon, 16 Dec 2024 11:33:07 +0000 (12:33 +0100)
doc/bird.sgml
proto/bgp/attrs.c
proto/bgp/bgp.c
proto/bgp/bgp.h
proto/bgp/config.Y

index f7519b814058b4a3c136f14cfeacf22953ec1a6c..09f711a9b570122a68f9c134d2a0c288f3e5272b 100644 (file)
@@ -3419,6 +3419,11 @@ using the following configuration parameters:
        otherwise the session will not be established. This behavior is defined
        in <rfc id="9234"> as "strict mode" and is used to enforce corresponding
        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>
 
 <sect1>Channel configuration
index 957fe108e0cab467c9ffc1d49923f66e5df90cb2..a2feaef534001457bfd01511c09c073c7ae15039 100644 (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 */
   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);
+
+  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);
+  }
 }
 
 
index ea9392ff4071bba64f5640f7f10273ae3b510010..5fc2b5fff6981d084e3c66f3f9db3dcea0853b4c 100644 (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));
 
   proto_announce_state_later(&p->p, pes);
+
+  p->tbf_mem = (struct tbf) TBF_DEFAULT_LOG_LIMITS;
   return P;
 }
 
index c12942ec1374c0643edeae2a0183e2ff6f1c382b..202e78ba39a0f4dc03b844e8dd06c07afac811e1 100644 (file)
@@ -146,6 +146,7 @@ struct bgp_config {
   int require_hostname;                        /* Require remote support for hostname [draft] */
   int require_gr;                      /* Require remote support for graceful restart [RFC 4724] */
   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 */
 };
 
@@ -392,6 +393,7 @@ struct bgp_proto {
   u8 last_error_class;                         /* Error class of last error */
   u32 last_error_code;                 /* Error code of last error. BGP protocol errors
                                           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), \
index 90dfc90579d6bcd0f5bdf5f78697ca08a1e526ae..aafd44ff75fe0e378345cd7112f9207ee9a41c4d 100644 (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,
        DYNAMIC, RANGE, NAME, DIGITS, AIGP, ORIGINATE, COST, ENFORCE,
        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)
 
@@ -80,6 +80,7 @@ bgp_proto_start: proto_start BGP {
      BGP_CFG->dynamic_name = "dynbgp";
      BGP_CFG->check_link = -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 REQUIRE ROLES bool ';' { BGP_CFG->require_roles = $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: