0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 17:51:53 +00:00

SNMP: Remove development comments

This commit is contained in:
Vojtech Vilimek 2023-10-19 16:46:18 +02:00
parent 3b87af96f3
commit 0caf003bf5
5 changed files with 9 additions and 245 deletions

View File

@ -166,8 +166,6 @@ snmp_bgp_notify_backward_trans(struct snmp_proto *p, struct bgp_proto *bgp)
void
snmp_bgp_register(struct snmp_proto *p)
{
//snmp_log("snmp_bgp_register()");
//u32 bgp_mib_prefix[] = {1, 15, 1};
u32 bgp_mib_prefix[] = { 1, 15 };
@ -568,7 +566,6 @@ oid_state_compare(const struct oid *oid, u8 state)
static struct oid *
update_bgp_oid(struct oid *oid, u8 state)
{
//snmp_log("update_bgp_oid()");
if (state == BGP_INTERNAL_END || state == BGP_INTERNAL_INVALID ||
state == BGP_INTERNAL_NO_VALUE)
return oid;
@ -589,7 +586,6 @@ update_bgp_oid(struct oid *oid, u8 state)
return oid;
}
//snmp_log("update work");
switch (state)
{
case BGP_INTERNAL_BGP:
@ -730,7 +726,6 @@ bgp_find_dynamic_oid(struct snmp_proto *p, struct oid *o_start, const struct oid
ASSUME(o_start != NULL);
ASSUME(o_end != NULL);
//snmp_log("bgp_find_dynamic_oid()");
ip4_addr ip4 = ip4_from_oid(o_start);
ip4_addr dest;
@ -746,42 +741,28 @@ bgp_find_dynamic_oid(struct snmp_proto *p, struct oid *o_start, const struct oid
ip4_from_u32(UINT32_MAX);
}
//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");
struct f_trie_walk_state ws;
trie_walk_init(&ws, p->bgp_trie, NULL, 0);
//snmp_log("walk init");
if (trie_walk_next(&ws, &net))
{
//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");
// TODO repair
struct oid *o = snmp_oid_duplicate(p->pool, o_start);
snmp_oid_ip4_index(o, 5, net4_prefix(&net));
return o;
}
else
{}//snmp_log("ip4_less() returned false for %I >= %I", net4_prefix(&net), dest);
}
else
{}//snmp_log("trie_walk_next() returned false, cleaning");
return NULL;
}
@ -790,25 +771,18 @@ static struct oid *
search_bgp_dynamic(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, uint contid
UNUSED, u8 next_state)
{
//snmp_log("search_bgp_dynamic() dynamic part Yaaay!");
struct oid *o_copy = o_start;
do
{
//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);
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");
} while (o_start == NULL && next_state < BGP_INTERNAL_END);
return o_start;
@ -833,7 +807,6 @@ snmp_bgp_find_next_oid(struct snmp_proto *p, struct oid *oid, uint UNUSED contid
int match = trie_walk_init(&ws, p->bgp_trie, &net, 1);
//snmp_log("match %d include %u", match, oid->include);
if (match && oid->include)
{
oid->include = 0;
@ -843,14 +816,11 @@ snmp_bgp_find_next_oid(struct snmp_proto *p, struct oid *oid, uint UNUSED contid
/* We skip the first match as we should not include ip address in oid */
if (match)
{
//snmp_log("continue");
trie_walk_next(&ws, &net);
}
if (trie_walk_next(&ws, &net))
{
//snmp_oid_dump(oid);
//snmp_log("setting up");
u32 res = ipa_to_u32(net_prefix(&net));
ASSUME(oid->n_subid == 9);
@ -861,7 +831,6 @@ snmp_bgp_find_next_oid(struct snmp_proto *p, struct oid *oid, uint UNUSED contid
return 1;
}
//snmp_log("bad");
return 0;
}
@ -869,27 +838,16 @@ static enum snmp_search_res
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);
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);
ASSUME(end_state <= BGP_INTERNAL_END);
//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);
int found;
while (!(found = snmp_bgp_find_next_oid(p, oid, contid)) && next_state <= end_state)
{
//snmp_log("loop");
next_state = snmp_bgp_next_state(next_state);
if (next_state == BGP_INTERNAL_IDENTIFIER)
break;
@ -913,7 +871,6 @@ snmp_bgp_search2(struct snmp_proto *p, struct oid **searched, const struct oid *
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);
if (bgp_state == BGP_INTERNAL_END)
{
@ -934,7 +891,6 @@ snmp_bgp_search2(struct snmp_proto *p, struct oid **searched, const struct oid *
if (is_dynamic(state) && !is_dynamic(bgp_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);
@ -944,7 +900,6 @@ snmp_bgp_search2(struct snmp_proto *p, struct oid **searched, const struct oid *
if (is_dynamic(bgp_state))
{
//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)
@ -954,7 +909,6 @@ snmp_bgp_search2(struct snmp_proto *p, struct oid **searched, const struct oid *
state = snmp_bgp_next_state(bgp_state);
if (state <= BGP_INTERNAL_IDENTIFIER)
{
//snmp_log("returning the local identifier");
*searched = update_bgp_oid(*searched, state);
return SNMP_SEARCH_OK;
}
@ -962,7 +916,6 @@ snmp_bgp_search2(struct snmp_proto *p, struct oid **searched, const struct oid *
// TODO add route table
/* end not found */
//snmp_log("reached unguarded code, returning END_OF_VIEW");
return SNMP_SEARCH_END_OF_VIEW;
}
@ -977,17 +930,13 @@ snmp_bgp_search(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, ui
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");
/* 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!");
return search_bgp_dynamic(p, o_start, o_end, contid, start_state);
}
/* o_start is not inclusive */
@ -996,7 +945,6 @@ snmp_bgp_search(struct snmp_proto *p, struct oid *o_start, struct oid *o_end, ui
if (!is_dynamic(next_state))
{
o_start = update_bgp_oid(o_start, next_state);
//snmp_log("next state is also not dynamic");
return o_start;
}
@ -1024,7 +972,6 @@ bgp_fill_dynamic(struct snmp_proto UNUSED *p, struct agentx_varbind *vb,
return pkt;
}
//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);
@ -1038,7 +985,6 @@ bgp_fill_dynamic(struct snmp_proto UNUSED *p, struct agentx_varbind *vb,
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);
}
/* We did not found binded BGP protocol. */
else
@ -1222,12 +1168,8 @@ bgp_fill_static(struct snmp_proto *p, struct agentx_varbind *vb, byte *pkt, uint
UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
{
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_bgp_state() check only prefix. To be sure on OID equivalence we need to
@ -1265,15 +1207,6 @@ UNUSED, uint contid UNUSED, int byte_ord UNUSED, u8 state)
break;
}
#if 0
snmp_log("bgp_fill_static: type %u packet %p", vb->type, pkt);
//snmp_oid_dump(oid);
/*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);
#endif
return pkt;
}

View File

@ -89,49 +89,31 @@ proto_name ;
snmp_context:
/* empty */ {
if (!this_bond)
{
//log(L_INFO "snmp_context no string alloc");
this_bond = cfg_alloc(sizeof(struct snmp_bond));
}
this_bond->context = NULL;
}
| CONTEXT DEFAULT {
if (!this_bond)
{
//log(L_INFO "snmp_context CONTEXT DEFAULT alloc");
this_bond = cfg_alloc(sizeof(struct snmp_bond));
}
this_bond->context = NULL;
}
| CONTEXT text {
if(!this_bond)
{
//log(L_INFO "snmp_context CONTEXT text alloc");
this_bond = cfg_alloc(sizeof(struct snmp_bond));
}
this_bond->context = $2;
SNMP_CFG->contexts++;
//log(L_INFO "storing context %s to bond at 0x%p", $2, this_bond);
}
;
snmp_bgp_bond: BGP symbol snmp_context
{
/* the snmp_context rule sets the correct value of this_bond */
/*log(L_INFO "this_bond (at 0x%p) has value %s", this_bond,
(this_bond->context) ? this_bond->context : "<no_val>");
*/
if (!this_bond)
{
//log(L_INFO "snmp_bgp_bond BGP symbol ... alloc");
this_bond = cfg_alloc(sizeof(struct snmp_bond));
//log(L_INFO "Unexpedted alloc in snmp_bgp_bond rule");
}
else
{
//log(L_INFO, "working with this_bond (at 0x%p)", this_bond);
}
this_bond->type = SNMP_BGP;
cf_assert_symbol($2, SYM_PROTO);

View File

@ -221,7 +221,6 @@ snmp_sock_err(sock *sk, int UNUSED err)
static void
snmp_start_locked(struct object_lock *lock)
{
//snmp_log("snmp_start_locked() - lock acquired; preparing socket");
struct snmp_proto *p = lock->data;
p->state = SNMP_LOCKED;
@ -323,7 +322,6 @@ snmp_ping_timeout(timer *tm)
static int
snmp_start(struct proto *P)
{
//snmp_log("snmp_start() - starting timer (almost)");
struct snmp_proto *p = (void *) P;
struct snmp_config *cf = (struct snmp_config *) P->cf;
@ -379,14 +377,12 @@ snmp_start(struct proto *P)
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);
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);
ASSUME(cf->contexts == p->context_max);
snmp_startup(p);

View File

@ -33,9 +33,6 @@ snmp_is_oid_empty(const struct oid *oid)
uint
snmp_pkt_len(const byte *start, const byte *end)
{
/*snmp_log("snmp_pkt_len start 0x%p end 0x%p res %u", start, end, (end - start)
- AGENTX_HEADER_SIZE);
*/
return (end - start) - AGENTX_HEADER_SIZE;
}
@ -443,19 +440,10 @@ snmp_register_same(struct snmp_register *r, struct agentx_header *h, u8 class)
void
snmp_register_ack(struct snmp_proto *p, struct agentx_header *h, u8 class)
{
//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;
WALK_LIST(reg, p->register_queue)
{
// 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, class))
{
struct snmp_registered_oid *ro = \
@ -471,12 +459,9 @@ h->packet_id);
add_tail(&p->bgp_registered, &ro->n);
//snmp_log(" register note find %u", list_length(&p->bgp_registered));
return;
}
}
//snmp_log("unknown registration");
}
void UNUSED
@ -522,14 +507,10 @@ snmp_varbind_type32(struct agentx_varbind *vb, uint size, enum agentx_type type,
ASSUME(agentx_type_size(type) == 4); /* type has 4B representation */
if (size < (uint) agentx_type_size(type))
{
//snmp_log("varbind type32 returned NULL");
return NULL;
}
vb->type = type;
u32 *data = SNMP_VB_DATA(vb);
//snmp_log("varbind type32 vb data 0x%p (from vb 0x%p)", data, (void *) vb);
*data = val;
return (byte *)(data + 1);
}
@ -564,15 +545,9 @@ inline byte *
snmp_varbind_ip4(struct agentx_varbind *vb, uint size, ip4_addr addr)
{
if (size < snmp_str_size_from_len(4))
{
//snmp_log("varbind ip4 NULL");
return NULL;
}
vb->type = AGENTX_IP_ADDRESS;
/*snmp_log("snmp_varbind_ip4 vb data 0x%p (from vb 0x%p)", SNMP_VB_DATA(vb), (void
*) vb);
*/
return snmp_put_ip4(SNMP_VB_DATA(vb), addr);
}
@ -580,15 +555,10 @@ inline byte *
snmp_varbind_nstr(struct agentx_varbind *vb, uint size, const char *str, uint len)
{
if (size < snmp_str_size_from_len(len))
{
//snmp_log("varbind nstr NULL");
return NULL;
}
vb->type = AGENTX_OCTET_STRING;
//die("snmp_varbind_nstr() %p.data = %p", vb, SNMP_VB_DATA(vb));
snmp_log("snmp_varbind_nstr vb data 0x%p (from vb 0x%p)", SNMP_VB_DATA(vb), (void *) vb);
//snmp_log("snmp_varbind_nstr() %p.data = %p", vb, SNMP_VB_DATA(vb));
return snmp_put_nstr(SNMP_VB_DATA(vb), str, len);
}

View File

@ -196,8 +196,6 @@ de_allocate_pdu(struct snmp_proto *p, struct oid *oid, u8 type)
if (size > AGENTX_HEADER_SIZE + )
{
//snmp_log("de_allocate_pdu()");
struct agentx_header *h;
SNMP_CREATE(pkt, struct agentx_header, h);
SNMP_BLANK_HEADER(h, type);
@ -207,9 +205,6 @@ de_allocate_pdu(struct snmp_proto *p, struct oid *oid, u8 type)
STORE_16(vb->type, AGENTX_OBJECT_ID);
STORE(vb->oid,
}
else
{}//snmp_log("de_allocate_pdu(): insufficient size");
}
*/
@ -234,12 +229,10 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint len, uint index, u8
if (c.size < sz)
{
//snmp_log("un_register_pdu() insufficient size");
snmp_manage_tbuf(p, &c);
buf = c.buffer;
}
//snmp_log("un_register_pdu()");
struct agentx_header *h = (struct agentx_header *) c.buffer;
ADVANCE(c.buffer, c.size, AGENTX_HEADER_SIZE);
@ -248,10 +241,6 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint len, uint index, u8
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;
@ -276,7 +265,6 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, uint len, uint index, u8
uint s = update_packet_size(p, buf, c.buffer);
//snmp_log("sending (un)register %s", snmp_pkt_type[type]);
sk_send(sk, s);
}
@ -301,10 +289,6 @@ close_pdu(struct snmp_proto *p, u8 reason)
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)
? '>':'<', AGENTX_HEADER_SIZE);
*/
/* +4B for reason */
if (c.size < AGENTX_HEADER_SIZE + 4)
{
@ -324,34 +308,29 @@ close_pdu(struct snmp_proto *p, u8 reason)
uint s = update_packet_size(p, buf, c.buffer);
//snmp_log("preparing to sk_send() (close)");
sk_send(sk, s);
}
static uint UNUSED
parse_close_pdu(struct snmp_proto UNUSED *p, byte UNUSED *req, uint UNUSED size)
{
/*
snmp_log("parse_close_pdu()");
// byte *pkt = req;
// sock *sk = p->sock;
#if 0
//byte *pkt = req;
//sock *sk = p->sock;
if (size < sizeof(struct agentx_header))
{
snmp_log("p_close early return");
return 0;
}
// struct agentx_header *h = (void *) req;
//struct agentx_header *h = (void *) req;
ADVANCE(req, size, AGENTX_HEADER_SIZE);
//snmp_log("after header %p", req);
p->state = SNMP_ERR;
// or snmp_cleanup(); // ??!
/* or snmp_cleanup(); // ??! */
proto_notify_state(&p->p, PS_DOWN);
*/
#endif
return 0;
}
@ -476,7 +455,6 @@ refresh_ids(struct snmp_proto *p, struct agentx_header *h)
static uint
parse_test_set_pdu(struct snmp_proto *p, byte *pkt, uint size)
{
//snmp_log("parse_test_set");
const byte *pkt_start = pkt; /* start of packet in RX-buffer */
uint ind = 0; /* index of the error */
uint s; /* final packat size */
@ -515,7 +493,6 @@ parse_test_set_pdu(struct snmp_proto *p, byte *pkt, uint size)
ADVANCE(pkt, pkt_size, clen);
size -= clen;
//snmp_log("test_set: parsed header and context");
/* 0 if there is piece, that we cannot set */
int all_possible = 0;
/* the all_possible is currently hard-coded with no support for writing to mib
@ -559,7 +536,6 @@ parse_test_set_pdu(struct snmp_proto *p, byte *pkt, uint size)
all_possible = snmp_testset(p, vb, tr, work, pkt_size);
mb_free(work);
}
//snmp_log("test_set parsed all varbinds");
mb_free(tr);
#endif
@ -574,7 +550,6 @@ error:
//response_err_ind(res, AGENTX_RES_RESOURCE_UNAVAILABLE, ind + 1);
response_err_ind(res, AGENTX_RES_NOT_WRITABLE, ind + 1);
//snmp_log("test_set sending response");
sk_send(sk, s);
return pkt - pkt_start;
}
@ -673,20 +648,14 @@ parse_cleanup_set_pdu(struct snmp_proto *p, byte *pkt, uint size)
static uint
parse_pkt(struct snmp_proto *p, byte *pkt, uint size, uint *skip)
{
//snmp_log("parse_pkt() pkt start: %p", pkt);
if (size < AGENTX_HEADER_SIZE)
return 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));
switch (h->type)
{
case AGENTX_RESPONSE_PDU:
//snmp_log("parse_pkt returning parse_response");
return parse_response(p, pkt, size);
case AGENTX_GET_PDU:
@ -717,7 +686,6 @@ parse_pkt(struct snmp_proto *p, byte *pkt, uint size, uint *skip)
default:
/* drop the packet with unknown type silently */
//snmp_log("unknown packet type %u", h->type);
return 0;
}
}
@ -744,8 +712,6 @@ unsupported_context(struct snmp_proto *p, struct agentx_response *r, uint size)
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));
if (size < sizeof(struct agentx_response))
return 0;
@ -755,21 +721,8 @@ parse_response(struct snmp_proto *p, byte *res, uint size)
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);
if (size < pkt_size + AGENTX_HEADER_SIZE)
{
//snmp_log("parse_response early return");
return 0;
}
/*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,
p->packet_id);
*/
//snmp_log(" pkt size %u", h->payload);
switch (r->error)
{
@ -830,18 +783,13 @@ parse_response(struct snmp_proto *p, byte *res, uint size)
static void
snmp_register_mibs(struct snmp_proto *p)
{
//snmp_log("snmp_register_mibs()");
snmp_bgp_register(p);
/* snmp_ospf_regsiter(p); ... */
//snmp_log("registering all done");
}
static void
do_response(struct snmp_proto *p, byte *buf, uint size)
{
//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;
@ -865,12 +813,9 @@ do_response(struct snmp_proto *p, byte *buf, uint size)
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));
break;
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);
@ -927,11 +872,8 @@ static int
snmp_get_next2(struct snmp_proto *p, struct oid *o_start, struct oid *o_end,
struct snmp_pdu *c)
{
//snmp_log("get_next2()");
enum snmp_search_res r;
//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);
struct agentx_varbind *vb = NULL;
switch (r)
@ -1071,7 +1013,6 @@ static uint
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()");
struct oid *o_start = NULL, *o_end = NULL;
byte *pkt = pkt_start;
@ -1096,10 +1037,7 @@ parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *s
* header picture, including the context octet string
*/
if (size < clen)
{
//snmp_log("size %u < %u clen, returning 0", size, clen);
goto wait;
}
/*
* It is a malformed packet if the context octet string should be longer than
@ -1162,8 +1100,6 @@ parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *s
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);
if (size < snmp_oid_sizeof(0))
goto partial;
@ -1184,12 +1120,10 @@ parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *s
*/
if (sz > size && ind > 0)
{
//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);
goto wait;
}
@ -1211,13 +1145,11 @@ parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *s
if (sz > size && ind > 0)
{
//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);
goto wait;
}
@ -1232,7 +1164,6 @@ parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *s
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");
c.error = AGENTX_RES_GEN_ERROR;
goto send;
}
@ -1288,14 +1219,11 @@ parse_gets2_pdu(struct snmp_proto *p, byte * const pkt_start, uint size, uint *s
}
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);
/* We send the message in TX-buffer. */
sk_send(sk, s);
// TODO think through the error state
@ -1308,13 +1236,10 @@ send:;
partial:
//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);
(c.byte_ord) ? put_u32(&h->payload, pkt_size) : (h->payload = pkt_size);
//snmp_log("new rx-buffer size %u", h->payload);
*skip = AGENTX_HEADER_SIZE;
/* number of bytes parsed from RX-buffer */
@ -1332,9 +1257,6 @@ wait:
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);
/* blank oid means unsupported */
struct oid *blank = snmp_oid_blank(p);
open_pdu(p, blank);
@ -1347,8 +1269,6 @@ snmp_start_subagent(struct snmp_proto *p)
void
snmp_stop_subagent(struct snmp_proto *p)
{
//snmp_log("snmp_stop_subagent() state %d", p->state);
if (p->state == SNMP_STOP)
close_pdu(p, AGENTX_CLOSE_SHUTDOWN);
}
@ -1366,12 +1286,9 @@ oid_prefix(struct oid *o, u32 *prefix, uint len)
int
snmp_rx(sock *sk, uint 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);
/*
* In some cases we want to save the header for future parsing, skip is number
@ -1379,39 +1296,25 @@ snmp_rx(sock *sk, uint size)
*/
uint skip = 0;
//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,
pkt_start + parsed_len);
*/
//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");
/* Incomplete packets */
if (skip != 0 || pkt_start != end)
{
//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);
sk->rpos = sk->rbuf + size + skip;
//snmp_log("snmp_rx returing 0");
return 0;
}
//snmp_log("snmp_rx returning 1");
return 1;
}
@ -1420,14 +1323,11 @@ void
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);
struct snmp_pdu c = SNMP_PDU_CONTEXT(sk);
if (c.size < AGENTX_HEADER_SIZE)
snmp_manage_tbuf(p, &c);
//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);
@ -1435,8 +1335,6 @@ snmp_ping(struct snmp_proto *p)
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);
/* sending only header -> pkt - buf */
uint s = update_packet_size(p, sk->tpos, c.buffer);
@ -1472,10 +1370,6 @@ has_inet_prefix(struct oid *o)
*/
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_is_oid_empty(bound));
*/
if (snmp_is_oid_empty(bound))
return 1;
@ -1489,7 +1383,6 @@ search_mib(struct snmp_proto *p, const struct oid *o_start, const struct oid *o_
struct oid *o_curr, struct snmp_pdu *c,
enum snmp_search_res *result)
{
//snmp_log("search_mib()");
ASSUME(o_start != NULL);
if (o_curr && (o_curr->n_subid < 2 || o_curr->ids[0] != 1))
@ -1509,7 +1402,6 @@ search_mib(struct snmp_proto *p, const struct oid *o_start, const struct oid *o_
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);
}
enum snmp_search_res r;
@ -1556,35 +1448,29 @@ struct oid *
snmp_prefixize(struct snmp_proto *proto, const struct oid *oid, int byte_ord)
{
ASSERT(oid != NULL);
//snmp_log("snmp_prefixize()");
if (snmp_is_oid_empty(oid))
{
/* allocate new zeroed oid */
//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");
return new;
}
if (oid->n_subid < 5)
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])
return NULL;
//{ snmp_log("different prefix"); return NULL; }
/* validity check here */
if (oid->ids[4] >= 256)
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));
@ -1642,7 +1528,6 @@ snmp_mib_fill2(struct snmp_proto *p, struct oid *oid,
void
snmp_manage_tbuf(struct snmp_proto UNUSED *p, struct snmp_pdu *c)
{
//snmp_log("snmp_manage_tbuf()");
sock *sk = p->sock;
sk_set_tbsize(sk, sk->tbsize + 2048);
@ -1652,8 +1537,6 @@ snmp_manage_tbuf(struct snmp_proto UNUSED *p, struct snmp_pdu *c)
static struct agentx_response *
prepare_response(struct snmp_proto *p, struct snmp_pdu *c)
{
//snmp_log("prepare_response()");
struct agentx_response *r = (void *) c->buffer;
struct agentx_header *h = &r->h;