[BGP_INTERNAL_NO_VALUE] = "BGP_INTERNAL_NO_VALUE",
};
+static inline uint
+snmp_bgp_fsm_state(struct bgp_proto *bgp_proto)
+{
+ const struct bgp_conn *bgp_conn = bgp_proto->conn;
+ const struct bgp_conn *bgp_in = &bgp_proto->incoming_conn;
+ const struct bgp_conn *bgp_out = &bgp_proto->outgoing_conn;
+
+ if (bgp_conn)
+ return bgp_conn->state;
+
+ if (MAX(bgp_in->state, bgp_out->state) == BS_CLOSE &&
+ MIN(bgp_in->state, bgp_out->state) != BS_CLOSE)
+ return MIN(bgp_in->state, bgp_out->state);
+ if (MIN(bgp_in->state, bgp_out->state) == BS_CLOSE)
+ return BS_IDLE;
+
+ return MAX(bgp_in->state, bgp_out->state);
+}
+
+
void
snmp_bgp_register(struct snmp_proto *p)
{
struct bgp_stats *bgp_stats = &bgp_proto->stats;
const struct bgp_config *bgp_conf = bgp_proto->cf;
- uint bgp_state;
-
- if (bgp_conn)
- bgp_state = bgp_conn->state;
- else if (MAX(bgp_in->state, bgp_out->state) == BS_CLOSE &&
- MIN(bgp_in->state, bgp_out->state) != BS_CLOSE)
- bgp_state = MIN(bgp_in->state, bgp_out->state);
- else if (MIN(bgp_in->state, bgp_out->state) == BS_CLOSE)
- bgp_state = BS_IDLE;
- else
- bgp_state = MAX(bgp_in->state, bgp_out->state);
+ uint bgp_state = snmp_bgp_fsm_state(bgp_proto);
- char last_error[2] = { bgp_proto->last_error_code & 0x00FF0000 >> 16,
- bgp_proto->last_error_code & 0x000000FF };
+ char last_error[2] = SNMP_BGP_LAST_ERROR(bgp_proto);
switch (state)
{
case BGP_INTERNAL_IDENTIFIER:
{
sock *sk = p->sock;
- struct snmp_pdu_context c = {
- .buffer = sk->tpos,
- .size = sk->tbuf + sk->tbsize - sk->tpos,
- };
+ struct snmp_pdu_context c = SNMP_PDU_CONTEXT(sk);
byte *buf = c.buffer;
// TODO should be configurable; with check on string length
struct agentx_header *h = (struct agentx_header *) c.buffer;
ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
SNMP_BLANK_HEADER(h, AGENTX_OPEN_PDU);
+ c.byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
STORE_U32(h->session_id, 1);
STORE_U32(h->transaction_id, 1);
{
sock *sk = p->sock;
- struct snmp_pdu_context c = {
- .buffer = sk->tpos,
- .size = sk->tbuf + sk->tbsize - sk->tpos,
- };
-
- if (c.size < AGENTX_HEADER_SIZE)
- {
- snmp_manage_tbuf(p, &c);
- }
-
- struct agentx_header *h = (struct agentx_header *) c.buffer;
- ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
- SNMP_BLANK_HEADER(h, AGENTX_NOTIFY_PDU);
- SNMP_SESSION(h, p);
-
- c.byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
+ struct snmp_pdu_context c = SNMP_PDU_CONTEXT(sk);
#define UPTIME_SIZE \
(6 * sizeof(u32)) /* sizeof( { u32 vb_type, u32 oid_hdr, u32 ids[4] } )*/
(7 * sizeof(u32)) /* sizeof( { u32 vb_type, u32 oid_hdr, u32 ids[6] } ) */
uint sz = AGENTX_HEADER_SIZE + TRAP0_HEADER_SIZE + snmp_oid_size(oid) \
- + snmp_varbind_hdr_size_from_oid(oid) + size;
+ + size;
if (include_uptime)
sz += UPTIME_SIZE;
-
+
if (c.size < sz)
snmp_manage_tbuf(p, &c);
+ struct agentx_header *h = (struct agentx_header *) c.buffer;
+ ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
+ SNMP_BLANK_HEADER(h, AGENTX_NOTIFY_PDU);
+ SNMP_SESSION(h, p);
+ c.byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
+
if (include_uptime)
{
/* sysUpTime.0 oid */
un_register_pdu(struct snmp_proto *p, struct oid *oid, uint index, uint len, u8 type, u8 is_instance)
{
sock *sk = p->sock;
- struct snmp_pdu_context c = {
- .buffer = sk->tpos,
- .size = sk->tbuf + sk->tbsize - sk->tpos,
- };
+ struct snmp_pdu_context c = SNMP_PDU_CONTEXT(sk);
byte *buf = c.buffer;
/* conditional +4 for upper-bound (optinal field) */
/* use new transactionID, reset packetID */
p->packet_id++;
SNMP_SESSION(h, p);
+ c.byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
/* do not override timeout */
STORE_U32(ur->timeout, 15);
close_pdu(struct snmp_proto *p, u8 reason)
{
sock *sk = p->sock;
- struct snmp_pdu_context c = {
- .buffer = sk->tpos,
- .size = sk->tbuf + sk->tbsize - sk->tpos,
- };
+ struct snmp_pdu_context c = SNMP_PDU_CONTEXT(sk);
byte *buf = c.buffer;
snmp_log("close_pdu() size: %u %c %u", c.size, (c.size > AGENTX_HEADER_SIZE + 4)
SNMP_BLANK_HEADER(h, AGENTX_CLOSE_PDU);
p->packet_id++;
SNMP_SESSION(h, p);
+ c.byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
snmp_put_fbyte(c.buffer, reason);
ADVANCE(c.buffer, c.size, 4);
break;
case SNMP_STOP:
- snmp_shutdown();
+ snmp_down(p);
break;
default:
uint pkt_size = LOAD_U32(h->payload, h->flags & AGENTX_NETWORK_BYTE_ORDER);
sock *sk = p->sock;
- struct snmp_pdu_context c = {
- .buffer = sk->tpos,
- .size = sk->tbuf + sk->tbsize - sk->tpos,
- .byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER,
- .error = AGENTX_RES_NO_ERROR,
- .context = 0,
- };
+ struct snmp_pdu_context c = SNMP_PDU_CONTEXT(sk);
+ // TODO better handling of endianness
+ c.byte_ord = 0; /* use little-endian */
uint clen; /* count of characters in context (without last '\0') */
char *context; /* newly allocated string of character */
sock *sk = p->sock;
snmp_dump_packet(sk->tpos, AGENTX_HEADER_SIZE + 4);
snmp_log("snmp_ping sk->tpos 0x%p", sk->tpos);
- struct snmp_pdu_context c = {
- .buffer = sk->tpos,
- .size = sk->tbuf + sk->tbsize - sk->tpos,
- };
+ struct snmp_pdu_context c = SNMP_PDU_CONTEXT(sk);
if (c.size < AGENTX_HEADER_SIZE)
snmp_manage_tbuf(p, &c);
SNMP_BLANK_HEADER(h, AGENTX_PING_PDU);
p->packet_id++;
SNMP_SESSION(h, p);
+ c.byte_ord = AGENTX_NETWORK_BYTE_ORDER;
snmp_log("sending ping packet ... tpos 0x%p", sk->tpos);
snmp_dump_packet(sk->tpos, AGENTX_HEADER_SIZE + 4);
}
#endif
+/*
void
snmp_tx(sock UNUSED *sk)
{
snmp_log("snmp_tx");
- //struct snmp_proto *p = sk->data;
-
- return;
-
-#if 0
- if (!p->partial_response)
- return;
-
- send_remaining_buffers(sk);
-#endif
}
+*/
static struct agentx_response *