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

SNMP: move pieces of show_info

This commit is contained in:
Vojtech Vilimek 2024-07-26 10:43:00 +02:00
parent a34fea55ec
commit 4b739be07c
5 changed files with 51 additions and 37 deletions

View 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.

View 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);

View 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.
*/
@ -118,6 +120,7 @@
#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);
}
/*

View 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

View 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__)