0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-25 18:30:04 +00:00
bird/proto/snmp/snmp.h

174 lines
3.7 KiB
C
Raw Normal View History

2022-08-01 13:01:49 +02: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 17:31:32 +02:00
#define _BIRD_SNMP_H_
2022-08-01 13:01:49 +02:00
2022-08-10 17:31:32 +02:00
#include "lib/ip.h"
#include "lib/socket.h"
#include "lib/timer.h"
#include "nest/bird.h"
#include "nest/protocol.h"
2022-09-30 09:36:09 +02:00
#include "filter/data.h"
2022-08-01 13:01:49 +02:00
#include "proto/bgp/bgp.h"
2022-08-10 17:31:32 +02:00
#define SNMP_UNDEFINED 0
#define SNMP_BGP 1
#define SNMP_OSPF 2
#define SNMP_INVALID 255
2022-08-10 17:31:32 +02:00
#define SNMP_PORT 705
#define SNMP_RX_BUFFER_SIZE 8192
#define SNMP_TX_BUFFER_SIZE 8192
2022-08-10 17:31:32 +02:00
2022-12-17 18:16:19 +01:00
enum snmp_proto_state {
2023-09-04 09:25:51 +02:00
SNMP_INIT = 1,
SNMP_LOCKED,
SNMP_OPEN,
SNMP_REGISTER,
SNMP_CONN,
SNMP_STOP,
SNMP_DOWN,
2022-12-17 18:16:19 +01:00
};
2022-09-06 18:04:29 +02:00
/* hash table macros */
2022-09-20 14:28:57 +02:00
#define SNMP_HASH_KEY(n) n->peer_ip
#define SNMP_HASH_NEXT(n) n->next
2022-09-06 18:04:29 +02:00
#define SNMP_HASH_EQ(ip1, ip2) ipa_equal(ip1, ip2)
#define SNMP_HASH_FN(ip) ipa_hash(ip)
2022-09-30 09:36:09 +02:00
#define SNMP_HASH_LESS4(ip1, ip2) ip4_less(ip1, ip2)
#define SNMP_HASH_LESS6(ip1, ip2) ip6_less(ip1, ip2)
/* hash table only store ip4 addresses */
#define SNMP_HASH_LESS(ip1, ip2) SNMP_HASH_LESS4(ip1,ip2)
/* context hash table macros */
#define SNMP_H_CONTEXT_KEY(c) c->context
#define SNMP_H_CONTEXT_NEXT(c) c->next
#define SNMP_H_CONTEXT_EQ(s1,s2) strcmp(s1,s2)
#define SNMP_H_CONTEXT_FN(s) mem_hash(s, strlen(s))
struct snmp_bond {
node n;
struct proto_config *proto;
u8 type;
const char *context;
};
2022-08-01 13:01:49 +02:00
struct snmp_config {
2022-08-10 17:31:32 +02:00
struct proto_config cf;
ip_addr local_ip;
ip_addr remote_ip;
u16 local_port;
u16 remote_port;
2023-10-11 10:44:18 +02:00
ip_addr bgp_local_id; /* BGP4-MIB related fields */
u32 bgp_local_as;
2022-08-10 17:31:32 +02:00
u8 timeout;
u8 priority;
2022-08-10 17:31:32 +02:00
//struct iface *iface;
u32 bonds;
uint contexts; /* Number of all conetexts including the default */
const char *description;
list bgp_entries;
// TODO add support for subagent oid identification
2022-08-01 13:01:49 +02:00
};
#define SNMP_BGP_P_REGISTERING 0x01
#define SNMP_BGP_P_REGISTERED 0x02
2022-09-20 14:28:57 +02:00
struct snmp_bgp_peer {
const struct bgp_config *config;
2022-09-06 18:04:29 +02:00
ip_addr peer_ip;
uint context_id;
u8 flags;
2022-09-20 14:28:57 +02:00
struct snmp_bgp_peer *next;
};
2022-09-06 18:04:29 +02:00
2022-12-10 18:08:00 +01:00
struct snmp_register {
node n;
u8 mib_class;
u32 session_id;
u32 transaction_id;
u32 packet_id;
struct oid *oid;
};
struct snmp_registered_oid {
node n;
struct oid *oid;
};
struct snmp_context {
const char *context; /* string name */
//uint length; /* strlen() of name */
uint context_id;
u8 flags;
struct snmp_context *next;
};
2022-08-01 13:01:49 +02:00
struct snmp_proto {
2022-08-10 17:31:32 +02:00
struct proto p;
struct object_lock *lock;
2023-10-18 18:06:24 +02:00
pool *pool; /* a shortcut to the procotol mem. pool */
linpool *lp; /* linpool for bgp_trie nodes */
2022-09-30 09:36:09 +02:00
2022-08-10 17:31:32 +02:00
ip_addr local_ip;
ip_addr remote_ip;
u16 local_port;
u16 remote_port;
2023-10-11 10:44:18 +02:00
2023-10-18 18:06:24 +02:00
ip_addr bgp_local_id; /* BGP4-MIB related fields */
2023-10-11 10:44:18 +02:00
u32 bgp_local_as;
2022-09-06 18:04:29 +02:00
2022-08-10 17:31:32 +02:00
sock *sock;
2023-09-04 14:01:08 +02:00
u8 timeout; /* timeout is part of MIB registration. It
specifies how long should the master
agent wait for request responses. */
2022-09-06 18:04:29 +02:00
2022-08-10 17:31:32 +02:00
u32 session_id;
u32 transaction_id;
u32 packet_id;
2022-09-06 18:04:29 +02:00
2022-12-10 18:08:00 +01:00
uint register_to_ack; /* counter of pending responses to register-pdu */
list register_queue; /* list containing snmp_register records */
list bgp_registered; /* list of currently registered bgp oids
2023-07-26 14:34:01 +02:00
* (struct snmp_registered_oid) */
2022-12-10 13:22:37 +01:00
// map
2022-09-30 09:36:09 +02:00
struct f_trie *bgp_trie;
2022-09-20 14:28:57 +02:00
HASH(struct snmp_bgp_peer) bgp_hash;
HASH(struct snmp_context) context_hash;
const struct snmp_context **context_id_map;
uint context_max;
2022-08-01 13:01:49 +02:00
struct tbf rl_gen;
2022-09-06 18:04:29 +02:00
2022-08-10 17:31:32 +02:00
timer *ping_timer;
2022-08-01 13:01:49 +02:00
2022-09-30 09:36:09 +02:00
uint startup_delay;
timer *startup_timer;
u8 state;
2022-08-01 13:01:49 +02:00
2022-09-30 09:36:09 +02:00
uint to_send;
uint errs;
2022-12-10 18:08:00 +01:00
};
2023-07-26 14:34:01 +02:00
2023-09-04 13:46:02 +02:00
//void snmp_tx(sock *sk);
void snmp_startup(struct snmp_proto *p);
void snmp_connected(sock *sk);
void snmp_startup_timeout(timer *tm);
void snmp_reconnect(timer *tm);
2022-12-10 18:08:00 +01:00
2022-08-01 13:01:49 +02:00
#endif