|
NAMEINSERT_OBJECT_OID_LINK_INDEX ,
INSERT_OBJECT_INT_LINK_INDEX ,
FIND_OBJECT_OID_LINK_INDEX ,
NEXT_OBJECT_OID_LINK_INDEX ,
FIND_OBJECT_INT_LINK_INDEX ,
NEXT_OBJECT_INT_LINK_INDEX ,
INSERT_OBJECT_OID_LINK ,
INSERT_OBJECT_INT_LINK ,
FIND_OBJECT_OID_LINK ,
NEXT_OBJECT_OID_LINK ,
FIND_OBJECT_INT_LINK ,
NEXT_OBJECT_INT_LINK ,
INSERT_OBJECT_OID ,
INSERT_OBJECT_INT ,
FIND_OBJECT_OID ,
FIND_OBJECT_INT ,
NEXT_OBJECT_OID ,
NEXT_OBJECT_INT , this_tick ,
start_tick , get_ticks ,
systemg , comm_define ,
community , oid_zeroDotZero ,
oid_usmUnknownEngineIDs ,
oid_usmNotInTimeWindows ,
reqid_allocate , reqid_next ,
reqid_base , reqid_istype ,
reqid_type , timer_start ,
timer_start_repeat ,
timer_stop , fd_select ,
fd_deselect , fd_suspend ,
fd_resume , or_register ,
or_unregister , buf_alloc ,
buf_size , snmp_input_start ,
snmp_input_finish ,
snmp_output , snmp_send_port ,
snmp_send_trap ,
snmp_pdu_auth_access
string_save , string_commit ,
string_rollback , string_get ,
string_get_max , string_free ,
ip_save , ip_rollback ,
ip_commit , ip_get ,
oid_save , oid_rollback ,
oid_commit , oid_get ,
index_decode , index_compare ,
index_compare_off ,
index_append ,
index_append_off ,
snmpd_usmstats ,
bsnmpd_get_usm_stats ,
bsnmpd_reset_usm_stats ,
usm_first_user , usm_next_user ,
usm_find_user , usm_new_user ,
usm_delete_user ,
usm_flush_users , usm_user ,
snmpd_target_stat ,
bsnmpd_get_target_stats ,
target_first_address ,
target_next_address ,
target_new_address ,
target_activate_address ,
target_delete_address ,
target_first_param ,
target_next_param ,
target_new_param ,
target_delete_param ,
target_first_notify ,
target_next_notify ,
target_new_notify ,
target_delete_notify ,
target_flush_all ,
target_address , target_param ,
target_notify —
SNMP daemon loadable module interface
LIBRARYBegemot SNMP library (libbsnmp, -lbsnmp)SYNOPSIS#include <bsnmp/snmpmod.h>
extern uint64_t this_tick;
uint64_t
extern struct systemg systemg; u_int
const char *
extern u_int community;
u_int
int32_t
int32_t
int
u_int
void *
void *
void
void *
void
void
int
u_int
void
void *
size_t
enum snmpd_input_err
enum snmpd_input_err
void
void
void
enum snmp_code
int
void
void
int
int
void
int
void
void
int
int
void
void
int
int
int
int
void
void
extern struct snmpd_usmstat snmpd_usmstats; struct snmpd_usmstat *
void
struct usm_user *
struct usm_user *
struct usm_user *
struct usm_user *
void
void
extern struct usm_user *usm_user; struct snmpd_target_stats *
struct target_address *
struct target_address *
struct target_address *
int
int
struct target_param *
struct target_param *
struct target_param *
int
struct target_notify *
struct target_notify *
struct target_notify *
int
void
extern const struct asn_oid
oid_usmUnknownEngineIDs;
DESCRIPTIONThe bsnmpd(1) SNMP daemon implements a minimal MIB which consists of the system group, part of the SNMP MIB, a private configuration MIB, a trap destination table, a UDP port table, a community table, a module table, a statistics group and a debugging group. All other MIBs are support through loadable modules. This allows bsnmpd(1) to use for task, that are not the classical SNMP task.MODULE LOADING AND UNLOADINGModules are loaded by writing to the module table. This table is indexed by a string, that identifies the module to the daemon. This identifier is used to select the correct configuration section from the configuration files and to identify resources allocated to this module. A row in the module table is created by writing a string of non-zero length to the begemotSnmpdModulePath column. This string must be the complete path to the file containing the module. A module can be unloaded by writing a zero length string to the path column of an existing row.Modules may depend on each other an hence must be loaded in the correct order. The dependencies are listed in the corresponding manual pages. Upon loading a module the SNMP daemon expects the module file to a export a global symbol config. This symbol should be a variable of type struct snmp_module: typedef enum snmpd_proxy_err (*proxy_err_f)(struct snmp_pdu *, void *, const struct asn_oid *, const struct sockaddr *, socklen_t, enum snmpd_input_err, int32_t); struct snmp_module { const char *comment; int (*init)(struct lmodule *, int argc, char *argv[]); int (*fini)(void); void (*idle)(void); void (*dump)(void); void (*config)(void); void (*start)(void); proxy_err_f proxy; const struct snmp_node *tree; u_int tree_size; void (*loading)(const struct lmodule *, int); }; This structure must be statically initialized and its fields have the following functions:
When everything is ok, the daemon merges the module's MIB tree
into its current global tree, calls the modules
When the module is unloaded, its MIB tree is removed from the
global one, the communities, request id ranges, running timers and selected
file descriptors are released, the IMPLEMENTING TABLESThere are a number of macros designed to help implementing SNMP tables. A problem while implementing a table is the support for the GETNEXT operator. The GETNEXT operation has to find out whether, given an arbitrary OID, the lessest table row, that has an OID higher than the given OID. The easiest way to do this is to keep the table as an ordered list of structures each one of which contains an OID that is the index of the table row. This allows easy removal, insertion and search.The helper macros assume, that the table is organized as a TAILQ (see queue(3) and each structure contains a struct asn_oid that is used as index. For simple tables with only a integer or unsigned index, an alternate form of the macros is available, that presume the existence of an integer or unsigned field as index field. The macros have name of the form {INSERT,FIND,NEXT}_OBJECT_{OID,INT}[_LINK[_INDEX]] The The macros The arguments to the macros are as follows:
DAEMON TIMESTAMPSThe variable this_tick contains the tick (there are 100 SNMP ticks in a second) when the current PDU processing was started. The variable start_tick contains the tick when the daemon was started. The functionget_ticks () returns the
current tick. The number of ticks since the daemon was started is
get_ticks() - start_tick THE SYSTEM GROUPThe scalar fields of the system group are held in the global variable systemg:struct systemg { u_char *descr; struct asn_oid object_id; u_char *contact; u_char *name; u_char *location; uint32_t services; uint32_t or_last_change; }; COMMUNITIESThe SNMP daemon implements a community table. On receipt of a request message the community string in that message is compared to each of the community strings in that table, if a match is found, the global variable community is set to the community identifier for that community. Community identifiers are unsigned integers. For the three standard communities there are three constants defined:#define COMM_INITIALIZE 0 #define COMM_READ 1 #define COMM_WRITE 2 community is set to
Modules can define additional communities. This may be necessary
to provide transport proxying (a PDU received on one communication link is
proxied to another link) or to implement non-UDP access points to SNMP. A
new community is defined with the function
The function returns a globally unique community identifier. If a SNMPv1 or SNMPv2 PDU is received who's community string matches, this identifier is set into the global community. The function All communities defined by a module are automatically released when the module is unloaded. THE USER-BASED SECURITY GROUPThe scalar statistics of the USM group are held in the global variable snmpd_usmstats:struct snmpd_usmstat { uint32_t unsupported_seclevels; uint32_t not_in_time_windows; uint32_t unknown_users; uint32_t unknown_engine_ids; uint32_t wrong_digests; uint32_t decrypt_errors; }; bsnmpd_get_usm_stats () returns a pointer to the global
structure containing the statistics.
bsnmpd_reset_usm_stats () clears the statistics of the
USM group.
A global list of configured USM users is maintained by the daemon. struct usm_user { struct snmp_user suser; uint8_t user_engine_id[SNMP_ENGINE_ID_SIZ]; uint32_t user_engine_len; char user_public[SNMP_ADM_STR32_SIZ]; uint32_t user_public_len; int32_t status; int32_t type; SLIST_ENTRY(usm_user) up; }; usm_new_user () adds an user entry in
the list, and usm_delete_user () deletes an existing
entry from the list. usm_flush_users () is used to
remove all configured USM users. usm_first_user () will
return the first user in the list, or NULL if the list
is empty. usm_next_user () will return the next user of
a given entry if one exists, or NULL . The list is
sorted according to the USM user name and Engine ID.
usm_find_user () returns the USM user entry matching
the given engine and uname or
NULL if an user with the specified name and engine id
is not present in the list.
THE MANAGEMENT TARGET GROUPThe Management Target group holds target address information used when sending SNMPv3 notifications.The scalar statistics of the Management Target group are held in the global variable snmpd_target_stats: struct snmpd_target_stats { uint32_t unavail_contexts; uint32_t unknown_contexts; }; bsnmpd_get_target_stats () returns a pointer to the
global structure containing the statistics.
Three global lists of configured management target addresses, parameters and notifications respectively are maintained by the daemon. struct target_address { char name[SNMP_ADM_STR32_SIZ]; uint8_t address[SNMP_UDP_ADDR_SIZ]; int32_t timeout; int32_t retry; char taglist[SNMP_TAG_SIZ]; char paramname[SNMP_ADM_STR32_SIZ]; int32_t type; int32_t socket; int32_t status; SLIST_ENTRY(target_address) ta; }; struct target_param { char name[SNMP_ADM_STR32_SIZ]; int32_t mpmodel; int32_t sec_model; char secname[SNMP_ADM_STR32_SIZ]; enum snmp_usm_level sec_level; int32_t type; int32_t status; SLIST_ENTRY(target_param) tp; }; struct target_notify { char name[SNMP_ADM_STR32_SIZ]; char taglist[SNMP_TAG_SIZ]; int32_t notify_type; int32_t type; int32_t status; SLIST_ENTRY(target_notify) tn; }; The daemon does not create or remove entries in the Management
Target group lists, it gives an interface to external loadable module(s) to
manage the lists. WELL KNOWN OIDSThe global variable oid_zeroDotZero contains the OID 0.0. The global variables oid_usmUnknownEngineIDs oid_usmNotInTimeWindows 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 in the SNMPv3 USM Engine Discovery.REQUEST ID RANGESFor modules that implement SNMP client functions besides SNMP agent functions it may be necessary to identify SNMP requests by their identifier to allow easier routing of responses to the correct sub-system. Request id ranges provide a way to acquire globally non-overlapping sub-ranges of the entire 31-bit id range.A request id range is allocated with
id = reqid_allocate(1000, module); allocates a range of 1000 request ids. The function returns the
request id range identifier or 0 if there is not enough identifier space.
The function Request id are allocated starting at the lowest one linear
throughout the range. If the client application may have a lot of
outstanding request the range must be large enough so that an id is not
reused until it is really expired. The function TIMERSThe SNMP daemon supports an arbitrary number of timers with SNMP tick granularity. The functiontimer_start () arranges for
the callback func to be called with the argument
uarg after ticks SNMP ticks have
expired. mod is the module that starts the timer. These
timers are one-shot, they are not restarted. Repeatable timers are started
with timer_start_repeat () which takes an additional
argument repeat_ticks. The argument
ticks gives the number of ticks until the first
execution of the callback, while repeat_ticks is the
number of ticks between invocations of the callback. Note, that currently the
number of initial ticks silently may be set identical to the number of ticks
between callback invocations. The function returns a timer identifier that can
be used to stop the timer via timer_stop (). If a
module is unloaded all timers started by the module that have not expired yet
are stopped.
FILE DESCRIPTOR SUPPORTA module may need to get input from socket file descriptors without blocking the daemon (for example to implement alternative SNMP transports).The function To temporarily suspend the file descriptor registration
OBJECT RESOURCESThe system group contains an object resource table. A module may create an entry in this table by callingor_register () with the
oid to be registered, a textual description in
str and a pointer to the module
mod. The registration can be removed with
or_unregister (). All registrations of a module are
automatically removed if the module is unloaded.
TRANSMIT AND RECEIVE BUFFERSA buffer is allocated viabuf_alloc (). The argument must
be 1 for transmit and 0 for receive buffers. The function may return
NULL if there is no memory available. The current
buffersize can be obtained with buf_size ().
PROCESSING PDUSFor modules that need to do their own PDU processing (for example for proxying) the following functions are available:Function
The function The function The function The function SIMPLE ACTION SUPPORTFor simple scalar variables that need no dependencies a number of support functions is available to handle the set, commit, rollback and get.The following functions are used for OCTET STRING scalars, either NUL terminated or not:
The following functions are used to process scalars of type IP-address:
The following functions handle OID-typed variables:
TABLE INDEX HANDLINGThe following functions help in handling table indexes:
SEE ALSOgensnmptree(1), bsnmpd(1), bsnmpagent(3), bsnmpclient(3), bsnmplib(3)STANDARDSThis implementation conforms to the applicable IETF RFCs and ITU-T recommendations.AUTHORSHartmut Brandt ⟨harti@FreeBSD.org⟩
Visit the GSP FreeBSD Man Page Interface. |