void
snmp_bgp_register(struct snmp_proto *p)
{
- snmp_log("snmp_bgp_register()");
+ //snmp_log("snmp_bgp_register()");
//u32 bgp_mib_prefix[] = {1, 15, 1};
u32 bgp_mib_prefix[] = { 1, 15 };
static struct oid *
update_bgp_oid(struct oid *oid, u8 state)
{
- snmp_log("update_bgp_oid()");
+ //snmp_log("update_bgp_oid()");
if (state == BGP_INTERNAL_END || state == BGP_INTERNAL_INVALID ||
state == BGP_INTERNAL_NO_VALUE)
return oid;
return oid;
}
- snmp_log("update work");
+ //snmp_log("update work");
switch (state)
{
case BGP_INTERNAL_BGP:
ASSUME(o_start != NULL);
ASSUME(o_end != NULL);
- snmp_log("bgp_find_dynamic_oid()");
+ //snmp_log("bgp_find_dynamic_oid()");
ip4_addr ip4 = ip4_from_oid(o_start);
ip4_addr dest;
ip4_from_u32(UINT32_MAX);
}
- snmp_log("ip addresses build (ip4) %I (dest) %I", ipa_from_ip4(ip4), ipa_from_ip4(dest));
+ //snmp_log("ip addresses build (ip4) %I (dest) %I", ipa_from_ip4(ip4), ipa_from_ip4(dest));
net_addr net;
net_fill_ip4(&net, ip4, IP4_MAX_PREFIX_LENGTH);
- snmp_log("dynamic part of BGP mib");
+ //snmp_log("dynamic part of BGP mib");
struct f_trie_walk_state ws;
trie_walk_init(&ws, p->bgp_trie, NULL, 0);
- snmp_log("walk init");
+ //snmp_log("walk init");
if (trie_walk_next(&ws, &net))
{
- snmp_log("trie_walk_next() returned true");
+ //snmp_log("trie_walk_next() returned true");
/*
* If the o_end is empty, then there are no conditions on the ip4 address.
int cmp = ip4_compare(net4_prefix(&net), dest);
if (cmp < 0 || (cmp == 0 && snmp_is_oid_empty(o_end)))
{
- snmp_log("ip4_less() returned true");
+ //snmp_log("ip4_less() returned true");
// TODO repair
struct oid *o = snmp_oid_duplicate(p->pool, o_start);
return o;
}
else
- snmp_log("ip4_less() returned false for %I >= %I", net4_prefix(&net), dest);
+ {}//snmp_log("ip4_less() returned false for %I >= %I", net4_prefix(&net), dest);
}
else
- snmp_log("trie_walk_next() returned false, cleaning");
+ {}//snmp_log("trie_walk_next() returned false, cleaning");
return NULL;
}
static struct oid *
search_bgp_dynamic(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, uint contid
-UNUSED, u8 current_state)
+UNUSED, u8 next_state)
{
- snmp_log("search_bgp_dynamic() dynamic part Yaaay!");
+ //snmp_log("search_bgp_dynamic() dynamic part Yaaay!");
- /* TODO can be remove after implementing all BGP4-MIB::bgpPeerTable columns */
- u8 next_state = current_state;
struct oid *o_copy = o_start;
do
{
- snmp_log("do-while state %u", next_state);
- snmp_oid_dump(o_start);
+ //snmp_log("do-while state %u", next_state);
+ //snmp_oid_dump(o_start);
o_start = o_copy = update_bgp_oid(o_copy, next_state);
o_start = bgp_find_dynamic_oid(p, o_start, o_end, next_state);
- snmp_log("found");
- snmp_oid_dump(o_start);
+ //snmp_log("found");
+ //snmp_oid_dump(o_start);
next_state = snmp_bgp_next_state(next_state);
/* The search in next state is done from beginning. */
o_start->ids[5] = o_start->ids[6] = o_start->ids[7] = o_start->ids[8] = 0;
o_start->include = 1;
- snmp_log("looping");
+ //snmp_log("looping");
} while (o_start == NULL && next_state < BGP_INTERNAL_END);
return o_start;
int match = trie_walk_init(&ws, p->bgp_trie, &net, 1);
- snmp_log("match %d include %u", match, oid->include);
+ //snmp_log("match %d include %u", match, oid->include);
if (match && oid->include)
{
oid->include = 0;
/* We skip the first match as we should not include ip address in oid */
if (match)
{
- snmp_log("continue");
+ //snmp_log("continue");
trie_walk_next(&ws, &net);
}
if (trie_walk_next(&ws, &net))
{
- snmp_oid_dump(oid);
- snmp_log("setting up");
+ //snmp_oid_dump(oid);
+ //snmp_log("setting up");
u32 res = ipa_to_u32(net_prefix(&net));
ASSUME(oid->n_subid == 9);
return 1;
}
- snmp_log("bad");
+ //snmp_log("bad");
return 0;
}
snmp_bgp_search_dynamic(struct snmp_proto *p, struct oid **searched, const struct oid *o_end, uint UNUSED contid, u8 next_state)
{
struct oid *oid = *searched;
- snmp_log(" **searched = 0x%p *oid = 0x%p", searched, oid);
- snmp_oid_dump(*searched);
- snmp_oid_dump(oid);
+ //snmp_log(" **searched = 0x%p *oid = 0x%p", searched, oid);
+ //snmp_oid_dump(*searched);
+ //snmp_oid_dump(oid);
u8 end_state = MIN(snmp_bgp_state(o_end), BGP_INTERNAL_PEER_TABLE_END);
- snmp_log("before assumption %s [%u] < %u INTERNAL_END", debug_bgp_states[end_state], end_state, BGP_INTERNAL_END);
+ //snmp_log("before assumption %s [%u] < %u INTERNAL_END", debug_bgp_states[end_state], end_state, BGP_INTERNAL_END);
ASSUME(end_state <= BGP_INTERNAL_END);
- snmp_log("before assupmtion oid 0x%p != NULL (0x0)", oid);
+ //snmp_log("before assupmtion oid 0x%p != NULL (0x0)", oid);
ASSUME(oid != NULL);
oid = update_bgp_oid(oid, next_state);
- snmp_log("update bgp oid to state %s [%d]", debug_bgp_states[next_state], next_state);
- snmp_oid_dump(*searched);
- snmp_oid_dump(oid);
+ //snmp_log("update bgp oid to state %s [%d]", debug_bgp_states[next_state], next_state);
+ //snmp_oid_dump(*searched);
+ //snmp_oid_dump(oid);
int found;
while (!(found = snmp_bgp_find_next_oid(p, oid, contid)) && next_state <= end_state)
{
- snmp_log("loop");
+ //snmp_log("loop");
next_state = snmp_bgp_next_state(next_state);
if (next_state == BGP_INTERNAL_IDENTIFIER)
enum snmp_search_res r = SNMP_SEARCH_END_OF_VIEW;
u8 bgp_state = snmp_bgp_state(*searched);
u8 state;
- snmp_log("snmp_bgp_search2() with state %s [%d]", debug_bgp_states[bgp_state], bgp_state);
+ //snmp_log("snmp_bgp_search2() with state %s [%d]", debug_bgp_states[bgp_state], bgp_state);
if (bgp_state == BGP_INTERNAL_END)
{
if (is_dynamic(state) && !is_dynamic(bgp_state))
{
- snmp_log("searching a dynamic successor of static state");
+ //snmp_log("searching a dynamic successor of static state");
for (uint i = 5; i < MIN(9, (*searched)->n_subid); i++)
(*searched)->ids[i] = 0;
r = snmp_bgp_search_dynamic(p, searched, o_end, contid, state);
if (is_dynamic(bgp_state))
{
- snmp_log("searching the dynamic states (peers)");
+ //snmp_log("searching the dynamic states (peers)");
r = snmp_bgp_search_dynamic(p, searched, o_end, contid, bgp_state);
if (r != SNMP_SEARCH_END_OF_VIEW)
state = snmp_bgp_next_state(bgp_state);
if (state <= BGP_INTERNAL_IDENTIFIER)
{
- snmp_log("returning the local identifier");
+ //snmp_log("returning the local identifier");
*searched = update_bgp_oid(*searched, state);
return SNMP_SEARCH_OK;
}
// TODO add route table
/* end not found */
- snmp_log("reached unguarded code, returning END_OF_VIEW");
+ //snmp_log("reached unguarded code, returning END_OF_VIEW");
return SNMP_SEARCH_END_OF_VIEW;
}
if (o_start->include && snmp_bgp_has_value(start_state) &&
!is_dynamic(start_state) && o_start->n_subid == 3)
{
- snmp_log("snmp_bgp_search() first search element (due to include field) returned");
+ //snmp_log("snmp_bgp_search() first search element (due to include field) returned");
/* We disable including for next time searching. */
o_start->include = 0;
return o_start;
else if (o_start->include && snmp_bgp_has_value(start_state) &&
is_dynamic(start_state))
{
- snmp_log("snmp_bgp_search() first search element matched dynamic entry!");
+ //snmp_log("snmp_bgp_search() first search element matched dynamic entry!");
return search_bgp_dynamic(p, o_start, o_end, contid, start_state);
}
if (!is_dynamic(next_state))
{
o_start = update_bgp_oid(o_start, next_state);
- snmp_log("next state is also not dynamic");
+ //snmp_log("next state is also not dynamic");
return o_start;
}
return pkt;
}
- snmp_log(" -> ip addr %I", addr);
+ //snmp_log(" -> ip addr %I", addr);
// TODO XXX deal with possible change of (remote) ip; BGP should restart and
// disappear
struct snmp_bgp_peer *pe = HASH_FIND(p->bgp_hash, SNMP_HASH, addr);
ipa_equal(addr, ((struct bgp_proto *) proto)->remote_ip))
{
bgp_proto = (struct bgp_proto *) proto;
- snmp_log("bgp_dynamic_fill() using bgp_proto %p", bgp_proto);
+ //snmp_log("bgp_dynamic_fill() using bgp_proto %p", bgp_proto);
}
/* We did not found binded BGP protocol. */
else
bgp_fill_static(struct snmp_proto *p, struct agentx_varbind *vb, byte *pkt, uint size
UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
{
- snmp_log("snmp bgp_fill_static ()\n");
- snmp_log("bgp_fill_static: vb->type %u, ptk %02x", vb->type, *((u32 *) pkt));
+ ASSUME((void *) pkt == (void *) vb);
+ //snmp_log("snmp bgp_fill_static ()\n");
+ //snmp_log("bgp_fill_static: vb->type %u, ptk %02x", vb->type, *((u32 *) pkt));
struct oid *oid = &vb->name;
- snmp_oid_dump(oid);
- snmp_log("bgp_fill_static");
+ //snmp_oid_dump(oid);
+ //snmp_log("bgp_fill_static");
/*
* snmp_bgp_state() check only prefix. To be sure on OID equivalence we need to
#if 0
snmp_log("bgp_fill_static: type %u packet %p", vb->type, pkt);
- snmp_oid_dump(oid);
+ //snmp_oid_dump(oid);
- snmp_log("snmp ended with non empty pkt %u starting from %p to %p\n", pkt -
+ /*snmp_log("snmp ended with non empty pkt %u starting from %p to %p\n", pkt -
temp, temp, pkt);
- snmp_dump_packet(temp, pkt - temp);
+*/
+ //snmp_dump_packet(temp, pkt - temp);
#endif
return pkt;
}
p->bgp_local_as = cf->bgp_local_as;
p->bgp_local_id = cf->bgp_local_id;
- snmp_log("changing proto_snmp state to INIT");
+ snmp_log("changing state to INIT");
p->state = SNMP_INIT;
p->timeout = cf->timeout;
- snmp_log("snmp_init() lip: %I:%u rip: %I:%u",
- cf->local_ip, cf->local_port, cf->remote_ip, cf->remote_port);
-
/* used when assigning the context ids in s_cont_create() */
p->context_max = 1;
p->context_id_map = NULL;
snmp_connected(sock *sk)
{
struct snmp_proto *p = sk->data;
- snmp_log("snmp_connected() connection created");
+ snmp_log("connection created");
p->state = SNMP_OPEN;
}
static void
-snmp_sock_err(sock *sk, int err)
+snmp_sock_err(sock *sk, int UNUSED err)
{
- snmp_log("snmp_sock_err() %s - err no: %d", strerror(err), err);
+ snmp_log("socket error '%s' (errno: %d)", strerror(err), err);
struct snmp_proto *p = sk->data;
p->errs++;
rfree(p->sock);
p->sock = NULL;
- snmp_log("changing proto_snmp state to LOCKED");
+ snmp_log("changing state to LOCKED");
p->state = SNMP_LOCKED;
p->startup_timer->hook = snmp_startup_timeout;
static void
snmp_start_locked(struct object_lock *lock)
{
- snmp_log("snmp_start_locked() - lock acquired; preparing socket");
+ //snmp_log("snmp_start_locked() - lock acquired; preparing socket");
struct snmp_proto *p = lock->data;
p->state = SNMP_LOCKED;
p->errs = 0;
}
+ snmp_log("opening socket");
if (sk_open(s) < 0)
{
// TODO rather set the startup timer, then reset whole SNMP proto
p->state != SNMP_LOCKED &&
p->state != SNMP_DOWN)
{
- snmp_log("startup() already in connected state %u", p->state);
return;
}
return;
}
- snmp_log("snmp_startup(), praparing lock");
+ snmp_log("preparing object lock");
p->state = SNMP_INIT;
- /* Starting AgentX communicaiton channel. */
-
struct object_lock *lock;
lock = p->lock = olock_new(p->pool);
lock->hook = snmp_start_locked;
lock->data = p;
- snmp_log("lock acquiring");
olock_acquire(lock);
-
- /*
- snmp_log("local ip: %I:%u, remote ip: %I:%u",
- p->local_ip, p->local_port, p->remote_ip, p->remote_port);
- */
}
/* this function is internal and shouldn't be used outside the snmp module */
static int
snmp_start(struct proto *P)
{
- snmp_log("snmp_start() - starting timer (almost)");
+ //snmp_log("snmp_start() - starting timer (almost)");
struct snmp_proto *p = (void *) P;
struct snmp_config *cf = (struct snmp_config *) P->cf;
/* We always have at least the default context */
p->context_id_map = mb_allocz(p->pool, cf->contexts * sizeof(struct snmp_context *));
- log(L_INFO "number of context allocated %d", cf->contexts);
+ //log(L_INFO "number of context allocated %d", cf->contexts);
struct snmp_context *defaultc = mb_alloc(p->pool, sizeof(struct snmp_context));
defaultc->context = "";
if (b->context)
{
const struct snmp_context *c = snmp_cont_create(p, b->context);
- snmp_log("creating snmp context %s with id %u, writing", b->context, c->context_id);
+ //snmp_log("creating snmp context %s with id %u, writing", b->context, c->context_id);
p->context_id_map[c->context_id] = c;
peer->context_id = c->context_id;
}
}
}
- snmp_log("values of context cf %u proto %u", cf->contexts, p->context_max);
+ //snmp_log("values of context cf %u proto %u", cf->contexts, p->context_max);
ASSUME(cf->contexts == p->context_max);
snmp_startup(p);
cli_msg(-1006, " remote ip: %I4", bcf->remote_ip);
cli_msg(-1006, " local port: %I4", bcf->local_port);
cli_msg(-1006, " remote port: %I4", bcf->remote_port);
+
/*
if (conn) {
cli_msg(-1006, " state: %u", conn->state);
cli_msg(-1006, " remote as: %u", conn->remote_caps->as4_number);
}
*/
+
cli_msg(-1006, " in updates: %u", bp->stats.rx_updates);
cli_msg(-1006, " out updates: %u", bp->stats.tx_updates);
cli_msg(-1006, " in total: %u", bp->stats.rx_messages);
static int
snmp_shutdown(struct proto *P)
{
- snmp_log("snmp_shutdown()");
struct snmp_proto *p = SKIP_BACK(struct snmp_proto, p, P);
tm_stop(p->ping_timer);
p->state == SNMP_CONN)
{
/* We have a connection established (at leased send out Open-PDU). */
+ snmp_log("changing state to STOP");
p->state = SNMP_STOP;
-
p->startup_timer->hook = snmp_stop_timeout;
-
tm_set(p->startup_timer, current_time() + p->timeout S);
-
snmp_stop_subagent(p);
return PS_STOP;
static uint parse_response(struct snmp_proto *p, byte *buf, uint size);
static void do_response(struct snmp_proto *p, byte *buf, uint size);
static uint parse_gets2_pdu(struct snmp_proto *p, byte *buf, uint size, uint *skip);
-static uint parse_close_pdu(struct snmp_proto *p, byte *buf, uint size);
static struct agentx_response *prepare_response(struct snmp_proto *p, struct snmp_pdu *c);
static void response_err_ind(struct agentx_response *res, uint err, uint ind);
static uint update_packet_size(struct snmp_proto *p, const byte *start, byte *end);
struct snmp_pdu c = SNMP_PDU_CONTEXT(sk);
byte *buf = c.buffer;
- /* +4 for timeout (1B with 4B alignment) */
- if (c.size < AGENTX_HEADER_SIZE + 4 + snmp_oid_size(oid) +
+#define TIMEOUT_SIZE 4 /* 1B timeout, 3B zero padding */
+ if (c.size < AGENTX_HEADER_SIZE + TIMEOUT_SIZE + snmp_oid_size(oid) +
+ snmp_str_size(cf->description))
{
snmp_manage_tbuf(p, &c);
buf = c.buffer;
}
- /* Function open_pdu() does not generate agentx_pkt. */
struct agentx_header *h = (struct agentx_header *) c.buffer;
ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
SNMP_BLANK_HEADER(h, AGENTX_OPEN_PDU);
snmp_log("sk_send sleep");
else
snmp_log("sk_send error");
+#undef TIMEOUT_SIZE
}
void
if (c.size < sz)
{
- snmp_log("un_register_pdu() insufficient size");
+ //snmp_log("un_register_pdu() insufficient size");
snmp_manage_tbuf(p, &c);
buf = c.buffer;
}
- snmp_log("un_register_pdu()");
+ //snmp_log("un_register_pdu()");
struct agentx_header *h = (struct agentx_header *) c.buffer;
ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
SNMP_SESSION(h, p);
c.byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
+/*
log("un_register_pdu contid %u s_cont (at 0x%p) %s", contid, sc, (sc &&
sc->context) ? sc->context : "<not_avail>");
-
+*/
SNMP_NON_DEFAULT_CONTEXT(h, c, contid);
struct agentx_un_register_hdr *ur = (struct agentx_un_register_hdr *) 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);
if (ret > 0)
snmp_log("sk_send OK!");
struct snmp_pdu 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_log("close_pdu() size: %u %c %u", c.size, (c.size > AGENTX_HEADER_SIZE + 4)
? '>':'<', AGENTX_HEADER_SIZE);
+*/
/* +4B for reason */
if (c.size < AGENTX_HEADER_SIZE + 4)
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);
if (ret > 0)
snmp_log("sk_send OK!");
sock *sk = p->sock;
//byte *buf = sk->tbuf;
//uint size = sk->tbsize;
- // TODO rename to pkt and add pkt_start
+ // TO-DO rename to pkt and add pkt_start
byte *buf = sk->tpos;
uint size = sk->tbuf + sk->tbsize - sk->tpos;
if (size < AGENTX_HEADER_SIZE + snmp_context_size(c) + snmp_oid_size(cap) + snmp_str_size_from_len(descr_len))
{
- /* TODO need more mem */
+ /* TO-DO need more mem */
return;
}
//byte *buf = sk->tbuf;
//uint size = sk->tbsize;
- // TODO rename to pkt and add pkt_start
+ // TO-DO rename to pkt and add pkt_start
byte *buf = sk->tpos;
uint size = sk->tbuf + sk->tbsize - sk->tpos;
if (size < AGENTX_HEADER_SIZE + snmp_context_size(c) + snmp_oid_size(cap))
{
- /* TODO need more mem */
+ /* TO-DO need more mem */
return;
}
* @size: number of packet bytes in buffer
* retval number of byte parsed
*
- * function parse_pkt() parses response-pdu and calls do_response().
- * returns number of bytes parsed by function excluding size of header.
+ * Returns number of bytes parsed from RX-buffer.
*/
static uint
parse_pkt(struct snmp_proto *p, byte *pkt, uint size, uint *skip)
{
- snmp_log("parse_pkt() pkt start: %p", pkt);
+ //snmp_log("parse_pkt() pkt start: %p", pkt);
if (size < AGENTX_HEADER_SIZE)
return 0;
uint parsed_len = 0;
struct agentx_header *h = (void *) pkt;
- snmp_log("parse_pkt got type %s (%d)", snmp_pkt_type[h->type], h->type);
- snmp_log("parse_pkt rx size %u", size);
- snmp_dump_packet((void *)h, MIN(h->payload, 256));
+ //snmp_log("parse_pkt got type %s (%d)", snmp_pkt_type[h->type], h->type);
+ //snmp_log("parse_pkt rx size %u", size);
+ //snmp_dump_packet((void *)h, MIN(h->payload, 256));
switch (h->type)
{
case AGENTX_RESPONSE_PDU:
- snmp_log("parse_pkt returning parse_response");
+ //snmp_log("parse_pkt returning parse_response");
parsed_len = parse_response(p, pkt, size);
break;
break;
*/
- /* should not happen */
default:
- snmp_log("unknown packet type %u", h->type);
+ /* drop the packet with unknown type silently */
+ //snmp_log("unknown packet type %u", h->type);
return 0;
}
- snmp_log("parse_pkt returning parsed length");
+ //snmp_log("parse_pkt returning parsed length");
return parsed_len;
}
static uint
parse_response(struct snmp_proto *p, byte *res, uint size)
{
- snmp_log("parse_response() g%u h%u", size, sizeof(struct agentx_header));
+ //snmp_log("parse_response() g%u h%u", size, sizeof(struct agentx_header));
if (size < sizeof(struct agentx_response))
return 0;
int byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
uint pkt_size = LOAD_U32(h->payload, byte_ord);
- snmp_log("p_res pkt_size %u", pkt_size);
+ //snmp_log("p_res pkt_size %u", pkt_size);
if (size < pkt_size + AGENTX_HEADER_SIZE)
{
- snmp_log("parse_response early return");
+ //snmp_log("parse_response early return");
return 0;
}
- snmp_log(" endianity: %s, session %u, transaction: %u",
+ /*snmp_log(" endianity: %s, session %u, transaction: %u",
(h->flags & AGENTX_NETWORK_BYTE_ORDER) ? "big end": "little end",
h->session_id, h->transaction_id);
- snmp_log(" sid: %3u\ttid: %3u\tpid: %3u", p->session_id, p->transaction_id,
+*/
+ /*snmp_log(" sid: %3u\ttid: %3u\tpid: %3u", p->session_id, p->transaction_id,
p->packet_id);
+*/
+ //snmp_log(" pkt size %u", h->payload);
- snmp_log(" pkt size %u", h->payload);
+ //snmp_log(" pkt size %u", h->payload);
if (r->error == AGENTX_RES_NO_ERROR)
do_response(p, res, size);
else
/* erronous packet should be dropped quietly */
- snmp_log("an error occured '%s'", snmp_errs[get_u16(&r->error) - SNMP_ERR_SHIFT]);
+ {}//snmp_log("an error occured '%s'", snmp_errs[get_u16(&r->error) - SNMP_ERR_SHIFT]);
return pkt_size + AGENTX_HEADER_SIZE;
}
static void
snmp_register_mibs(struct snmp_proto *p)
{
- snmp_log("snmp_register_mibs()");
+ //snmp_log("snmp_register_mibs()");
snmp_bgp_register(p);
+ /* snmp_ospf_regsiter(p); ... */
- snmp_log("registering all done");
+ //snmp_log("registering all done");
}
static void
do_response(struct snmp_proto *p, byte *buf, uint size)
{
- snmp_log("do_response()");
+ //snmp_log("do_response()");
struct agentx_response *r = (void *) buf;
struct agentx_header *h = &r->h;
int byte_ord = h->flags & AGENTX_NETWORK_BYTE_ORDER;
snmp_log("changing state to REGISTER");
p->state = SNMP_REGISTER;
snmp_register_mibs(p);
- snmp_log("do_response state SNMP_INIT register list %u", list_length(&p->register_queue));
+ //snmp_log("do_response state SNMP_INIT register list %u", list_length(&p->register_queue));
break;
- case SNMP_REGISTER:
- snmp_log("do_response state SNMP_REGISTER register list %u", list_length(&p->register_queue));
+ case SNMP_REGISTER:;
+ //snmp_log("do_response state SNMP_REGISTER register list %u", list_length(&p->register_queue));
byte *pkt = buf;
ADVANCE(pkt, size, AGENTX_HEADER_SIZE);
if (p->register_to_ack == 0)
{
- snmp_log("changing proto_snmp state to CONNECTED");
+ snmp_log("changing state to CONNECTED");
p->state = SNMP_CONN;
proto_notify_state(&p->p, PS_UP);
}
snmp_get_next2(struct snmp_proto *p, struct oid *o_start, struct oid *o_end,
struct snmp_pdu *c)
{
- snmp_log("get_next2()");
+ //snmp_log("get_next2()");
enum snmp_search_res r;
- snmp_log("next2() o_end %p", o_end);
+ //snmp_log("next2() o_end %p", o_end);
struct oid *o_copy = search_mib(p, o_start, o_end, NULL, c, &r);
- snmp_log("next2()2 o_end %p", o_end);
+ //snmp_log("next2()2 o_end %p", o_end);
struct agentx_varbind *vb = NULL;
switch (r)
static inline uint
update_packet_size(struct snmp_proto *p, const byte *start, byte *end)
{
- /* work even for partial messages */
struct agentx_header *h = (void *) p->sock->tpos;
-
size_t s = snmp_pkt_len(start, end);
STORE_U32(h->payload, s);
return AGENTX_HEADER_SIZE + s;
parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *skip)
{
// TODO checks for c.size underflow
- snmp_log("parse_gets2_pdu()");
+ //snmp_log("parse_gets2_pdu()");
struct oid *o_start = NULL, *o_end = NULL;
byte *pkt = pkt_start;
*/
if (size < clen)
{
- snmp_log("size %u < %u clen, returning 0", size, clen);
+ //snmp_log("size %u < %u clen, returning 0", size, clen);
goto wait;
}
uint ind = 0;
while (c.error == AGENTX_RES_NO_ERROR && size > 0 && pkt_size > 0)
{
- snmp_log("iter %u size %u remaining %u/%u", ind + 1, c.buffer - sk->tpos, size, pkt_size);
+ //snmp_log("iter %u size %u remaining %u/%u", ind + 1, c.buffer - sk->tpos, size, pkt_size);
if (size < snmp_oid_sizeof(0))
goto partial;
*/
if (sz > size && ind > 0)
{
- snmp_log("sz %u > %u size && ind %u > 1", sz, size, ind + 1);
+ //snmp_log("sz %u > %u size && ind %u > 1", sz, size, ind + 1);
goto partial; /* send already processed part */
}
else if (sz > size)
{
- snmp_log("sz %u > %u size; returning 0", sz, size);
+ //snmp_log("sz %u > %u size; returning 0", sz, size);
goto wait;
}
if (sz > size && ind > 0)
{
- snmp_log("sz2 %u > %u size && ind %u > 1", sz, size, ind + 1);
+ //snmp_log("sz2 %u > %u size && ind %u > 1", sz, size, ind + 1);
size += snmp_oid_size(o_start_b);
goto partial;
}
else if (sz > size)
{
- snmp_log("sz2 %u > %u size; returning 0", sz, size);
+ //snmp_log("sz2 %u > %u size; returning 0", sz, size);
goto wait;
}
if (!snmp_is_oid_empty(o_end) && snmp_oid_compare(o_start, o_end) > 0)
{
- snmp_log("snmp_gets2() o_start does not preceed o_end, returning GEN_ERROR");
+ //snmp_log("snmp_gets2() o_start does not preceed o_end, returning GEN_ERROR");
c.error = AGENTX_RES_GEN_ERROR;
goto send;
}
}
}
-send:
- snmp_log("gets2: sending response ...");
+send:;
+ //snmp_log("gets2: sending response ...");
struct agentx_response *res = (void *) sk->tbuf;
/* We update the error, index pair on the beginning of the packet. */
response_err_ind(res, c.error, ind + 1);
uint s = update_packet_size(p, (byte *) response_header, c.buffer);
- 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. */
int ret = sk_send(sk, s);
if (ret > 0)
partial:
- snmp_log("partial packet");
+ //snmp_log("partial packet");
/* The context octet is not added into response pdu. */
/* need to tweak RX buffer packet size */
- snmp_log("old rx-buffer size %u", h->payload);
+ //snmp_log("old rx-buffer size %u", h->payload);
(c.byte_ord) ? put_u32(&h->payload, pkt_size) : (h->payload = pkt_size);
- snmp_log("new rx-buffer size %u", h->payload);
+ //snmp_log("new rx-buffer size %u", h->payload);
*skip = AGENTX_HEADER_SIZE;
p->partial_response = response_header;
void
snmp_start_subagent(struct snmp_proto *p)
{
- snmp_log("snmp_start_subagent() starting subagent");
- snmp_log("DEBUG p->bgp_local_as %u", p->bgp_local_as);
+ //snmp_log("snmp_start_subagent() starting subagent");
+ //snmp_log("DEBUG p->bgp_local_as %u", p->bgp_local_as);
/* blank oid means unsupported */
struct oid *blank = snmp_oid_blank(p);
void
snmp_stop_subagent(struct snmp_proto *p)
{
- snmp_log("snmp_stop_subagent() state %d", p->state);
+ //snmp_log("snmp_stop_subagent() state %d", p->state);
if (p->state == SNMP_STOP)
close_pdu(p, AGENTX_CLOSE_SHUTDOWN);
int
snmp_rx(sock *sk, uint size)
{
- snmp_log("snmp_rx() size %u", size);
+ //snmp_log("snmp_rx() size %u", size);
//snmp_dump_packet(sk->tbuf, 64);
struct snmp_proto *p = sk->data;
byte *pkt_start = sk->rbuf;
byte *end = pkt_start + size;
- snmp_log("snmp_rx rbuf 0x%p rpos 0x%p", sk->rbuf, sk->rpos);
+ //snmp_log("snmp_rx rbuf 0x%p rpos 0x%p", sk->rbuf, sk->rpos);
/*
* In some cases we want to save the header for future parsing, skip is number
*/
uint skip = 0;
- snmp_log("snmp_rx before loop");
+ //snmp_log("snmp_rx before loop");
while (end >= pkt_start + AGENTX_HEADER_SIZE && skip == 0)
{
uint parsed_len = parse_pkt(p, pkt_start, size, &skip);
- snmp_log("snmp_rx loop end %p parsed >>> %u <<< curr %p", end, parsed_len,
+ /*snmp_log("snmp_rx loop end %p parsed >>> %u <<< curr %p", end, parsed_len,
pkt_start + parsed_len);
- snmp_log("snmp_rx loop2 rpos 0x%p", sk->rpos);
+*/
+ //snmp_log("snmp_rx loop2 rpos 0x%p", sk->rpos);
if (parsed_len == 0)
break;
pkt_start += parsed_len;
size -= parsed_len;
}
- snmp_log("snmp_rx loop finished");
+ //snmp_log("snmp_rx loop finished");
/* Incomplete packets */
if (skip != 0 || pkt_start != end)
{
- snmp_log("snmp_rx memmove");
- snmp_dump_packet(sk->rbuf, SNMP_RX_BUFFER_SIZE);
+ //snmp_log("snmp_rx memmove");
+ //snmp_dump_packet(sk->rbuf, SNMP_RX_BUFFER_SIZE);
memmove(sk->rbuf + skip, pkt_start, size);
- snmp_log("after change; sk->rbuf 0x%p sk->rpos 0x%p", sk->rbuf, sk->rpos);
- snmp_dump_packet(sk->rbuf, size + skip);
- snmp_log("tweaking rpos 0x%p (size %u skip %u)", sk->rpos, size, skip);
+ //snmp_log("after change; sk->rbuf 0x%p sk->rpos 0x%p", sk->rbuf, sk->rpos);
+ //snmp_dump_packet(sk->rbuf, size + skip);
+ //snmp_log("tweaking rpos 0x%p (size %u skip %u)", sk->rpos, size, skip);
sk->rpos = sk->rbuf + size + skip;
- snmp_log("snmp_rx returing 0");
+ //snmp_log("snmp_rx returing 0");
return 0;
}
- snmp_log("snmp_rx returning 1");
+ //snmp_log("snmp_rx returning 1");
return 1;
}
snmp_ping(struct snmp_proto *p)
{
sock *sk = p->sock;
- snmp_dump_packet(sk->tpos, AGENTX_HEADER_SIZE + 4);
- snmp_log("snmp_ping sk->tpos 0x%p", sk->tpos);
+ //snmp_dump_packet(sk->tpos, AGENTX_HEADER_SIZE + 4);
+ //snmp_log("snmp_ping sk->tpos 0x%p", sk->tpos);
struct snmp_pdu c = SNMP_PDU_CONTEXT(sk);
if (c.size < AGENTX_HEADER_SIZE)
snmp_manage_tbuf(p, &c);
- snmp_log("ping_pdu()");
+ //snmp_log("ping_pdu()");
struct agentx_header *h = (struct agentx_header *) c.buffer;
ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
SNMP_BLANK_HEADER(h, AGENTX_PING_PDU);
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);
+ //snmp_log("sending ping packet ... tpos 0x%p", sk->tpos);
+ //snmp_dump_packet(sk->tpos, AGENTX_HEADER_SIZE + 4);
/* sending only header -> pkt - buf */
uint s = update_packet_size(p, sk->tpos, c.buffer);
*/
int snmp_search_check_end_oid(const struct oid *found, const struct oid *bound)
{
- snmp_log("upper_bound_check(*f, *b) %p %p is_empty() %d", found, bound,
+ /*snmp_log("upper_bound_check(*f, *b) %p %p is_empty() %d", found, bound,
snmp_is_oid_empty(bound));
+*/
if (snmp_is_oid_empty(bound))
return 1;
struct oid *o_curr, struct snmp_pdu *c,
enum snmp_search_res *result)
{
- snmp_log("search_mib()");
+ //snmp_log("search_mib()");
ASSUME(o_start != NULL);
if (o_curr && (o_curr->n_subid < 2 || o_curr->ids[0] != 1))
snmp_get_mib_class(o_curr) < snmp_get_mib_class(o_end))
{
o_end = blank = snmp_oid_blank(p);
- snmp_log("search_mib() o_end points to blank oid now %p", o_end);
+ //snmp_log("search_mib() o_end points to blank oid now %p", o_end);
}
enum snmp_search_res r;
snmp_prefixize(struct snmp_proto *proto, const struct oid *oid, int byte_ord)
{
ASSERT(oid != NULL);
- snmp_log("snmp_prefixize()");
+ //snmp_log("snmp_prefixize()");
if (snmp_is_oid_empty(oid))
{
/* allocate new zeroed oid */
- snmp_log("blank");
+ //snmp_log("blank");
return snmp_oid_blank(proto);
}
/* already in prefixed form */
else if (oid->prefix != 0) {
struct oid *new = snmp_oid_duplicate(proto->pool, oid);
- snmp_log("already prefixed");
+ //snmp_log("already prefixed");
return new;
}
if (oid->n_subid < 5)
- { snmp_log("too small"); return NULL; }
+ return NULL;
+ //{ snmp_log("too small"); return NULL; }
for (int i = 0; i < 4; i++)
if (LOAD_U32(oid->ids[i], byte_ord) != snmp_internet[i])
- { snmp_log("different prefix"); return NULL; }
+ return NULL;
+ //{ snmp_log("different prefix"); return NULL; }
/* validity check here */
if (oid->ids[4] >= 256)
- { snmp_log("outside byte first id"); return NULL; }
+ return NULL;
+ //{ snmp_log("outside byte first id"); return NULL; }
struct oid *new = mb_alloc(proto->pool,
sizeof(struct oid) + MAX((oid->n_subid - 5) * sizeof(u32), 0));
case SNMP_CLASS_INVALID:
case SNMP_CLASS_END:
default:
+ break;
vb->type = AGENTX_NO_SUCH_OBJECT;
ADVANCE(c->buffer, c->size, snmp_varbind_header_size(vb));
}
void
snmp_manage_tbuf(struct snmp_proto UNUSED *p, struct snmp_pdu *c)
{
- snmp_log("snmp_manage_tbuf()");
+ //snmp_log("snmp_manage_tbuf()");
sock *sk = p->sock;
sk_set_tbsize(sk, sk->tbsize + 2048);
c->size += 2048;
}
-/*
-void
-snmp_tx(sock UNUSED *sk)
-{
- snmp_log("snmp_tx");
-}
-*/
-
-
static struct agentx_response *
prepare_response(struct snmp_proto *p, struct snmp_pdu *c)
{
- snmp_log("prepare_response()");
+ //snmp_log("prepare_response()");
if (!p->partial_response)
{