1f06ca4afSHartmut Brandt /*
2f06ca4afSHartmut Brandt * Copyright (c) 2001-2003
3f06ca4afSHartmut Brandt * Fraunhofer Institute for Open Communication Systems (FhG Fokus).
4f06ca4afSHartmut Brandt * All rights reserved.
5f06ca4afSHartmut Brandt *
6f06ca4afSHartmut Brandt * Author: Harti Brandt <harti@freebsd.org>
7f06ca4afSHartmut Brandt *
8896052c1SHartmut Brandt * Redistribution and use in source and binary forms, with or without
9896052c1SHartmut Brandt * modification, are permitted provided that the following conditions
10896052c1SHartmut Brandt * are met:
11896052c1SHartmut Brandt * 1. Redistributions of source code must retain the above copyright
12896052c1SHartmut Brandt * notice, this list of conditions and the following disclaimer.
13f06ca4afSHartmut Brandt * 2. Redistributions in binary form must reproduce the above copyright
14f06ca4afSHartmut Brandt * notice, this list of conditions and the following disclaimer in the
15f06ca4afSHartmut Brandt * documentation and/or other materials provided with the distribution.
16f06ca4afSHartmut Brandt *
17896052c1SHartmut Brandt * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18896052c1SHartmut Brandt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19896052c1SHartmut Brandt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20896052c1SHartmut Brandt * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21896052c1SHartmut Brandt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22896052c1SHartmut Brandt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23896052c1SHartmut Brandt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24896052c1SHartmut Brandt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25896052c1SHartmut Brandt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26896052c1SHartmut Brandt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27896052c1SHartmut Brandt * SUCH DAMAGE.
28f06ca4afSHartmut Brandt *
29896052c1SHartmut Brandt * $Begemot: bsnmp/snmp_mibII/mibII_ifstack.c,v 1.7 2004/08/06 08:47:00 brandt Exp $
30f06ca4afSHartmut Brandt *
31f06ca4afSHartmut Brandt * ifStackTable. Read-only.
32f06ca4afSHartmut Brandt */
33f06ca4afSHartmut Brandt #include "mibII.h"
34f06ca4afSHartmut Brandt
35f06ca4afSHartmut Brandt int
mib_ifstack_create(const struct mibif * lower,const struct mibif * upper)36f06ca4afSHartmut Brandt mib_ifstack_create(const struct mibif *lower, const struct mibif *upper)
37f06ca4afSHartmut Brandt {
38f06ca4afSHartmut Brandt struct mibifstack *stack;
39f06ca4afSHartmut Brandt
40f06ca4afSHartmut Brandt if ((stack = malloc(sizeof(*stack))) == NULL)
41f06ca4afSHartmut Brandt return (-1);
42f06ca4afSHartmut Brandt
43f06ca4afSHartmut Brandt stack->index.len = 2;
44f06ca4afSHartmut Brandt stack->index.subs[0] = upper ? upper->index : 0;
45f06ca4afSHartmut Brandt stack->index.subs[1] = lower ? lower->index : 0;
46f06ca4afSHartmut Brandt
47f06ca4afSHartmut Brandt INSERT_OBJECT_OID(stack, &mibifstack_list);
48f06ca4afSHartmut Brandt
49f06ca4afSHartmut Brandt mib_ifstack_last_change = get_ticks();
50f06ca4afSHartmut Brandt
51f06ca4afSHartmut Brandt return (0);
52f06ca4afSHartmut Brandt }
53f06ca4afSHartmut Brandt
54f06ca4afSHartmut Brandt void
mib_ifstack_delete(const struct mibif * lower,const struct mibif * upper)55f06ca4afSHartmut Brandt mib_ifstack_delete(const struct mibif *lower, const struct mibif *upper)
56f06ca4afSHartmut Brandt {
57f06ca4afSHartmut Brandt struct mibifstack *stack;
58f06ca4afSHartmut Brandt
59f06ca4afSHartmut Brandt TAILQ_FOREACH(stack, &mibifstack_list, link)
60f06ca4afSHartmut Brandt if (stack->index.subs[0] == (upper ? upper->index : 0) &&
61f06ca4afSHartmut Brandt stack->index.subs[1] == (lower ? lower->index : 0)) {
62f06ca4afSHartmut Brandt TAILQ_REMOVE(&mibifstack_list, stack, link);
63f06ca4afSHartmut Brandt free(stack);
64f06ca4afSHartmut Brandt mib_ifstack_last_change = get_ticks();
65f06ca4afSHartmut Brandt return;
66f06ca4afSHartmut Brandt }
67f06ca4afSHartmut Brandt }
68f06ca4afSHartmut Brandt
69f06ca4afSHartmut Brandt int
op_ifstack(struct snmp_context * ctx __unused,struct snmp_value * value,u_int sub,u_int iidx __unused,enum snmp_op op)70f06ca4afSHartmut Brandt op_ifstack(struct snmp_context *ctx __unused, struct snmp_value *value,
71f06ca4afSHartmut Brandt u_int sub, u_int iidx __unused, enum snmp_op op)
72f06ca4afSHartmut Brandt {
73f06ca4afSHartmut Brandt struct mibifstack *stack;
74f06ca4afSHartmut Brandt
75f06ca4afSHartmut Brandt switch (op) {
76f06ca4afSHartmut Brandt
77f06ca4afSHartmut Brandt case SNMP_OP_GETNEXT:
78f06ca4afSHartmut Brandt if ((stack = NEXT_OBJECT_OID(&mibifstack_list, &value->var, sub)) == NULL)
79f06ca4afSHartmut Brandt return (SNMP_ERR_NOSUCHNAME);
80f06ca4afSHartmut Brandt index_append(&value->var, sub, &stack->index);
81f06ca4afSHartmut Brandt break;
82f06ca4afSHartmut Brandt
83f06ca4afSHartmut Brandt case SNMP_OP_GET:
84f06ca4afSHartmut Brandt if ((stack = FIND_OBJECT_OID(&mibifstack_list, &value->var, sub)) == NULL)
85f06ca4afSHartmut Brandt return (SNMP_ERR_NOSUCHNAME);
86f06ca4afSHartmut Brandt break;
87f06ca4afSHartmut Brandt
88f06ca4afSHartmut Brandt case SNMP_OP_SET:
89f06ca4afSHartmut Brandt if ((stack = FIND_OBJECT_OID(&mibifstack_list, &value->var, sub)) == NULL)
90f06ca4afSHartmut Brandt return (SNMP_ERR_NO_CREATION);
91f06ca4afSHartmut Brandt return (SNMP_ERR_NOT_WRITEABLE);
92f06ca4afSHartmut Brandt
93f06ca4afSHartmut Brandt case SNMP_OP_ROLLBACK:
94f06ca4afSHartmut Brandt case SNMP_OP_COMMIT:
95f06ca4afSHartmut Brandt abort();
96f06ca4afSHartmut Brandt }
97f06ca4afSHartmut Brandt
98f06ca4afSHartmut Brandt switch (value->var.subs[sub - 1]) {
99f06ca4afSHartmut Brandt
100f06ca4afSHartmut Brandt case LEAF_ifStackStatus:
101f06ca4afSHartmut Brandt value->v.integer = 1;
102f06ca4afSHartmut Brandt break;
103f06ca4afSHartmut Brandt }
104f06ca4afSHartmut Brandt return (SNMP_ERR_NOERROR);
105f06ca4afSHartmut Brandt }
106