snmpmod.h revision 216594
1122394Sharti/* 2122394Sharti * Copyright (c) 2001-2003 3122394Sharti * Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4122394Sharti * All rights reserved. 5122394Sharti * 6122394Sharti * Author: Harti Brandt <harti@freebsd.org> 7133211Sharti * 8216594Ssyrinx * Copyright (c) 2010 The FreeBSD Foundation 9216594Ssyrinx * All rights reserved. 10216594Ssyrinx * 11216594Ssyrinx * Portions of this software were developed by Shteryana Sotirova Shopova 12216594Ssyrinx * under sponsorship from the FreeBSD Foundation. 13216594Ssyrinx * 14133211Sharti * Redistribution and use in source and binary forms, with or without 15133211Sharti * modification, are permitted provided that the following conditions 16133211Sharti * are met: 17133211Sharti * 1. Redistributions of source code must retain the above copyright 18133211Sharti * notice, this list of conditions and the following disclaimer. 19122394Sharti * 2. Redistributions in binary form must reproduce the above copyright 20122394Sharti * notice, this list of conditions and the following disclaimer in the 21122394Sharti * documentation and/or other materials provided with the distribution. 22133211Sharti * 23133211Sharti * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 24133211Sharti * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25133211Sharti * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26133211Sharti * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 27133211Sharti * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28133211Sharti * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29133211Sharti * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30133211Sharti * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31133211Sharti * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32133211Sharti * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33133211Sharti * SUCH DAMAGE. 34122394Sharti * 35156066Sharti * $Begemot: bsnmp/snmpd/snmpmod.h,v 1.32 2006/02/14 09:04:20 brandt_h Exp $ 36122394Sharti * 37122394Sharti * SNMP daemon data and functions exported to modules. 38122394Sharti */ 39122394Sharti#ifndef snmpmod_h_ 40122394Sharti#define snmpmod_h_ 41122394Sharti 42122394Sharti#include <sys/types.h> 43122394Sharti#include <sys/socket.h> 44122394Sharti#include <net/if.h> 45122394Sharti#include <netinet/in.h> 46122394Sharti#include "asn1.h" 47122394Sharti#include "snmp.h" 48122394Sharti#include "snmpagent.h" 49122394Sharti 50122394Sharti#define MAX_MOD_ARGS 16 51122394Sharti 52122394Sharti/* 53122394Sharti * These macros help to handle object lists for SNMP tables. They use 54122394Sharti * tail queues to hold the objects in ascending order in the list. 55150920Sharti * ordering can be done either on an integer/unsigned field, an asn_oid 56150920Sharti * or an ordering function. 57122394Sharti */ 58122394Sharti#define INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \ 59122394Sharti __typeof (PTR) _lelem; \ 60122394Sharti \ 61122394Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 62122394Sharti if (asn_compare_oid(&_lelem->INDEX, &(PTR)->INDEX) > 0) \ 63122394Sharti break; \ 64122394Sharti if (_lelem == NULL) \ 65122394Sharti TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \ 66122394Sharti else \ 67122394Sharti TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \ 68150920Sharti } while (0) 69122394Sharti 70122394Sharti#define INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, INDEX) do { \ 71122394Sharti __typeof (PTR) _lelem; \ 72122394Sharti \ 73122394Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 74122394Sharti if ((asn_subid_t)_lelem->INDEX > (asn_subid_t)(PTR)->INDEX)\ 75122394Sharti break; \ 76122394Sharti if (_lelem == NULL) \ 77122394Sharti TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \ 78122394Sharti else \ 79122394Sharti TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \ 80150920Sharti } while (0) 81122394Sharti 82150920Sharti#define INSERT_OBJECT_FUNC_LINK(PTR, LIST, LINK, FUNC) do { \ 83150920Sharti __typeof (PTR) _lelem; \ 84150920Sharti \ 85150920Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 86150920Sharti if ((FUNC)(_lelem, (PTR)) > 0) \ 87150920Sharti break; \ 88150920Sharti if (_lelem == NULL) \ 89150920Sharti TAILQ_INSERT_TAIL((LIST), (PTR), LINK); \ 90150920Sharti else \ 91150920Sharti TAILQ_INSERT_BEFORE(_lelem, (PTR), LINK); \ 92150920Sharti } while (0) 93150920Sharti 94150920Sharti#define INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, LINK, FUNC) do { \ 95150920Sharti __typeof (PTR) _lelem; \ 96150920Sharti \ 97150920Sharti TAILQ_FOREACH_REVERSE(_lelem, (LIST), HEAD, LINK) \ 98150920Sharti if ((FUNC)(_lelem, (PTR)) < 0) \ 99150920Sharti break; \ 100150920Sharti if (_lelem == NULL) \ 101150920Sharti TAILQ_INSERT_HEAD((LIST), (PTR), LINK); \ 102150920Sharti else \ 103150920Sharti TAILQ_INSERT_AFTER((LIST), _lelem, (PTR), LINK); \ 104150920Sharti } while (0) 105150920Sharti 106122394Sharti#define FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({ \ 107122394Sharti __typeof (TAILQ_FIRST(LIST)) _lelem; \ 108122394Sharti \ 109122394Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 110122394Sharti if (index_compare(OID, SUB, &_lelem->INDEX) == 0) \ 111122394Sharti break; \ 112122394Sharti (_lelem); \ 113122394Sharti }) 114122394Sharti 115122394Sharti#define NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({ \ 116122394Sharti __typeof (TAILQ_FIRST(LIST)) _lelem; \ 117122394Sharti \ 118122394Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 119122394Sharti if (index_compare(OID, SUB, &_lelem->INDEX) < 0) \ 120122394Sharti break; \ 121122394Sharti (_lelem); \ 122122394Sharti }) 123122394Sharti 124122394Sharti#define FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({ \ 125122394Sharti __typeof (TAILQ_FIRST(LIST)) _lelem; \ 126122394Sharti \ 127122394Sharti if ((OID)->len - SUB != 1) \ 128122394Sharti _lelem = NULL; \ 129122394Sharti else \ 130122394Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 131122394Sharti if ((OID)->subs[SUB] == (asn_subid_t)_lelem->INDEX)\ 132122394Sharti break; \ 133122394Sharti (_lelem); \ 134122394Sharti }) 135122394Sharti 136122394Sharti#define NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, INDEX) ({ \ 137122394Sharti __typeof (TAILQ_FIRST(LIST)) _lelem; \ 138122394Sharti \ 139122394Sharti if ((OID)->len - SUB == 0) \ 140122394Sharti _lelem = TAILQ_FIRST(LIST); \ 141122394Sharti else \ 142122394Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 143122394Sharti if ((OID)->subs[SUB] < (asn_subid_t)_lelem->INDEX)\ 144122394Sharti break; \ 145122394Sharti (_lelem); \ 146122394Sharti }) 147122394Sharti 148150920Sharti#define FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({ \ 149150920Sharti __typeof (TAILQ_FIRST(LIST)) _lelem; \ 150150920Sharti \ 151150920Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 152150920Sharti if ((FUNC)(OID, SUB, _lelem) == 0) \ 153150920Sharti break; \ 154150920Sharti (_lelem); \ 155150920Sharti }) 156150920Sharti 157150920Sharti#define NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, LINK, FUNC) ({ \ 158150920Sharti __typeof (TAILQ_FIRST(LIST)) _lelem; \ 159150920Sharti \ 160150920Sharti TAILQ_FOREACH(_lelem, (LIST), LINK) \ 161150920Sharti if ((FUNC)(OID, SUB, _lelem) < 0) \ 162150920Sharti break; \ 163150920Sharti (_lelem); \ 164150920Sharti }) 165150920Sharti 166122394Sharti/* 167122394Sharti * Macros for the case where the index field is called 'index' 168122394Sharti */ 169122394Sharti#define INSERT_OBJECT_OID_LINK(PTR, LIST, LINK) \ 170122394Sharti INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, LINK, index) 171122394Sharti 172122394Sharti#define INSERT_OBJECT_INT_LINK(PTR, LIST, LINK) do { \ 173122394Sharti INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, LINK, index) 174122394Sharti 175122394Sharti#define FIND_OBJECT_OID_LINK(LIST, OID, SUB, LINK) \ 176122394Sharti FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, index) 177122394Sharti 178122394Sharti#define NEXT_OBJECT_OID_LINK(LIST, OID, SUB, LINK) \ 179122394Sharti NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, LINK, index) 180122394Sharti 181122394Sharti#define FIND_OBJECT_INT_LINK(LIST, OID, SUB, LINK) \ 182122394Sharti FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, index) 183122394Sharti 184122394Sharti#define NEXT_OBJECT_INT_LINK(LIST, OID, SUB, LINK) \ 185122394Sharti NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, LINK, index) 186122394Sharti 187122394Sharti/* 188122394Sharti * Macros for the case where the index field is called 'index' and the 189122394Sharti * link field 'link'. 190122394Sharti */ 191122394Sharti#define INSERT_OBJECT_OID(PTR, LIST) \ 192122394Sharti INSERT_OBJECT_OID_LINK_INDEX(PTR, LIST, link, index) 193122394Sharti 194122394Sharti#define INSERT_OBJECT_INT(PTR, LIST) \ 195122394Sharti INSERT_OBJECT_INT_LINK_INDEX(PTR, LIST, link, index) 196122394Sharti 197150920Sharti#define INSERT_OBJECT_FUNC_REV(PTR, LIST, HEAD, FUNC) \ 198150920Sharti INSERT_OBJECT_FUNC_LINK_REV(PTR, LIST, HEAD, link, FUNC) 199150920Sharti 200122394Sharti#define FIND_OBJECT_OID(LIST, OID, SUB) \ 201122394Sharti FIND_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index) 202122394Sharti 203122394Sharti#define FIND_OBJECT_INT(LIST, OID, SUB) \ 204122394Sharti FIND_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index) 205122394Sharti 206150920Sharti#define FIND_OBJECT_FUNC(LIST, OID, SUB, FUNC) \ 207150920Sharti FIND_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC) 208150920Sharti 209122394Sharti#define NEXT_OBJECT_OID(LIST, OID, SUB) \ 210122394Sharti NEXT_OBJECT_OID_LINK_INDEX(LIST, OID, SUB, link, index) 211122394Sharti 212122394Sharti#define NEXT_OBJECT_INT(LIST, OID, SUB) \ 213122394Sharti NEXT_OBJECT_INT_LINK_INDEX(LIST, OID, SUB, link, index) 214122394Sharti 215150920Sharti#define NEXT_OBJECT_FUNC(LIST, OID, SUB, FUNC) \ 216150920Sharti NEXT_OBJECT_FUNC_LINK(LIST, OID, SUB, link, FUNC) 217150920Sharti 218122394Shartistruct lmodule; 219122394Sharti 220146525Sharti/* The tick when the program was started. This is the absolute time of 221146525Sharti * the start in 100th of a second. */ 222146525Shartiextern uint64_t start_tick; 223122394Sharti 224146525Sharti/* The tick when the current packet was received. This is the absolute 225146525Sharti * time in 100th of second. */ 226146525Shartiextern uint64_t this_tick; 227122394Sharti 228146525Sharti/* Get the current absolute time in 100th of a second. */ 229146525Shartiuint64_t get_ticks(void); 230146525Sharti 231122394Sharti/* 232122394Sharti * Return code for proxy function 233122394Sharti */ 234122394Shartienum snmpd_proxy_err { 235122394Sharti /* proxy code will process the PDU */ 236122394Sharti SNMPD_PROXY_OK, 237122394Sharti /* proxy code does not process PDU */ 238122394Sharti SNMPD_PROXY_REJ, 239122394Sharti /* drop this PDU */ 240122394Sharti SNMPD_PROXY_DROP, 241122394Sharti /* drop because of bad community */ 242122394Sharti SNMPD_PROXY_BADCOMM, 243122394Sharti /* drop because of bad community use */ 244122394Sharti SNMPD_PROXY_BADCOMMUSE 245122394Sharti}; 246122394Sharti 247122394Sharti/* 248122394Sharti * Input handling 249122394Sharti */ 250122394Shartienum snmpd_input_err { 251122394Sharti /* proceed with packet */ 252122394Sharti SNMPD_INPUT_OK, 253122394Sharti /* fatal error in packet, ignore it */ 254122394Sharti SNMPD_INPUT_FAILED, 255122394Sharti /* value encoding has wrong length in a SET operation */ 256122394Sharti SNMPD_INPUT_VALBADLEN, 257122394Sharti /* value encoding is out of range */ 258122394Sharti SNMPD_INPUT_VALRANGE, 259122394Sharti /* value has bad encoding */ 260122394Sharti SNMPD_INPUT_VALBADENC, 261124861Sharti /* need more data (truncated packet) */ 262124861Sharti SNMPD_INPUT_TRUNC, 263133211Sharti /* unknown community */ 264133211Sharti SNMPD_INPUT_BAD_COMM, 265122394Sharti}; 266122394Sharti 267122394Sharti/* 268122394Sharti * Every loadable module must have one of this structures with 269122394Sharti * the external name 'config'. 270122394Sharti */ 271122394Shartistruct snmp_module { 272122394Sharti /* a comment describing what this module implements */ 273122394Sharti const char *comment; 274122394Sharti 275150920Sharti /* the initialization function */ 276122394Sharti int (*init)(struct lmodule *, int argc, char *argv[]); 277122394Sharti 278122394Sharti /* the finalisation function */ 279122394Sharti int (*fini)(void); 280122394Sharti 281122394Sharti /* the idle function */ 282122394Sharti void (*idle)(void); 283122394Sharti 284122394Sharti /* the dump function */ 285122394Sharti void (*dump)(void); 286122394Sharti 287122394Sharti /* re-configuration function */ 288122394Sharti void (*config)(void); 289122394Sharti 290122394Sharti /* start operation */ 291122394Sharti void (*start)(void); 292122394Sharti 293122394Sharti /* proxy a PDU */ 294124861Sharti enum snmpd_proxy_err (*proxy)(struct snmp_pdu *, void *, 295122394Sharti const struct asn_oid *, const struct sockaddr *, socklen_t, 296124861Sharti enum snmpd_input_err, int32_t, int); 297122394Sharti 298122394Sharti /* the tree this module is going to server */ 299122394Sharti const struct snmp_node *tree; 300122394Sharti u_int tree_size; 301122394Sharti 302122394Sharti /* function called, when another module was unloaded/loaded */ 303122394Sharti void (*loading)(const struct lmodule *, int); 304122394Sharti}; 305122394Sharti 306122394Sharti/* 307122394Sharti * Stuff exported to modules 308122394Sharti */ 309122394Sharti 310122394Sharti/* 311122394Sharti * The system group. 312122394Sharti */ 313122394Shartistruct systemg { 314122394Sharti u_char *descr; 315122394Sharti struct asn_oid object_id; 316122394Sharti u_char *contact; 317122394Sharti u_char *name; 318122394Sharti u_char *location; 319122394Sharti u_int32_t services; 320122394Sharti u_int32_t or_last_change; 321122394Sharti}; 322122394Shartiextern struct systemg systemg; 323122394Sharti 324122394Sharti/* 325122394Sharti * Community support. 326122394Sharti * 327122394Sharti * We have 2 fixed communities for SNMP read and write access. Modules 328122394Sharti * can create their communities dynamically. They are deleted automatically 329122394Sharti * if the module is unloaded. 330122394Sharti */ 331122394Sharti#define COMM_INITIALIZE 0 332122394Sharti#define COMM_READ 1 333122394Sharti#define COMM_WRITE 2 334122394Sharti 335122394Shartiu_int comm_define(u_int, const char *descr, struct lmodule *, const char *str); 336122394Sharticonst char * comm_string(u_int); 337122394Sharti 338122394Sharti/* community for current packet */ 339122394Shartiextern u_int community; 340122394Sharti 341216294Ssyrinx/* 342216294Ssyrinx * SNMP User-based Security Model data. Modified via the snmp_usm(3) module. 343216294Ssyrinx */ 344216294Ssyrinxstruct snmpd_usmstat { 345216294Ssyrinx uint32_t unsupported_seclevels; 346216294Ssyrinx uint32_t not_in_time_windows; 347216294Ssyrinx uint32_t unknown_users; 348216294Ssyrinx uint32_t unknown_engine_ids; 349216294Ssyrinx uint32_t wrong_digests; 350216294Ssyrinx uint32_t decrypt_errors; 351216294Ssyrinx}; 352216294Ssyrinx 353216294Ssyrinxextern struct snmpd_usmstat snmpd_usmstats; 354216294Ssyrinxstruct snmpd_usmstat *bsnmpd_get_usm_stats(void); 355216294Ssyrinxvoid bsnmpd_reset_usm_stats(void); 356216294Ssyrinx 357216294Ssyrinxstruct usm_user { 358216294Ssyrinx struct snmp_user suser; 359216294Ssyrinx uint8_t user_engine_id[SNMP_ENGINE_ID_SIZ]; 360216294Ssyrinx uint32_t user_engine_len; 361216294Ssyrinx char user_public[SNMP_ADM_STR32_SIZ]; 362216294Ssyrinx uint32_t user_public_len; 363216294Ssyrinx int32_t status; 364216294Ssyrinx int32_t type; 365216294Ssyrinx SLIST_ENTRY(usm_user) up; 366216294Ssyrinx}; 367216294Ssyrinx 368216294SsyrinxSLIST_HEAD(usm_userlist, usm_user); 369216294Ssyrinxstruct usm_user *usm_first_user(void); 370216294Ssyrinxstruct usm_user *usm_next_user(struct usm_user *); 371216294Ssyrinxstruct usm_user *usm_find_user(uint8_t *, uint32_t, char *); 372216294Ssyrinxstruct usm_user *usm_new_user(uint8_t *, uint32_t, char *); 373216294Ssyrinxvoid usm_delete_user(struct usm_user *); 374216294Ssyrinxvoid usm_flush_users(void); 375216294Ssyrinx 376216294Ssyrinx/* USM user for current packet */ 377216294Ssyrinxextern struct usm_user *usm_user; 378216294Ssyrinx 379216294Ssyrinx/* 380216294Ssyrinx * SNMP View-based Access Control Model data. Modified via the snmp_vacm(3) module. 381216294Ssyrinx */ 382216294Ssyrinxstruct vacm_group; 383216294Ssyrinx 384216294Ssyrinxstruct vacm_user { 385216294Ssyrinx /* Security user name from USM */ 386216294Ssyrinx char secname[SNMP_ADM_STR32_SIZ]; 387216294Ssyrinx int32_t sec_model; 388216294Ssyrinx /* Back pointer to user assigned group name */ 389216294Ssyrinx struct vacm_group *group; 390216294Ssyrinx int32_t type; 391216294Ssyrinx int32_t status; 392216294Ssyrinx SLIST_ENTRY(vacm_user) vvu; 393216294Ssyrinx SLIST_ENTRY(vacm_user) vvg; 394216294Ssyrinx}; 395216294Ssyrinx 396216294SsyrinxSLIST_HEAD(vacm_userlist, vacm_user); 397216294Ssyrinx 398216294Ssyrinxstruct vacm_group { 399216294Ssyrinx char groupname[SNMP_ADM_STR32_SIZ]; 400216294Ssyrinx struct vacm_userlist group_users; 401216294Ssyrinx SLIST_ENTRY(vacm_group) vge; 402216294Ssyrinx}; 403216294Ssyrinx 404216294SsyrinxSLIST_HEAD(vacm_grouplist, vacm_group); 405216294Ssyrinx 406216294Ssyrinxstruct vacm_access { 407216294Ssyrinx /* The group name is index, not a column in the table */ 408216294Ssyrinx struct vacm_group *group; 409216294Ssyrinx char ctx_prefix[SNMP_ADM_STR32_SIZ]; 410216294Ssyrinx int32_t sec_model; 411216294Ssyrinx int32_t sec_level; 412216294Ssyrinx int32_t ctx_match; 413216294Ssyrinx struct vacm_view *read_view; 414216294Ssyrinx struct vacm_view *write_view; 415216294Ssyrinx struct vacm_view *notify_view; 416216294Ssyrinx int32_t type; 417216294Ssyrinx int32_t status; 418216294Ssyrinx TAILQ_ENTRY(vacm_access) vva; 419216294Ssyrinx}; 420216294Ssyrinx 421216294SsyrinxTAILQ_HEAD(vacm_accesslist, vacm_access); 422216294Ssyrinx 423216294Ssyrinxstruct vacm_view { 424216294Ssyrinx char viewname[SNMP_ADM_STR32_SIZ]; /* key */ 425216294Ssyrinx struct asn_oid subtree; /* key */ 426216294Ssyrinx uint8_t mask[16]; 427216294Ssyrinx uint8_t exclude; 428216294Ssyrinx int32_t type; 429216294Ssyrinx int32_t status; 430216294Ssyrinx SLIST_ENTRY(vacm_view) vvl; 431216294Ssyrinx}; 432216294Ssyrinx 433216294SsyrinxSLIST_HEAD(vacm_viewlist, vacm_view); 434216294Ssyrinx 435216294Ssyrinxstruct vacm_context { 436216294Ssyrinx /* The ID of the module that registered this context */ 437216294Ssyrinx int32_t regid; 438216294Ssyrinx char ctxname[SNMP_ADM_STR32_SIZ]; 439216294Ssyrinx SLIST_ENTRY(vacm_context) vcl; 440216294Ssyrinx}; 441216294Ssyrinx 442216294SsyrinxSLIST_HEAD(vacm_contextlist, vacm_context); 443216294Ssyrinx 444216294Ssyrinxvoid vacm_groups_init(void); 445216294Ssyrinxstruct vacm_user *vacm_first_user(void); 446216294Ssyrinxstruct vacm_user *vacm_next_user(struct vacm_user *); 447216294Ssyrinxstruct vacm_user *vacm_new_user(int32_t, char *); 448216294Ssyrinxint vacm_delete_user(struct vacm_user *); 449216294Ssyrinxint vacm_user_set_group(struct vacm_user *, u_char *, u_int); 450216294Ssyrinxstruct vacm_access *vacm_first_access_rule(void); 451216294Ssyrinxstruct vacm_access *vacm_next_access_rule(struct vacm_access *); 452216294Ssyrinxstruct vacm_access *vacm_new_access_rule(char *, char *, int32_t, int32_t); 453216294Ssyrinxint vacm_delete_access_rule(struct vacm_access *); 454216294Ssyrinxstruct vacm_view *vacm_first_view(void); 455216294Ssyrinxstruct vacm_view *vacm_next_view(struct vacm_view *); 456216294Ssyrinxstruct vacm_view *vacm_new_view(char *, struct asn_oid *); 457216294Ssyrinxint vacm_delete_view(struct vacm_view *); 458216294Ssyrinxstruct vacm_context *vacm_first_context(void); 459216294Ssyrinxstruct vacm_context *vacm_next_context(struct vacm_context *); 460216294Ssyrinxstruct vacm_context *vacm_add_context(char *, int32_t); 461216294Ssyrinxvoid vacm_flush_contexts(int32_t); 462216294Ssyrinx 463216294Ssyrinx/* 464216594Ssyrinx * RFC 3413 SNMP Management Target & Notification MIB 465216594Ssyrinx */ 466216594Ssyrinx 467216594Ssyrinxstruct snmpd_target_stats { 468216594Ssyrinx uint32_t unavail_contexts; 469216594Ssyrinx uint32_t unknown_contexts; 470216594Ssyrinx}; 471216594Ssyrinx 472216594Ssyrinx#define SNMP_UDP_ADDR_SIZ 6 473216594Ssyrinx#define SNMP_TAG_SIZ (255 + 1) 474216594Ssyrinx 475216594Ssyrinxstruct target_address { 476216594Ssyrinx char name[SNMP_ADM_STR32_SIZ]; 477216594Ssyrinx uint8_t address[SNMP_UDP_ADDR_SIZ]; 478216594Ssyrinx int32_t timeout; 479216594Ssyrinx int32_t retry; 480216594Ssyrinx char taglist[SNMP_TAG_SIZ]; 481216594Ssyrinx char paramname[SNMP_ADM_STR32_SIZ]; 482216594Ssyrinx int32_t type; 483216594Ssyrinx int32_t socket; 484216594Ssyrinx int32_t status; 485216594Ssyrinx SLIST_ENTRY(target_address) ta; 486216594Ssyrinx}; 487216594Ssyrinx 488216594SsyrinxSLIST_HEAD(target_addresslist, target_address); 489216594Ssyrinx 490216594Ssyrinxstruct target_param { 491216594Ssyrinx char name[SNMP_ADM_STR32_SIZ]; 492216594Ssyrinx int32_t mpmodel; 493216594Ssyrinx int32_t sec_model; 494216594Ssyrinx char secname[SNMP_ADM_STR32_SIZ]; 495216594Ssyrinx enum snmp_usm_level sec_level; 496216594Ssyrinx int32_t type; 497216594Ssyrinx int32_t status; 498216594Ssyrinx SLIST_ENTRY(target_param) tp; 499216594Ssyrinx}; 500216594Ssyrinx 501216594SsyrinxSLIST_HEAD(target_paramlist, target_param); 502216594Ssyrinx 503216594Ssyrinxstruct target_notify { 504216594Ssyrinx char name[SNMP_ADM_STR32_SIZ]; 505216594Ssyrinx char taglist[SNMP_TAG_SIZ]; 506216594Ssyrinx int32_t notify_type; 507216594Ssyrinx int32_t type; 508216594Ssyrinx int32_t status; 509216594Ssyrinx SLIST_ENTRY(target_notify) tn; 510216594Ssyrinx}; 511216594Ssyrinx 512216594SsyrinxSLIST_HEAD(target_notifylist, target_notify); 513216594Ssyrinx 514216594Ssyrinxextern struct snmpd_target_stats snmpd_target_stats; 515216594Ssyrinxstruct snmpd_target_stats *bsnmpd_get_target_stats(void); 516216594Ssyrinxstruct target_address *target_first_address(void); 517216594Ssyrinxstruct target_address *target_next_address(struct target_address *); 518216594Ssyrinxstruct target_address *target_new_address(char *); 519216594Ssyrinxint target_activate_address(struct target_address *); 520216594Ssyrinxint target_delete_address(struct target_address *); 521216594Ssyrinxstruct target_param *target_first_param(void); 522216594Ssyrinxstruct target_param *target_next_param(struct target_param *); 523216594Ssyrinxstruct target_param *target_new_param(char *); 524216594Ssyrinxint target_delete_param(struct target_param *); 525216594Ssyrinxstruct target_notify *target_first_notify(void); 526216594Ssyrinxstruct target_notify *target_next_notify(struct target_notify *); 527216594Ssyrinxstruct target_notify *target_new_notify(char *); 528216594Ssyrinxint target_delete_notify (struct target_notify *); 529216594Ssyrinxvoid target_flush_all(void); 530216594Ssyrinx 531216594Ssyrinx/* 532122394Sharti * Well known OIDs 533122394Sharti */ 534122394Shartiextern const struct asn_oid oid_zeroDotZero; 535122394Sharti 536216294Ssyrinx/* SNMPv3 Engine Discovery */ 537216294Ssyrinxextern const struct asn_oid oid_usmUnknownEngineIDs; 538216294Ssyrinxextern const struct asn_oid oid_usmNotInTimeWindows; 539216294Ssyrinx 540122394Sharti/* 541122394Sharti * Request ID ranges. 542122394Sharti * 543122394Sharti * A module can request a range of request ids and associate them with a 544122394Sharti * type field. All ranges are deleted if a module is unloaded. 545122394Sharti */ 546122394Shartiu_int reqid_allocate(int size, struct lmodule *); 547122394Shartiint32_t reqid_next(u_int type); 548122394Shartiint32_t reqid_base(u_int type); 549122394Shartiint reqid_istype(int32_t reqid, u_int type); 550122394Shartiu_int reqid_type(int32_t reqid); 551122394Sharti 552122394Sharti/* 553122394Sharti * Timers. 554122394Sharti */ 555122394Shartivoid *timer_start(u_int, void (*)(void *), void *, struct lmodule *); 556150920Shartivoid *timer_start_repeat(u_int, u_int, void (*)(void *), void *, 557150920Sharti struct lmodule *); 558122394Shartivoid timer_stop(void *); 559122394Sharti 560122394Sharti/* 561122394Sharti * File descriptors 562122394Sharti */ 563122394Shartivoid *fd_select(int, void (*)(int, void *), void *, struct lmodule *); 564122394Shartivoid fd_deselect(void *); 565122394Shartivoid fd_suspend(void *); 566122394Shartiint fd_resume(void *); 567122394Sharti 568122394Sharti/* 569122394Sharti * Object resources 570122394Sharti */ 571122394Shartiu_int or_register(const struct asn_oid *, const char *, struct lmodule *); 572122394Shartivoid or_unregister(u_int); 573122394Sharti 574122394Sharti/* 575122394Sharti * Buffers 576122394Sharti */ 577122394Shartivoid *buf_alloc(int tx); 578122394Shartisize_t buf_size(int tx); 579122394Sharti 580122394Sharti/* decode PDU and find community */ 581122394Shartienum snmpd_input_err snmp_input_start(const u_char *, size_t, const char *, 582124861Sharti struct snmp_pdu *, int32_t *, size_t *); 583122394Sharti 584122394Sharti/* process the pdu. returns either _OK or _FAILED */ 585122394Shartienum snmpd_input_err snmp_input_finish(struct snmp_pdu *, const u_char *, 586122394Sharti size_t, u_char *, size_t *, const char *, enum snmpd_input_err, int32_t, 587122394Sharti void *); 588122394Sharti 589124861Shartivoid snmp_output(struct snmp_pdu *, u_char *, size_t *, const char *); 590124861Shartivoid snmp_send_port(void *, const struct asn_oid *, struct snmp_pdu *, 591122394Sharti const struct sockaddr *, socklen_t); 592216594Ssyrinxenum snmp_code snmp_pdu_auth_access(struct snmp_pdu *, int32_t *); 593122394Sharti 594122394Sharti/* sending traps */ 595122394Shartivoid snmp_send_trap(const struct asn_oid *, ...); 596122394Sharti 597122394Sharti/* 598122394Sharti * Action support 599122394Sharti */ 600122394Shartiint string_save(struct snmp_value *, struct snmp_context *, ssize_t, u_char **); 601122394Shartivoid string_commit(struct snmp_context *); 602122394Shartivoid string_rollback(struct snmp_context *, u_char **); 603122394Shartiint string_get(struct snmp_value *, const u_char *, ssize_t); 604155429Shartiint string_get_max(struct snmp_value *, const u_char *, ssize_t, size_t); 605122394Shartivoid string_free(struct snmp_context *); 606122394Sharti 607122394Shartiint ip_save(struct snmp_value *, struct snmp_context *, u_char *); 608122394Shartivoid ip_rollback(struct snmp_context *, u_char *); 609122394Shartivoid ip_commit(struct snmp_context *); 610122394Shartiint ip_get(struct snmp_value *, u_char *); 611122394Sharti 612122394Shartiint oid_save(struct snmp_value *, struct snmp_context *, struct asn_oid *); 613122394Shartivoid oid_rollback(struct snmp_context *, struct asn_oid *); 614122394Shartivoid oid_commit(struct snmp_context *); 615122394Shartiint oid_get(struct snmp_value *, const struct asn_oid *); 616122394Sharti 617122394Shartiint index_decode(const struct asn_oid *oid, u_int sub, u_int code, ...); 618122394Shartiint index_compare(const struct asn_oid *, u_int, const struct asn_oid *); 619122394Shartiint index_compare_off(const struct asn_oid *, u_int, const struct asn_oid *, 620122394Sharti u_int); 621122394Shartivoid index_append(struct asn_oid *, u_int, const struct asn_oid *); 622122394Shartivoid index_append_off(struct asn_oid *, u_int, const struct asn_oid *, u_int); 623122394Sharti 624122394Sharti#endif 625