Do not add 'default:' cases inside a switch() on an enum like the

SNMP option argument. That way the compiler will give a warning in
case of a missing or an extra but unknown 'case:'.
Do the same for SNMP LEAF objects to be prepared once gensnmptree will
auto-generate enums for those too.
Add an abort() after the switch() instead of the 'default:' to catch
any errors. The nice side effect is that the compiler will correctly
track supposed to be 'uninitialized' variables with that.

When trying to set a value sanity check it before calling the OS
dependent API of snmp_bridge to tell whether it is an attempt to
set a bad value or a general error.

Suggested by:	harti (first part)
Approved by:	bz (mentor)
This commit is contained in:
Shteryana Shopova 2006-12-15 20:01:57 +00:00
parent b613495e3c
commit f02a1e5794
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=165253
6 changed files with 500 additions and 419 deletions

View File

@ -397,7 +397,6 @@ int
op_dot1d_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
struct tp_entry *te;
@ -412,37 +411,36 @@ op_dot1d_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_GET:
if ((te = bridge_addrs_get(&val->var, sub, bif)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((te = bridge_addrs_getnext(&val->var, sub, bif)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
bridge_addrs_index_append(&val->var, sub, te);
break;
goto get;
case SNMP_OP_SET:
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
break;
}
abort();
ret = SNMP_ERR_NOERROR;
get:
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dTpFdbAddress:
ret = string_get(val, te->tp_addr, ETHER_ADDR_LEN);
break;
return (string_get(val, te->tp_addr, ETHER_ADDR_LEN));
case LEAF_dot1dTpFdbPort :
val->v.integer = te->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dTpFdbStatus:
val->v.integer = te->status;
break;
return (SNMP_ERR_NOERROR);
}
return (ret);
abort();
}
/*
@ -547,7 +545,6 @@ int
op_begemot_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct tp_entry *te;
if (time(NULL) - address_list_age > bridge_get_data_maxage())
@ -557,7 +554,7 @@ op_begemot_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_GET:
if ((te = bridge_addrs_begemot_get(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((te = bridge_addrs_begemot_getnext(&val->var,
@ -565,29 +562,28 @@ op_begemot_tp_fdb(struct snmp_context *c __unused, struct snmp_value *val,
bridge_addrs_begemot_index_append(&val->var,
sub, te) < 0)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_SET:
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
break;
}
abort();
ret = SNMP_ERR_NOERROR;
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeTpFdbAddress:
ret = string_get(val, te->tp_addr, ETHER_ADDR_LEN);
break;
return (string_get(val, te->tp_addr, ETHER_ADDR_LEN));
case LEAF_begemotBridgeTpFdbPort:
val->v.integer = te->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpFdbStatus:
val->v.integer = te->status;
break;
return (SNMP_ERR_NOERROR);
}
return (ret);
abort();
}

View File

@ -628,7 +628,6 @@ int
op_dot1d_base(struct snmp_context *ctx __unused, struct snmp_value *value,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
if ((bif = bridge_get_default()) == NULL)
@ -638,41 +637,36 @@ op_dot1d_base(struct snmp_context *ctx __unused, struct snmp_value *value,
bridge_update_bif(bif) <= 0) /* It was just deleted. */
return (SNMP_ERR_NOSUCHNAME);
ret = SNMP_ERR_NOERROR;
switch (op) {
case SNMP_OP_GET:
switch (value->var.subs[sub - 1]) {
case LEAF_dot1dBaseBridgeAddress:
ret = string_get(value, bif->br_addr.octet,
ETHER_ADDR_LEN);
break;
return (string_get(value, bif->br_addr.octet,
ETHER_ADDR_LEN));
case LEAF_dot1dBaseNumPorts:
value->v.integer = bif->num_ports;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dBaseType:
value->v.integer = bif->br_type;
break;
abort();
return (SNMP_ERR_NOERROR);
}
break;
abort();
case SNMP_OP_SET:
ret = SNMP_ERR_NOT_WRITEABLE;
break;
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_GETNEXT:
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
abort();
break;
}
return (ret);
abort();
}
int
op_dot1d_stp(struct snmp_context *ctx, struct snmp_value *value,
uint sub, uint iidx __unused, enum snmp_op op)
op_dot1d_stp(struct snmp_context *ctx, struct snmp_value *val, uint sub,
uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
@ -686,107 +680,139 @@ op_dot1d_stp(struct snmp_context *ctx, struct snmp_value *value,
switch (op) {
case SNMP_OP_GET:
switch (value->var.subs[sub - 1]) {
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpProtocolSpecification:
value->v.integer = bif->prot_spec;
break;
val->v.integer = bif->prot_spec;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPriority:
value->v.integer = bif->priority;
break;
val->v.integer = bif->priority;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpTimeSinceTopologyChange:
if (bridge_get_time_since_tc(bif,
&(value->v.uint32)) < 0)
&(val->v.uint32)) < 0)
return (SNMP_ERR_GENERR);
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpTopChanges:
value->v.uint32 = bif->top_changes;
break;
val->v.uint32 = bif->top_changes;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpDesignatedRoot:
return (string_get(value, bif->design_root,
return (string_get(val, bif->design_root,
SNMP_BRIDGE_ID_LEN));
case LEAF_dot1dStpRootCost:
value->v.integer = bif->root_cost;
break;
val->v.integer = bif->root_cost;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpRootPort:
value->v.integer = bif->root_port;
break;
val->v.integer = bif->root_port;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpMaxAge:
value->v.integer = bif->max_age;
break;
val->v.integer = bif->max_age;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpHelloTime:
value->v.integer = bif->hello_time;
break;
val->v.integer = bif->hello_time;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpHoldTime:
value->v.integer = bif->hold_time;
break;
val->v.integer = bif->hold_time;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpForwardDelay:
value->v.integer = bif->fwd_delay;
break;
val->v.integer = bif->fwd_delay;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpBridgeMaxAge:
value->v.integer = bif->bridge_max_age;
break;
val->v.integer = bif->bridge_max_age;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpBridgeHelloTime:
value->v.integer = bif->bridge_hello_time;
break;
val->v.integer = bif->bridge_hello_time;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpBridgeForwardDelay:
value->v.integer = bif->bridge_fwd_delay;
break;
case LEAF_dot1dStpVersion:
value->v.integer = bif->stp_version;
break;
case LEAF_dot1dStpTxHoldCount:
value->v.integer = bif->tx_hold_count;
}
val->v.integer = bif->bridge_fwd_delay;
return (SNMP_ERR_NOERROR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpVersion:
val->v.integer = bif->stp_version;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpTxHoldCount:
val->v.integer = bif->tx_hold_count;
return (SNMP_ERR_NOERROR);
}
abort();
case SNMP_OP_GETNEXT:
abort();
case SNMP_OP_SET:
switch (value->var.subs[sub - 1]) {
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpPriority:
if (val->v.integer > SNMP_BRIDGE_MAX_PRIORITY ||
val->v.integer % 4096 != 0)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->priority;
ret = bridge_set_priority(bif, value->v.integer);
break;
if (bridge_set_priority(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpBridgeMaxAge:
if (val->v.integer < SNMP_BRIDGE_MIN_MAGE ||
val->v.integer > SNMP_BRIDGE_MAX_MAGE)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->bridge_max_age;
ret = bridge_set_maxage(bif, value->v.integer);
break;
if (bridge_set_maxage(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpBridgeHelloTime:
if (val->v.integer < SNMP_BRIDGE_MIN_HTIME ||
val->v.integer > SNMP_BRIDGE_MAX_HTIME)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->bridge_hello_time;
ret = bridge_set_hello_time(bif, value->v.integer);
break;
if (bridge_set_hello_time(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpBridgeForwardDelay:
if (val->v.integer < SNMP_BRIDGE_MIN_FDELAY ||
val->v.integer > SNMP_BRIDGE_MAX_FDELAY)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->bridge_fwd_delay;
ret = bridge_set_forward_delay(bif, value->v.integer);
break;
if (bridge_set_forward_delay(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpVersion:
if (val->v.integer != dot1dStpVersion_stpCompatible &&
val->v.integer != dot1dStpVersion_rstp)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->stp_version;
ret = bridge_set_stp_version(bif, value->v.integer);
break;
if (bridge_set_stp_version(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpTxHoldCount:
if (val->v.integer < SNMP_BRIDGE_MIN_TXHC ||
val->v.integer > SNMP_BRIDGE_MAX_TXHC)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->tx_hold_count;
ret = bridge_set_tx_hold_count(bif, value->v.integer);
break;
if (bridge_set_tx_hold_count(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpProtocolSpecification:
case LEAF_dot1dStpTimeSinceTopologyChange:
@ -799,18 +825,11 @@ op_dot1d_stp(struct snmp_context *ctx, struct snmp_value *value,
case LEAF_dot1dStpHoldTime:
case LEAF_dot1dStpForwardDelay:
return (SNMP_ERR_NOT_WRITEABLE);
default:
return (SNMP_ERR_NOSUCHNAME);
}
if (ret == -2)
return (SNMP_ERR_WRONG_VALUE);
else if (ret < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
abort();
case SNMP_OP_ROLLBACK:
switch (value->var.subs[sub - 1]) {
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpPriority:
bridge_set_priority(bif, ctx->scratch->int1);
break;
@ -836,7 +855,7 @@ op_dot1d_stp(struct snmp_context *ctx, struct snmp_value *value,
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
int
@ -857,23 +876,32 @@ op_dot1d_tp(struct snmp_context *ctx, struct snmp_value *value,
switch (value->var.subs[sub - 1]) {
case LEAF_dot1dTpLearnedEntryDiscards:
value->v.uint32 = bif->lrnt_drops;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dTpAgingTime:
value->v.integer = bif->age_time;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
case SNMP_OP_GETNEXT:
abort();
case SNMP_OP_SET:
if (value->var.subs[sub - 1] == LEAF_dot1dTpAgingTime) {
ctx->scratch->int1 = bif->age_time;
if (bridge_set_aging_time(bif, value->v.integer) < 0)
return (SNMP_ERR_GENERR);
switch (value->var.subs[sub - 1]) {
case LEAF_dot1dTpLearnedEntryDiscards:
return (SNMP_ERR_NOT_WRITEABLE);
case LEAF_dot1dTpAgingTime:
if (value->v.integer < SNMP_BRIDGE_MIN_AGE_TIME ||
value->v.integer > SNMP_BRIDGE_MAX_AGE_TIME)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->age_time;
if (bridge_set_aging_time(bif, value->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
case SNMP_OP_ROLLBACK:
if (value->var.subs[sub - 1] == LEAF_dot1dTpAgingTime)
@ -884,7 +912,7 @@ op_dot1d_tp(struct snmp_context *ctx, struct snmp_value *value,
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
/*
@ -1095,7 +1123,6 @@ int
op_begemot_base_bridge(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
if (time(NULL) - bridge_list_age > bridge_get_data_maxage())
@ -1105,13 +1132,13 @@ op_begemot_base_bridge(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_GET:
if ((bif = bridge_if_index_get(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((bif = bridge_if_index_getnext(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
bridge_if_index_append(&val->var, sub, bif);
break;
goto get;
case SNMP_OP_SET:
switch (val->var.subs[sub - 1]) {
@ -1130,42 +1157,37 @@ op_begemot_base_bridge(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (bridge_commit_if_status(val, sub));
default:
abort();
}
abort();
ret = SNMP_ERR_NOERROR;
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeBaseName:
ret = string_get(val, bif->bif_name, -1);
break;
return (string_get(val, bif->bif_name, -1));
case LEAF_begemotBridgeBaseAddress:
ret = string_get(val, bif->br_addr.octet, ETHER_ADDR_LEN);
break;
return (string_get(val, bif->br_addr.octet, ETHER_ADDR_LEN));
case LEAF_begemotBridgeBaseNumPorts:
val->v.integer = bif->num_ports;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBaseType:
val->v.integer = bif->br_type;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBaseStatus:
val->v.integer = bif->if_status;
break;
return (SNMP_ERR_NOERROR);
}
return (ret);
abort();
}
int
op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
if (time(NULL) - bridge_list_age > bridge_get_data_maxage())
@ -1175,13 +1197,13 @@ op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_GET:
if ((bif = bridge_if_index_get(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((bif = bridge_if_index_getnext(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
bridge_if_index_append(&val->var, sub, bif);
break;
goto get;
case SNMP_OP_SET:
if ((bif = bridge_if_index_get(&val->var, sub)) == NULL)
@ -1189,34 +1211,65 @@ op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpPriority:
if (val->v.integer > SNMP_BRIDGE_MAX_PRIORITY ||
val->v.integer % 4096 != 0)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->priority;
ret = bridge_set_priority(bif, val->v.integer);
break;
if (bridge_set_priority(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpBridgeMaxAge:
if (val->v.integer < SNMP_BRIDGE_MIN_MAGE ||
val->v.integer > SNMP_BRIDGE_MAX_MAGE)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->bridge_max_age;
ret = bridge_set_maxage(bif, val->v.integer);
break;
if (bridge_set_maxage(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpBridgeHelloTime:
if (val->v.integer < SNMP_BRIDGE_MIN_HTIME ||
val->v.integer > SNMP_BRIDGE_MAX_HTIME)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->bridge_hello_time;
ret = bridge_set_hello_time(bif, val->v.integer);
break;
if (bridge_set_hello_time(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpBridgeForwardDelay:
if (val->v.integer < SNMP_BRIDGE_MIN_FDELAY ||
val->v.integer > SNMP_BRIDGE_MAX_FDELAY)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->bridge_fwd_delay;
ret = bridge_set_forward_delay(bif, val->v.integer);
break;
if (bridge_set_forward_delay(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpVersion:
if (val->v.integer !=
begemotBridgeStpVersion_stpCompatible &&
val->v.integer != begemotBridgeStpVersion_rstp)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->stp_version;
ret = bridge_set_stp_version(bif, val->v.integer);
break;
if (bridge_set_stp_version(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpTxHoldCount:
if (val->v.integer < SNMP_BRIDGE_MIN_TXHC ||
val->v.integer > SNMP_BRIDGE_MAX_TXHC)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->tx_hold_count;
ret = bridge_set_tx_hold_count(bif, val->v.integer);
break;
if (bridge_set_tx_hold_count(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpProtocolSpecification:
case LEAF_begemotBridgeStpTimeSinceTopologyChange:
@ -1229,16 +1282,8 @@ op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
case LEAF_begemotBridgeStpHoldTime:
case LEAF_begemotBridgeStpForwardDelay:
return (SNMP_ERR_NOT_WRITEABLE);
default:
return (SNMP_ERR_NOSUCHNAME);
}
if (ret == 0)
return (SNMP_ERR_NOERROR);
else if (ret == -2)
return (SNMP_ERR_WRONG_VALUE);
return (SNMP_ERR_GENERR);
abort();
case SNMP_OP_ROLLBACK:
if ((bif = bridge_if_index_get(&val->var, sub)) == NULL)
@ -1273,81 +1318,77 @@ op_begemot_stp(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
abort();
ret = SNMP_ERR_NOERROR;
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpProtocolSpecification:
val->v.integer = bif->prot_spec;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPriority:
val->v.integer = bif->priority;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpTimeSinceTopologyChange:
if (bridge_get_time_since_tc(bif, &(val->v.uint32)) < 0)
return (SNMP_ERR_GENERR);
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpTopChanges:
val->v.uint32 = bif->top_changes;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpDesignatedRoot:
ret = string_get(val, bif->design_root, SNMP_BRIDGE_ID_LEN);
break;
return (string_get(val, bif->design_root, SNMP_BRIDGE_ID_LEN));
case LEAF_begemotBridgeStpRootCost:
val->v.integer = bif->root_cost;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpRootPort:
val->v.integer = bif->root_port;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpMaxAge:
val->v.integer = bif->max_age;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpHelloTime:
val->v.integer = bif->hello_time;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpHoldTime:
val->v.integer = bif->hold_time;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpForwardDelay:
val->v.integer = bif->fwd_delay;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpBridgeMaxAge:
val->v.integer = bif->bridge_max_age;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpBridgeHelloTime:
val->v.integer = bif->bridge_hello_time;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpBridgeForwardDelay:
val->v.integer = bif->bridge_fwd_delay;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpVersion:
val->v.integer = bif->stp_version;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpTxHoldCount:
val->v.integer = bif->tx_hold_count;
break;
return (SNMP_ERR_NOERROR);
}
return (ret);
abort();
}
int
@ -1363,13 +1404,13 @@ op_begemot_tp(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_GET:
if ((bif = bridge_if_index_get(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((bif = bridge_if_index_getnext(&val->var, sub)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
bridge_if_index_append(&val->var, sub, bif);
break;
goto get;
case SNMP_OP_SET:
if ((bif = bridge_if_index_get(&val->var, sub)) == NULL)
@ -1377,6 +1418,10 @@ op_begemot_tp(struct snmp_context *ctx, struct snmp_value *val,
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeTpAgingTime:
if (val->v.integer < SNMP_BRIDGE_MIN_AGE_TIME ||
val->v.integer > SNMP_BRIDGE_MAX_AGE_TIME)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bif->age_time;
if (bridge_set_aging_time(bif, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
@ -1410,24 +1455,23 @@ op_begemot_tp(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
abort();
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeTpLearnedEntryDiscards:
val->v.uint32 = bif->lrnt_drops;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpAgingTime:
val->v.integer = bif->age_time;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpMaxAddresses:
val->v.integer = bif->max_addrs;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}

View File

@ -95,23 +95,22 @@ op_begemot_bridge_pf(struct snmp_context *ctx, struct snmp_value *val,
if ((k_val = snmp_truth2val(val->v.integer)) < 0)
return (SNMP_ERR_BADVALUE);
return (SNMP_ERR_NOERROR);
case SNMP_OP_GET:
break;
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgePfilStatus:
case LEAF_begemotBridgePfilMembers:
case LEAF_begemotBridgePfilIpOnly:
case LEAF_begemotBridgeLayer2PfStatus:
if (bridge_do_pfctl(val->var.subs[sub - 1] - 1,
op, &k_val) < 0)
return (SNMP_ERR_GENERR);
val->v.integer = val2snmp_truth(k_val);
return (SNMP_ERR_NOERROR);
}
abort();
}
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgePfilStatus:
case LEAF_begemotBridgePfilMembers:
case LEAF_begemotBridgePfilIpOnly:
case LEAF_begemotBridgeLayer2PfStatus:
if (bridge_do_pfctl(val->var.subs[sub - 1] - 1,
op, &k_val) < 0)
return (SNMP_ERR_GENERR);
val->v.integer = val2snmp_truth(k_val);
break;
abort();
}
return (SNMP_ERR_NOERROR);
abort();
}

View File

@ -360,7 +360,7 @@ op_dot1d_base_port(struct snmp_context *c __unused, struct snmp_value *val,
if ((bp = bridge_port_find(val->var.subs[sub],
bif)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if (val->var.len - sub == 0) {
@ -374,43 +374,47 @@ op_dot1d_base_port(struct snmp_context *c __unused, struct snmp_value *val,
}
val->var.len = sub + 1;
val->var.subs[sub] = bp->port_no;
break;
goto get;
case SNMP_OP_SET:
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
break;
}
abort();
get:
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dBasePort:
val->v.integer = bp->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dBasePortIfIndex:
val->v.integer = bp->if_idx;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dBasePortCircuit:
val->v.oid = bp->circuit;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dBasePortDelayExceededDiscards:
val->v.uint32 = bp->dly_ex_drops;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dBasePortMtuExceededDiscards:
val->v.uint32 = bp->dly_mtu_drops;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
int
op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
struct bridge_port *bp;
@ -428,7 +432,7 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
if ((bp = bridge_port_find(val->var.subs[sub],
bif)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if (val->var.len - sub == 0) {
@ -442,7 +446,7 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
}
val->var.len = sub + 1;
val->var.subs[sub] = bp->port_no;
break;
goto get;
case SNMP_OP_SET:
if (val->var.len - sub != 1)
@ -453,20 +457,37 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpPortPriority:
if (val->v.integer < 0 || val->v.integer > 255)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->priority;
ret = bridge_port_set_priority(bif->bif_name, bp,
val->v.integer);
break;
if (bridge_port_set_priority(bif->bif_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortEnable:
if (val->v.integer != dot1dStpPortEnable_enabled &&
val->v.integer != dot1dStpPortEnable_disabled)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->enable;
ret = bridge_port_set_stp_enable(bif->bif_name,
bp, val->v.integer);
break;
if (bridge_port_set_stp_enable(bif->bif_name,
bp, val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortPathCost:
if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
val->v.integer > SNMP_PORT_MAX_PATHCOST)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->path_cost;
ret = bridge_port_set_path_cost(bif->bif_name, bp,
val->v.integer);
break;
if (bridge_port_set_path_cost(bif->bif_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPort:
case LEAF_dot1dStpPortState:
case LEAF_dot1dStpPortDesignatedRoot:
@ -475,14 +496,8 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case LEAF_dot1dStpPortDesignatedPort:
case LEAF_dot1dStpPortForwardTransitions:
return (SNMP_ERR_NOT_WRITEABLE);
default:
return (SNMP_ERR_NOSUCHNAME);
}
if (ret == 0)
return (SNMP_ERR_NOERROR);
else if (ret == -2)
return (SNMP_ERR_WRONG_VALUE);
return (SNMP_ERR_GENERR);
abort();
case SNMP_OP_ROLLBACK:
if ((bp = bridge_port_find(val->var.subs[sub],
@ -506,55 +521,58 @@ op_dot1d_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
abort();
ret = SNMP_ERR_NOERROR;
get:
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpPort:
val->v.integer = bp->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortPriority:
val->v.integer = bp->priority;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortState:
val->v.integer = bp->state;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortEnable:
val->v.integer = bp->enable;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortPathCost:
val->v.integer = bp->path_cost;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortDesignatedRoot:
ret = string_get(val, bp->design_root,
SNMP_BRIDGE_ID_LEN);
break;
return (string_get(val, bp->design_root,
SNMP_BRIDGE_ID_LEN));
case LEAF_dot1dStpPortDesignatedCost:
val->v.integer = bp->design_cost;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortDesignatedBridge:
ret = string_get(val, bp->design_bridge,
SNMP_BRIDGE_ID_LEN);
break;
return (string_get(val, bp->design_bridge,
SNMP_BRIDGE_ID_LEN));
case LEAF_dot1dStpPortDesignatedPort:
ret = string_get(val, bp->design_port, 2);
break;
return (string_get(val, bp->design_port, 2));
case LEAF_dot1dStpPortForwardTransitions:
val->v.uint32 = bp->fwd_trans;
break;
return (SNMP_ERR_NOERROR);
}
return (ret);
abort();
}
int
op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_if *bif;
struct bridge_port *bp;
@ -572,7 +590,7 @@ op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
if ((bp = bridge_port_find(val->var.subs[sub],
bif)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if (val->var.len - sub == 0) {
@ -586,7 +604,7 @@ op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
}
val->var.len = sub + 1;
val->var.subs[sub] = bp->port_no;
break;
goto get;
case SNMP_OP_SET:
if (val->var.len - sub != 1)
@ -597,33 +615,44 @@ op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpPortAdminEdgePort:
if (val->v.integer != TruthValue_true &&
val->v.integer != TruthValue_false)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->admin_edge;
ret = bridge_port_set_admin_edge(bif->bif_name, bp,
val->v.integer);
break;
if (bridge_port_set_admin_edge(bif->bif_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortAdminPointToPoint:
if (val->v.integer < 0 || val->v.integer >
StpPortAdminPointToPointType_auto)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->admin_p2p;
ret = bridge_port_set_admin_p2p(bif->bif_name, bp,
val->v.integer);
break;
if (bridge_port_set_admin_p2p(bif->bif_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortAdminPathCost:
if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
val->v.integer > SNMP_PORT_MAX_PATHCOST)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->admin_path_cost;
ret = bridge_port_set_path_cost(bif->bif_name, bp,
val->v.integer);
break;
if (bridge_port_set_path_cost(bif->bif_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortProtocolMigration:
case LEAF_dot1dStpPortOperEdgePort:
case LEAF_dot1dStpPortOperPointToPoint:
return (SNMP_ERR_NOT_WRITEABLE);
default:
return (SNMP_ERR_NOSUCHNAME);
}
if (ret == 0)
return (SNMP_ERR_NOERROR);
else if (ret == -2)
return (SNMP_ERR_WRONG_VALUE);
return (SNMP_ERR_GENERR);
abort();
case SNMP_OP_ROLLBACK:
if ((bp = bridge_port_find(val->var.subs[sub],
@ -648,33 +677,37 @@ op_dot1d_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
abort();
get:
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dStpPortProtocolMigration:
val->v.integer = bp->proto_migr;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortAdminEdgePort:
val->v.integer = bp->admin_edge;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortOperEdgePort:
val->v.integer = bp->oper_edge;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortAdminPointToPoint:
val->v.integer = bp->admin_p2p;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortOperPointToPoint:
val->v.integer = bp->oper_p2p;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dStpPortAdminPathCost:
val->v.integer = bp->admin_path_cost;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
int
@ -698,7 +731,7 @@ op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
if ((bp = bridge_port_find(val->var.subs[sub],
bif)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if (val->var.len - sub == 0) {
@ -712,36 +745,41 @@ op_dot1d_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
}
val->var.len = sub + 1;
val->var.subs[sub] = bp->port_no;
break;
goto get;
case SNMP_OP_SET:
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
break;
}
abort();
get:
switch (val->var.subs[sub - 1]) {
case LEAF_dot1dTpPort:
val->v.integer = bp->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dTpPortMaxInfo:
val->v.integer = bp->max_info;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dTpPortInFrames:
val->v.uint32 = bp->in_frames;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dTpPortOutFrames:
val->v.uint32 = bp->out_frames;
break;
return (SNMP_ERR_NOERROR);
case LEAF_dot1dTpPortInDiscards:
val->v.uint32 = bp->in_drops;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
/*
@ -1036,7 +1074,7 @@ op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int8_t status, which;
struct bridge_port *bp = NULL;
struct bridge_port *bp;
if (time(NULL) - ports_list_age > bridge_get_data_maxage())
bridge_update_all_ports();
@ -1052,7 +1090,7 @@ op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val,
if ((bp = bridge_port_index_get(&val->var, sub,
status)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if (which == LEAF_begemotBridgeBaseSpanEnabled ||
@ -1062,7 +1100,7 @@ op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val,
status)) == NULL ||
bridge_port_index_append(&val->var, sub, bp) < 0)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_SET:
switch (which) {
@ -1095,36 +1133,42 @@ op_begemot_base_port(struct snmp_context *ctx, struct snmp_value *val,
return (SNMP_ERR_NOERROR);
}
abort();
get:
switch (which) {
case LEAF_begemotBridgeBasePort:
val->v.integer = bp->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBasePortIfIndex:
val->v.integer = bp->if_idx;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBaseSpanEnabled:
val->v.integer = bp->span_enable;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBasePortDelayExceededDiscards:
val->v.uint32 = bp->dly_ex_drops;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBasePortMtuExceededDiscards:
val->v.uint32 = bp->dly_mtu_drops;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeBasePortStatus:
val->v.integer = bp->status;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
int
op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_port *bp;
const char *b_name;
@ -1135,13 +1179,13 @@ op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_GET:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_SET:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
@ -1149,23 +1193,41 @@ op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
if ((b_name = bridge_if_find_name(bp->sysindex)) == NULL)
return (SNMP_ERR_GENERR);
ret = SNMP_ERR_NOERROR;
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpPortPriority:
if (val->v.integer < 0 || val->v.integer > 255)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->priority;
ret = bridge_port_set_priority(b_name, bp,
val->v.integer);
break;
if (bridge_port_set_priority(b_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortEnable:
if (val->v.integer !=
begemotBridgeStpPortEnable_enabled ||
val->v.integer !=
begemotBridgeStpPortEnable_disabled)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->enable;
ret = bridge_port_set_stp_enable(b_name, bp,
val->v.integer);
break;
if (bridge_port_set_stp_enable(b_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortPathCost:
if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
val->v.integer > SNMP_PORT_MAX_PATHCOST)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->path_cost;
ret = bridge_port_set_path_cost(b_name, bp,
val->v.integer);
break;
if (bridge_port_set_path_cost(b_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPort:
case LEAF_begemotBridgeStpPortState:
case LEAF_begemotBridgeStpPortDesignatedRoot:
@ -1175,11 +1237,7 @@ op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case LEAF_begemotBridgeStpPortForwardTransitions:
return (SNMP_ERR_NOT_WRITEABLE);
}
if (ret == 0)
return (SNMP_ERR_NOERROR);
else if (ret == -2)
return (SNMP_ERR_WRONG_VALUE);
return (SNMP_ERR_GENERR);
abort();
case SNMP_OP_ROLLBACK:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL ||
@ -1204,53 +1262,56 @@ op_begemot_stp_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
abort();
ret = SNMP_ERR_NOERROR;
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpPort:
val->v.integer = bp->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortPriority:
val->v.integer = bp->priority;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortState:
val->v.integer = bp->state;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortEnable:
val->v.integer = bp->enable;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortPathCost:
val->v.integer = bp->path_cost;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortDesignatedRoot:
ret = string_get(val, bp->design_root, SNMP_BRIDGE_ID_LEN);
break;
return (string_get(val, bp->design_root, SNMP_BRIDGE_ID_LEN));
case LEAF_begemotBridgeStpPortDesignatedCost:
val->v.integer = bp->design_cost;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortDesignatedBridge:
ret = string_get(val, bp->design_bridge, SNMP_BRIDGE_ID_LEN);
break;
return (string_get(val, bp->design_bridge, SNMP_BRIDGE_ID_LEN));
case LEAF_begemotBridgeStpPortDesignatedPort:
ret = string_get(val, bp->design_port, 2);
break;
return (string_get(val, bp->design_port, 2));
case LEAF_begemotBridgeStpPortForwardTransitions:
val->v.uint32 = bp->fwd_trans;
break;
return (SNMP_ERR_NOERROR);
}
return (ret);
abort();
}
int
op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
uint sub, uint iidx __unused, enum snmp_op op)
{
int ret;
struct bridge_port *bp;
const char *b_name;
@ -1261,13 +1322,13 @@ op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_GET:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_SET:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
@ -1277,33 +1338,44 @@ op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpPortAdminEdgePort:
if (val->v.integer != TruthValue_true &&
val->v.integer != TruthValue_false)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->admin_edge;
ret = bridge_port_set_admin_edge(b_name, bp,
val->v.integer);
break;
if (bridge_port_set_admin_edge(b_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortAdminPointToPoint:
if (val->v.integer < 0 || val->v.integer >
StpPortAdminPointToPointType_auto)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->admin_p2p;
ret = bridge_port_set_admin_p2p(b_name, bp,
val->v.integer);
break;
if (bridge_port_set_admin_p2p(b_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortAdminPathCost:
if (val->v.integer < SNMP_PORT_MIN_PATHCOST ||
val->v.integer > SNMP_PORT_MAX_PATHCOST)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bp->admin_path_cost;
ret = bridge_port_set_path_cost(b_name, bp,
val->v.integer);
break;
if (bridge_port_set_path_cost(b_name, bp,
val->v.integer) < 0)
return (SNMP_ERR_GENERR);
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortProtocolMigration:
case LEAF_begemotBridgeStpPortOperEdgePort:
case LEAF_begemotBridgeStpPortOperPointToPoint:
return (SNMP_ERR_NOT_WRITEABLE);
default:
return (SNMP_ERR_NOSUCHNAME);
}
if (ret == 0)
return (SNMP_ERR_NOERROR);
else if (ret == -2)
return (SNMP_ERR_WRONG_VALUE);
return (SNMP_ERR_GENERR);
abort();
case SNMP_OP_ROLLBACK:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL ||
@ -1328,33 +1400,37 @@ op_begemot_stp_ext_port(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_COMMIT:
return (SNMP_ERR_NOERROR);
default:
abort();
}
abort();
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeStpPortProtocolMigration:
val->v.integer = bp->proto_migr;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortAdminEdgePort:
val->v.integer = bp->admin_edge;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortOperEdgePort:
val->v.integer = bp->oper_edge;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortAdminPointToPoint:
val->v.integer = bp->admin_p2p;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortOperPointToPoint:
val->v.integer = bp->oper_p2p;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeStpPortAdminPathCost:
val->v.integer = bp->admin_path_cost;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
int
@ -1370,40 +1446,45 @@ op_begemot_tp_port(struct snmp_context *c __unused, struct snmp_value *val,
case SNMP_OP_GET:
if ((bp = bridge_port_index_get(&val->var, sub, 0)) == NULL)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_GETNEXT:
if ((bp = bridge_port_index_getnext(&val->var, sub, 0)) ==
NULL || bridge_port_index_append(&val->var, sub, bp) < 0)
return (SNMP_ERR_NOSUCHNAME);
break;
goto get;
case SNMP_OP_SET:
return (SNMP_ERR_NOT_WRITEABLE);
case SNMP_OP_ROLLBACK:
case SNMP_OP_COMMIT:
default:
abort();
break;
}
abort();
get:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeTpPort:
val->v.integer = bp->port_no;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpPortMaxInfo:
val->v.integer = bp->max_info;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpPortInFrames:
val->v.uint32 = bp->in_frames;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpPortOutFrames:
val->v.uint32 = bp->out_frames;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeTpPortInDiscards:
val->v.uint32 = bp->in_drops;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}

View File

@ -168,16 +168,17 @@ op_begemot_bridge_config(struct snmp_context *ctx, struct snmp_value *val,
case SNMP_OP_GET:
switch (val->var.subs[sub - 1]) {
case LEAF_begemotBridgeDefaultBridgeIf:
string_get(val, bridge_get_default_name(), -1);
break;
return (string_get(val, bridge_get_default_name(), -1));
case LEAF_begemotBridgeDataUpdate:
val->v.integer = bridge_data_maxage;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeDataPoll:
val->v.integer = bridge_poll_ticks / 100;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
case SNMP_OP_GETNEXT:
abort();
@ -197,22 +198,24 @@ op_begemot_bridge_config(struct snmp_context *ctx, struct snmp_value *val,
if (bridge_set_default_name(val->v.octetstring.octets,
val->v.octetstring.len) < 0)
return (SNMP_ERR_BADVALUE);
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeDataUpdate:
if (val->v.integer < SNMP_BRIDGE_DATA_MAXAGE_MIN ||
val->v.integer > SNMP_BRIDGE_DATA_MAXAGE_MAX)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = bridge_data_maxage;
bridge_data_maxage = val->v.integer;
break;
return (SNMP_ERR_NOERROR);
case LEAF_begemotBridgeDataPoll:
if (val->v.integer < SNMP_BRIDGE_POLL_INTERVAL_MIN ||
val->v.integer > SNMP_BRIDGE_POLL_INTERVAL_MAX)
return (SNMP_ERR_WRONG_VALUE);
ctx->scratch->int1 = val->v.integer;
break;
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
case SNMP_OP_ROLLBACK:
switch (val->var.subs[sub - 1]) {
@ -239,7 +242,7 @@ op_begemot_bridge_config(struct snmp_context *ctx, struct snmp_value *val,
return (SNMP_ERR_NOERROR);
}
return (SNMP_ERR_NOERROR);
abort();
}
/*

View File

@ -285,10 +285,6 @@ bridge_set_priority(struct bridge_if *bif, int32_t priority)
struct ifdrv ifd;
struct ifbrparam b_param;
/* Sanity check. */
if (priority > SNMP_BRIDGE_MAX_PRIORITY || priority % 4096 != 0)
return (-1);
strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ);
ifd.ifd_len = sizeof(b_param);
ifd.ifd_data = &b_param;
@ -332,10 +328,6 @@ bridge_set_maxage(struct bridge_if *bif, int32_t max_age)
struct ifdrv ifd;
struct ifbrparam b_param;
if (max_age < SNMP_BRIDGE_MIN_MAGE ||
max_age > SNMP_BRIDGE_MAX_MAGE)
return (-2);
strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ);
ifd.ifd_len = sizeof(b_param);
ifd.ifd_data = &b_param;
@ -358,10 +350,6 @@ bridge_set_hello_time(struct bridge_if *bif, int32_t hello_time)
struct ifdrv ifd;
struct ifbrparam b_param;
if (hello_time < SNMP_BRIDGE_MIN_HTIME ||
hello_time > SNMP_BRIDGE_MAX_HTIME)
return (-2);
strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ);
ifd.ifd_len = sizeof(b_param);
ifd.ifd_data = &b_param;
@ -384,10 +372,6 @@ bridge_set_forward_delay(struct bridge_if *bif, int32_t fwd_delay)
struct ifdrv ifd;
struct ifbrparam b_param;
if (fwd_delay < SNMP_BRIDGE_MIN_FDELAY ||
fwd_delay > SNMP_BRIDGE_MAX_FDELAY)
return (-2);
strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ);
ifd.ifd_len = sizeof(b_param);
ifd.ifd_data = &b_param;
@ -410,11 +394,6 @@ bridge_set_aging_time(struct bridge_if *bif, int32_t age_time)
struct ifdrv ifd;
struct ifbrparam b_param;
/* Sanity check. */
if (age_time < SNMP_BRIDGE_MIN_AGE_TIME ||
age_time > SNMP_BRIDGE_MAX_AGE_TIME)
return (-1);
strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ);
ifd.ifd_len = sizeof(b_param);
ifd.ifd_data = &b_param;
@ -491,10 +470,6 @@ bridge_set_stp_version(struct bridge_if *bif __unused,
struct ifdrv ifd;
struct ifbrparam b_param;
if (stp_proto != dot1dStpVersion_stpCompatible &&
stp_proto != dot1dStpVersion_rstp)
return (-2);
strlcpy(ifd.ifd_name, bif->bif_name, IFNAMSIZ);
ifd.ifd_len = sizeof(b_param);
ifd.ifd_data = &b_param;
@ -777,9 +752,6 @@ bridge_port_set_priority(const char *bif_name, struct bridge_port *bp,
struct ifdrv ifd;
struct ifbreq b_req;
if (priority < 0 || priority > 255)
return (-2);
strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name));
ifd.ifd_len = sizeof(b_req);
ifd.ifd_data = &b_req;
@ -811,10 +783,6 @@ bridge_port_set_stp_enable(const char *bif_name, struct bridge_port *bp,
if (bp->enable == enable)
return (0);
if (enable != dot1dStpPortEnable_enabled &&
enable != dot1dStpPortEnable_disabled)
return (-2);
bzero(&b_req, sizeof(b_req));
strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name));
ifd.ifd_len = sizeof(b_req);
@ -854,11 +822,7 @@ bridge_port_set_path_cost(const char *bif_name, struct bridge_port *bp,
struct ifdrv ifd;
struct ifbreq b_req;
#if __FreeBSD_version > 700024
if (path_cost < SNMP_PORT_MIN_PATHCOST ||
path_cost > SNMP_PORT_MAX_PATHCOST)
return (-2);
#else
#if __FreeBSD_version < 700025
if (path_cost < SNMP_PORT_MIN_PATHCOST ||
path_cost > SNMP_PORT_PATHCOST_OBSOLETE)
return (-2);
@ -901,9 +865,6 @@ bridge_port_set_admin_p2p(const char *bif_name __unused,
if (bp->admin_p2p == admin_p2p)
return (0);
if (admin_p2p > StpPortAdminPointToPointType_auto)
return (-2);
bzero(&b_req, sizeof(b_req));
strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name));
ifd.ifd_len = sizeof(b_req);
@ -959,9 +920,6 @@ bridge_port_set_admin_edge(const char *bif_name __unused,
if (bp->admin_edge == enable)
return (0);
if (enable != TruthValue_true && enable != TruthValue_false)
return (-2);
bzero(&b_req, sizeof(b_req));
strlcpy(ifd.ifd_name, bif_name, sizeof(ifd.ifd_name));
ifd.ifd_len = sizeof(b_req);