/contrib/bsnmp/snmpd/snmpd.h

https://bitbucket.org/freebsd/freebsd-head/ · C++ Header · 340 lines · 189 code · 57 blank · 94 comment · 0 complexity · 7db32668e8c5b0f34c0dab2e57889635 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/snmpd/snmpd.h,v 1.24 2004/08/06 08:47:13 brandt Exp $
  30. *
  31. * Private SNMPd data and functions.
  32. */
  33. #ifdef USE_LIBBEGEMOT
  34. #include <rpoll.h>
  35. #else
  36. #include <isc/eventlib.h>
  37. #endif
  38. #define PATH_SYSCONFIG "/etc:/usr/etc:/usr/local/etc"
  39. #ifdef USE_LIBBEGEMOT
  40. #define evTimerID int
  41. #define evFileID int
  42. #endif
  43. /*************************************************************
  44. *
  45. * Communities
  46. */
  47. struct community {
  48. struct lmodule *owner; /* who created the community */
  49. u_int private;/* private name for the module */
  50. u_int value; /* value of this community */
  51. u_char * string; /* the community string */
  52. const u_char * descr; /* description */
  53. TAILQ_ENTRY(community) link;
  54. struct asn_oid index;
  55. };
  56. /* list of all known communities */
  57. extern TAILQ_HEAD(community_list, community) community_list;
  58. /*************************************************************
  59. *
  60. * Request IDs.
  61. */
  62. struct idrange {
  63. u_int type; /* type id */
  64. int32_t base; /* base of this range */
  65. int32_t size; /* size of this range */
  66. int32_t next; /* generator */
  67. struct lmodule *owner; /* owner module */
  68. TAILQ_ENTRY(idrange) link;
  69. };
  70. /* list of all known ranges */
  71. extern TAILQ_HEAD(idrange_list, idrange) idrange_list;
  72. /* identifier generator */
  73. extern u_int next_idrange;
  74. /* request id generator for traps */
  75. extern u_int trap_reqid;
  76. /*************************************************************
  77. *
  78. * Timers
  79. */
  80. struct timer {
  81. void (*func)(void *);/* user function */
  82. void *udata; /* user data */
  83. evTimerID id; /* timer id */
  84. struct lmodule *owner; /* owner of the timer */
  85. LIST_ENTRY(timer) link;
  86. };
  87. /* list of all current timers */
  88. extern LIST_HEAD(timer_list, timer) timer_list;
  89. /*************************************************************
  90. *
  91. * File descriptors
  92. */
  93. struct fdesc {
  94. int fd; /* the file descriptor */
  95. void (*func)(int, void *);/* user function */
  96. void *udata; /* user data */
  97. evFileID id; /* file id */
  98. struct lmodule *owner; /* owner module of the file */
  99. LIST_ENTRY(fdesc) link;
  100. };
  101. /* list of all current selected files */
  102. extern LIST_HEAD(fdesc_list, fdesc) fdesc_list;
  103. /*************************************************************
  104. *
  105. * Loadable modules
  106. */
  107. # define LM_SECTION_MAX 14
  108. struct lmodule {
  109. char section[LM_SECTION_MAX + 1]; /* and index */
  110. char *path;
  111. u_int flags;
  112. void *handle;
  113. const struct snmp_module *config;
  114. TAILQ_ENTRY(lmodule) link;
  115. TAILQ_ENTRY(lmodule) start;
  116. struct asn_oid index;
  117. };
  118. #define LM_STARTED 0x0001
  119. #define LM_ONSTARTLIST 0x0002
  120. extern TAILQ_HEAD(lmodules, lmodule) lmodules;
  121. struct lmodule *lm_load(const char *, const char *);
  122. void lm_unload(struct lmodule *);
  123. void lm_start(struct lmodule *);
  124. /*************************************************************
  125. *
  126. * SNMP ports
  127. */
  128. /*
  129. * Common input stuff
  130. */
  131. struct port_input {
  132. int fd; /* socket */
  133. void *id; /* evSelect handle */
  134. int stream : 1; /* stream socket */
  135. int cred : 1; /* want credentials */
  136. struct sockaddr *peer; /* last received packet */
  137. socklen_t peerlen;
  138. int priv : 1; /* peer is privileged */
  139. u_char *buf; /* receive buffer */
  140. size_t buflen; /* buffer length */
  141. size_t length; /* received length */
  142. size_t consumed; /* how many bytes used */
  143. };
  144. struct tport {
  145. struct asn_oid index; /* table index of this tp point */
  146. TAILQ_ENTRY(tport) link; /* table link */
  147. struct transport *transport; /* who handles this */
  148. };
  149. TAILQ_HEAD(tport_list, tport);
  150. int snmpd_input(struct port_input *, struct tport *);
  151. void snmpd_input_close(struct port_input *);
  152. /*
  153. * Transport domain
  154. */
  155. #define TRANS_NAMELEN 64
  156. struct transport_def {
  157. const char *name; /* name of this transport */
  158. struct asn_oid id; /* OBJID of this transport */
  159. int (*start)(void);
  160. int (*stop)(int);
  161. void (*close_port)(struct tport *);
  162. int (*init_port)(struct tport *);
  163. ssize_t (*send)(struct tport *, const u_char *, size_t,
  164. const struct sockaddr *, size_t);
  165. };
  166. struct transport {
  167. struct asn_oid index; /* transport table index */
  168. TAILQ_ENTRY(transport) link; /* ... and link */
  169. u_int or_index; /* registration index */
  170. struct tport_list table; /* list of open ports */
  171. const struct transport_def *vtab;
  172. };
  173. TAILQ_HEAD(transport_list, transport);
  174. extern struct transport_list transport_list;
  175. void trans_insert_port(struct transport *, struct tport *);
  176. void trans_remove_port(struct tport *);
  177. struct tport *trans_find_port(struct transport *,
  178. const struct asn_oid *, u_int);
  179. struct tport *trans_next_port(struct transport *,
  180. const struct asn_oid *, u_int);
  181. struct tport *trans_first_port(struct transport *);
  182. struct tport *trans_iter_port(struct transport *,
  183. int (*)(struct tport *, intptr_t), intptr_t);
  184. int trans_register(const struct transport_def *, struct transport **);
  185. int trans_unregister(struct transport *);
  186. /*************************************************************
  187. *
  188. * SNMPd scalar configuration.
  189. */
  190. struct snmpd {
  191. /* transmit buffer size */
  192. u_int32_t txbuf;
  193. /* receive buffer size */
  194. u_int32_t rxbuf;
  195. /* disable community table */
  196. int comm_dis;
  197. /* authentication traps */
  198. int auth_traps;
  199. /* source address for V1 traps */
  200. u_char trap1addr[4];
  201. /* version enable flags */
  202. uint32_t version_enable;
  203. };
  204. extern struct snmpd snmpd;
  205. #define VERS_ENABLE_V1 0x00000001
  206. #define VERS_ENABLE_V2C 0x00000002
  207. #define VERS_ENABLE_V3 0x00000004
  208. #define VERS_ENABLE_ALL (VERS_ENABLE_V1 | VERS_ENABLE_V2C | VERS_ENABLE_V3)
  209. /*
  210. * The debug group
  211. */
  212. struct debug {
  213. u_int dump_pdus;
  214. u_int logpri;
  215. u_int evdebug;
  216. };
  217. extern struct debug debug;
  218. /*
  219. * SNMPd statistics table
  220. */
  221. struct snmpd_stats {
  222. u_int32_t inPkts; /* total packets received */
  223. u_int32_t inBadVersions; /* unknown version number */
  224. u_int32_t inASNParseErrs; /* fatal parse errors */
  225. u_int32_t inBadCommunityNames;
  226. u_int32_t inBadCommunityUses;
  227. u_int32_t proxyDrops; /* dropped by proxy function */
  228. u_int32_t silentDrops;
  229. u_int32_t inBadPduTypes;
  230. u_int32_t inTooLong;
  231. u_int32_t noTxbuf;
  232. u_int32_t noRxbuf;
  233. };
  234. extern struct snmpd_stats snmpd_stats;
  235. /*
  236. * SNMPd Engine
  237. */
  238. extern struct snmp_engine snmpd_engine;
  239. /*
  240. * OR Table
  241. */
  242. struct objres {
  243. TAILQ_ENTRY(objres) link;
  244. u_int index;
  245. struct asn_oid oid; /* the resource OID */
  246. char descr[256];
  247. u_int32_t uptime;
  248. struct lmodule *module;
  249. };
  250. TAILQ_HEAD(objres_list, objres);
  251. extern struct objres_list objres_list;
  252. /*
  253. * Trap Sink Table
  254. */
  255. struct trapsink {
  256. TAILQ_ENTRY(trapsink) link;
  257. struct asn_oid index;
  258. u_int status;
  259. int socket;
  260. u_char comm[SNMP_COMMUNITY_MAXLEN];
  261. int version;
  262. };
  263. enum {
  264. TRAPSINK_ACTIVE = 1,
  265. TRAPSINK_NOT_IN_SERVICE = 2,
  266. TRAPSINK_NOT_READY = 3,
  267. TRAPSINK_DESTROY = 6,
  268. TRAPSINK_V1 = 1,
  269. TRAPSINK_V2 = 2,
  270. };
  271. TAILQ_HEAD(trapsink_list, trapsink);
  272. extern struct trapsink_list trapsink_list;
  273. extern const char *syspath;
  274. /* snmpSerialNo */
  275. extern int32_t snmp_serial_no;
  276. int init_actvals(void);
  277. extern char engine_file[];
  278. int init_snmpd_engine(void);
  279. int set_snmpd_engine(void);
  280. int read_config(const char *, struct lmodule *);
  281. int define_macro(const char *name, const char *value);
  282. #define LOG_ASN1_ERRORS 0x10000000
  283. #define LOG_SNMP_ERRORS 0x20000000