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.12 2004/04/13 15:18:15 novo 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 40 struct snmp_dependency; 41 42 enum snmp_ret { 43 /* OK, generate a response */ 44 SNMP_RET_OK = 0, 45 /* Error, ignore packet (no response) */ 46 SNMP_RET_IGN = 1, 47 /* Error, generate response from original packet */ 48 SNMP_RET_ERR = 2 49 }; 50 51 /* Semi-Opaque object for SET operations */ 52 struct snmp_context { 53 u_int var_index; 54 struct snmp_scratch *scratch; 55 struct snmp_dependency *dep; 56 void *data; /* user data */ 57 enum snmp_ret code; /* return code */ 58 }; 59 60 struct snmp_scratch { 61 void *ptr1; 62 void *ptr2; 63 u_int32_t int1; 64 u_int32_t int2; 65 }; 66 67 enum snmp_depop { 68 SNMP_DEPOP_COMMIT, 69 SNMP_DEPOP_ROLLBACK, 70 SNMP_DEPOP_FINISH 71 }; 72 73 typedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *, 74 enum snmp_depop); 75 76 struct snmp_dependency { 77 struct asn_oid obj; 78 struct asn_oid idx; 79 }; 80 81 /* 82 * The TREE 83 */ 84 enum snmp_node_type { 85 SNMP_NODE_LEAF = 1, 86 SNMP_NODE_COLUMN 87 }; 88 89 enum snmp_op { 90 SNMP_OP_GET = 1, 91 SNMP_OP_GETNEXT, 92 SNMP_OP_SET, 93 SNMP_OP_COMMIT, 94 SNMP_OP_ROLLBACK, 95 }; 96 97 typedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *, 98 u_int, u_int, enum snmp_op); 99 100 struct snmp_node { 101 struct asn_oid oid; 102 const char *name; /* name of the leaf */ 103 enum snmp_node_type type; /* type of this node */ 104 enum snmp_syntax syntax; 105 snmp_op_t op; 106 u_int flags; 107 u_int32_t index; /* index data */ 108 void *data; /* application data */ 109 void *tree_data; /* application data */ 110 }; 111 extern struct snmp_node *tree; 112 extern u_int tree_size; 113 114 #define SNMP_NODE_CANSET 0x0001 /* SET allowed */ 115 116 #define SNMP_INDEXES_MAX 7 117 #define SNMP_INDEX_SHIFT 4 118 #define SNMP_INDEX_MASK 0xf 119 #define SNMP_INDEX_COUNT(V) ((V) & SNMP_INDEX_MASK) 120 #define SNMP_INDEX(V,I) \ 121 (((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK) 122 123 enum { 124 SNMP_TRACE_GET = 0x00000001, 125 SNMP_TRACE_GETNEXT = 0x00000002, 126 SNMP_TRACE_SET = 0x00000004, 127 SNMP_TRACE_DEPEND = 0x00000008, 128 SNMP_TRACE_FIND = 0x00000010, 129 }; 130 /* trace flag for the following functions */ 131 extern u_int snmp_trace; 132 133 /* called to write the trace */ 134 extern void (*snmp_debug)(const char *fmt, ...); 135 136 enum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 137 struct snmp_pdu *resp, void *); 138 enum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b, 139 struct snmp_pdu *resp, void *); 140 enum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b, 141 struct snmp_pdu *resp, void *); 142 enum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b, 143 struct snmp_pdu *resp, void *); 144 145 enum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *, 146 struct asn_buf *); 147 148 struct snmp_dependency *snmp_dep_lookup(struct snmp_context *, 149 const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t); 150 151 struct snmp_context *snmp_init_context(void); 152 int snmp_dep_commit(struct snmp_context *); 153 int snmp_dep_rollback(struct snmp_context *); 154 void snmp_dep_finish(struct snmp_context *); 155 156 #endif 157