2022-08-01 11:01:49 +00:00
|
|
|
/*
|
|
|
|
* BIRD -- Simple Network Management Protocol (SNMP)
|
|
|
|
*
|
|
|
|
* (c) 2022 Vojtech Vilimek <vojtech.vilimek@nic.cz>
|
|
|
|
* (c) 2022 CZ.NIC z.s.p.o
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _BIRD_SNMP_H_
|
2022-08-10 15:31:32 +00:00
|
|
|
#define _BIRD_SNMP_H_
|
2022-08-01 11:01:49 +00:00
|
|
|
|
2022-08-10 15:31:32 +00:00
|
|
|
#include "lib/ip.h"
|
|
|
|
#include "lib/socket.h"
|
2024-01-10 11:21:46 +00:00
|
|
|
#include "lib/resource.h"
|
2022-08-10 15:31:32 +00:00
|
|
|
#include "lib/timer.h"
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "nest/protocol.h"
|
2022-09-30 07:36:09 +00:00
|
|
|
#include "filter/data.h"
|
2024-05-24 13:20:30 +00:00
|
|
|
#include "proto/bgp/bgp.h" // TODO remove me
|
2022-08-10 15:31:32 +00:00
|
|
|
|
2022-08-02 14:04:25 +00:00
|
|
|
#define SNMP_UNDEFINED 0
|
|
|
|
#define SNMP_BGP 1
|
|
|
|
#define SNMP_OSPF 2
|
|
|
|
#define SNMP_INVALID 255
|
|
|
|
|
2022-08-10 15:31:32 +00:00
|
|
|
#define SNMP_PORT 705
|
|
|
|
|
2023-08-08 17:00:54 +00:00
|
|
|
#define SNMP_RX_BUFFER_SIZE 8192
|
|
|
|
#define SNMP_TX_BUFFER_SIZE 8192
|
2024-01-23 23:23:31 +00:00
|
|
|
#define SNMP_PKT_SIZE_MAX 8192
|
2022-08-10 15:31:32 +00:00
|
|
|
|
2022-12-17 17:16:19 +00:00
|
|
|
enum snmp_proto_state {
|
2023-11-15 14:03:55 +00:00
|
|
|
SNMP_DOWN = 0,
|
2023-09-04 07:25:51 +00:00
|
|
|
SNMP_INIT = 1,
|
|
|
|
SNMP_LOCKED,
|
|
|
|
SNMP_OPEN,
|
|
|
|
SNMP_REGISTER,
|
|
|
|
SNMP_CONN,
|
|
|
|
SNMP_STOP,
|
2023-10-25 10:56:23 +00:00
|
|
|
SNMP_RESET,
|
2022-12-17 17:16:19 +00:00
|
|
|
};
|
2022-09-06 16:04:29 +00:00
|
|
|
|
2024-05-24 13:20:30 +00:00
|
|
|
enum snmp_tags {
|
|
|
|
EMPTY_TAG = 0,
|
|
|
|
BGP4_TAG,
|
|
|
|
};
|
|
|
|
|
2022-08-02 14:04:25 +00:00
|
|
|
struct snmp_bond {
|
|
|
|
node n;
|
2023-11-15 14:03:55 +00:00
|
|
|
struct proto_config *config;
|
2022-08-02 14:04:25 +00:00
|
|
|
u8 type;
|
|
|
|
};
|
|
|
|
|
2022-08-01 11:01:49 +00:00
|
|
|
struct snmp_config {
|
2022-08-10 15:31:32 +00:00
|
|
|
struct proto_config cf;
|
2024-01-10 11:21:46 +00:00
|
|
|
ip4_addr local_ip;
|
|
|
|
ip4_addr remote_ip;
|
2022-08-10 15:31:32 +00:00
|
|
|
u16 local_port;
|
|
|
|
u16 remote_port;
|
2023-10-11 08:44:18 +00:00
|
|
|
|
2024-01-10 11:21:46 +00:00
|
|
|
ip4_addr bgp_local_id; /* BGP4-MIB related fields */
|
2023-10-11 08:44:18 +00:00
|
|
|
u32 bgp_local_as;
|
|
|
|
|
2023-11-15 14:03:55 +00:00
|
|
|
btime timeout;
|
|
|
|
btime startup_delay;
|
2023-09-04 11:58:59 +00:00
|
|
|
u8 priority;
|
2024-01-23 23:23:31 +00:00
|
|
|
//struct iface *iface; TODO
|
2023-09-11 11:06:20 +00:00
|
|
|
u32 bonds;
|
2024-01-23 23:23:31 +00:00
|
|
|
const char *description; /* The order of fields is not arbitrary */
|
|
|
|
list bgp_entries; /* We want dynamically allocated fields to be
|
|
|
|
* at the end of the config struct.
|
|
|
|
* We use this fact to check differences of
|
|
|
|
* nonallocated parts of configs with memcpy
|
|
|
|
*/
|
|
|
|
//const struct oid *oid_identifier; TODO
|
2022-08-01 11:01:49 +00:00
|
|
|
};
|
|
|
|
|
2023-09-11 11:06:20 +00:00
|
|
|
#define SNMP_BGP_P_REGISTERING 0x01
|
|
|
|
#define SNMP_BGP_P_REGISTERED 0x02
|
|
|
|
|
2022-09-20 12:28:57 +00:00
|
|
|
struct snmp_bgp_peer {
|
2023-11-15 14:03:55 +00:00
|
|
|
const struct bgp_proto *bgp_proto;
|
|
|
|
ip4_addr peer_ip; /* used as hash key */
|
2022-09-20 12:28:57 +00:00
|
|
|
struct snmp_bgp_peer *next;
|
|
|
|
};
|
2022-09-06 16:04:29 +00:00
|
|
|
|
2022-12-10 17:08:00 +00:00
|
|
|
struct snmp_registered_oid {
|
|
|
|
node n;
|
|
|
|
struct oid *oid;
|
|
|
|
};
|
|
|
|
|
2024-05-24 13:20:30 +00:00
|
|
|
struct mib_tree; /* see mib_tree.h */
|
|
|
|
|
2022-08-01 11:01:49 +00:00
|
|
|
struct snmp_proto {
|
2022-08-10 15:31:32 +00:00
|
|
|
struct proto p;
|
|
|
|
struct object_lock *lock;
|
2023-10-18 16:06:24 +00:00
|
|
|
pool *pool; /* a shortcut to the procotol mem. pool */
|
|
|
|
linpool *lp; /* linpool for bgp_trie nodes */
|
2024-01-10 11:21:46 +00:00
|
|
|
slab *request_storage; /* manages storages storage for incomming requests */
|
2022-09-30 07:36:09 +00:00
|
|
|
|
2024-01-10 11:21:46 +00:00
|
|
|
enum snmp_proto_state state;
|
|
|
|
|
|
|
|
ip4_addr local_ip;
|
|
|
|
ip4_addr remote_ip;
|
2022-08-10 15:31:32 +00:00
|
|
|
u16 local_port;
|
|
|
|
u16 remote_port;
|
2023-10-11 08:44:18 +00:00
|
|
|
|
2024-01-10 11:21:46 +00:00
|
|
|
ip4_addr bgp_local_id; /* BGP4-MIB related fields */
|
2023-10-11 08:44:18 +00:00
|
|
|
u32 bgp_local_as;
|
2022-09-06 16:04:29 +00:00
|
|
|
|
2022-08-10 15:31:32 +00:00
|
|
|
sock *sock;
|
2024-01-10 11:21:46 +00:00
|
|
|
|
|
|
|
|
2023-11-15 14:03:55 +00:00
|
|
|
btime timeout; /* timeout is part of MIB registration. It
|
2023-09-04 12:01:08 +00:00
|
|
|
specifies how long should the master
|
|
|
|
agent wait for request responses. */
|
2022-09-06 16:04:29 +00:00
|
|
|
|
2022-08-10 15:31:32 +00:00
|
|
|
u32 session_id;
|
|
|
|
u32 transaction_id;
|
|
|
|
u32 packet_id;
|
2022-09-06 16:04:29 +00:00
|
|
|
|
2023-11-15 14:03:55 +00:00
|
|
|
uint registrations_to_ack; /* counter of pending responses to register-pdu */
|
|
|
|
list registration_queue; /* list containing snmp_register records */
|
2022-12-10 12:22:37 +00:00
|
|
|
|
|
|
|
// map
|
2022-09-30 07:36:09 +00:00
|
|
|
struct f_trie *bgp_trie;
|
2022-09-20 12:28:57 +00:00
|
|
|
HASH(struct snmp_bgp_peer) bgp_hash;
|
2022-08-01 11:01:49 +00:00
|
|
|
struct tbf rl_gen;
|
2022-09-06 16:04:29 +00:00
|
|
|
|
2024-01-10 11:21:46 +00:00
|
|
|
list pending_pdus;
|
|
|
|
|
2022-08-10 15:31:32 +00:00
|
|
|
timer *ping_timer;
|
2023-11-15 14:03:55 +00:00
|
|
|
btime startup_delay;
|
2022-09-30 07:36:09 +00:00
|
|
|
timer *startup_timer;
|
2024-05-24 13:20:30 +00:00
|
|
|
|
|
|
|
struct mib_tree *mib_tree;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct snmp_registration;
|
|
|
|
struct agentx_response; /* declared in subagent.h */
|
|
|
|
typedef void (*snmp_reg_hook_t)(struct snmp_proto *p, const struct agentx_response *res, struct snmp_registration *reg);
|
|
|
|
|
|
|
|
struct snmp_registration {
|
|
|
|
node n;
|
|
|
|
u8 mib_class;
|
|
|
|
u32 session_id;
|
|
|
|
u32 transaction_id;
|
|
|
|
u32 packet_id;
|
|
|
|
struct oid *oid;
|
|
|
|
snmp_reg_hook_t reg_hook_ok; /* hook called when successful response to OID registration is recieved */
|
|
|
|
snmp_reg_hook_t reg_hook_fail; /* hook called when OID registration fail */
|
2022-12-10 17:08:00 +00:00
|
|
|
};
|
2023-07-26 12:34:01 +00:00
|
|
|
|
2023-09-04 11:46:02 +00:00
|
|
|
//void snmp_tx(sock *sk);
|
2023-10-18 11:30:14 +00:00
|
|
|
void snmp_startup(struct snmp_proto *p);
|
|
|
|
void snmp_connected(sock *sk);
|
|
|
|
void snmp_startup_timeout(timer *tm);
|
|
|
|
void snmp_reconnect(timer *tm);
|
2024-01-23 23:23:31 +00:00
|
|
|
int snmp_set_state(struct snmp_proto *p, enum snmp_proto_state state);
|
2023-10-18 11:30:14 +00:00
|
|
|
|
2024-01-23 23:23:31 +00:00
|
|
|
void snmp_reset(struct snmp_proto *p);
|
2022-12-10 17:08:00 +00:00
|
|
|
|
2022-08-01 11:01:49 +00:00
|
|
|
#endif
|