]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
bgp/attrs: Protocols print warnings when the size of memory they allocated is big...
authorKaterina Kubecova <katerina.kubecova@nic.cz>
Mon, 16 Dec 2024 10:37:10 +0000 (11:37 +0100)
committerKaterina Kubecova <katerina.kubecova@nic.cz>
Mon, 16 Dec 2024 10:41:19 +0000 (11:41 +0100)
doc/bird.sgml
proto/bgp/attrs.c
proto/bgp/bgp.c
proto/bgp/bgp.h
proto/bgp/config.Y

index f7519b814058b4a3c136f14cfeacf22953ec1a6c..9d92848776ce109d197115bb442fc4f1e8366c3a 100644 (file)
@@ -3419,6 +3419,10 @@ 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/switch/</tag>
+        If this option is set, the bgp protocol prints warning when it consumes at least
+        given size of memory.
 </descrip>
 
 <sect1>Channel configuration
index 957fe108e0cab467c9ffc1d49923f66e5df90cb2..4af986ae6ab08c12a812f8a6263e8c7278be18ca 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 ((int) mem.effective + (int) mem.overhead >= p->cf->tx_size_warning)
+      log_rl(&p->tbf_mem, L_WARN "%s: allocated %i in pool ()", 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..4c921aabc15e6ed71d1f77c2a9d9d12dbefc2989 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] */
+  int 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..27ed3fc38f37e2f7185f7403884338ce0aefa252 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 = -1;
    }
  ;
 
@@ -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 = $4; }
  ;
 
 bgp_afi: