0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2025-01-18 15:01:53 +00:00

Extension for varbind TimeTicks, varbind type sizes

This commit is contained in:
Vojtech Vilimek 2023-08-08 17:00:20 +02:00
parent c8cda68762
commit bdf68b3240
2 changed files with 17 additions and 4 deletions

View File

@ -10,8 +10,6 @@
#include "snmp_utils.h" #include "snmp_utils.h"
int agentx_type_size(enum agentx_type t);
/** /**
* snmp_is_oid_empty - check if oid is null-valued * snmp_is_oid_empty - check if oid is null-valued
* @oid: object identifier to check * @oid: object identifier to check
@ -162,7 +160,7 @@ snmp_create_varbind(byte *buf, struct oid *oid)
{ {
struct agentx_varbind *vb = (void*) buf; struct agentx_varbind *vb = (void*) buf;
vb->pad = 0; vb->pad = 0;
memcpy(&vb->name, oid, snmp_oid_size(oid)); snmp_oid_copy(&vb->name, oid);
return vb; return vb;
} }
@ -411,8 +409,9 @@ snmp_register_create(struct snmp_proto *p, u8 mib_class)
r->n.prev = r->n.next = NULL; r->n.prev = r->n.next = NULL;
r->session_id = p->session_id; r->session_id = p->session_id;
/* will be incremented by SNMP_SESSION() macro during packet assembly */
r->transaction_id = p->transaction_id; r->transaction_id = p->transaction_id;
r->packet_id = p->packet_id; r->packet_id = p->packet_id + 1;
r->mib_class = mib_class; r->mib_class = mib_class;
@ -434,10 +433,15 @@ snmp_register_ack(struct snmp_proto *p, struct agentx_header *h)
{ {
snmp_log("snmp_register_ack()"); snmp_log("snmp_register_ack()");
snmp_log("got sid: %u tid: %u pid: %u", h->session_id, h->transaction_id,
h->packet_id);
struct snmp_register *reg; struct snmp_register *reg;
WALK_LIST(reg, p->register_queue) WALK_LIST(reg, p->register_queue)
{ {
// TODO add support for more mib trees (other than BGP) // TODO add support for more mib trees (other than BGP)
snmp_log("checking registration request sid: %u tid: %u pid: %u",
reg->session_id, reg->transaction_id, reg->packet_id);
if (snmp_register_same(reg, h, SNMP_BGP4_MIB)) if (snmp_register_same(reg, h, SNMP_BGP4_MIB))
{ {
struct snmp_registered_oid *ro = \ struct snmp_registered_oid *ro = \
@ -529,6 +533,12 @@ snmp_varbind_counter32(struct agentx_varbind *vb, uint size, u32 val)
return snmp_varbind_type32(vb, size, AGENTX_COUNTER_32, val); return snmp_varbind_type32(vb, size, AGENTX_COUNTER_32, val);
} }
inline byte *
snmp_varbind_ticks(struct agentx_varbind *vb, uint size, u32 val)
{
return snmp_varbind_type32(vb, size, AGENTX_TIME_TICKS, val);
}
inline byte * inline byte *
snmp_varbind_gauge32(struct agentx_varbind *vb, uint size, s64 val) snmp_varbind_gauge32(struct agentx_varbind *vb, uint size, s64 val)
{ {

View File

@ -51,10 +51,13 @@ void snmp_register_ack(struct snmp_proto *p, struct agentx_header *h);
byte *snmp_varbind_int(struct agentx_varbind *vb, uint size, u32 val); byte *snmp_varbind_int(struct agentx_varbind *vb, uint size, u32 val);
byte *snmp_varbind_counter32(struct agentx_varbind *vb, uint size, u32 val); byte *snmp_varbind_counter32(struct agentx_varbind *vb, uint size, u32 val);
byte *snmp_varbind_gauge32(struct agentx_varbind *vb, uint size, s64 val); byte *snmp_varbind_gauge32(struct agentx_varbind *vb, uint size, s64 val);
byte *snmp_varbind_ticks(struct agentx_varbind *vb, uint size, u32 val);
byte *snmp_varbind_ip4(struct agentx_varbind *vb, uint size, ip4_addr addr); byte *snmp_varbind_ip4(struct agentx_varbind *vb, uint size, ip4_addr addr);
byte *snmp_varbind_nstr(struct agentx_varbind *vb, uint size, const char *str, uint len); byte *snmp_varbind_nstr(struct agentx_varbind *vb, uint size, const char *str, uint len);
void snmp_dump_packet(byte *pkt, uint size); void snmp_dump_packet(byte *pkt, uint size);
enum agentx_type snmp_search_res_to_type(enum snmp_search_res res); enum agentx_type snmp_search_res_to_type(enum snmp_search_res res);
int agentx_type_size(enum agentx_type t);
#endif #endif