/contrib/bsnmp/lib/snmpagent.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 152 lines · 91 code · 20 blank · 41 comment · 0 complexity · b7974aa4a2b21957baecd0d90a8ecf53 MD5 · raw file

  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 and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * $Begemot: bsnmp/lib/snmpagent.h,v 1.13 2004/08/06 08:46:56 brandt Exp $
  30. *
  31. * Header file for SNMP functions. This requires snmp.h to be included.
  32. */
  33. #ifndef snmp_agent_h_
  34. #define snmp_agent_h_
  35. struct snmp_dependency;
  36. enum snmp_ret {
  37. /* OK, generate a response */
  38. SNMP_RET_OK = 0,
  39. /* Error, ignore packet (no response) */
  40. SNMP_RET_IGN = 1,
  41. /* Error, generate response from original packet */
  42. SNMP_RET_ERR = 2
  43. };
  44. /* Semi-Opaque object for SET operations */
  45. struct snmp_context {
  46. u_int var_index;
  47. struct snmp_scratch *scratch;
  48. struct snmp_dependency *dep;
  49. void *data; /* user data */
  50. enum snmp_ret code; /* return code */
  51. };
  52. struct snmp_scratch {
  53. void *ptr1;
  54. void *ptr2;
  55. uint32_t int1;
  56. uint32_t int2;
  57. };
  58. enum snmp_depop {
  59. SNMP_DEPOP_COMMIT,
  60. SNMP_DEPOP_ROLLBACK,
  61. SNMP_DEPOP_FINISH
  62. };
  63. typedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *,
  64. enum snmp_depop);
  65. struct snmp_dependency {
  66. struct asn_oid obj;
  67. struct asn_oid idx;
  68. };
  69. /*
  70. * The TREE
  71. */
  72. enum snmp_node_type {
  73. SNMP_NODE_LEAF = 1,
  74. SNMP_NODE_COLUMN
  75. };
  76. enum snmp_op {
  77. SNMP_OP_GET = 1,
  78. SNMP_OP_GETNEXT,
  79. SNMP_OP_SET,
  80. SNMP_OP_COMMIT,
  81. SNMP_OP_ROLLBACK,
  82. };
  83. typedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *,
  84. u_int, u_int, enum snmp_op);
  85. struct snmp_node {
  86. struct asn_oid oid;
  87. const char *name; /* name of the leaf */
  88. enum snmp_node_type type; /* type of this node */
  89. enum snmp_syntax syntax;
  90. snmp_op_t op;
  91. u_int flags;
  92. uint32_t index; /* index data */
  93. void *data; /* application data */
  94. void *tree_data; /* application data */
  95. };
  96. extern struct snmp_node *tree;
  97. extern u_int tree_size;
  98. #define SNMP_NODE_CANSET 0x0001 /* SET allowed */
  99. #define SNMP_INDEXES_MAX 7
  100. #define SNMP_INDEX_SHIFT 4
  101. #define SNMP_INDEX_MASK 0xf
  102. #define SNMP_INDEX_COUNT(V) ((V) & SNMP_INDEX_MASK)
  103. #define SNMP_INDEX(V,I) \
  104. (((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & SNMP_INDEX_MASK)
  105. enum {
  106. SNMP_TRACE_GET = 0x00000001,
  107. SNMP_TRACE_GETNEXT = 0x00000002,
  108. SNMP_TRACE_SET = 0x00000004,
  109. SNMP_TRACE_DEPEND = 0x00000008,
  110. SNMP_TRACE_FIND = 0x00000010,
  111. };
  112. /* trace flag for the following functions */
  113. extern u_int snmp_trace;
  114. /* called to write the trace */
  115. extern void (*snmp_debug)(const char *fmt, ...);
  116. enum snmp_ret snmp_get(struct snmp_pdu *pdu, struct asn_buf *resp_b,
  117. struct snmp_pdu *resp, void *);
  118. enum snmp_ret snmp_getnext(struct snmp_pdu *pdu, struct asn_buf *resp_b,
  119. struct snmp_pdu *resp, void *);
  120. enum snmp_ret snmp_getbulk(struct snmp_pdu *pdu, struct asn_buf *resp_b,
  121. struct snmp_pdu *resp, void *);
  122. enum snmp_ret snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
  123. struct snmp_pdu *resp, void *);
  124. enum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *,
  125. struct asn_buf *);
  126. struct snmp_dependency *snmp_dep_lookup(struct snmp_context *,
  127. const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t);
  128. struct snmp_context *snmp_init_context(void);
  129. int snmp_dep_commit(struct snmp_context *);
  130. int snmp_dep_rollback(struct snmp_context *);
  131. void snmp_dep_finish(struct snmp_context *);
  132. #endif