mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-03-11 17:08:46 +00:00
SNMP: Code improvements
This commit is contained in:
parent
6c59bcdfbb
commit
faa6262573
@ -252,13 +252,9 @@ snmp_start_locked(struct object_lock *lock)
|
|||||||
}
|
}
|
||||||
|
|
||||||
snmp_log("opening socket");
|
snmp_log("opening socket");
|
||||||
|
/* Try opening the socket, schedule a retry on fail */
|
||||||
if (sk_open(s) < 0)
|
if (sk_open(s) < 0)
|
||||||
{
|
tm_set(p->startup_timer, current_time() + p->timeout S);
|
||||||
// TODO rather set the startup timer, then reset whole SNMP proto
|
|
||||||
log(L_ERR "Cannot open listening socket");
|
|
||||||
snmp_down(p);
|
|
||||||
// TODO go back to SNMP_INIT and try reconnecting after timeout
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* this function is internal and shouldn't be used outside the snmp module */
|
/* this function is internal and shouldn't be used outside the snmp module */
|
||||||
@ -307,10 +303,7 @@ static void
|
|||||||
snmp_stop_timeout(timer *t)
|
snmp_stop_timeout(timer *t)
|
||||||
{
|
{
|
||||||
snmp_log("stop timer triggered");
|
snmp_log("stop timer triggered");
|
||||||
|
snmp_down(t->data);
|
||||||
struct snmp_proto *p = t->data;
|
|
||||||
|
|
||||||
snmp_down(p);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -38,7 +38,7 @@ static struct oid *search_mib(struct snmp_proto *p, const struct oid *o_start, c
|
|||||||
|
|
||||||
u32 snmp_internet[] = { SNMP_ISO, SNMP_ORG, SNMP_DOD, SNMP_INTERNET };
|
u32 snmp_internet[] = { SNMP_ISO, SNMP_ORG, SNMP_DOD, SNMP_INTERNET };
|
||||||
|
|
||||||
static const char * const snmp_errs[] = {
|
static const char * const snmp_errs[] UNUSED = {
|
||||||
#define SNMP_ERR_SHIFT 256
|
#define SNMP_ERR_SHIFT 256
|
||||||
[AGENTX_RES_OPEN_FAILED - SNMP_ERR_SHIFT] = "Open failed",
|
[AGENTX_RES_OPEN_FAILED - SNMP_ERR_SHIFT] = "Open failed",
|
||||||
[AGENTX_RES_NOT_OPEN - SNMP_ERR_SHIFT] = "Not open",
|
[AGENTX_RES_NOT_OPEN - SNMP_ERR_SHIFT] = "Not open",
|
||||||
@ -55,7 +55,7 @@ static const char * const snmp_errs[] = {
|
|||||||
[AGENTX_RES_PROCESSING_ERR - SNMP_ERR_SHIFT] = "Processing error",
|
[AGENTX_RES_PROCESSING_ERR - SNMP_ERR_SHIFT] = "Processing error",
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char * const snmp_pkt_type[] = {
|
static const char * const snmp_pkt_type[] UNUSED = {
|
||||||
[AGENTX_OPEN_PDU] = "Open-PDU",
|
[AGENTX_OPEN_PDU] = "Open-PDU",
|
||||||
[AGENTX_CLOSE_PDU] = "Close-PDU",
|
[AGENTX_CLOSE_PDU] = "Close-PDU",
|
||||||
[AGENTX_REGISTER_PDU] = "Register-PDU",
|
[AGENTX_REGISTER_PDU] = "Register-PDU",
|
||||||
@ -108,13 +108,7 @@ open_pdu(struct snmp_proto *p, struct oid *oid)
|
|||||||
c.buffer = snmp_put_str(c.buffer, cf->description);
|
c.buffer = snmp_put_str(c.buffer, cf->description);
|
||||||
|
|
||||||
uint s = update_packet_size(p, buf, c.buffer);
|
uint s = update_packet_size(p, buf, c.buffer);
|
||||||
int ret = sk_send(sk, s);
|
sk_send(sk, s);
|
||||||
if (ret > 0)
|
|
||||||
snmp_log("sk_send OK!");
|
|
||||||
else if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else
|
|
||||||
snmp_log("sk_send error");
|
|
||||||
#undef TIMEOUT_SIZE
|
#undef TIMEOUT_SIZE
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -184,13 +178,7 @@ snmp_notify_pdu(struct snmp_proto *p, struct oid *oid, void *data, uint size, in
|
|||||||
ADVANCE(c.buffer, c.size, size);
|
ADVANCE(c.buffer, c.size, size);
|
||||||
|
|
||||||
uint s = update_packet_size(p, sk->tbuf, c.buffer);
|
uint s = update_packet_size(p, sk->tbuf, c.buffer);
|
||||||
int ret = sk_send(sk, s);
|
sk_send(sk, s);
|
||||||
if (ret > 0)
|
|
||||||
snmp_log("sk_send OK!");
|
|
||||||
else if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else
|
|
||||||
snmp_log("sk_send error");
|
|
||||||
|
|
||||||
#undef TRAP0_HEADER_SIZE
|
#undef TRAP0_HEADER_SIZE
|
||||||
#undef UPTIME_SIZE
|
#undef UPTIME_SIZE
|
||||||
@ -289,13 +277,7 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint len, uint index, u8
|
|||||||
uint s = update_packet_size(p, buf, c.buffer);
|
uint s = update_packet_size(p, buf, c.buffer);
|
||||||
|
|
||||||
//snmp_log("sending (un)register %s", snmp_pkt_type[type]);
|
//snmp_log("sending (un)register %s", snmp_pkt_type[type]);
|
||||||
int ret = sk_send(sk, s);
|
sk_send(sk, s);
|
||||||
if (ret > 0)
|
|
||||||
snmp_log("sk_send OK!");
|
|
||||||
else if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else
|
|
||||||
snmp_log("sk_send error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Register-PDU */
|
/* Register-PDU */
|
||||||
@ -343,13 +325,7 @@ close_pdu(struct snmp_proto *p, u8 reason)
|
|||||||
uint s = update_packet_size(p, buf, c.buffer);
|
uint s = update_packet_size(p, buf, c.buffer);
|
||||||
|
|
||||||
//snmp_log("preparing to sk_send() (close)");
|
//snmp_log("preparing to sk_send() (close)");
|
||||||
int ret = sk_send(sk, s);
|
sk_send(sk, s);
|
||||||
if (ret > 0)
|
|
||||||
snmp_log("sk_send OK!");
|
|
||||||
else if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else
|
|
||||||
snmp_log("sk_send error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
@ -394,13 +370,7 @@ addagentcaps_pdu(struct snmp_proto *p, struct oid *cap, char *descr,
|
|||||||
// make a note in the snmp_proto structure
|
// make a note in the snmp_proto structure
|
||||||
|
|
||||||
//int ret = sk_send(sk, buf - sk->tbuf);
|
//int ret = sk_send(sk, buf - sk->tbuf);
|
||||||
int ret = sk_send(sk, buf - sk->tpos);
|
sk_send(sk, buf - sk->tpos);
|
||||||
if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else if (ret < 0)
|
|
||||||
snmp_log("sk_send err");
|
|
||||||
else
|
|
||||||
log(L_INFO, "sk_send ok !!");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UNUSED
|
static void UNUSED
|
||||||
@ -438,14 +408,7 @@ removeagentcaps_pdu(struct snmp_proto *p, struct oid *cap, struct agentx_context
|
|||||||
|
|
||||||
// update state in snmp_proto structure
|
// update state in snmp_proto structure
|
||||||
|
|
||||||
//int ret = sk_send(sk, buf - sk->tbuf);
|
sk_send(sk, buf - sk->tpos);
|
||||||
int ret = sk_send(sk, buf - sk->tpos);
|
|
||||||
if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else if (ret < 0)
|
|
||||||
snmp_log("sk_send err");
|
|
||||||
else
|
|
||||||
log(L_INFO, "sk_send ok !!");
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -1024,13 +987,7 @@ send:;
|
|||||||
//snmp_log("sending response to Get-PDU, GetNext-PDU or GetBulk-PDU request (size %u)...", s);
|
//snmp_log("sending response to Get-PDU, GetNext-PDU or GetBulk-PDU request (size %u)...", s);
|
||||||
|
|
||||||
/* We send the message in TX-buffer. */
|
/* We send the message in TX-buffer. */
|
||||||
int ret = sk_send(sk, s);
|
sk_send(sk, s);
|
||||||
if (ret > 0)
|
|
||||||
snmp_log("sk_send OK!");
|
|
||||||
else if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else
|
|
||||||
snmp_log("sk_send error");
|
|
||||||
// TODO think through the error state
|
// TODO think through the error state
|
||||||
|
|
||||||
mb_free(o_start);
|
mb_free(o_start);
|
||||||
@ -1173,13 +1130,7 @@ snmp_ping(struct snmp_proto *p)
|
|||||||
/* sending only header -> pkt - buf */
|
/* sending only header -> pkt - buf */
|
||||||
uint s = update_packet_size(p, sk->tpos, c.buffer);
|
uint s = update_packet_size(p, sk->tpos, c.buffer);
|
||||||
|
|
||||||
int ret = sk_send(sk, s);
|
sk_send(sk, s);
|
||||||
if (ret > 0)
|
|
||||||
snmp_log("sk_send OK!");
|
|
||||||
else if (ret == 0)
|
|
||||||
snmp_log("sk_send sleep");
|
|
||||||
else
|
|
||||||
snmp_log("sk_send error");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int
|
static inline int
|
||||||
|
@ -122,7 +122,7 @@ enum snmp_search_res {
|
|||||||
buf += 4 + snmp_str_size_from_len(length); })
|
buf += 4 + snmp_str_size_from_len(length); })
|
||||||
|
|
||||||
#define SNMP_LOAD_CONTEXT(hdr, buf, cont, cont_len) ({ \
|
#define SNMP_LOAD_CONTEXT(hdr, buf, cont, cont_len) ({ \
|
||||||
if ((hdr)->flags & AGENTX_NON_DEFAULT_CONTEXT) \
|
if (cont = NULL, cont_len = 0, (hdr)->flags & AGENTX_NON_DEFAULT_CONTEXT) \
|
||||||
LOAD_STR((buf), (cont), (cont_len), \
|
LOAD_STR((buf), (cont), (cont_len), \
|
||||||
(hdr)->flags & AGENTX_NETWORK_BYTE_ORDER); })
|
(hdr)->flags & AGENTX_NETWORK_BYTE_ORDER); })
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user