mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-03-22 06:17:04 +00:00
SNMP: snmp_pdu simplification
This commit is contained in:
parent
4b7989aa45
commit
373b343e0c
@ -36,7 +36,7 @@
|
|||||||
const struct bgp_stats UNUSED *stats; \
|
const struct bgp_stats UNUSED *stats; \
|
||||||
const struct bgp_config UNUSED *config
|
const struct bgp_config UNUSED *config
|
||||||
|
|
||||||
#define POPULATE_BGP4(addr, proto, conn, stats, config) populate_bgp4(d, &(addr), &(proto), &(conn), &(stats), &(config))
|
#define POPULATE_BGP4(addr, proto, conn, stats, config) populate_bgp4(c, &(addr), &(proto), &(conn), &(stats), &(config))
|
||||||
|
|
||||||
static inline void ip4_to_oid(struct oid *oid, ip4_addr addr);
|
static inline void ip4_to_oid(struct oid *oid, ip4_addr addr);
|
||||||
|
|
||||||
@ -234,7 +234,7 @@ snmp_bgp_notify_backward_trans(struct snmp_proto *p, struct bgp_proto *bgp)
|
|||||||
void
|
void
|
||||||
snmp_bgp4_register(struct snmp_proto *p)
|
snmp_bgp4_register(struct snmp_proto *p)
|
||||||
{
|
{
|
||||||
u32 bgp_mib_prefix[] = { 1, BGP4_MIB }; // TODO remove constant
|
u32 bgp_mib_prefix[] = { SNMP_MIB_2, BGP4_MIB };
|
||||||
|
|
||||||
{
|
{
|
||||||
/* Register the whole BGP4-MIB::bgp root tree node */
|
/* Register the whole BGP4-MIB::bgp root tree node */
|
||||||
@ -332,10 +332,10 @@ print_bgp_record(const struct bgp_proto *bgp_proto)
|
|||||||
|
|
||||||
|
|
||||||
static inline enum snmp_search_res
|
static inline enum snmp_search_res
|
||||||
populate_bgp4(struct snmp_data *d, ip4_addr *addr, const struct bgp_proto **proto, const struct bgp_conn
|
populate_bgp4(struct snmp_pdu *c, ip4_addr *addr, const struct bgp_proto **proto, const struct bgp_conn
|
||||||
**conn, const struct bgp_stats **stats, const struct bgp_config **config)
|
**conn, const struct bgp_stats **stats, const struct bgp_config **config)
|
||||||
{
|
{
|
||||||
const struct oid * const oid = &d->c->sr_vb_start->name;
|
const struct oid * const oid = &c->sr_vb_start->name;
|
||||||
if (snmp_bgp_valid_ip4(oid) && LOAD_U8(oid->n_subid) == 9)
|
if (snmp_bgp_valid_ip4(oid) && LOAD_U8(oid->n_subid) == 9)
|
||||||
*addr = ip4_from_oid(oid);
|
*addr = ip4_from_oid(oid);
|
||||||
else
|
else
|
||||||
@ -344,7 +344,7 @@ populate_bgp4(struct snmp_data *d, ip4_addr *addr, const struct bgp_proto **prot
|
|||||||
return SNMP_SEARCH_NO_INSTANCE;
|
return SNMP_SEARCH_NO_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct snmp_bgp_peer *pe = snmp_hash_find(d->p, *addr);
|
struct snmp_bgp_peer *pe = snmp_hash_find(c->p, *addr);
|
||||||
if (!pe)
|
if (!pe)
|
||||||
{
|
{
|
||||||
snmp_log("populate() hash find failed");
|
snmp_log("populate() hash find failed");
|
||||||
@ -356,7 +356,7 @@ populate_bgp4(struct snmp_data *d, ip4_addr *addr, const struct bgp_proto **prot
|
|||||||
if (!ipa_is_ip4(bgp_proto->remote_ip))
|
if (!ipa_is_ip4(bgp_proto->remote_ip))
|
||||||
{
|
{
|
||||||
log(L_ERR "%s: Found BGP protocol instance with IPv6 address", bgp_proto->p.name);
|
log(L_ERR "%s: Found BGP protocol instance with IPv6 address", bgp_proto->p.name);
|
||||||
d->c->error = AGENTX_RES_GEN_ERROR;
|
c->error = AGENTX_RES_GEN_ERROR;
|
||||||
return SNMP_SEARCH_NO_INSTANCE;
|
return SNMP_SEARCH_NO_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -366,7 +366,7 @@ populate_bgp4(struct snmp_data *d, ip4_addr *addr, const struct bgp_proto **prot
|
|||||||
/* Here, we could be in problem as the bgp_proto IP address could be changed */
|
/* Here, we could be in problem as the bgp_proto IP address could be changed */
|
||||||
log(L_ERR "%s: Stored hash key IP address and peer remote address differ "
|
log(L_ERR "%s: Stored hash key IP address and peer remote address differ "
|
||||||
"(%I, %I).", bgp_proto->p.name, proto_ip, pe->peer_ip);
|
"(%I, %I).", bgp_proto->p.name, proto_ip, pe->peer_ip);
|
||||||
d->c->error = AGENTX_RES_GEN_ERROR;
|
c->error = AGENTX_RES_GEN_ERROR;
|
||||||
return SNMP_SEARCH_NO_INSTANCE;
|
return SNMP_SEARCH_NO_INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,28 +379,28 @@ populate_bgp4(struct snmp_data *d, ip4_addr *addr, const struct bgp_proto **prot
|
|||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_bgp_version(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_bgp_version(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill ver");
|
snmp_log("fill ver");
|
||||||
if (LOAD_U8(d->c->sr_vb_start->name.n_subid) != 3)
|
if (LOAD_U8(c->sr_vb_start->name.n_subid) != 3)
|
||||||
return SNMP_SEARCH_NO_INSTANCE;
|
return SNMP_SEARCH_NO_INSTANCE;
|
||||||
d->c->size -= snmp_str_size_from_len(1);
|
c->size -= snmp_str_size_from_len(1);
|
||||||
snmp_varbind_nstr(d->c, BGP4_VERSIONS, 1);
|
snmp_varbind_nstr(c, BGP4_VERSIONS, 1);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_local_as(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_local_as(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill as");
|
snmp_log("fill as");
|
||||||
if (LOAD_U8(d->c->sr_vb_start->name.n_subid) != 3)
|
if (LOAD_U8(c->sr_vb_start->name.n_subid) != 3)
|
||||||
return SNMP_SEARCH_NO_INSTANCE;
|
return SNMP_SEARCH_NO_INSTANCE;
|
||||||
snmp_varbind_int(d->c, d->p->bgp_local_as);
|
snmp_varbind_int(c, c->p->bgp_local_as);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_peer_id(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_peer_id(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill peer id");
|
snmp_log("fill peer id");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -413,14 +413,14 @@ fill_peer_id(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
|
|
||||||
if (fsm_state == BGP4_MIB_OPENCONFIRM || fsm_state == BGP4_MIB_ESTABLISHED)
|
if (fsm_state == BGP4_MIB_OPENCONFIRM || fsm_state == BGP4_MIB_ESTABLISHED)
|
||||||
// TODO last
|
// TODO last
|
||||||
snmp_varbind_ip4(d->c, ip4_from_u32(bgp_proto->remote_id));
|
snmp_varbind_ip4(c, ip4_from_u32(bgp_proto->remote_id));
|
||||||
else
|
else
|
||||||
snmp_varbind_ip4(d->c, IP4_NONE);
|
snmp_varbind_ip4(c, IP4_NONE);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_peer_state(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_peer_state(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill peer state");
|
snmp_log("fill peer state");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -431,12 +431,12 @@ fill_peer_state(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
|
|
||||||
uint fsm_state = snmp_bgp_fsm_state(bgp_proto);
|
uint fsm_state = snmp_bgp_fsm_state(bgp_proto);
|
||||||
|
|
||||||
snmp_varbind_int(d->c, fsm_state);
|
snmp_varbind_int(c, fsm_state);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_admin_status(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_admin_status(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill adm status");
|
snmp_log("fill adm status");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -446,14 +446,14 @@ fill_admin_status(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
if (bgp_proto->p.disabled)
|
if (bgp_proto->p.disabled)
|
||||||
snmp_varbind_int(d->c, AGENTX_ADMIN_STOP);
|
snmp_varbind_int(c, AGENTX_ADMIN_STOP);
|
||||||
else
|
else
|
||||||
snmp_varbind_int(d->c, AGENTX_ADMIN_START);
|
snmp_varbind_int(c, AGENTX_ADMIN_START);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_neg_version(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_neg_version(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill neg ver");
|
snmp_log("fill neg ver");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -465,14 +465,14 @@ fill_neg_version(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
uint fsm_state = snmp_bgp_fsm_state(bgp_proto);
|
uint fsm_state = snmp_bgp_fsm_state(bgp_proto);
|
||||||
|
|
||||||
if (fsm_state == BGP4_MIB_ESTABLISHED || fsm_state == BGP4_MIB_ESTABLISHED)
|
if (fsm_state == BGP4_MIB_ESTABLISHED || fsm_state == BGP4_MIB_ESTABLISHED)
|
||||||
snmp_varbind_int(d->c, BGP4_MIB_NEGOTIATED_VER_VALUE);
|
snmp_varbind_int(c, BGP4_MIB_NEGOTIATED_VER_VALUE);
|
||||||
else
|
else
|
||||||
snmp_varbind_int(d->c, BGP4_MIB_NEGOTIATED_VER_NO_VALUE);
|
snmp_varbind_int(c, BGP4_MIB_NEGOTIATED_VER_NO_VALUE);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_local_addr(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_local_addr(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("bgp4_mib fill local addr");
|
snmp_log("bgp4_mib fill local addr");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -484,12 +484,12 @@ fill_local_addr(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_ip4(d->c, ipa_to_ip4(bgp_proto->local_ip));
|
snmp_varbind_ip4(c, ipa_to_ip4(bgp_proto->local_ip));
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_local_port(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_local_port(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("bgp4_mib fill local port");
|
snmp_log("bgp4_mib fill local port");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -498,12 +498,12 @@ fill_local_port(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_int(d->c, bgp_conf->local_port);
|
snmp_varbind_int(c, bgp_conf->local_port);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_remote_addr(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_remote_addr(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("bgp4_mib fill remote addr");
|
snmp_log("bgp4_mib fill remote addr");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -512,12 +512,12 @@ fill_remote_addr(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_ip4(d->c, ipa_to_ip4(bgp_proto->remote_ip));
|
snmp_varbind_ip4(c, ipa_to_ip4(bgp_proto->remote_ip));
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_remote_port(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_remote_port(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("bgp4_mib fill remote port");
|
snmp_log("bgp4_mib fill remote port");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -526,12 +526,12 @@ fill_remote_port(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_int(d->c, bgp_conf->remote_port);
|
snmp_varbind_int(c, bgp_conf->remote_port);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_remote_as(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_remote_as(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill rem as");
|
snmp_log("fill rem as");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -540,12 +540,12 @@ fill_remote_as(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_int(d->c, bgp_proto->remote_as);
|
snmp_varbind_int(c, bgp_proto->remote_as);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_in_updates(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_in_updates(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill in updates");
|
snmp_log("fill in updates");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -554,12 +554,12 @@ fill_in_updates(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_counter32(d->c, bgp_stats->rx_updates);
|
snmp_varbind_counter32(c, bgp_stats->rx_updates);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_out_updates(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_out_updates(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill out updates");
|
snmp_log("fill out updates");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -568,12 +568,12 @@ fill_out_updates(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_counter32(d->c, bgp_stats->tx_updates);
|
snmp_varbind_counter32(c, bgp_stats->tx_updates);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_in_total_msg(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_in_total_msg(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill in total");
|
snmp_log("fill in total");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -582,12 +582,12 @@ fill_in_total_msg(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_counter32(d->c, bgp_stats->rx_messages);
|
snmp_varbind_counter32(c, bgp_stats->rx_messages);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_out_total_msg(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_out_total_msg(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill out total");
|
snmp_log("fill out total");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -596,12 +596,12 @@ fill_out_total_msg(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_counter32(d->c, bgp_stats->tx_messages);
|
snmp_varbind_counter32(c, bgp_stats->tx_messages);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_last_err(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_last_err(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill last err");
|
snmp_log("fill last err");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -613,12 +613,12 @@ fill_last_err(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
char last_error[2];
|
char last_error[2];
|
||||||
snmp_bgp_last_error(bgp_proto, last_error);
|
snmp_bgp_last_error(bgp_proto, last_error);
|
||||||
|
|
||||||
snmp_varbind_nstr(d->c, last_error, 2);
|
snmp_varbind_nstr(c, last_error, 2);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_established_trans(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_established_trans(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill est trans");
|
snmp_log("fill est trans");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -627,13 +627,13 @@ fill_established_trans(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_counter32(d->c,
|
snmp_varbind_counter32(c,
|
||||||
bgp_stats->fsm_established_transitions);
|
bgp_stats->fsm_established_transitions);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_established_time(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_established_time(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill est time");
|
snmp_log("fill est time");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -643,13 +643,13 @@ fill_established_time(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
|
|
||||||
snmp_varbind_gauge32(d->c,
|
snmp_varbind_gauge32(c,
|
||||||
(current_time() - bgp_proto->last_established) TO_S);
|
(current_time() - bgp_proto->last_established) TO_S);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_retry_interval(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_retry_interval(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill retry int");
|
snmp_log("fill retry int");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -658,12 +658,12 @@ fill_retry_interval(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_int(d->c, bgp_conf->connect_retry_time);
|
snmp_varbind_int(c, bgp_conf->connect_retry_time);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_hold_time(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_hold_time(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill hold time");
|
snmp_log("fill hold time");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -672,12 +672,12 @@ fill_hold_time(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_int(d->c, (bgp_conn) ? bgp_conn->hold_time : 0);
|
snmp_varbind_int(c, (bgp_conn) ? bgp_conn->hold_time : 0);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_keep_alive(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_keep_alive(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill keepalive");
|
snmp_log("fill keepalive");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -687,15 +687,15 @@ fill_keep_alive(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
if (!bgp_conf->hold_time)
|
if (!bgp_conf->hold_time)
|
||||||
snmp_varbind_int(d->c, 0);
|
snmp_varbind_int(c, 0);
|
||||||
else
|
else
|
||||||
snmp_varbind_int(d->c,
|
snmp_varbind_int(c,
|
||||||
(bgp_conn) ? bgp_conn->keepalive_time : 0);
|
(bgp_conn) ? bgp_conn->keepalive_time : 0);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_hold_time_conf(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_hold_time_conf(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill hold time c");
|
snmp_log("fill hold time c");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -704,12 +704,12 @@ fill_hold_time_conf(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_int(d->c, bgp_conf->hold_time);
|
snmp_varbind_int(c, bgp_conf->hold_time);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_keep_alive_conf(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_keep_alive_conf(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill keepalive c");
|
snmp_log("fill keepalive c");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -720,15 +720,15 @@ fill_keep_alive_conf(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
|
|
||||||
|
|
||||||
if (!bgp_conf->keepalive_time)
|
if (!bgp_conf->keepalive_time)
|
||||||
snmp_varbind_int(d->c, 0);
|
snmp_varbind_int(c, 0);
|
||||||
else
|
else
|
||||||
snmp_varbind_int(d->c,
|
snmp_varbind_int(c,
|
||||||
(bgp_conn) ? bgp_conn->keepalive_time : 0);
|
(bgp_conn) ? bgp_conn->keepalive_time : 0);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_min_as_org_interval(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_min_as_org_interval(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill min org int");
|
snmp_log("fill min org int");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -738,12 +738,12 @@ fill_min_as_org_interval(struct mib_walk_state *walk UNUSED, struct snmp_data *d
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
/* value should be in 1..65535 but is not supported by bird */
|
/* value should be in 1..65535 but is not supported by bird */
|
||||||
snmp_varbind_int(d->c, 0);
|
snmp_varbind_int(c, 0);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_route_adv_interval(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_route_adv_interval(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill rt adv int");
|
snmp_log("fill rt adv int");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -753,12 +753,12 @@ fill_route_adv_interval(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
return res;
|
return res;
|
||||||
|
|
||||||
/* value should be in 1..65535 but is not supported by bird */
|
/* value should be in 1..65535 but is not supported by bird */
|
||||||
snmp_varbind_int(d->c, 0);
|
snmp_varbind_int(c, 0);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_in_update_elapsed_time(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_in_update_elapsed_time(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fil in elapsed");
|
snmp_log("fil in elapsed");
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
@ -767,19 +767,19 @@ fill_in_update_elapsed_time(struct mib_walk_state *walk UNUSED, struct snmp_data
|
|||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
return res;
|
return res;
|
||||||
|
|
||||||
snmp_varbind_gauge32(d->c,
|
snmp_varbind_gauge32(c,
|
||||||
(current_time() - bgp_proto->last_rx_update) TO_S
|
(current_time() - bgp_proto->last_rx_update) TO_S
|
||||||
);
|
);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
static enum snmp_search_res
|
static enum snmp_search_res
|
||||||
fill_local_id(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
fill_local_id(struct mib_walk_state *walk UNUSED, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
snmp_log("fill local id");
|
snmp_log("fill local id");
|
||||||
if (LOAD_U8(d->c->sr_vb_start->name.n_subid) != 3)
|
if (LOAD_U8(c->sr_vb_start->name.n_subid) != 3)
|
||||||
return SNMP_SEARCH_NO_INSTANCE;
|
return SNMP_SEARCH_NO_INSTANCE;
|
||||||
snmp_varbind_ip4(d->c, d->p->bgp_local_id);
|
snmp_varbind_ip4(c, c->p->bgp_local_id);
|
||||||
return SNMP_SEARCH_OK;
|
return SNMP_SEARCH_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -787,10 +787,9 @@ fill_local_id(struct mib_walk_state *walk UNUSED, struct snmp_data *d)
|
|||||||
* bgp4_next_peer
|
* bgp4_next_peer
|
||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
bgp4_next_peer(struct mib_walk_state *state, struct snmp_data *data)
|
bgp4_next_peer(struct mib_walk_state *state, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
//struct agentx_varbind *vb = data->c->sr_vb_start;
|
struct oid *oid = &c->sr_vb_start->name;
|
||||||
struct oid *oid = &data->c->sr_vb_start->name;
|
|
||||||
|
|
||||||
/* BGP4-MIB::bgpPeerIdentifier */
|
/* BGP4-MIB::bgpPeerIdentifier */
|
||||||
STATIC_OID(9) bgp4_peer_id = {
|
STATIC_OID(9) bgp4_peer_id = {
|
||||||
@ -816,14 +815,14 @@ bgp4_next_peer(struct mib_walk_state *state, struct snmp_data *data)
|
|||||||
int old = snmp_oid_size(oid);
|
int old = snmp_oid_size(oid);
|
||||||
int new = snmp_oid_size(peer_oid);
|
int new = snmp_oid_size(peer_oid);
|
||||||
|
|
||||||
if (new - old > 0 && (uint) new - old > data->c->size)
|
if (new - old > 0 && (uint) new - old > c->size)
|
||||||
{
|
{
|
||||||
snmp_log("bgp4_next_peer small buffer");
|
snmp_log("bgp4_next_peer small buffer");
|
||||||
snmp_manage_tbuf(data->p, data->c);
|
snmp_manage_tbuf(c->p, c);
|
||||||
oid = &data->c->sr_vb_start->name; // TODO fix sr_vb_start in manage_tbuf
|
oid = &c->sr_vb_start->name; // TODO fix sr_vb_start in manage_tbuf
|
||||||
}
|
}
|
||||||
|
|
||||||
data->c->buffer += (new - old);
|
c->buffer += (new - old);
|
||||||
|
|
||||||
snmp_oid_copy(oid, peer_oid);
|
snmp_oid_copy(oid, peer_oid);
|
||||||
STORE_U8(oid->include, 1);
|
STORE_U8(oid->include, 1);
|
||||||
@ -840,7 +839,7 @@ bgp4_next_peer(struct mib_walk_state *state, struct snmp_data *data)
|
|||||||
net_fill_ip4(&net, ip4, IP4_MAX_PREFIX_LENGTH);
|
net_fill_ip4(&net, ip4, IP4_MAX_PREFIX_LENGTH);
|
||||||
struct f_trie_walk_state ws;
|
struct f_trie_walk_state ws;
|
||||||
|
|
||||||
int match = trie_walk_init(&ws, data->p->bgp_trie, &net, 1);
|
int match = trie_walk_init(&ws, c->p->bgp_trie, &net, 1);
|
||||||
|
|
||||||
if (match && LOAD_U8(oid->include) && precise)
|
if (match && LOAD_U8(oid->include) && precise)
|
||||||
{
|
{
|
||||||
@ -931,7 +930,7 @@ snmp_bgp4_start(struct snmp_proto *p)
|
|||||||
|
|
||||||
struct {
|
struct {
|
||||||
u32 id;
|
u32 id;
|
||||||
enum snmp_search_res (*filler)(struct mib_walk_state *state, struct snmp_data *data);
|
enum snmp_search_res (*filler)(struct mib_walk_state *state, struct snmp_pdu *c);
|
||||||
enum agentx_type type;
|
enum agentx_type type;
|
||||||
int size;
|
int size;
|
||||||
} leafs[] = {
|
} leafs[] = {
|
||||||
@ -977,7 +976,7 @@ snmp_bgp4_start(struct snmp_proto *p)
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
enum snmp_search_res (*filler)(struct mib_walk_state *state, struct snmp_data *data);
|
enum snmp_search_res (*filler)(struct mib_walk_state *state, struct snmp_pdu *c);
|
||||||
enum agentx_type type;
|
enum agentx_type type;
|
||||||
int size;
|
int size;
|
||||||
} entry_leafs[] = {
|
} entry_leafs[] = {
|
||||||
|
@ -41,7 +41,7 @@ struct mib_leaf {
|
|||||||
* AGENTX_INVALID, it is expected that filler() hook will also fill
|
* AGENTX_INVALID, it is expected that filler() hook will also fill
|
||||||
* the VarBind type.
|
* the VarBind type.
|
||||||
*/
|
*/
|
||||||
enum snmp_search_res (*filler)(struct mib_walk_state *state, struct snmp_data *data);
|
enum snmp_search_res (*filler)(struct mib_walk_state *state, struct snmp_pdu *context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* call_next - signal multileaf
|
* call_next - signal multileaf
|
||||||
@ -56,7 +56,7 @@ struct mib_leaf {
|
|||||||
* Hook may be NULL meaning the leaf node is not multileaf/subtree.
|
* Hook may be NULL meaning the leaf node is not multileaf/subtree.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int (*call_next)(struct mib_walk_state *state, struct snmp_data *data);
|
int (*call_next)(struct mib_walk_state *state, struct snmp_pdu *context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* type of produced VarBind, may be replaced in packet instanciation by
|
* type of produced VarBind, may be replaced in packet instanciation by
|
||||||
|
@ -12,8 +12,9 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
inline void
|
inline void
|
||||||
snmp_pdu_context(struct snmp_pdu *pdu, sock *sk)
|
snmp_pdu_context(struct snmp_pdu *pdu, struct snmp_proto *p, sock *sk)
|
||||||
{
|
{
|
||||||
|
pdu->p = p;
|
||||||
pdu->error = AGENTX_RES_NO_ERROR;
|
pdu->error = AGENTX_RES_NO_ERROR;
|
||||||
pdu->buffer = sk->tpos;
|
pdu->buffer = sk->tpos;
|
||||||
pdu->size = sk->tbuf + sk->tbsize - sk->tpos;
|
pdu->size = sk->tbuf + sk->tbsize - sk->tpos;
|
||||||
@ -1061,13 +1062,13 @@ snmp_oid_common_ancestor(const struct oid *left, const struct oid *right, struct
|
|||||||
* SNMP MIB tree walking
|
* SNMP MIB tree walking
|
||||||
*/
|
*/
|
||||||
struct mib_leaf *
|
struct mib_leaf *
|
||||||
snmp_walk_init(struct mib_tree *tree, struct mib_walk_state *walk, const struct oid *oid, struct snmp_data *data)
|
snmp_walk_init(struct mib_tree *tree, struct mib_walk_state *walk, const struct oid *oid, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
mib_tree_walk_init(walk, tree);
|
mib_tree_walk_init(walk, tree);
|
||||||
|
|
||||||
snmp_vb_to_tx(data->p, oid, data->c);
|
snmp_vb_to_tx(c->p, oid, c);
|
||||||
|
|
||||||
mib_node_u *node = mib_tree_find(tree, walk, &data->c->sr_vb_start->name);
|
mib_node_u *node = mib_tree_find(tree, walk, &c->sr_vb_start->name);
|
||||||
|
|
||||||
// TODO hide me in mib_tree code
|
// TODO hide me in mib_tree code
|
||||||
/* mib_tree_find() returns NULL if the oid is longer than existing any path */
|
/* mib_tree_find() returns NULL if the oid is longer than existing any path */
|
||||||
@ -1079,7 +1080,7 @@ snmp_walk_init(struct mib_tree *tree, struct mib_walk_state *walk, const struct
|
|||||||
|
|
||||||
// TODO alter the varbind
|
// TODO alter the varbind
|
||||||
struct mib_leaf *
|
struct mib_leaf *
|
||||||
snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *walk, struct snmp_data *data)
|
snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *walk, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
ASSUME(tree && walk);
|
ASSUME(tree && walk);
|
||||||
|
|
||||||
@ -1093,52 +1094,52 @@ snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *walk, struct snmp_d
|
|||||||
|
|
||||||
if (mib_node_is_leaf(node) && leaf->call_next)
|
if (mib_node_is_leaf(node) && leaf->call_next)
|
||||||
{
|
{
|
||||||
const struct oid *oid = &data->c->sr_vb_start->name;
|
const struct oid *oid = &c->sr_vb_start->name;
|
||||||
if (mib_tree_walk_oid_compare(walk, oid) > 0)
|
if (mib_tree_walk_oid_compare(walk, oid) > 0)
|
||||||
{
|
{
|
||||||
int old = snmp_oid_size(&data->c->sr_vb_start->name);
|
int old = snmp_oid_size(&c->sr_vb_start->name);
|
||||||
if (mib_tree_walk_to_oid(walk,
|
if (mib_tree_walk_to_oid(walk,
|
||||||
&data->c->sr_vb_start->name, 20 * sizeof(u32)))
|
&c->sr_vb_start->name, 20 * sizeof(u32)))
|
||||||
{
|
{
|
||||||
snmp_log("walk_next copy failed");
|
snmp_log("walk_next copy failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int new = snmp_oid_size(&data->c->sr_vb_start->name);
|
int new = snmp_oid_size(&c->sr_vb_start->name);
|
||||||
data->c->buffer += (new - old);
|
c->buffer += (new - old);
|
||||||
}
|
}
|
||||||
|
|
||||||
found = !leaf->call_next(walk, data);
|
found = !leaf->call_next(walk, c);
|
||||||
}
|
}
|
||||||
else if (mib_node_is_leaf(node) && LOAD_U8(data->c->sr_vb_start->name.include))
|
else if (mib_node_is_leaf(node) && LOAD_U8(c->sr_vb_start->name.include))
|
||||||
{
|
{
|
||||||
found = 1;
|
found = 1;
|
||||||
STORE_U8(data->c->sr_vb_start->name.include, 0);
|
STORE_U8(c->sr_vb_start->name.include, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
const struct oid *oid = &data->c->sr_vb_start->name;
|
const struct oid *oid = &c->sr_vb_start->name;
|
||||||
u32 skip = (walk->id_pos < LOAD_U8(oid->n_subid)) ?
|
u32 skip = (walk->id_pos < LOAD_U8(oid->n_subid)) ?
|
||||||
LOAD_U32(oid->ids[walk->id_pos]) : 0;
|
LOAD_U32(oid->ids[walk->id_pos]) : 0;
|
||||||
while (!found && (leaf = mib_tree_walk_next_leaf(tree, walk, skip)) != NULL)
|
while (!found && (leaf = mib_tree_walk_next_leaf(tree, walk, skip)) != NULL)
|
||||||
{
|
{
|
||||||
/* mib_tree_walk_next() forces VarBind's name OID overwriting */
|
/* mib_tree_walk_next() forces VarBind's name OID overwriting */
|
||||||
int old = snmp_oid_size(&data->c->sr_vb_start->name);
|
int old = snmp_oid_size(&c->sr_vb_start->name);
|
||||||
// TODO autogrow
|
// TODO autogrow
|
||||||
if (mib_tree_walk_to_oid(walk, &data->c->sr_vb_start->name, 20 * sizeof(u32)))
|
if (mib_tree_walk_to_oid(walk, &c->sr_vb_start->name, 20 * sizeof(u32)))
|
||||||
{
|
{
|
||||||
snmp_log("walk_next copy failed");
|
snmp_log("walk_next copy failed");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
int new = snmp_oid_size(&data->c->sr_vb_start->name);
|
int new = snmp_oid_size(&c->sr_vb_start->name);
|
||||||
data->c->buffer += (new - old);
|
c->buffer += (new - old);
|
||||||
|
|
||||||
if (leaf->call_next && !leaf->call_next(walk, data))
|
if (leaf->call_next && !leaf->call_next(walk, c))
|
||||||
found = 1;
|
found = 1;
|
||||||
else if (!leaf->call_next)
|
else if (!leaf->call_next)
|
||||||
found = 1;
|
found = 1;
|
||||||
|
|
||||||
oid = &data->c->sr_vb_start->name;
|
oid = &c->sr_vb_start->name;
|
||||||
skip = (walk->id_pos < LOAD_U8(oid->n_subid)) ?
|
skip = (walk->id_pos < LOAD_U8(oid->n_subid)) ?
|
||||||
LOAD_U32(oid->ids[walk->id_pos]) : 0;
|
LOAD_U32(oid->ids[walk->id_pos]) : 0;
|
||||||
}
|
}
|
||||||
@ -1150,9 +1151,9 @@ snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *walk, struct snmp_d
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum snmp_search_res
|
enum snmp_search_res
|
||||||
snmp_walk_fill(struct mib_leaf *leaf, struct mib_walk_state *walk, struct snmp_data *data)
|
snmp_walk_fill(struct mib_leaf *leaf, struct mib_walk_state *walk, struct snmp_pdu *c)
|
||||||
{
|
{
|
||||||
struct agentx_varbind *vb = data->c->sr_vb_start;
|
struct agentx_varbind *vb = c->sr_vb_start;
|
||||||
|
|
||||||
if (!leaf)
|
if (!leaf)
|
||||||
return SNMP_SEARCH_NO_OBJECT;
|
return SNMP_SEARCH_NO_OBJECT;
|
||||||
@ -1177,15 +1178,15 @@ snmp_walk_fill(struct mib_leaf *leaf, struct mib_walk_state *walk, struct snmp_d
|
|||||||
|
|
||||||
snmp_log("walk_fill got size %u based on lt %u ls %u, calling filler()", size, leaf->type, leaf->size);
|
snmp_log("walk_fill got size %u based on lt %u ls %u, calling filler()", size, leaf->type, leaf->size);
|
||||||
|
|
||||||
if (size >= data->c->size)
|
if (size >= c->size)
|
||||||
{
|
{
|
||||||
snmp_log("walk_fill small buffer size %d to %d", size, data->c->size);
|
snmp_log("walk_fill small buffer size %d to %d", size, c->size);
|
||||||
snmp_manage_tbuf(data->p, data->c);
|
snmp_manage_tbuf(c->p, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum snmp_search_res res = leaf->filler(walk, data);
|
enum snmp_search_res res = leaf->filler(walk, c);
|
||||||
|
|
||||||
vb = data->c->sr_vb_start;
|
vb = c->sr_vb_start;
|
||||||
|
|
||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
snmp_set_varbind_type(vb, snmp_search_res_to_type(res));
|
snmp_set_varbind_type(vb, snmp_search_res_to_type(res));
|
||||||
|
@ -62,7 +62,7 @@ void snmp_varbind_duplicate_hdr(struct snmp_proto *p, struct agentx_varbind **vb
|
|||||||
*/
|
*/
|
||||||
void snmp_session(const struct snmp_proto *p, struct agentx_header *h);
|
void snmp_session(const struct snmp_proto *p, struct agentx_header *h);
|
||||||
int snmp_has_context(const struct agentx_header *h);
|
int snmp_has_context(const struct agentx_header *h);
|
||||||
void snmp_pdu_context(struct snmp_pdu *pdu, sock *sk);
|
void snmp_pdu_context(struct snmp_pdu *pdu, struct snmp_proto *p, sock *sk);
|
||||||
struct oid *snmp_oid_duplicate(pool *pool, const struct oid *oid);
|
struct oid *snmp_oid_duplicate(pool *pool, const struct oid *oid);
|
||||||
struct oid *snmp_oid_blank(struct snmp_proto *p);
|
struct oid *snmp_oid_blank(struct snmp_proto *p);
|
||||||
|
|
||||||
@ -114,8 +114,8 @@ enum agentx_type snmp_search_res_to_type(enum snmp_search_res res);
|
|||||||
/*
|
/*
|
||||||
* SNMP MIB tree walking
|
* SNMP MIB tree walking
|
||||||
*/
|
*/
|
||||||
struct mib_leaf *snmp_walk_init(struct mib_tree *tree, struct mib_walk_state *state, const struct oid *start_rx, struct snmp_data *data);
|
struct mib_leaf *snmp_walk_init(struct mib_tree *tree, struct mib_walk_state *state, const struct oid *start_rx, struct snmp_pdu *context);
|
||||||
struct mib_leaf *snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *state, struct snmp_data *data);
|
struct mib_leaf *snmp_walk_next(struct mib_tree *tree, struct mib_walk_state *state, struct snmp_pdu *context);
|
||||||
enum snmp_search_res snmp_walk_fill(struct mib_leaf *leaf, struct mib_walk_state *state, struct snmp_data *data);
|
enum snmp_search_res snmp_walk_fill(struct mib_leaf *leaf, struct mib_walk_state *state, struct snmp_pdu *context);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -169,7 +169,7 @@ snmp_simple_response(struct snmp_proto *p, enum agentx_response_errs error, u16
|
|||||||
{
|
{
|
||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
ASSUME(c.size >= sizeof(struct agentx_response));
|
ASSUME(c.size >= sizeof(struct agentx_response));
|
||||||
|
|
||||||
@ -193,7 +193,7 @@ open_pdu(struct snmp_proto *p, struct oid *oid)
|
|||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
|
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
#define TIMEOUT_SIZE sizeof(u32) /* 1B timeout, 3B zero padding */
|
#define TIMEOUT_SIZE sizeof(u32) /* 1B timeout, 3B zero padding */
|
||||||
|
|
||||||
@ -247,7 +247,7 @@ snmp_notify_pdu(struct snmp_proto *p, struct oid *oid, void *data, uint size, in
|
|||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
|
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
#define UPTIME_SIZE \
|
#define UPTIME_SIZE \
|
||||||
sizeof( struct { u32 vb_type; u32 oid_hdr; u32 ids[4]; } )
|
sizeof( struct { u32 vb_type; u32 oid_hdr; u32 ids[4]; } )
|
||||||
@ -352,7 +352,7 @@ un_register_pdu(struct snmp_proto *p, struct oid *oid, u32 bound, uint index, en
|
|||||||
const struct snmp_config *cf = SKIP_BACK(struct snmp_config, cf, p->p.cf);
|
const struct snmp_config *cf = SKIP_BACK(struct snmp_config, cf, p->p.cf);
|
||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
#define BOUND_SIZE sizeof(u32)
|
#define BOUND_SIZE sizeof(u32)
|
||||||
/* conditional +4 for upper-bound (optinal field) */
|
/* conditional +4 for upper-bound (optinal field) */
|
||||||
@ -441,7 +441,7 @@ close_pdu(struct snmp_proto *p, enum agentx_close_reasons reason)
|
|||||||
{
|
{
|
||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
#define REASON_SIZE sizeof(u32)
|
#define REASON_SIZE sizeof(u32)
|
||||||
if (c.size < AGENTX_HEADER_SIZE + REASON_SIZE)
|
if (c.size < AGENTX_HEADER_SIZE + REASON_SIZE)
|
||||||
@ -538,7 +538,7 @@ parse_test_set_pdu(struct snmp_proto *p, byte * const pkt_start)
|
|||||||
|
|
||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
if (c.size < AGENTX_HEADER_SIZE)
|
if (c.size < AGENTX_HEADER_SIZE)
|
||||||
{
|
{
|
||||||
@ -601,7 +601,7 @@ parse_sets_pdu(struct snmp_proto *p, byte * const pkt_start, enum agentx_respons
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, p->sock);
|
snmp_pdu_context(&c, p, p->sock);
|
||||||
if (c.size < sizeof(struct agentx_response))
|
if (c.size < sizeof(struct agentx_response))
|
||||||
{
|
{
|
||||||
snmp_log("parse_sets_pdu small buffer");
|
snmp_log("parse_sets_pdu small buffer");
|
||||||
@ -1081,18 +1081,14 @@ void
|
|||||||
snmp_get_pdu(struct snmp_proto *p, struct snmp_pdu *c, const struct oid *o_start, struct mib_walk_state *walk)
|
snmp_get_pdu(struct snmp_proto *p, struct snmp_pdu *c, const struct oid *o_start, struct mib_walk_state *walk)
|
||||||
{
|
{
|
||||||
snmp_log("snmp_get_pdu()");
|
snmp_log("snmp_get_pdu()");
|
||||||
struct snmp_data d = {
|
|
||||||
.p = p,
|
|
||||||
.c = c,
|
|
||||||
};
|
|
||||||
|
|
||||||
struct mib_leaf *leaf;
|
struct mib_leaf *leaf;
|
||||||
leaf = snmp_walk_init(p->mib_tree, walk, o_start, &d);
|
leaf = snmp_walk_init(p->mib_tree, walk, o_start, c);
|
||||||
|
|
||||||
snmp_log("found node %p", leaf);
|
snmp_log("found node %p", leaf);
|
||||||
|
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
res = snmp_walk_fill(leaf, walk, &d);
|
res = snmp_walk_fill(leaf, walk, c);
|
||||||
|
|
||||||
snmp_log("fill result %u", res);
|
snmp_log("fill result %u", res);
|
||||||
|
|
||||||
@ -1103,16 +1099,11 @@ snmp_get_pdu(struct snmp_proto *p, struct snmp_pdu *c, const struct oid *o_start
|
|||||||
int
|
int
|
||||||
snmp_get_next_pdu(struct snmp_proto *p, struct snmp_pdu *c, const struct oid *o_start, struct mib_walk_state *walk)
|
snmp_get_next_pdu(struct snmp_proto *p, struct snmp_pdu *c, const struct oid *o_start, struct mib_walk_state *walk)
|
||||||
{
|
{
|
||||||
struct snmp_data d = {
|
(void) snmp_walk_init(p->mib_tree, walk, o_start, c);
|
||||||
.p = p,
|
struct mib_leaf *leaf = snmp_walk_next(p->mib_tree, walk, c);
|
||||||
.c = c,
|
|
||||||
};
|
|
||||||
|
|
||||||
(void) snmp_walk_init(p->mib_tree, walk, o_start, &d);
|
|
||||||
struct mib_leaf *leaf = snmp_walk_next(p->mib_tree, walk, &d);
|
|
||||||
|
|
||||||
enum snmp_search_res res;
|
enum snmp_search_res res;
|
||||||
res = snmp_walk_fill(leaf, walk, &d);
|
res = snmp_walk_fill(leaf, walk, c);
|
||||||
|
|
||||||
if (res != SNMP_SEARCH_OK)
|
if (res != SNMP_SEARCH_OK)
|
||||||
snmp_set_varbind_type(c->sr_vb_start, AGENTX_END_OF_MIB_VIEW);
|
snmp_set_varbind_type(c->sr_vb_start, AGENTX_END_OF_MIB_VIEW);
|
||||||
@ -1204,7 +1195,7 @@ parse_gets_pdu(struct snmp_proto *p, byte * const pkt_start)
|
|||||||
|
|
||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get-Bulk processing stops if all the varbind have type END_OF_MIB_VIEW
|
* Get-Bulk processing stops if all the varbind have type END_OF_MIB_VIEW
|
||||||
@ -1396,7 +1387,7 @@ snmp_ping(struct snmp_proto *p)
|
|||||||
|
|
||||||
sock *sk = p->sock;
|
sock *sk = p->sock;
|
||||||
struct snmp_pdu c;
|
struct snmp_pdu c;
|
||||||
snmp_pdu_context(&c, sk);
|
snmp_pdu_context(&c, p, sk);
|
||||||
|
|
||||||
if (c.size < AGENTX_HEADER_SIZE)
|
if (c.size < AGENTX_HEADER_SIZE)
|
||||||
return;
|
return;
|
||||||
@ -1480,11 +1471,11 @@ snmp_manage_tbuf2(struct snmp_proto *p, void **ptr, struct snmp_pdu *c)
|
|||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
snmp_tbuf_reserve(struct snmp_data *data, size_t size)
|
snmp_tbuf_reserve(struct snmp_pdu *c, size_t size)
|
||||||
{
|
{
|
||||||
if (size > data->c->size)
|
if (size > c->size)
|
||||||
{
|
{
|
||||||
snmp_manage_tbuf(data->p, data->c);
|
snmp_manage_tbuf(c->p, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,6 +305,7 @@ enum agentx_response_errs {
|
|||||||
|
|
||||||
/* SNMP PDU info */
|
/* SNMP PDU info */
|
||||||
struct snmp_pdu {
|
struct snmp_pdu {
|
||||||
|
struct snmp_proto *p;
|
||||||
/* TX buffer */
|
/* TX buffer */
|
||||||
byte *buffer; /* pointer to buffer */
|
byte *buffer; /* pointer to buffer */
|
||||||
uint size; /* unused space in buffer */
|
uint size; /* unused space in buffer */
|
||||||
@ -316,17 +317,6 @@ struct snmp_pdu {
|
|||||||
/* Control */
|
/* Control */
|
||||||
enum agentx_response_errs error; /* storage for result of current action */
|
enum agentx_response_errs error; /* storage for result of current action */
|
||||||
u32 index; /* index on which the error was found */
|
u32 index; /* index on which the error was found */
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
/*
|
|
||||||
* snmp_data - Comprehensive hadle for Agentx PDU state
|
|
||||||
* @p: SNMP protocol instance
|
|
||||||
* @c: contextual data for currrently constructed AgentX PDU
|
|
||||||
*/
|
|
||||||
struct snmp_data {
|
|
||||||
struct snmp_proto *p;
|
|
||||||
struct snmp_pdu *c;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct snmp_packet_info {
|
struct snmp_packet_info {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user