2022-11-22 13:16:09 +00:00
|
|
|
#ifndef _BIRD_SNMP_UTILS_H_
|
|
|
|
#define _BIRD_SNMP_UTILS_H_
|
|
|
|
|
|
|
|
#include "subagent.h"
|
2024-07-04 14:33:44 +00:00
|
|
|
#include "mib_tree.h"
|
2022-11-22 13:16:09 +00:00
|
|
|
|
2023-10-18 11:30:14 +00:00
|
|
|
uint snmp_pkt_len(const byte *start, const byte *end);
|
2024-01-23 23:23:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* AgentX Variable Biding (VarBind) utils
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AgentX - Variable Binding (VarBind) type utils
|
|
|
|
*/
|
|
|
|
int agentx_type_size(enum agentx_type t);
|
|
|
|
|
|
|
|
/* type Octet String */
|
2023-07-26 12:02:23 +00:00
|
|
|
size_t snmp_str_size_from_len(uint len);
|
2022-11-22 13:16:09 +00:00
|
|
|
size_t snmp_str_size(const char *str);
|
2024-01-23 23:23:31 +00:00
|
|
|
|
|
|
|
/* type OID - Object Identifier */
|
2023-07-26 12:02:23 +00:00
|
|
|
int snmp_is_oid_empty(const struct oid *oid);
|
2024-04-22 10:55:33 +00:00
|
|
|
int snmp_oid_is_prefixable(const struct oid *oid);
|
2024-01-23 23:23:31 +00:00
|
|
|
uint snmp_oid_size(const struct oid *o);
|
|
|
|
size_t snmp_oid_size_from_len(uint n_subid);
|
|
|
|
void snmp_oid_copy(struct oid *dest, const struct oid *src);
|
2024-04-22 10:55:33 +00:00
|
|
|
void snmp_oid_copy2(struct oid *dest, const struct oid *src);
|
2024-01-23 23:23:31 +00:00
|
|
|
int snmp_oid_compare(const struct oid *first, const struct oid *second);
|
2024-04-22 10:55:33 +00:00
|
|
|
void snmp_oid_common_ancestor(const struct oid *left, const struct oid *right, struct oid *result);
|
2024-08-09 22:07:49 +00:00
|
|
|
void snmp_oid_from_buf(struct oid *dest, const struct oid *src);
|
|
|
|
void snmp_oid_to_buf(struct oid *dest, const struct oid *src);
|
2024-04-22 10:55:33 +00:00
|
|
|
|
|
|
|
static inline int
|
|
|
|
snmp_oid_is_prefixed(const struct oid *oid)
|
|
|
|
{
|
|
|
|
return LOAD_U8(oid->prefix) != 0;
|
|
|
|
}
|
2024-01-23 23:23:31 +00:00
|
|
|
|
|
|
|
/* type IPv4 */
|
2023-07-26 12:02:23 +00:00
|
|
|
int snmp_valid_ip4_index(const struct oid *o, uint start);
|
|
|
|
int snmp_valid_ip4_index_unsafe(const struct oid *o, uint start);
|
2024-01-23 23:23:31 +00:00
|
|
|
void snmp_oid_ip4_index(struct oid *o, uint start, ip4_addr addr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AgentX - Variable Binding (VarBind) manupulation
|
|
|
|
*/
|
2024-08-09 22:07:49 +00:00
|
|
|
uint snmp_varbind_header_size(const struct oid *vb_name);
|
2024-01-10 11:21:46 +00:00
|
|
|
uint snmp_varbind_size(const struct agentx_varbind *vb, uint limit);
|
|
|
|
uint snmp_varbind_size_unsafe(const struct agentx_varbind *vb);
|
2024-01-23 23:23:31 +00:00
|
|
|
size_t snmp_varbind_size_from_len(uint n_subid, enum agentx_type t, uint len);
|
2024-08-13 15:47:15 +00:00
|
|
|
int snmp_test_varbind_type(u16 type);
|
2024-01-23 23:23:31 +00:00
|
|
|
void *snmp_varbind_data(const struct agentx_varbind *vb);
|
2024-07-23 11:48:20 +00:00
|
|
|
struct oid *snmp_varbind_set_name_len(struct snmp_pdu *c, struct agentx_varbind **vb, u8 len);
|
|
|
|
void snmp_varbind_duplicate_hdr(struct snmp_pdu *c, struct agentx_varbind **vb);
|
2024-01-23 23:23:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* AgentX - PDU headers, types, contexts
|
|
|
|
*/
|
2023-11-15 10:29:19 +00:00
|
|
|
void snmp_session(const struct snmp_proto *p, struct agentx_header *h);
|
|
|
|
int snmp_has_context(const struct agentx_header *h);
|
2024-07-17 11:03:26 +00:00
|
|
|
void snmp_pdu_context(struct snmp_pdu *pdu, struct snmp_proto *p, sock *sk);
|
2023-07-26 12:02:23 +00:00
|
|
|
struct oid *snmp_oid_duplicate(pool *pool, const struct oid *oid);
|
2022-12-10 17:08:00 +00:00
|
|
|
struct oid *snmp_oid_blank(struct snmp_proto *p);
|
|
|
|
|
2024-01-23 23:23:31 +00:00
|
|
|
int snmp_test_close_reason(byte value);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AgentX - TX buffer manipulation
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Functions filling buffer a typed value */
|
2024-05-24 13:20:30 +00:00
|
|
|
void snmp_varbind_int(struct snmp_pdu *c, u32 val);
|
|
|
|
void snmp_varbind_counter32(struct snmp_pdu *c, u32 val);
|
|
|
|
void snmp_varbind_gauge32(struct snmp_pdu *c, s64 time);
|
|
|
|
void snmp_varbind_ticks(struct snmp_pdu *c, u32 val);
|
|
|
|
void snmp_varbind_ip4(struct snmp_pdu *c, ip4_addr addr);
|
|
|
|
void snmp_varbind_nstr(struct snmp_pdu *c, const char *str, uint len);
|
2024-08-09 22:07:49 +00:00
|
|
|
void snmp_varbind_oid(struct snmp_pdu *c, const struct oid *oid_val);
|
2022-11-22 13:16:09 +00:00
|
|
|
|
2024-01-23 23:23:31 +00:00
|
|
|
/* Raw */
|
2022-11-22 13:16:09 +00:00
|
|
|
byte *snmp_no_such_object(byte *buf, struct agentx_varbind *vb, struct oid *oid);
|
|
|
|
byte *snmp_no_such_instance(byte *buf, struct agentx_varbind *vb, struct oid *oid);
|
|
|
|
byte *snmp_put_str(byte *buf, const char *str);
|
2023-07-26 12:02:23 +00:00
|
|
|
byte *snmp_put_nstr(byte *buf, const char *str, uint len);
|
2022-11-22 13:16:09 +00:00
|
|
|
byte *snmp_put_blank(byte *buf);
|
2023-07-26 12:02:23 +00:00
|
|
|
byte *snmp_put_ip4(byte *buf, ip4_addr ip4);
|
2022-11-22 13:16:09 +00:00
|
|
|
byte *snmp_put_fbyte(byte *buf, u8 data);
|
|
|
|
|
2022-12-10 17:08:00 +00:00
|
|
|
|
2024-01-23 23:23:31 +00:00
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Helpers, Misc, Debugging
|
|
|
|
*
|
|
|
|
*/
|
2024-07-23 11:48:20 +00:00
|
|
|
struct snmp_registration *snmp_registration_create(struct snmp_proto *p, enum agentx_mibs mib);
|
2024-08-13 15:53:45 +00:00
|
|
|
int snmp_registration_match(struct snmp_registration *r, struct agentx_header *h);
|
2022-12-17 17:16:19 +00:00
|
|
|
|
|
|
|
void snmp_dump_packet(byte *pkt, uint size);
|
2024-01-23 23:23:31 +00:00
|
|
|
void snmp_oid_dump(const struct oid *oid);
|
2024-04-22 10:55:33 +00:00
|
|
|
void snmp_oid_log(const struct oid *oid);
|
2023-07-26 12:02:23 +00:00
|
|
|
|
|
|
|
enum agentx_type snmp_search_res_to_type(enum snmp_search_res res);
|
2023-08-08 15:00:20 +00:00
|
|
|
|
2024-04-22 10:55:33 +00:00
|
|
|
#define AGENTX_TYPE_INT_SIZE ((uint) agentx_type_size(AGENTX_INTEGER))
|
|
|
|
#define AGENTX_TYPE_IP4_SIZE ((uint) agentx_type_size(AGENTX_IP_ADDRESS))
|
|
|
|
#define AGENTX_TYPE_COUNTER32_SIZE ((uint) agentx_type_size(AGENTX_COUNTER_32))
|
|
|
|
|
2024-07-04 14:33:44 +00:00
|
|
|
/*
|
|
|
|
* SNMP MIB tree walking
|
|
|
|
*/
|
2024-07-17 11:03:26 +00:00
|
|
|
struct mib_leaf *snmp_walk_init(struct mib_tree *tree, struct mib_walk_state *state, const struct oid *start_rx, struct snmp_pdu *context);
|
|
|
|
struct mib_leaf *snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *state, struct snmp_pdu *context);
|
|
|
|
enum snmp_search_res snmp_walk_fill(struct mib_leaf *leaf, struct mib_walk_state *state, struct snmp_pdu *context);
|
2024-07-04 14:33:44 +00:00
|
|
|
|
2022-11-22 13:16:09 +00:00
|
|
|
#endif
|