snmpagent.h revision 124861
1/* 2 * Copyright (c) 2001-2003 3 * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4 * All rights reserved. 5 * 6 * Author: Harti Brandt <harti@freebsd.org> 7 * 8 * Redistribution of this software and documentation and use in source and 9 * binary forms, with or without modification, are permitted provided that 10 * the following conditions are met: 11 * 12 * 1. Redistributions of source code or documentation must retain the above 13 * copyright notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of the Institute nor the names of its contributors 18 * may be used to endorse or promote products derived from this software 19 * without specific prior written permission. 20 * 21 * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY FRAUNHOFER FOKUS 22 * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 23 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND 24 * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 25 * FRAUNHOFER FOKUS OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 31 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 * $Begemot: bsnmp/lib/snmpagent.h,v 1.10 2003/12/03 09:55:58 hbb Exp $ 34 * 35 * Header file for SNMP functions. This requires snmp.h to be included. 36 */ 37#ifndef snmp_agent_h_ 38#define snmp_agent_h_ 39 40struct snmp_dependency; 41 42/* Semi-Opaque object for SET operations */ 43struct snmp_context { 44 u_int var_index; 45 struct snmp_scratch *scratch; 46 struct snmp_dependency *dep; 47 void *data; /* user data */ 48}; 49 50struct snmp_scratch { 51 void *ptr1; 52 void *ptr2; 53 u_int32_t int1; 54 u_int32_t int2; 55}; 56 57enum snmp_depop { 58 SNMP_DEPOP_COMMIT, 59 SNMP_DEPOP_ROLLBACK 60}; 61 62typedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *, 63 enum snmp_depop); 64 65struct snmp_dependency { 66 struct asn_oid obj; 67 struct asn_oid idx; 68}; 69 70/* 71 * Functions to be called at the end of a SET operation. 72 */ 73typedef void (*snmp_set_finish_t)(struct snmp_context *, int fail, void *); 74 75/* 76 * The TREE 77 */ 78enum snmp_node_type { 79 SNMP_NODE_LEAF = 1, 80 SNMP_NODE_COLUMN 81}; 82 83enum snmp_op { 84 SNMP_OP_GET = 1, 85 SNMP_OP_GETNEXT, 86 SNMP_OP_SET, 87 SNMP_OP_COMMIT, 88 SNMP_OP_ROLLBACK, 89}; 90 91enum snmp_ret { 92 /* OK, generate a response */ 93 SNMP_RET_OK = 0, 94 /* Error, ignore packet (no response) */ 95 SNMP_RET_IGN = 1, 96 /* Error, generate response from original packet */ 97 SNMP_RET_ERR = 2 98}; 99 100typedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *, 101 u_int, u_int, enum snmp_op); 102 103struct snmp_node { 104 struct asn_oid oid; 105 const char *name; /* name of the leaf */ 106 enum snmp_node_type type; /* type of this node */ 107 enum snmp_syntax syntax; 108 snmp_op_t op; 109 u_int flags; 110 u_int32_t index; /* index data */ 111 void *data; /* application data */ 112}; 113extern struct snmp_node *tree; 114extern u_int tree_size; 115 116#define SNMP_NODE_CANSET 0x0001 /* SET allowed */ 117 118#define SNMP_INDEXES_MAX 7 119#define SNMP_INDEX_SHIFT 4 120#define SNMP_INDEX_MASK 0xf 121#define SNMP_INDEX_COUNT(V) ((V) & SNMP_INDEX_MASK) 122#define SNMP_INDEX(V,I) \ 123 (((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK) 124 125enum { 126 SNMP_TRACE_GET = 0x00000001, 127 SNMP_TRACE_GETNEXT = 0x00000002, 128 SNMP_TRACE_SET = 0x00000004, 129 SNMP_TRACE_DEPEND = 0x00000008, 130 SNMP_TRACE_FIND = 0x00000010, 131}; 132/* trace flag for the following functions */ 133extern u_int snmp_trace; 134 135/* called to write the trace */ 136extern void (*snmp_debug)(const char *fmt, ...); 137 138enum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 139 struct snmp_pdu *resp, void *); 140enum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b, 141 struct snmp_pdu *resp, void *); 142enum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b, 143 struct snmp_pdu *resp, void *); 144enum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b, 145 struct snmp_pdu *resp, void *); 146 147enum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *, 148 struct asn_buf *); 149 150struct snmp_dependency *snmp_dep_lookup(struct snmp_context *, 151 const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t); 152 153int snmp_set_atfinish(struct snmp_context *, snmp_set_finish_t func, void *arg); 154 155struct snmp_context *snmp_init_context(void); 156int snmp_dep_commit(struct snmp_context *); 157int snmp_dep_rollback(struct snmp_context *); 158 159#endif 160