1122394Sharti/* 2122394Sharti * Copyright (c) 2001-2003 3122394Sharti * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4122394Sharti * All rights reserved. 5122394Sharti * 6122394Sharti * Author: Harti Brandt <harti@freebsd.org> 7133211Sharti * 8133211Sharti * Redistribution and use in source and binary forms, with or without 9133211Sharti * modification, are permitted provided that the following conditions 10133211Sharti * are met: 11133211Sharti * 1. Redistributions of source code must retain the above copyright 12133211Sharti * notice, this list of conditions and the following disclaimer. 13122394Sharti * 2. Redistributions in binary form must reproduce the above copyright 14122394Sharti * notice, this list of conditions and the following disclaimer in the 15122394Sharti * documentation and/or other materials provided with the distribution. 16133211Sharti * 17133211Sharti * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18133211Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19133211Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20133211Sharti * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21133211Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22133211Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23133211Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24133211Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25133211Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26133211Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27133211Sharti * SUCH DAMAGE. 28122394Sharti * 29133211Sharti * $Begemot: bsnmp/lib/snmpagent.h,v 1.13 2004/08/06 08:46:56 brandt Exp $ 30122394Sharti * 31122394Sharti * Header file for SNMP functions. This requires snmp.h to be included. 32122394Sharti */ 33122394Sharti#ifndef snmp_agent_h_ 34122394Sharti#define snmp_agent_h_ 35122394Sharti 36122394Shartistruct snmp_dependency; 37122394Sharti 38128237Shartienum snmp_ret { 39128237Sharti /* OK, generate a response */ 40128237Sharti SNMP_RET_OK = 0, 41128237Sharti /* Error, ignore packet (no response) */ 42128237Sharti SNMP_RET_IGN = 1, 43128237Sharti /* Error, generate response from original packet */ 44128237Sharti SNMP_RET_ERR = 2 45128237Sharti}; 46128237Sharti 47122394Sharti/* Semi-Opaque object for SET operations */ 48122394Shartistruct snmp_context { 49122394Sharti u_int var_index; 50122394Sharti struct snmp_scratch *scratch; 51122394Sharti struct snmp_dependency *dep; 52122394Sharti void *data; /* user data */ 53128237Sharti enum snmp_ret code; /* return code */ 54122394Sharti}; 55122394Sharti 56122394Shartistruct snmp_scratch { 57122394Sharti void *ptr1; 58122394Sharti void *ptr2; 59133211Sharti uint32_t int1; 60133211Sharti uint32_t int2; 61122394Sharti}; 62122394Sharti 63122394Shartienum snmp_depop { 64122394Sharti SNMP_DEPOP_COMMIT, 65128237Sharti SNMP_DEPOP_ROLLBACK, 66128237Sharti SNMP_DEPOP_FINISH 67122394Sharti}; 68122394Sharti 69122394Shartitypedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *, 70122394Sharti enum snmp_depop); 71122394Sharti 72122394Shartistruct snmp_dependency { 73122394Sharti struct asn_oid obj; 74122394Sharti struct asn_oid idx; 75122394Sharti}; 76122394Sharti 77122394Sharti/* 78122394Sharti * The TREE 79122394Sharti */ 80122394Shartienum snmp_node_type { 81122394Sharti SNMP_NODE_LEAF = 1, 82122394Sharti SNMP_NODE_COLUMN 83122394Sharti}; 84122394Sharti 85122394Shartienum snmp_op { 86122394Sharti SNMP_OP_GET = 1, 87122394Sharti SNMP_OP_GETNEXT, 88122394Sharti SNMP_OP_SET, 89122394Sharti SNMP_OP_COMMIT, 90122394Sharti SNMP_OP_ROLLBACK, 91122394Sharti}; 92122394Sharti 93122394Shartitypedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *, 94122394Sharti u_int, u_int, enum snmp_op); 95122394Sharti 96122394Shartistruct snmp_node { 97122394Sharti struct asn_oid oid; 98122394Sharti const char *name; /* name of the leaf */ 99122394Sharti enum snmp_node_type type; /* type of this node */ 100122394Sharti enum snmp_syntax syntax; 101122394Sharti snmp_op_t op; 102122394Sharti u_int flags; 103133211Sharti uint32_t index; /* index data */ 104122394Sharti void *data; /* application data */ 105128237Sharti void *tree_data; /* application data */ 106122394Sharti}; 107122394Shartiextern struct snmp_node *tree; 108122394Shartiextern u_int tree_size; 109122394Sharti 110122394Sharti#define SNMP_NODE_CANSET 0x0001 /* SET allowed */ 111122394Sharti 112122394Sharti#define SNMP_INDEXES_MAX 7 113122394Sharti#define SNMP_INDEX_SHIFT 4 114122394Sharti#define SNMP_INDEX_MASK 0xf 115122394Sharti#define SNMP_INDEX_COUNT(V) ((V) & SNMP_INDEX_MASK) 116122394Sharti#define SNMP_INDEX(V,I) \ 117122394Sharti (((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK) 118122394Sharti 119122394Shartienum { 120122394Sharti SNMP_TRACE_GET = 0x00000001, 121122394Sharti SNMP_TRACE_GETNEXT = 0x00000002, 122122394Sharti SNMP_TRACE_SET = 0x00000004, 123122394Sharti SNMP_TRACE_DEPEND = 0x00000008, 124122394Sharti SNMP_TRACE_FIND = 0x00000010, 125122394Sharti}; 126122394Sharti/* trace flag for the following functions */ 127122394Shartiextern u_int snmp_trace; 128122394Sharti 129122394Sharti/* called to write the trace */ 130122394Shartiextern void (*snmp_debug)(const char *fmt, ...); 131122394Sharti 132122394Shartienum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 133122394Sharti struct snmp_pdu *resp, void *); 134122394Shartienum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b, 135122394Sharti struct snmp_pdu *resp, void *); 136122394Shartienum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b, 137122394Sharti struct snmp_pdu *resp, void *); 138122394Shartienum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b, 139122394Sharti struct snmp_pdu *resp, void *); 140122394Sharti 141122394Shartienum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *, 142122394Sharti struct asn_buf *); 143122394Sharti 144122394Shartistruct snmp_dependency *snmp_dep_lookup(struct snmp_context *, 145122394Sharti const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t); 146122394Sharti 147122394Shartistruct snmp_context *snmp_init_context(void); 148122394Shartiint snmp_dep_commit(struct snmp_context *); 149122394Shartiint snmp_dep_rollback(struct snmp_context *); 150128237Shartivoid snmp_dep_finish(struct snmp_context *); 151122394Sharti 152122394Sharti#endif 153