]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
SNMP: move pieces of show_info
authorVojtech Vilimek <vojtech.vilimek@nic.cz>
Fri, 26 Jul 2024 08:43:00 +0000 (10:43 +0200)
committerVojtech Vilimek <vojtech.vilimek@nic.cz>
Fri, 26 Jul 2024 08:43:00 +0000 (10:43 +0200)
proto/snmp/bgp4_mib.c
proto/snmp/bgp4_mib.h
proto/snmp/snmp.c
proto/snmp/subagent.c
proto/snmp/subagent.h

index 134b3d3bd41b59d1b2b7ff0d0b4de24276facb50..b13ed463dc11b3b43363b2a75034a008c72ef7ed 100644 (file)
@@ -8,6 +8,8 @@
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 
+#include "nest/cli.h"
+
 #include "snmp.h"
 #include "snmp_utils.h"
 #include "subagent.h"
@@ -863,9 +865,35 @@ bgp4_next_peer(struct mib_walk_state *state, struct snmp_pdu *c)
   return 1;
 }
 
+/*
+ * snmp_bgp4_show_info - display info BGP4-MIB
+ * @p: SNMP protocol instance
+ *
+ * Print info about BGP4-MIB status and bound bgp peers to cli.
+ */
+void
+snmp_bgp4_show_info(struct snmp_proto *p)
+{
+  cli_msg(-1006, "    BGP4-MIB");
+  cli_msg(-1006, "      Local AS %u", p->bgp_local_as);
+  cli_msg(-1006, "      Local router id %R", p->bgp_local_id);
+  cli_msg(-1006, "      BGP peers");
+
+  if (!snmp_is_active(p))
+    return;
+
+  HASH_WALK(p->bgp_hash, next, peer)
+  {
+    cli_msg(-1006, "        protocol name: %s", peer->bgp_proto->p.name);
+    cli_msg(-1006, "        Remote IPv4 address: %I4", peer->peer_ip);
+    cli_msg(-1006, "        Remote router id %R", peer->bgp_proto->remote_id);
+  }
+  HASH_WALK_END;
+}
+
 /*
  * snmp_bgp4_start - prepare BGP4-MIB
- * @p - SNMP protocol instance holding memory pool
+ * @p: SNMP protocol instance holding memory pool
  *
  * This function create all runtime bindings to BGP procotol structures.
  * It is gruaranteed that the BGP protocols exist.
index 2639e1a2c0c63afb163022e94cab8045a07e03f1..c486a0df00e9a5c6ab76fac39bc9f04b4085290b 100644 (file)
@@ -48,10 +48,9 @@ enum bgp4_admin_status {
   BGP4_ADMIN_START = 2,
 };
 
-u8 snmp_bgp_get_valid(u8 state);
-u8 snmp_bgp_getnext_valid(u8 state);
-
+void snmp_bgp4_start(struct snmp_proto *p);
 void snmp_bgp4_register(struct snmp_proto *p);
+void snmp_bgp4_show_info(struct snmp_proto *p);
 
 enum snmp_search_res snmp_bgp_search(struct snmp_proto *p, struct agentx_varbind **vb_search, const struct oid *o_end, struct snmp_pdu *c);
 enum snmp_search_res snmp_bgp_search2(struct snmp_proto *p, struct oid **searched, const struct oid *o_end, uint contid);
index 2168e490ca448d8888398b8a2ca937a020970668..900c62d1b53862fc8057f2a9a7f49780080c8d92 100644 (file)
@@ -1,6 +1,8 @@
-/**    BIRD -- Simple Network Management Protocol (SNMP) *
- *      (c) 2022 Vojtech Vilimek <vojtech.vilimek@nic.cz>
- *      (c) 2022 CZ.NIC z.s.p.o.
+/*
+ *     BIRD -- Simple Network Management Procotol (SNMP)
+ *
+ *     (c) 2024 Vojtech Vilimek <vojtech.vilimek@nic.cz>
+ *     (c) 2024 CZ.NIC z.s.p.o.
  *
  *     Can be freely distributed and used under the terms of the GNU GPL.
  */
 #include "subagent.h"
 #include "snmp_utils.h"
 #include "mib_tree.h"
+#include "bgp4_mib.h"
 
 // TODO: remove me
 #include "proto/bgp/bgp.h"
@@ -325,10 +328,11 @@ snmp_set_state(struct snmp_proto *p, enum snmp_proto_state state)
     return PS_DOWN;
 
   case SNMP_RESET:
+    // TODO remove SNMP_RESET state
     DBG("snmp -> SNMP_RESET\n");
     ASSUME(last == SNMP_REGISTER || last == SNMP_CONN);
     ASSUME(p->sock);
-    tm_stop(p->ping_timer);
+    snmp_stop_subagent(p);
     // FIXME: special treatment for SNMP_OPEN last state?
     p->sock->rx_hook = snmp_rx_skip;
     p->sock->tx_hook = snmp_tx_skip;
@@ -397,6 +401,8 @@ snmp_cleanup(struct snmp_proto *p)
 
   rfree(p->lp);
   p->bgp_trie = NULL;
+
+  p->state = SNMP_DOWN;
 }
 
 /*
@@ -439,6 +445,7 @@ snmp_reset(struct snmp_proto *p)
 void
 snmp_stop(struct snmp_proto *p)
 {
+  // TODO: add option for passing close reason for agentx-Close-PDU
   proto_notify_state(&p->p, snmp_set_state(p, SNMP_STOP));
 }
 
@@ -656,22 +663,7 @@ snmp_show_proto_info(struct proto *P)
   cli_msg(-1006, "  SNMP state %u", p->state);
   cli_msg(-1006, "  MIBs");
 
-  // TODO move me into the bgp_mib.c
-  cli_msg(-1006, "    BGP4-MIB");
-  cli_msg(-1006, "      Local AS %u", p->bgp_local_as);
-  cli_msg(-1006, "      Local router id %R", p->bgp_local_id);
-  cli_msg(-1006, "      BGP peers");
-
-  if (p->state == SNMP_DOWN || p->state == SNMP_RESET)
-    return;
-
-  HASH_WALK(p->bgp_hash, next, peer)
-  {
-    cli_msg(-1006, "    protocol name: %s", peer->bgp_proto->p.name);
-    cli_msg(-1006, "    Remote IPv4 address: %I4", peer->peer_ip);
-    cli_msg(-1006, "    Remote router id %R", peer->bgp_proto->remote_id);
-  }
-  HASH_WALK_END;
+  snmp_bgp4_show_info(p);
 }
 
 /*
index 6e23e90c884e585fd0a9704ae10534bd145233c4..470c283a346cfe0cd0b059bda0a1142d133005b1 100644 (file)
@@ -60,14 +60,6 @@ static uint update_packet_size(struct agentx_header *start, byte *end);
 /* standard SNMP internet prefix (.1.3.6.1) */
 const u32 snmp_internet[] = { SNMP_ISO, SNMP_ORG, SNMP_DOD, SNMP_INTERNET };
 
-static inline int
-snmp_is_active(struct snmp_proto *p)
-{
-  /* Note: states in which we have opened socket */
-  return p->state == SNMP_OPEN || p->state == SNMP_REGISTER ||
-      p->state == SNMP_CONN;
-}
-
 /*
  * snmp_header - store packet information into buffer
  * @h: pointer to created packet header in TX-buffer
index cf53a2123c93f53e436614f9f8dc747b851b4c48..109da6b765136bbc9fe6c61e0ab1019280e293af 100644 (file)
@@ -12,10 +12,6 @@ void snmp_ping(struct snmp_proto *p);
 
 #define AGENTX_VERSION              1
 
-#define SNMP_STATE_START 0
-#define SNMP_STATE_BGP 1
-#define SNMP_STATE_INVALID 2
-
 /* standard snmp internet prefix */
 #define SNMP_ISO         1           /* last of oid .1               */
 #define SNMP_ORG         3           /* last of oid .1.3             */
@@ -369,13 +365,20 @@ void snmp_notify_pdu(struct snmp_proto *p, struct oid *oid, void *data, uint siz
 
 int snmp_tbuf_reserve(struct snmp_pdu *c, size_t bytes);
 
+static inline int
+snmp_is_active(const struct snmp_proto *p)
+{
+  /* Note: states in which we have opened socket */
+  return p->state == SNMP_OPEN || p->state == SNMP_REGISTER ||
+      p->state == SNMP_CONN;
+}
+
 void snmp_vb_to_tx(struct snmp_pdu *c, const struct oid *oid);
 u8 snmp_get_mib_class(const struct oid *oid);
 
 void snmp_register_mibs(struct snmp_proto *p);
 
 /* MIB modules */
-void snmp_bgp4_start(struct snmp_proto *p);
 
 #if 1
 #define snmp_log(...) log(L_INFO "SNMP " __VA_ARGS__)