/contrib/bsnmp/snmpd/snmpmod.3

https://bitbucket.org/freebsd/freebsd-head/ · Unknown · 1184 lines · 1182 code · 2 blank · 0 comment · 0 complexity · 9813cb9d369a060b7534051beeb470d0 MD5 · raw file

  1. .\"
  2. .\" Copyright (c) 2004-2005
  3. .\" Hartmut Brandt.
  4. .\" All rights reserved.
  5. .\" Copyright (c) 2001-2003
  6. .\" Fraunhofer Institute for Open Communication Systems (FhG Fokus).
  7. .\" All rights reserved.
  8. .\"
  9. .\" Author: Harti Brandt <harti@FreeBSD.org>
  10. .\"
  11. .\" Redistribution and use in source and binary forms, with or without
  12. .\" modification, are permitted provided that the following conditions
  13. .\" are met:
  14. .\" 1. Redistributions of source code must retain the above copyright
  15. .\" notice, this list of conditions and the following disclaimer.
  16. .\" 2. Redistributions in binary form must reproduce the above copyright
  17. .\" notice, this list of conditions and the following disclaimer in the
  18. .\" documentation and/or other materials provided with the distribution.
  19. .\"
  20. .\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  21. .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  23. .\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
  24. .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  26. .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  27. .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  28. .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  29. .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. .\" SUCH DAMAGE.
  31. .\"
  32. .\" $Begemot: bsnmp/snmpd/snmpmod.3,v 1.14 2005/10/04 13:30:35 brandt_h Exp $
  33. .\"
  34. .Dd December 19, 2010
  35. .Dt SNMPMOD 3
  36. .Os
  37. .Sh NAME
  38. .Nm INSERT_OBJECT_OID_LINK_INDEX ,
  39. .Nm INSERT_OBJECT_INT_LINK_INDEX ,
  40. .Nm FIND_OBJECT_OID_LINK_INDEX ,
  41. .Nm NEXT_OBJECT_OID_LINK_INDEX ,
  42. .Nm FIND_OBJECT_INT_LINK_INDEX ,
  43. .Nm NEXT_OBJECT_INT_LINK_INDEX ,
  44. .Nm INSERT_OBJECT_OID_LINK ,
  45. .Nm INSERT_OBJECT_INT_LINK ,
  46. .Nm FIND_OBJECT_OID_LINK ,
  47. .Nm NEXT_OBJECT_OID_LINK ,
  48. .Nm FIND_OBJECT_INT_LINK ,
  49. .Nm NEXT_OBJECT_INT_LINK ,
  50. .Nm INSERT_OBJECT_OID ,
  51. .Nm INSERT_OBJECT_INT ,
  52. .Nm FIND_OBJECT_OID ,
  53. .Nm FIND_OBJECT_INT ,
  54. .Nm NEXT_OBJECT_OID ,
  55. .Nm NEXT_OBJECT_INT ,
  56. .Nm this_tick ,
  57. .Nm start_tick ,
  58. .Nm get_ticks ,
  59. .Nm systemg ,
  60. .Nm comm_define ,
  61. .Nm community ,
  62. .Nm oid_zeroDotZero ,
  63. .Nm oid_usmUnknownEngineIDs ,
  64. .Nm oid_usmNotInTimeWindows ,
  65. .Nm reqid_allocate ,
  66. .Nm reqid_next ,
  67. .Nm reqid_base ,
  68. .Nm reqid_istype ,
  69. .Nm reqid_type ,
  70. .Nm timer_start ,
  71. .Nm timer_start_repeat ,
  72. .Nm timer_stop ,
  73. .Nm fd_select ,
  74. .Nm fd_deselect ,
  75. .Nm fd_suspend ,
  76. .Nm fd_resume ,
  77. .Nm or_register ,
  78. .Nm or_unregister ,
  79. .Nm buf_alloc ,
  80. .Nm buf_size ,
  81. .Nm snmp_input_start ,
  82. .Nm snmp_input_finish ,
  83. .Nm snmp_output ,
  84. .Nm snmp_send_port ,
  85. .Nm snmp_send_trap ,
  86. .Nm snmp_pdu_auth_access
  87. .Nm string_save ,
  88. .Nm string_commit ,
  89. .Nm string_rollback ,
  90. .Nm string_get ,
  91. .Nm string_get_max ,
  92. .Nm string_free ,
  93. .Nm ip_save ,
  94. .Nm ip_rollback ,
  95. .Nm ip_commit ,
  96. .Nm ip_get ,
  97. .Nm oid_save ,
  98. .Nm oid_rollback ,
  99. .Nm oid_commit ,
  100. .Nm oid_get ,
  101. .Nm index_decode ,
  102. .Nm index_compare ,
  103. .Nm index_compare_off ,
  104. .Nm index_append ,
  105. .Nm index_append_off,
  106. .Nm snmpd_usmstats,
  107. .Nm bsnmpd_get_usm_stats,
  108. .Nm bsnmpd_reset_usm_stats,
  109. .Nm usm_first_user,
  110. .Nm usm_next_user,
  111. .Nm usm_find_user,
  112. .Nm usm_new_user,
  113. .Nm usm_delete_user,
  114. .Nm usm_flush_users,
  115. .Nm usm_user
  116. .Nm snmpd_target_stat
  117. .Nm bsnmpd_get_target_stats
  118. .Nm target_first_address
  119. .Nm target_next_address
  120. .Nm target_new_address
  121. .Nm target_activate_address
  122. .Nm target_delete_address
  123. .Nm target_first_param
  124. .Nm target_next_param
  125. .Nm target_new_param
  126. .Nm target_delete_param
  127. .Nm target_first_notify
  128. .Nm target_next_notify
  129. .Nm target_new_notify
  130. .Nm target_delete_notify
  131. .Nm target_flush_all
  132. .Nm target_address
  133. .Nm target_param
  134. .Nm target_notify
  135. .Nd "SNMP daemon loadable module interface"
  136. .Sh LIBRARY
  137. Begemot SNMP library
  138. .Pq libbsnmp, -lbsnmp
  139. .Sh SYNOPSIS
  140. .In bsnmp/snmpmod.h
  141. .Fn INSERT_OBJECT_OID_LINK_INDEX "PTR" "LIST" "LINK" "INDEX"
  142. .Fn INSERT_OBJECT_INT_LINK_INDEX "PTR" "LIST" "LINK" "INDEX"
  143. .Fn FIND_OBJECT_OID_LINK_INDEX "LIST" "OID" "SUB" "LINK" "INDEX"
  144. .Fn FIND_OBJECT_INT_LINK_INDEX "LIST" "OID" "SUB" "LINK" "INDEX"
  145. .Fn NEXT_OBJECT_OID_LINK_INDEX "LIST" "OID" "SUB" "LINK" "INDEX"
  146. .Fn NEXT_OBJECT_INT_LINK_INDEX "LIST" "OID" "SUB" "LINK" "INDEX"
  147. .Fn INSERT_OBJECT_OID_LINK "PTR" "LIST" "LINK"
  148. .Fn INSERT_OBJECT_INT_LINK "PTR" "LIST" "LINK"
  149. .Fn FIND_OBJECT_OID_LINK "LIST" "OID" "SUB" "LINK"
  150. .Fn FIND_OBJECT_INT_LINK "LIST" "OID" "SUB" "LINK"
  151. .Fn NEXT_OBJECT_OID_LINK "LIST" "OID" "SUB" "LINK"
  152. .Fn NEXT_OBJECT_INT_LINK "LIST" "OID" "SUB" "LINK"
  153. .Fn INSERT_OBJECT_OID "PTR" "LIST"
  154. .Fn INSERT_OBJECT_INT "PTR" "LIST"
  155. .Fn FIND_OBJECT_OID "LIST" "OID" "SUB"
  156. .Fn FIND_OBJECT_INT "LIST" "OID" "SUB"
  157. .Fn NEXT_OBJECT_OID "LIST" "OID" "SUB"
  158. .Fn NEXT_OBJECT_INT "LIST" "OID" "SUB"
  159. .Vt extern uint64_t this_tick ;
  160. .Vt extern uint64_t start_tick ;
  161. .Ft uint64_t
  162. .Fn get_ticks "void"
  163. .Vt extern struct systemg systemg ;
  164. .Ft u_int
  165. .Fn comm_define "u_int priv" "const char *descr" "struct lmodule *mod" "const char *str"
  166. .Ft const char *
  167. .Fn comm_string "u_int comm"
  168. .Vt extern u_int community ;
  169. .Vt extern const struct asn_oid oid_zeroDotZero ;
  170. .Ft u_int
  171. .Fn reqid_allocate "int size" "struct lmodule *mod"
  172. .Ft int32_t
  173. .Fn reqid_next "u_int type"
  174. .Ft int32_t
  175. .Fn reqid_base "u_int type"
  176. .Ft int
  177. .Fn reqid_istype "int32_t reqid" "u_int type"
  178. .Ft u_int
  179. .Fn reqid_type "int32_t reqid"
  180. .Ft void *
  181. .Fn timer_start "u_int ticks" "void (*func)(void *)" "void *uarg" "struct lmodule *mod"
  182. .Ft void *
  183. .Fn timer_start_repeat "u_int ticks" "u_int repeat_ticks" "void (*func)(void *)" "void *uarg" "struct lmodule *mod"
  184. .Ft void
  185. .Fn timer_stop "void *timer_id"
  186. .Ft void *
  187. .Fn fd_select "int fd" "void (*func)(int, void *)" "void *uarg" "struct lmodule *mod"
  188. .Ft void
  189. .Fn fd_deselect "void *fd_id"
  190. .Ft void
  191. .Fn fd_suspend "void *fd_id"
  192. .Ft int
  193. .Fn fd_resume "void *fd_id"
  194. .Ft u_int
  195. .Fn or_register "const struct asn_oid *oid" "const char *descr" "struct lmodule *mod"
  196. .Ft void
  197. .Fn or_unregister "u_int or_id"
  198. .Ft void *
  199. .Fn buf_alloc "int tx"
  200. .Ft size_t
  201. .Fn buf_size "int tx"
  202. .Ft enum snmpd_input_err
  203. .Fo snmp_input_start
  204. .Fa "const u_char *buf" "size_t len" "const char *source"
  205. .Fa "struct snmp_pdu *pdu" "int32_t *ip" "size_t *pdulen"
  206. .Fc
  207. .Ft enum snmpd_input_err
  208. .Fo snmp_input_finish
  209. .Fa "struct snmp_pdu *pdu" "const u_char *rcvbuf"
  210. .Fa "size_t rcvlen" "u_char *sndbuf" "size_t *sndlen" "const char *source"
  211. .Fa "enum snmpd_input_err ierr" "int32_t ip" "void *data"
  212. .Fc
  213. .Ft void
  214. .Fo snmp_output
  215. .Fa "struct snmp_pdu *pdu" "u_char *sndbuf" "size_t *sndlen"
  216. .Fa "const char *dest"
  217. .Fc
  218. .Ft void
  219. .Fo snmp_send_port
  220. .Fa "void *trans" "const struct asn_oid *port"
  221. .Fa "struct snmp_pdu *pdu" "const struct sockaddr *addr" "socklen_t addrlen"
  222. .Fc
  223. .Ft void
  224. .Fn snmp_send_trap "const struct asn_oid *oid" "..."
  225. .Ft enum snmp_code
  226. .Fn snmp_pdu_auth_access "struct snmp_pdu *pdu" "int32_t *ip"
  227. .Ft int
  228. .Fn string_save "struct snmp_value *val" "struct snmp_context *ctx" "ssize_t req_size" "u_char **strp"
  229. .Ft void
  230. .Fn string_commit "struct snmp_context *ctx"
  231. .Ft void
  232. .Fn string_rollback "struct snmp_context *ctx" "u_char **strp"
  233. .Ft int
  234. .Fn string_get "struct snmp_value *val" "const u_char *str" "ssize_t len"
  235. .Ft int
  236. .Fn string_get_max "struct snmp_value *val" "const u_char *str" "ssize_t len" "size_t maxlen"
  237. .Ft void
  238. .Fn string_free "struct snmp_context *ctx"
  239. .Ft int
  240. .Fn ip_save "struct snmp_value *val" "struct snmp_context *ctx" "u_char *ipa"
  241. .Ft void
  242. .Fn ip_rollback "struct snmp_context *ctx" "u_char *ipa"
  243. .Ft void
  244. .Fn ip_commit "struct snmp_context *ctx"
  245. .Ft int
  246. .Fn ip_get "struct snmp_value *val" "u_char *ipa"
  247. .Ft int
  248. .Fn oid_save "struct snmp_value *val" "struct snmp_context *ctx" "struct asn_oid *oid"
  249. .Ft void
  250. .Fn oid_rollback "struct snmp_context *ctx" "struct asn_oid *oid"
  251. .Ft void
  252. .Fn oid_commit "struct snmp_context *ctx"
  253. .Ft int
  254. .Fn oid_get "struct snmp_value *val" "const struct asn_oid *oid"
  255. .Ft int
  256. .Fn index_decode "const struct asn_oid *oid" "u_int sub" "u_int code" "..."
  257. .Ft int
  258. .Fn index_compare "const struct asn_oid *oid1" "u_int sub" "const struct asn_oid *oid2"
  259. .Ft int
  260. .Fn index_compare_off "const struct asn_oid *oid1" "u_int sub" "const struct asn_oid *oid2" "u_int off"
  261. .Ft void
  262. .Fn index_append "struct asn_oid *dst" "u_int sub" "const struct asn_oid *src"
  263. .Ft void
  264. .Fn index_append_off "struct asn_oid *dst" "u_int sub" "const struct asn_oid *src" "u_int off"
  265. .Vt extern struct snmpd_usmstat snmpd_usmstats ;
  266. .Ft struct snmpd_usmstat *
  267. .Fn bsnmpd_get_usm_stats "void"
  268. .Ft void
  269. .Fn bsnmpd_reset_usm_stats "void"
  270. .Ft struct usm_user *
  271. .Fn usm_first_user "void"
  272. .Ft struct usm_user *
  273. .Fn usm_next_user "struct usm_user *uuser"
  274. .Ft struct usm_user *
  275. .Fn usm_find_user "uint8_t *engine" "uint32_t elen" "char *uname"
  276. .Ft struct usm_user *
  277. .Fn usm_new_user "uint8_t *engine" "uint32_t elen" "char *uname"
  278. .Ft void
  279. .Fn usm_delete_user "struct usm_user *"
  280. .Ft void
  281. .Fn usm_flush_users "void"
  282. .Vt extern struct usm_user *usm_user;
  283. .Ft struct snmpd_target_stats *
  284. .Fn bsnmpd_get_target_stats "void"
  285. .Ft struct target_address *
  286. .Fn target_first_address "void"
  287. .Ft struct target_address *
  288. .Fn target_next_address "struct target_address *"
  289. .Ft struct target_address *
  290. .Fn target_new_address "char *"
  291. .Ft int
  292. .Fn target_activate_address "struct target_address *"
  293. .Ft int
  294. .Fn target_delete_address "struct target_address *"
  295. .Ft struct target_param *
  296. .Fn target_first_param "void"
  297. .Ft struct target_param *
  298. .Fn target_next_param "struct target_param *"
  299. .Ft struct target_param *
  300. .Fn target_new_param "char *"
  301. .Ft int
  302. .Fn target_delete_param "struct target_param *"
  303. .Ft struct target_notify *
  304. .Fn target_first_notify "void"
  305. .Ft struct target_notify *
  306. .Fn target_next_notify "struct target_notify *"
  307. .Ft struct target_notify *
  308. .Fn target_new_notify "char *"
  309. .Ft int
  310. .Fn target_delete_notify "struct target_notify *"
  311. .Ft void
  312. .Fn target_flush_all "void"
  313. .Vt extern const struct asn_oid oid_usmUnknownEngineIDs;
  314. .Vt extern const struct asn_oid oid_usmNotInTimeWindows;
  315. .Sh DESCRIPTION
  316. The
  317. .Xr bsnmpd 1
  318. SNMP daemon implements a minimal MIB which consists of the system group, part
  319. of the SNMP MIB, a private configuration MIB, a trap destination table, a
  320. UDP port table, a community table, a module table, a statistics group and
  321. a debugging group.
  322. All other MIBs are support through loadable modules.
  323. This allows
  324. .Xr bsnmpd 1
  325. to use for task, that are not the classical SNMP task.
  326. .Ss MODULE LOADING AND UNLOADING
  327. Modules are loaded by writing to the module table.
  328. This table is indexed by a string, that identifies the module to the daemon.
  329. This identifier is used
  330. to select the correct configuration section from the configuration files and
  331. to identify resources allocated to this module.
  332. A row in the module table is
  333. created by writing a string of non-zero length to the
  334. .Va begemotSnmpdModulePath
  335. column.
  336. This string must be the complete path to the file containing the module.
  337. A module can be unloaded by writing a zero length string to the path column
  338. of an existing row.
  339. .Pp
  340. Modules may depend on each other an hence must be loaded in the correct order.
  341. The dependencies are listed in the corresponding manual pages.
  342. .Pp
  343. Upon loading a module the SNMP daemon expects the module file to a export
  344. a global symbol
  345. .Va config .
  346. This symbol should be a variable of type
  347. .Vt struct snmp_module :
  348. .Bd -literal -offset indent
  349. typedef enum snmpd_proxy_err (*proxy_err_f)(struct snmp_pdu *, void *,
  350. const struct asn_oid *, const struct sockaddr *, socklen_t,
  351. enum snmpd_input_err, int32_t);
  352. struct snmp_module {
  353. const char *comment;
  354. int (*init)(struct lmodule *, int argc, char *argv[]);
  355. int (*fini)(void);
  356. void (*idle)(void);
  357. void (*dump)(void);
  358. void (*config)(void);
  359. void (*start)(void);
  360. proxy_err_f proxy;
  361. const struct snmp_node *tree;
  362. u_int tree_size;
  363. void (*loading)(const struct lmodule *, int);
  364. };
  365. .Ed
  366. .Pp
  367. This structure must be statically initialized and its fields have the
  368. following functions:
  369. .Bl -tag -width ".It Va tree_size"
  370. .It Va comment
  371. This is a string that will be visible in the module table.
  372. It should give some hint about the function of this module.
  373. .It Va init
  374. This function is called upon loading the module.
  375. The module pointer should
  376. be stored by the module because it is needed in other calls and the
  377. argument vector will contain the arguments to this module from the daemons
  378. command line.
  379. This function should return 0 if everything is ok or an UNIX error code (see
  380. .Xr errno 3 ) .
  381. Once the function returns 0, the
  382. .Va fini
  383. function is called when the module is unloaded.
  384. .It Va fini
  385. The module is unloaded.
  386. This gives the module a chance to free resources that
  387. are not automatically freed.
  388. Be sure to free all memory, because daemons tend to run very long.
  389. This function pointer may be
  390. .Li NULL
  391. if it is not needed.
  392. .It Va idle
  393. If this function pointer is not
  394. .Li NULL ,
  395. the function pointed to by it is called whenever the daemon is going
  396. to wait for an event.
  397. Try to avoid using this feature.
  398. .It Va dump
  399. Whenever the daemon receives a
  400. .Li SIGUSR1
  401. it dumps it internal state via
  402. .Xr syslog 3 .
  403. If the
  404. .Va dump
  405. field is not
  406. .Li NULL
  407. it is called by the daemon to dump the state of the module.
  408. .It Va config
  409. Whenever the daemon receives a
  410. .Li SIGHUP
  411. signal it re-reads its configuration file.
  412. If the
  413. .Va config
  414. field is not
  415. .Li NULL
  416. it is called after reading the configuration file to give the module a chance
  417. to adapt to the new configuration.
  418. .It Va start
  419. If not
  420. .Li NULL
  421. this function is called after successful loading and initializing the module
  422. to start its actual operation.
  423. .It Va proxy
  424. If the daemon receives a PDU and that PDU has a community string whose
  425. community was registered by this module and
  426. .Va proxy
  427. is not
  428. .Li NULL
  429. than this function is called to handle the PDU.
  430. .It Va tree
  431. This is a pointer to the node array for the MIB tree implemented by this module.
  432. .It Va tree_size
  433. This is the number of nodes in
  434. .Va tree .
  435. .It Va loading
  436. If this pointer is not
  437. .Li NULL
  438. it is called whenever another module was loaded or unloaded.
  439. It gets a
  440. pointer to that module and a flag that is 0 for unloading and 1 for loading.
  441. .El
  442. .Pp
  443. When everything is ok, the daemon merges the module's MIB tree into its current
  444. global tree, calls the modules
  445. .Fn init
  446. function.
  447. If this function returns an error, the modules MIB tree is removed from
  448. the global one and the module is unloaded.
  449. If initialization is successful, the modules
  450. .Fn start
  451. function is called.
  452. After it returns the
  453. .Fn loaded
  454. functions of all modules (including the loaded one) are called.
  455. .Pp
  456. When the module is unloaded, its MIB tree is removed from the global one,
  457. the communities, request id ranges, running timers and selected file
  458. descriptors are released, the
  459. .Fn fini
  460. function is called, the module file is unloaded and the
  461. .Fn loaded
  462. functions of all other modules are called.
  463. .Ss IMPLEMENTING TABLES
  464. There are a number of macros designed to help implementing SNMP tables.
  465. A problem while implementing a table is the support for the GETNEXT operator.
  466. The GETNEXT operation has to find out whether, given an arbitrary OID, the
  467. lessest table row, that has an OID higher than the given OID.
  468. The easiest way
  469. to do this is to keep the table as an ordered list of structures each one
  470. of which contains an OID that is the index of the table row.
  471. This allows easy removal, insertion and search.
  472. .Pp
  473. The helper macros assume, that the table is organized as a TAILQ (see
  474. .Xr queue 3
  475. and each structure contains a
  476. .Vt struct asn_oid
  477. that is used as index.
  478. For simple tables with only a integer or unsigned index, an alternate form
  479. of the macros is available, that presume the existence of an integer or
  480. unsigned field as index field.
  481. .Pp
  482. The macros have name of the form
  483. .Bd -literal -offset indent
  484. {INSERT,FIND,NEXT}_OBJECT_{OID,INT}[_LINK[_INDEX]]
  485. .Ed
  486. .Pp
  487. The
  488. .Fn INSERT_*
  489. macros are used in the SET operation to insert a new table row into the table.
  490. The
  491. .Fn FIND_*
  492. macros are used in the GET operation to find a specific row in the table.
  493. The
  494. .Fn NEXT_*
  495. macros are used in the GETNEXT operation to find the next row in the table.
  496. The last two macros return a pointer to the row structure if a row is found,
  497. .Li NULL
  498. otherwise.
  499. The macros
  500. .Fn *_OBJECT_OID_*
  501. assume the existence of a
  502. .Vt struct asn_oid
  503. that is used as index, the macros
  504. .Fn *_OBJECT_INT_*
  505. assume the existence of an unsigned integer field that is used as index.
  506. .Pp
  507. The macros
  508. .Fn *_INDEX
  509. allow the explicit naming of the index field in the parameter
  510. .Fa INDEX ,
  511. whereas the other macros assume that this field is named
  512. .Va index .
  513. The macros
  514. .Fn *_LINK_*
  515. allow the explicit naming of the link field of the tail queues, the others
  516. assume that the link field is named
  517. .Va link .
  518. Explicitly naming the link field may be necessary if the same structures
  519. are held in two or more different tables.
  520. .Pp
  521. The arguments to the macros are as follows:
  522. .Bl -tag -width "INDEX"
  523. .It Fa PTR
  524. A pointer to the new structure to be inserted into the table.
  525. .It Fa LIST
  526. A pointer to the tail queue head.
  527. .It Fa LINK
  528. The name of the link field in the row structure.
  529. .It Fa INDEX
  530. The name of the index field in the row structure.
  531. .It Fa OID
  532. Must point to the
  533. .Va var
  534. field of the
  535. .Fa value
  536. argument to the node operation callback.
  537. This is the OID to search for.
  538. .It Fa SUB
  539. This is the index of the start of the table index in the OID pointed to
  540. by
  541. .Fa OID .
  542. This is usually the same as the
  543. .Fa sub
  544. argument to the node operation callback.
  545. .El
  546. .Ss DAEMON TIMESTAMPS
  547. The variable
  548. .Va this_tick
  549. contains the tick (there are 100 SNMP ticks in a second) when
  550. the current PDU processing was started.
  551. The variable
  552. .Va start_tick
  553. contains the tick when the daemon was started.
  554. The function
  555. .Fn get_ticks
  556. returns the current tick.
  557. The number of ticks since the daemon was started
  558. is
  559. .Bd -literal -offset indent
  560. get_ticks() - start_tick
  561. .Ed
  562. .Ss THE SYSTEM GROUP
  563. The scalar fields of the system group are held in the global variable
  564. .Va systemg :
  565. .Bd -literal -offset indent
  566. struct systemg {
  567. u_char *descr;
  568. struct asn_oid object_id;
  569. u_char *contact;
  570. u_char *name;
  571. u_char *location;
  572. uint32_t services;
  573. uint32_t or_last_change;
  574. };
  575. .Ed
  576. .Ss COMMUNITIES
  577. The SNMP daemon implements a community table.
  578. On recipte of a request message
  579. the community string in that message is compared to each of the community
  580. strings in that table, if a match is found, the global variable
  581. .Va community
  582. is set to the community identifier for that community.
  583. Community identifiers are unsigned integers.
  584. For the three standard communities there are three constants defined:
  585. .Bd -literal -offset indent
  586. #define COMM_INITIALIZE 0
  587. #define COMM_READ 1
  588. #define COMM_WRITE 2
  589. .Ed
  590. .Pp
  591. .Va community
  592. is set to
  593. .Li COMM_INITIALIZE
  594. while the assignments in the configuration file are processed.
  595. To
  596. .Li COMM_READ
  597. or
  598. .Li COMM_WRITE
  599. when the community strings for the read-write or read-only community are found
  600. in the incoming PDU.
  601. .Pp
  602. Modules can define additional communities.
  603. This may be necessary to provide
  604. transport proxying (a PDU received on one communication link is proxied to
  605. another link) or to implement non-UDP access points to SNMP.
  606. A new community is defined with the function
  607. .Fn comm_define .
  608. It takes the following parameters:
  609. .Bl -tag -width ".It Fa descr"
  610. .It Fa priv
  611. This is an integer identifying the community to the module.
  612. Each module has its own namespace with regard to this parameter.
  613. The community table is indexed with the module name and this identifier.
  614. .It Fa descr
  615. This is a string providing a human readable description of the community.
  616. It is visible in the community table.
  617. .It Fa mod
  618. This is the module defining the community.
  619. .It Fa str
  620. This is the initial community string.
  621. .El
  622. .Pp
  623. The function returns a globally unique community identifier.
  624. If a SNMPv1 or SNMPv2 PDU is
  625. received who's community string matches, this identifier is set into the global
  626. .Va community .
  627. .Pp
  628. The function
  629. .Fn comm_string
  630. returns the current community string for the given community.
  631. .Pp
  632. All communities defined by a module are automatically released when the module
  633. is unloaded.
  634. .Ss THE USER-BASED SECURITY GROUP
  635. The scalar statistics of the USM group are held in the global variable
  636. .Va snmpd_usmstats :
  637. .Bd -literal -offset indent
  638. struct snmpd_usmstat {
  639. uint32_t unsupported_seclevels;
  640. uint32_t not_in_time_windows;
  641. uint32_t unknown_users;
  642. uint32_t unknown_engine_ids;
  643. uint32_t wrong_digests;
  644. uint32_t decrypt_errors;
  645. };
  646. .Ed
  647. .Fn bsnmpd_get_usm_stats
  648. returns a pointer to the global structure containing the statistics.
  649. .Fn bsnmpd_reset_usm_stats
  650. clears the statistics of the USM group.
  651. .Pp
  652. A global list of configured USM users is maintained by the daemon.
  653. .Bd -literal -offset indent
  654. struct usm_user {
  655. struct snmp_user suser;
  656. uint8_t user_engine_id[SNMP_ENGINE_ID_SIZ];
  657. uint32_t user_engine_len;
  658. char user_public[SNMP_ADM_STR32_SIZ];
  659. uint32_t user_public_len;
  660. int32_t status;
  661. int32_t type;
  662. SLIST_ENTRY(usm_user) up;
  663. };
  664. .Ed
  665. This structure represents an USM user. The daemon only responds to SNMPv3 PDUs
  666. with user credentials matching an USM user entry in its global list.
  667. If a SNMPv3 PDU is received, whose security model is USM, the global
  668. .Va usm_user
  669. is set to point at the user entry that matches the credentials contained in
  670. the PDU.
  671. However, the daemon does not create or remove USM users, it gives an interface
  672. to external loadable module(s) to manage the list.
  673. .Fn usm_new_user
  674. adds an user entry in the list, and
  675. .Fn usm_delete_user
  676. deletes an existing entry from the list.
  677. .Fn usm_flush_users
  678. is used to remove all configured USM users.
  679. .Fn usm_first_user
  680. will return the first user in the list, or
  681. .Li NULL
  682. if the list is empty.
  683. .Fn usm_next_user
  684. will return the next user of a given entry if one exists, or
  685. .Li NULL .
  686. The list is sorted according to the USM user name and Engine ID.
  687. .Fn usm_find_user
  688. returns the USM user entry matching the given
  689. .Fa engine
  690. and
  691. .Fa uname
  692. or
  693. .Li NULL
  694. if an user with the specified name and engine id is not present in the list.
  695. .Ss THE MANAGEMENT TARGET GROUP
  696. The Management Target group holds target address information used when sending
  697. SNMPv3 notifications.
  698. .Pp
  699. The scalar statistics of the Management Target group are held in the global
  700. variable
  701. .Va snmpd_target_stats :
  702. .Bd -literal -offset indent
  703. struct snmpd_target_stats {
  704. uint32_t unavail_contexts;
  705. uint32_t unknown_contexts;
  706. };
  707. .Ed
  708. .Fn bsnmpd_get_target_stats
  709. returns a pointer to the global structure containing the statistics.
  710. .Pp
  711. Three global lists of configured management target addresses, parameters and
  712. notifications respectively are maintained by the daemon.
  713. .Bd -literal -offset indent
  714. struct target_address {
  715. char name[SNMP_ADM_STR32_SIZ];
  716. uint8_t address[SNMP_UDP_ADDR_SIZ];
  717. int32_t timeout;
  718. int32_t retry;
  719. char taglist[SNMP_TAG_SIZ];
  720. char paramname[SNMP_ADM_STR32_SIZ];
  721. int32_t type;
  722. int32_t socket;
  723. int32_t status;
  724. SLIST_ENTRY(target_address) ta;
  725. };
  726. .Ed
  727. This structure represents a SNMPv3 Management Target address. Each time a SNMP
  728. TRAP is send the daemon will send the Trap to all active Management Target
  729. addresses in its global list.
  730. .Bd -literal -offset indent
  731. struct target_param {
  732. char name[SNMP_ADM_STR32_SIZ];
  733. int32_t mpmodel;
  734. int32_t sec_model;
  735. char secname[SNMP_ADM_STR32_SIZ];
  736. enum snmp_usm_level sec_level;
  737. int32_t type;
  738. int32_t status;
  739. SLIST_ENTRY(target_param) tp;
  740. };
  741. .Ed
  742. This structure represents the information used to generate SNMP messages to the
  743. associated SNMPv3 Management Target addresses.
  744. .Bd -literal -offset indent
  745. struct target_notify {
  746. char name[SNMP_ADM_STR32_SIZ];
  747. char taglist[SNMP_TAG_SIZ];
  748. int32_t notify_type;
  749. int32_t type;
  750. int32_t status;
  751. SLIST_ENTRY(target_notify) tn;
  752. };
  753. .Ed
  754. This structure represents Notification Tag entries - SNMP notifications are sent
  755. to the Target address for each entry in the Management Target Address list that
  756. has a tag matching the specified tag in this structure.
  757. .Pp
  758. The daemon does not create or remove entries in the Management Target group
  759. lists, it gives an interface to external loadable module(s) to manage the lists.
  760. .Fn target_new_address
  761. adds a target address entry, and
  762. .Fn target_delete_address
  763. deletes an existing entry from the target address list.
  764. .Fn target_activate_address
  765. creates a socket associated with the target address entry so that SNMP
  766. notifications may actually be send to that target address.
  767. .Fn target_first_address
  768. will return a pointer to the first target address entry in the list, while
  769. .Fn target_next_address
  770. will return a pointer to the next target address of a given entry if one exists.
  771. .Fn target_new_param
  772. adds a target parameters' entry, and
  773. .Fn target_delete_param
  774. deletes an existing entry from the target parameters list.
  775. .Fn target_first_param
  776. will return a pointer to the first target parameters' entry in the list, while
  777. .Fn target_next_param
  778. will return a pointer to the next target parameters of a given entry if one
  779. exists.
  780. .Fn target_new_notify
  781. adds a notification target entry, and
  782. .Fn target_delete_notify
  783. deletes an existing entry from the notification target list.
  784. .Fn target_first_notify
  785. will return a pointer to the first notification target entry in the list, while
  786. .Fn target_next_notify
  787. will return a pointer to the next notification target of a given entry if one
  788. exists.
  789. .Fn target_flush_all
  790. is used to remove all configured data from the three global Management Target
  791. Group lists.
  792. .Ss WELL KNOWN OIDS
  793. The global variable
  794. .Va oid_zeroDotZero
  795. contains the OID 0.0.
  796. The global variables
  797. .Va oid_usmUnknownEngineIDs
  798. .Va oid_usmNotInTimeWindows
  799. contains the OIDs 1.3.6.1.6.3.15.1.1.4.0 and 1.3.6.1.6.3.15.1.1.2.0 used
  800. in the SNMPv3 USM Engine Discovery.
  801. .Ss REQUEST ID RANGES
  802. For modules that implement SNMP client functions besides SNMP agent functions
  803. it may be necessary to identify SNMP requests by their identifier to allow
  804. easier routing of responses to the correct sub-system.
  805. Request id ranges
  806. provide a way to acquire globally non-overlapping sub-ranges of the entire
  807. 31-bit id range.
  808. .Pp
  809. A request id range is allocated with
  810. .Fn reqid_allocate .
  811. The arguments are: the size of the range and the module allocating the range.
  812. For example, the call
  813. .Bd -literal -offset indent
  814. id = reqid_allocate(1000, module);
  815. .Ed
  816. .Pp
  817. allocates a range of 1000 request ids.
  818. The function returns the request
  819. id range identifier or 0 if there is not enough identifier space.
  820. The function
  821. .Fn reqid_base
  822. returns the lowest request id in the given range.
  823. .Pp
  824. Request id are allocated starting at the lowest one linear throughout the range.
  825. If the client application may have a lot of outstanding request the range
  826. must be large enough so that an id is not reused until it is really expired.
  827. .Fn reqid_next
  828. returns the sequentially next id in the range.
  829. .Pp
  830. The function
  831. .Fn reqid_istype
  832. checks whether the request id
  833. .Fa reqid
  834. is within the range identified by
  835. .Fa type .
  836. The function
  837. .Fn reqid_type
  838. returns the range identifier for the given
  839. .Fa reqid
  840. or 0 if the request id is in none of the ranges.
  841. .Ss TIMERS
  842. The SNMP daemon supports an arbitrary number of timers with SNMP tick granularity.
  843. The function
  844. .Fn timer_start
  845. arranges for the callback
  846. .Fa func
  847. to be called with the argument
  848. .Fa uarg
  849. after
  850. .Fa ticks
  851. SNMP ticks have expired.
  852. .Fa mod
  853. is the module that starts the timer.
  854. These timers are one-shot, they are not restarted.
  855. Repeatable timers are started with
  856. .Fn timer_start_repeat
  857. which takes an additional argument
  858. .Fa repeat_ticks .
  859. The argument
  860. .Fa ticks
  861. gives the number of ticks until the first execution of the callback, while
  862. .Fa repeat_ticks
  863. is the number of ticks between invocations of the callback.
  864. Note, that currently the number of initial ticks silently may be set identical
  865. to the number of ticks between callback invocations.
  866. The function returns a timer identifier that can be used to stop the timer via
  867. .Fn timer_stop .
  868. If a module is unloaded all timers started by the module that have not expired
  869. yet are stopped.
  870. .Ss FILE DESCRIPTOR SUPPORT
  871. A module may need to get input from socket file descriptors without blocking
  872. the daemon (for example to implement alternative SNMP transports).
  873. .Pp
  874. The function
  875. .Fn fd_select
  876. causes the callback function
  877. .Fa func
  878. to be called with the file descriptor
  879. .Fa fd
  880. and the user argument
  881. .Fa uarg
  882. whenever the file descriptor
  883. .Fa fd
  884. can be read or has a close condition.
  885. If the file descriptor is not in
  886. non-blocking mode, it is set to non-blocking mode.
  887. If the callback is not needed anymore,
  888. .Fn fd_deselect
  889. may be called with the value returned from
  890. .Fn fd_select .
  891. All file descriptors selected by a module are automatically deselected when
  892. the module is unloaded.
  893. .Pp
  894. To temporarily suspend the file descriptor registration
  895. .Fn fd_suspend
  896. can be called.
  897. This also causes the file descriptor to be switched back to
  898. blocking mode if it was blocking prior the call to
  899. .Fn fd_select .
  900. This is necessary to do synchronous input on a selected socket.
  901. The effect of
  902. .Fn fd_suspend
  903. can be undone with
  904. .Fn fd_resume .
  905. .Ss OBJECT RESOURCES
  906. The system group contains an object resource table.
  907. A module may create an entry in this table by calling
  908. .Fn or_register
  909. with the
  910. .Fa oid
  911. to be registered, a textual description in
  912. .Fa str
  913. and a pointer to the module
  914. .Fa mod .
  915. The registration can be removed with
  916. .Fn or_unregister .
  917. All registrations of a module are automatically removed if the module is
  918. unloaded.
  919. .Ss TRANSMIT AND RECEIVE BUFFERS
  920. A buffer is allocated via
  921. .Fn buf_alloc .
  922. The argument must be 1 for transmit and 0 for receive buffers.
  923. The function may return
  924. .Li NULL
  925. if there is no memory available.
  926. The current buffersize can be obtained with
  927. .Fn buf_size .
  928. .Sh PROCESSING PDUS
  929. For modules that need to do their own PDU processing (for example for proxying)
  930. the following functions are available:
  931. .Pp
  932. Function
  933. .Fn snmp_input_start
  934. decodes the PDU, searches the community, and sets the global
  935. .Va this_tick .
  936. It returns one of the following error codes:
  937. .Bl -tag -width ".It Er SNMPD_INPUT_VALBADLEN"
  938. .It Er SNMPD_INPUT_OK
  939. Everything ok, continue with processing.
  940. .It Er SNMPD_INPUT_FAILED
  941. The PDU could not be decoded, has a wrong version or an unknown
  942. community string.
  943. .It Er SNMPD_INPUT_VALBADLEN
  944. A SET PDU had a value field in a binding with a wrong length field in an
  945. ASN.1 header.
  946. .It Er SNMPD_INPUT_VALRANGE
  947. A SET PDU had a value field in a binding with a value that is out of range
  948. for the given ASN.1 type.
  949. .It Er SNMPD_INPUT_VALBADENC
  950. A SET PDU had a value field in a binding with wrong ASN.1 encoding.
  951. .It Er SNMPD_INPUT_TRUNC
  952. The buffer appears to contain a valid begin of a PDU, but is too short.
  953. For streaming transports this means that the caller must save what he
  954. already has and trying to obtain more input and reissue this input to
  955. the function.
  956. For datagram transports this means that part of the
  957. datagram was lost and the input should be ignored.
  958. .El
  959. .Pp
  960. The function
  961. .Fn snmp_input_finish
  962. does the other half of processing: if
  963. .Fn snmp_input_start
  964. did not return OK, tries to construct an error response.
  965. If the start was OK, it calls the correct function from
  966. .Xr bsnmpagent 3
  967. to execute the request and depending on the outcome constructs a response or
  968. error response PDU or ignores the request PDU.
  969. It returns either
  970. .Er SNMPD_INPUT_OK
  971. or
  972. .Er SNMPD_INPUT_FAILED .
  973. In the first case a response PDU was constructed and should be sent.
  974. .Pp
  975. The function
  976. .Fn snmp_output
  977. takes a PDU and encodes it.
  978. .Pp
  979. The function
  980. .Fn snmp_send_port
  981. takes a PDU, encodes it and sends it through the given port (identified by
  982. the transport and the index in the port table) to the given address.
  983. .Pp
  984. The function
  985. .Fn snmp_send_trap
  986. sends a trap to all trap destinations.
  987. The arguments are the
  988. .Fa oid
  989. identifying the trap and a NULL-terminated list of
  990. .Vt struct snmp_value
  991. pointers that are to be inserted into the trap binding list.
  992. .Fn snmp_pdu_auth_access
  993. verifies whether access to the object IDs contained in the
  994. .Fa pdu
  995. should be granted or denied, according to the configured View-Based Access
  996. rules.
  997. .Fa ip
  998. contains the index of the first varbinding to which access was denied, or 0 if
  999. access to all varbindings in the PDU is granted.
  1000. .Ss SIMPLE ACTION SUPPORT
  1001. For simple scalar variables that need no dependencies a number of support
  1002. functions is available to handle the set, commit, rollback and get.
  1003. .Pp
  1004. The following functions are used for OCTET STRING scalars, either NUL terminated
  1005. or not:
  1006. .Bl -tag -width "XXXXXXXXX"
  1007. .It Fn string_save
  1008. should be called for SNMP_OP_SET.
  1009. .Fa value
  1010. and
  1011. .Fa ctx
  1012. are the resp\&.\& arguments to the node callback.
  1013. .Fa valp
  1014. is a pointer to the pointer that holds the current value and
  1015. .Fa req_size
  1016. should be -1 if any size of the string is acceptable or a number larger or
  1017. equal zero if the string must have a specific size.
  1018. The function saves
  1019. the old value in the scratch area (note, that any initial value must have
  1020. been allocated by
  1021. .Xr malloc 3 ) ,
  1022. allocates a new string, copies over the new value, NUL-terminates it and
  1023. sets the new current value.
  1024. .It Fn string_commit
  1025. simply frees the saved old value in the scratch area.
  1026. .It Fn string_rollback
  1027. frees the new value, and puts back the old one.
  1028. .It Fn string_get
  1029. is used for GET or GETNEXT.
  1030. The function
  1031. .It Fn string_get_max
  1032. can be used instead of
  1033. .Fn string_get
  1034. to ensure that the returned string has a certain maximum length.
  1035. If
  1036. .Fa len
  1037. is -1, the length is computed via
  1038. .Xr strlen 3
  1039. from the current string value.
  1040. If the current value is NULL,
  1041. a OCTET STRING of zero length is returned.
  1042. .It Fn string_free
  1043. must be called if either rollback or commit fails to free the saved old value.
  1044. .El
  1045. .Pp
  1046. The following functions are used to process scalars of type IP-address:
  1047. .Bl -tag -width "XXXXXXXXX"
  1048. .It Fn ip_save
  1049. Saves the current value in the scratch area and sets the new value from
  1050. .Fa valp .
  1051. .It Fn ip_commit
  1052. Does nothing.
  1053. .It Fn ip_rollback
  1054. Restores the old IP address from the scratch area.
  1055. .It Fn ip_get
  1056. Retrieves the IP current address.
  1057. .El
  1058. .Pp
  1059. The following functions handle OID-typed variables:
  1060. .Bl -tag -width "XXXXXXXXX"
  1061. .It Fn oid_save
  1062. Saves the current value in the scratch area by allocating a
  1063. .Vt struct asn_oid
  1064. with
  1065. .Xr malloc 3
  1066. and sets the new value from
  1067. .Fa oid .
  1068. .It Fn oid_commit
  1069. Frees the old value in the scratch area.
  1070. .It Fn oid_rollback
  1071. Restores the old OID from the scratch area and frees the old OID.
  1072. .It Fn oid_get
  1073. Retrieves the OID
  1074. .El
  1075. .Ss TABLE INDEX HANDLING
  1076. The following functions help in handling table indexes:
  1077. .Bl -tag -width "XXXXXXXXX"
  1078. .It Fn index_decode
  1079. Decodes the index part of the OID.
  1080. The parameter
  1081. .Fa oid
  1082. must be a pointer to the
  1083. .Va var
  1084. field of the
  1085. .Fa value
  1086. argument of the node callback.
  1087. The
  1088. .Fa sub
  1089. argument must be the index of the start of the index in the OID (this is
  1090. the
  1091. .Fa sub
  1092. argument to the node callback).
  1093. .Fa code
  1094. is the index expression (parameter
  1095. .Fa idx
  1096. to the node callback).
  1097. These parameters are followed by parameters depending on the syntax of the index
  1098. elements as follows:
  1099. .Bl -tag -width ".It Li OCTET STRING"
  1100. .It Li INTEGER
  1101. .Vt int32_t *
  1102. expected as argument.
  1103. .It Li COUNTER64
  1104. .Vt uint64_t *
  1105. expected as argument.
  1106. Note, that this syntax is illegal for indexes.
  1107. .It Li OCTET STRING
  1108. A
  1109. .Vt u_char **
  1110. and a
  1111. .Vt size_t *
  1112. expected as arguments.
  1113. A buffer is allocated to hold the decoded string.
  1114. .It Li OID
  1115. A
  1116. .Vt struct asn_oid *
  1117. is expected as argument.
  1118. .It Li IP ADDRESS
  1119. A
  1120. .Vt u_int8_t *
  1121. expected as argument that points to a buffer of at least four byte.
  1122. .It Li COUNTER, GAUGE, TIMETICKS
  1123. A
  1124. .Vt u_int32_t
  1125. expected.
  1126. .It Li NULL
  1127. No argument expected.
  1128. .El
  1129. .It Fn index_compare
  1130. compares the current variable with an OID.
  1131. .Fa oid1
  1132. and
  1133. .Fa sub
  1134. come from the node callback arguments
  1135. .Fa value->var
  1136. and
  1137. .Fa sub
  1138. resp.
  1139. .Fa oid2
  1140. is the OID to compare to.
  1141. The function returns -1, 0, +1 when the
  1142. variable is lesser, equal, higher to the given OID.
  1143. .Fa oid2
  1144. must contain only the index part of the table column.
  1145. .It Fn index_compare_off
  1146. is equivalent to
  1147. .Fn index_compare
  1148. except that it takes an additional parameter
  1149. .Fa off
  1150. that causes it to ignore the first
  1151. .Fa off
  1152. components of both indexes.
  1153. .It Fn index_append
  1154. appends OID
  1155. .Fa src
  1156. beginning at position
  1157. .Fa sub
  1158. to
  1159. .Fa dst .
  1160. .It Fn index_append_off
  1161. appends OID
  1162. .Fa src
  1163. beginning at position
  1164. .Fa off
  1165. to
  1166. .Fa dst
  1167. beginning at position
  1168. .Fa sub
  1169. +
  1170. .Fa off .
  1171. .El
  1172. .Sh SEE ALSO
  1173. .Xr gensnmptree 1 ,
  1174. .Xr bsnmpd 1 ,
  1175. .Xr bsnmpagent 3 ,
  1176. .Xr bsnmpclient 3 ,
  1177. .Xr bsnmplib 3
  1178. .Sh STANDARDS
  1179. This implementation conforms to the applicable IETF RFCs and ITU-T
  1180. recommendations.
  1181. .Sh AUTHORS
  1182. .An Hartmut Brandt Aq harti@FreeBSD.org