コード例 #1
0
/*
 * Port table
 */
int
op_snmp_port(struct snmp_context *ctx, struct snmp_value *value,
    u_int sub, u_int iidx, enum snmp_op op)
{
	asn_subid_t which = value->var.subs[sub-1];
	struct udp_port *p;
	u_int8_t addr[4];
	u_int32_t port;

	switch (op) {

	  case SNMP_OP_GETNEXT:
		if ((p = (struct udp_port *)trans_next_port(my_trans,
		    &value->var, sub)) == NULL)
			return (SNMP_ERR_NOSUCHNAME);
		index_append(&value->var, sub, &p->tport.index);
		break;

	  case SNMP_OP_GET:
		if ((p = (struct udp_port *)trans_find_port(my_trans,
		    &value->var, sub)) == NULL)
			return (SNMP_ERR_NOSUCHNAME);
		break;

	  case SNMP_OP_SET:
		p = (struct udp_port *)trans_find_port(my_trans,
		    &value->var, sub);
		ctx->scratch->int1 = (p != NULL);

		if (which != LEAF_begemotSnmpdPortStatus)
			abort();
		if (!TRUTH_OK(value->v.integer))
			return (SNMP_ERR_WRONG_VALUE);

		ctx->scratch->int2 = TRUTH_GET(value->v.integer);

		if (ctx->scratch->int2) {
			/* open an SNMP port */
			if (p != NULL)
				/* already open - do nothing */
				return (SNMP_ERR_NOERROR);

			if (index_decode(&value->var, sub, iidx, addr, &port))
				return (SNMP_ERR_NO_CREATION);
			return (udp_open_port(addr, port, &p));

		} else {
			/* close SNMP port - do in commit */
		}
		return (SNMP_ERR_NOERROR);

	  case SNMP_OP_ROLLBACK:
		p = (struct udp_port *)trans_find_port(my_trans,
		    &value->var, sub);
		if (ctx->scratch->int1 == 0) {
			/* did not exist */
			if (ctx->scratch->int2 == 1) {
				/* created */
				if (p != NULL)
					udp_close_port(&p->tport);
			}
		}
		return (SNMP_ERR_NOERROR);

	  case SNMP_OP_COMMIT:
		p = (struct udp_port *)trans_find_port(my_trans,
		    &value->var, sub);
		if (ctx->scratch->int1 == 1) {
			/* did exist */
			if (ctx->scratch->int2 == 0) {
				/* delete */
				if (p != NULL)
					udp_close_port(&p->tport);
			}
		}
		return (SNMP_ERR_NOERROR);

	  default:
		abort();
	}

	/*
	 * Come here to fetch the value
	 */
	switch (which) {

	  case LEAF_begemotSnmpdPortStatus:
		value->v.integer = 1;
		break;

	  default:
		abort();
	}

	return (SNMP_ERR_NOERROR);
}
コード例 #2
0
ファイル: action.c プロジェクト: 2trill2spill/freebsd
/*************************************************************
 *
 * Debug group
 */
int
op_debug(struct snmp_context *ctx, struct snmp_value *value, u_int sub,
    u_int iidx __unused, enum snmp_op op)
{
	asn_subid_t which = value->var.subs[sub - 1];

	switch (op) {

	  case SNMP_OP_GETNEXT:
		abort();

	  case SNMP_OP_GET:
		switch (which) {

		  case LEAF_begemotSnmpdDebugDumpPdus:
			value->v.integer = TRUTH_MK(debug.dump_pdus);
			break;

		  case LEAF_begemotSnmpdDebugSnmpTrace:
			value->v.uint32 = snmp_trace;
			break;

		  case LEAF_begemotSnmpdDebugSyslogPri:
			value->v.integer = debug.logpri;
			break;
		}
		return (SNMP_ERR_NOERROR);

	  case SNMP_OP_SET:
		switch (which) {

		  case LEAF_begemotSnmpdDebugDumpPdus:
			if (!TRUTH_OK(value->v.integer))
				return (SNMP_ERR_WRONG_VALUE);
			ctx->scratch->int1 = debug.dump_pdus;
			debug.dump_pdus = TRUTH_GET(value->v.integer);
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotSnmpdDebugSnmpTrace:
			ctx->scratch->int1 = snmp_trace;
			snmp_trace = value->v.uint32;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotSnmpdDebugSyslogPri:
			if (value->v.integer < 0 || value->v.integer > 8)
				return (SNMP_ERR_WRONG_VALUE);
			ctx->scratch->int1 = debug.logpri;
			debug.logpri = (u_int)value->v.integer;
			return (SNMP_ERR_NOERROR);
		}
		return (SNMP_ERR_NO_CREATION);

	  case SNMP_OP_ROLLBACK:
		switch (which) {

		  case LEAF_begemotSnmpdDebugDumpPdus:
			debug.dump_pdus = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotSnmpdDebugSnmpTrace:
			snmp_trace = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotSnmpdDebugSyslogPri:
			debug.logpri = ctx->scratch->int1;
			return (SNMP_ERR_NOERROR);
		}
		abort();

	  case SNMP_OP_COMMIT:
		switch (which) {

		  case LEAF_begemotSnmpdDebugDumpPdus:
		  case LEAF_begemotSnmpdDebugSnmpTrace:
			return (SNMP_ERR_NOERROR);

		  case LEAF_begemotSnmpdDebugSyslogPri:
			if (debug.logpri == 0)
				setlogmask(0);
			else
				setlogmask(LOG_UPTO(debug.logpri - 1));
			return (SNMP_ERR_NOERROR);
		}
		abort();
	}
	abort();
}