Path: blob/main/contrib/bsnmp/snmp_mibII/mibII_ifstack.c
39478 views
/*1* Copyright (c) 2001-20032* Fraunhofer Institute for Open Communication Systems (FhG Fokus).3* All rights reserved.4*5* Author: Harti Brandt <[email protected]>6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15*16* THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND17* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE18* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE19* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE20* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL21* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS22* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)23* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT24* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY25* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF26* SUCH DAMAGE.27*28* $Begemot: bsnmp/snmp_mibII/mibII_ifstack.c,v 1.7 2004/08/06 08:47:00 brandt Exp $29*30* ifStackTable. Read-only.31*/32#include "mibII.h"3334int35mib_ifstack_create(const struct mibif *lower, const struct mibif *upper)36{37struct mibifstack *stack;3839if ((stack = malloc(sizeof(*stack))) == NULL)40return (-1);4142stack->index.len = 2;43stack->index.subs[0] = upper ? upper->index : 0;44stack->index.subs[1] = lower ? lower->index : 0;4546INSERT_OBJECT_OID(stack, &mibifstack_list);4748mib_ifstack_last_change = get_ticks();4950return (0);51}5253void54mib_ifstack_delete(const struct mibif *lower, const struct mibif *upper)55{56struct mibifstack *stack;5758TAILQ_FOREACH(stack, &mibifstack_list, link)59if (stack->index.subs[0] == (upper ? upper->index : 0) &&60stack->index.subs[1] == (lower ? lower->index : 0)) {61TAILQ_REMOVE(&mibifstack_list, stack, link);62free(stack);63mib_ifstack_last_change = get_ticks();64return;65}66}6768int69op_ifstack(struct snmp_context *ctx __unused, struct snmp_value *value,70u_int sub, u_int iidx __unused, enum snmp_op op)71{72struct mibifstack *stack;7374switch (op) {7576case SNMP_OP_GETNEXT:77if ((stack = NEXT_OBJECT_OID(&mibifstack_list, &value->var, sub)) == NULL)78return (SNMP_ERR_NOSUCHNAME);79index_append(&value->var, sub, &stack->index);80break;8182case SNMP_OP_GET:83if ((stack = FIND_OBJECT_OID(&mibifstack_list, &value->var, sub)) == NULL)84return (SNMP_ERR_NOSUCHNAME);85break;8687case SNMP_OP_SET:88if ((stack = FIND_OBJECT_OID(&mibifstack_list, &value->var, sub)) == NULL)89return (SNMP_ERR_NO_CREATION);90return (SNMP_ERR_NOT_WRITEABLE);9192case SNMP_OP_ROLLBACK:93case SNMP_OP_COMMIT:94abort();95}9697switch (value->var.subs[sub - 1]) {9899case LEAF_ifStackStatus:100value->v.integer = 1;101break;102}103return (SNMP_ERR_NOERROR);104}105106107