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/lib/snmpagent.h,v 1.13 2004/08/06 08:46:56 brandt Exp $ 30f06ca4afSHartmut Brandt * 31f06ca4afSHartmut Brandt * Header file for SNMP functions. This requires snmp.h to be included. 32f06ca4afSHartmut Brandt */ 33f06ca4afSHartmut Brandt #ifndef snmp_agent_h_ 34f06ca4afSHartmut Brandt #define snmp_agent_h_ 35f06ca4afSHartmut Brandt 36f06ca4afSHartmut Brandt struct snmp_dependency; 37f06ca4afSHartmut Brandt 388eecd77aSHartmut Brandt enum snmp_ret { 398eecd77aSHartmut Brandt /* OK, generate a response */ 408eecd77aSHartmut Brandt SNMP_RET_OK = 0, 418eecd77aSHartmut Brandt /* Error, ignore packet (no response) */ 428eecd77aSHartmut Brandt SNMP_RET_IGN = 1, 438eecd77aSHartmut Brandt /* Error, generate response from original packet */ 448eecd77aSHartmut Brandt SNMP_RET_ERR = 2 458eecd77aSHartmut Brandt }; 468eecd77aSHartmut Brandt 47f06ca4afSHartmut Brandt /* Semi-Opaque object for SET operations */ 48f06ca4afSHartmut Brandt struct snmp_context { 49f06ca4afSHartmut Brandt u_int var_index; 50f06ca4afSHartmut Brandt struct snmp_scratch *scratch; 51f06ca4afSHartmut Brandt struct snmp_dependency *dep; 52f06ca4afSHartmut Brandt void *data; /* user data */ 538eecd77aSHartmut Brandt enum snmp_ret code; /* return code */ 54f06ca4afSHartmut Brandt }; 55f06ca4afSHartmut Brandt 56f06ca4afSHartmut Brandt struct snmp_scratch { 57f06ca4afSHartmut Brandt void *ptr1; 58f06ca4afSHartmut Brandt void *ptr2; 59896052c1SHartmut Brandt uint32_t int1; 60896052c1SHartmut Brandt uint32_t int2; 61f06ca4afSHartmut Brandt }; 62f06ca4afSHartmut Brandt 63f06ca4afSHartmut Brandt enum snmp_depop { 64f06ca4afSHartmut Brandt SNMP_DEPOP_COMMIT, 658eecd77aSHartmut Brandt SNMP_DEPOP_ROLLBACK, 668eecd77aSHartmut Brandt SNMP_DEPOP_FINISH 67f06ca4afSHartmut Brandt }; 68f06ca4afSHartmut Brandt 69f06ca4afSHartmut Brandt typedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *, 70f06ca4afSHartmut Brandt enum snmp_depop); 71f06ca4afSHartmut Brandt 72f06ca4afSHartmut Brandt struct snmp_dependency { 73f06ca4afSHartmut Brandt struct asn_oid obj; 74f06ca4afSHartmut Brandt struct asn_oid idx; 75f06ca4afSHartmut Brandt }; 76f06ca4afSHartmut Brandt 77f06ca4afSHartmut Brandt /* 78f06ca4afSHartmut Brandt * The TREE 79f06ca4afSHartmut Brandt */ 80f06ca4afSHartmut Brandt enum snmp_node_type { 81f06ca4afSHartmut Brandt SNMP_NODE_LEAF = 1, 82f06ca4afSHartmut Brandt SNMP_NODE_COLUMN 83f06ca4afSHartmut Brandt }; 84f06ca4afSHartmut Brandt 85f06ca4afSHartmut Brandt enum snmp_op { 86f06ca4afSHartmut Brandt SNMP_OP_GET = 1, 87f06ca4afSHartmut Brandt SNMP_OP_GETNEXT, 88f06ca4afSHartmut Brandt SNMP_OP_SET, 89f06ca4afSHartmut Brandt SNMP_OP_COMMIT, 90f06ca4afSHartmut Brandt SNMP_OP_ROLLBACK, 91f06ca4afSHartmut Brandt }; 92f06ca4afSHartmut Brandt 93f06ca4afSHartmut Brandt typedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *, 94f06ca4afSHartmut Brandt u_int, u_int, enum snmp_op); 95f06ca4afSHartmut Brandt 96f06ca4afSHartmut Brandt struct snmp_node { 97f06ca4afSHartmut Brandt struct asn_oid oid; 98f06ca4afSHartmut Brandt const char *name; /* name of the leaf */ 99f06ca4afSHartmut Brandt enum snmp_node_type type; /* type of this node */ 100f06ca4afSHartmut Brandt enum snmp_syntax syntax; 101f06ca4afSHartmut Brandt snmp_op_t op; 102f06ca4afSHartmut Brandt u_int flags; 103896052c1SHartmut Brandt uint32_t index; /* index data */ 104f06ca4afSHartmut Brandt void *data; /* application data */ 1058eecd77aSHartmut Brandt void *tree_data; /* application data */ 106f06ca4afSHartmut Brandt }; 107f06ca4afSHartmut Brandt extern struct snmp_node *tree; 108f06ca4afSHartmut Brandt extern u_int tree_size; 109f06ca4afSHartmut Brandt 110f06ca4afSHartmut Brandt #define SNMP_NODE_CANSET 0x0001 /* SET allowed */ 111f06ca4afSHartmut Brandt 112f06ca4afSHartmut Brandt #define SNMP_INDEXES_MAX 7 113f06ca4afSHartmut Brandt #define SNMP_INDEX_SHIFT 4 114f06ca4afSHartmut Brandt #define SNMP_INDEX_MASK 0xf 115f06ca4afSHartmut Brandt #define SNMP_INDEX_COUNT(V) ((V) & SNMP_INDEX_MASK) 116f06ca4afSHartmut Brandt #define SNMP_INDEX(V,I) \ 117f06ca4afSHartmut Brandt (((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK) 118f06ca4afSHartmut Brandt 119f06ca4afSHartmut Brandt enum { 120f06ca4afSHartmut Brandt SNMP_TRACE_GET = 0x00000001, 121f06ca4afSHartmut Brandt SNMP_TRACE_GETNEXT = 0x00000002, 122f06ca4afSHartmut Brandt SNMP_TRACE_SET = 0x00000004, 123f06ca4afSHartmut Brandt SNMP_TRACE_DEPEND = 0x00000008, 124f06ca4afSHartmut Brandt SNMP_TRACE_FIND = 0x00000010, 125f06ca4afSHartmut Brandt }; 126f06ca4afSHartmut Brandt /* trace flag for the following functions */ 127f06ca4afSHartmut Brandt extern u_int snmp_trace; 128f06ca4afSHartmut Brandt 129f06ca4afSHartmut Brandt /* called to write the trace */ 130f06ca4afSHartmut Brandt extern void (*snmp_debug)(const char *fmt, ...); 131f06ca4afSHartmut Brandt 132f06ca4afSHartmut Brandt enum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b, 133f06ca4afSHartmut Brandt struct snmp_pdu *resp, void *); 134f06ca4afSHartmut Brandt enum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b, 135f06ca4afSHartmut Brandt struct snmp_pdu *resp, void *); 136f06ca4afSHartmut Brandt enum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b, 137f06ca4afSHartmut Brandt struct snmp_pdu *resp, void *); 138f06ca4afSHartmut Brandt enum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b, 139f06ca4afSHartmut Brandt struct snmp_pdu *resp, void *); 140f06ca4afSHartmut Brandt 141f06ca4afSHartmut Brandt enum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *, 142f06ca4afSHartmut Brandt struct asn_buf *); 143f06ca4afSHartmut Brandt 144f06ca4afSHartmut Brandt struct snmp_dependency *snmp_dep_lookup(struct snmp_context *, 145f06ca4afSHartmut Brandt const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t); 146f06ca4afSHartmut Brandt 147f06ca4afSHartmut Brandt struct snmp_context *snmp_init_context(void); 148f06ca4afSHartmut Brandt int snmp_dep_commit(struct snmp_context *); 149f06ca4afSHartmut Brandt int snmp_dep_rollback(struct snmp_context *); 1508eecd77aSHartmut Brandt void snmp_dep_finish(struct snmp_context *); 151f06ca4afSHartmut Brandt 152f06ca4afSHartmut Brandt #endif 153