* 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"
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.
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);
-/** 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"
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;
rfree(p->lp);
p->bgp_trie = NULL;
+
+ p->state = SNMP_DOWN;
}
/*
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));
}
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);
}
/*
/* 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
#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 */
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__)