1f06ca4afSHartmut Brandt.\" 2f06ca4afSHartmut Brandt.\" Copyright (c) 2001-2003 3f06ca4afSHartmut Brandt.\" Fraunhofer Institute for Open Communication Systems (FhG Fokus). 4f06ca4afSHartmut Brandt.\" All rights reserved. 5f06ca4afSHartmut Brandt.\" 6f06ca4afSHartmut Brandt.\" Author: Harti Brandt <harti@freebsd.org> 7f06ca4afSHartmut Brandt.\" 8896052c1SHartmut Brandt.\" Redistribution and use in source and binary forms, with or without 9896052c1SHartmut Brandt.\" modification, are permitted provided that the following conditions 10896052c1SHartmut Brandt.\" are met: 11896052c1SHartmut Brandt.\" 1. Redistributions of source code must retain the above copyright 12896052c1SHartmut Brandt.\" notice, this list of conditions and the following disclaimer. 13f06ca4afSHartmut Brandt.\" 2. Redistributions in binary form must reproduce the above copyright 14f06ca4afSHartmut Brandt.\" notice, this list of conditions and the following disclaimer in the 15f06ca4afSHartmut Brandt.\" documentation and/or other materials provided with the distribution. 16f06ca4afSHartmut Brandt.\" 17896052c1SHartmut Brandt.\" THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND 18896052c1SHartmut Brandt.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19896052c1SHartmut Brandt.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20896052c1SHartmut Brandt.\" ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE 21896052c1SHartmut Brandt.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22896052c1SHartmut Brandt.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23896052c1SHartmut Brandt.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24896052c1SHartmut Brandt.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25896052c1SHartmut Brandt.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26896052c1SHartmut Brandt.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27896052c1SHartmut Brandt.\" SUCH DAMAGE. 28f06ca4afSHartmut Brandt.\" 29896052c1SHartmut Brandt.\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.6 2004/08/06 08:46:51 brandt Exp $ 30f06ca4afSHartmut Brandt.\" 31f06ca4afSHartmut Brandt.Dd August 16, 2002 32f06ca4afSHartmut Brandt.Dt bsnmpagent 3 33f06ca4afSHartmut Brandt.Os 34f06ca4afSHartmut Brandt.Sh NAME 358eecd77aSHartmut Brandt.Nm bsnmpagent 36f06ca4afSHartmut Brandt.Nm snmp_depop_t , 37f06ca4afSHartmut Brandt.Nm snmp_op_t , 38f06ca4afSHartmut Brandt.Nm tree , 39f06ca4afSHartmut Brandt.Nm tree_size , 40f06ca4afSHartmut Brandt.Nm snmp_trace , 41f06ca4afSHartmut Brandt.Nm snmp_debug , 42f06ca4afSHartmut Brandt.Nm snmp_get , 43f06ca4afSHartmut Brandt.Nm snmp_getnext , 44f06ca4afSHartmut Brandt.Nm snmp_getbulk , 45f06ca4afSHartmut Brandt.Nm snmp_set , 46f06ca4afSHartmut Brandt.Nm snmp_make_errresp , 47f06ca4afSHartmut Brandt.Nm snmp_dep_lookup , 48f06ca4afSHartmut Brandt.Nm snmp_init_context , 49f06ca4afSHartmut Brandt.Nm snmp_dep_commit , 508eecd77aSHartmut Brandt.Nm snmp_dep_rollback , 518eecd77aSHartmut Brandt.Nm snmp_dep_finish 52f06ca4afSHartmut Brandt.Nd "SNMP agent library" 53f06ca4afSHartmut Brandt.Sh LIBRARY 54f06ca4afSHartmut BrandtBegemot SNMP library 55f06ca4afSHartmut Brandt.Pq libbsnmp, -lbsnmp 56f06ca4afSHartmut Brandt.Sh SYNOPSIS 57f06ca4afSHartmut Brandt.In asn1.h 58f06ca4afSHartmut Brandt.In snmp.h 59f06ca4afSHartmut Brandt.In snmpagent.h 60f06ca4afSHartmut Brandt.Ft typedef int 61f06ca4afSHartmut Brandt.Fn (*snmp_depop_t) "struct snmp_context *ctx" "struct snmp_dependency *dep" "enum snmp_depop op" 62f06ca4afSHartmut Brandt.Ft typedef int 63f06ca4afSHartmut Brandt.Fn (*snmp_op_t) "struct snmp_context *ctx" "struct snmp_value *val" "u_int len" "u_int idx" "enum snmp_op op" 64f06ca4afSHartmut Brandt.Vt extern struct snmp_node *tree ; 65f06ca4afSHartmut Brandt.Vt extern u_int tree_size ; 66f06ca4afSHartmut Brandt.Vt extern u_int snmp_trace ; 67f06ca4afSHartmut Brandt.Vt extern void (*snmp_debug)(const char *fmt, ...) ; 68f06ca4afSHartmut Brandt.Ft enum snmp_ret 69f06ca4afSHartmut Brandt.Fn snmp_get "struct snmp_pdu *pdu" "struct asn_buf *resp_b" "struct snmp_pdu *resp" "void *data" 70f06ca4afSHartmut Brandt.Ft enum snmp_ret 71f06ca4afSHartmut Brandt.Fn snmp_getnext "struct snmp_pdu *pdu" "struct asn_buf *resp_b" "struct snmp_pdu *resp" "void *data" 72f06ca4afSHartmut Brandt.Ft enum snmp_ret 73f06ca4afSHartmut Brandt.Fn snmp_getbulk "struct snmp_pdu *pdu" "struct asn_buf *resp_b" "struct snmp_pdu *resp" "void *data" 74f06ca4afSHartmut Brandt.Ft enum snmp_ret 75f06ca4afSHartmut Brandt.Fn snmp_set "struct snmp_pdu *pdu" "struct asn_buf *resp_b" "struct snmp_pdu *resp" "void *data" 76f06ca4afSHartmut Brandt.Ft enum snmp_ret 77f06ca4afSHartmut Brandt.Fn snmp_make_errresp "const struct snmp_pdu *pdu" "struct asn_buf *req_b" "struct asn_buf *resp_b" 78f06ca4afSHartmut Brandt.Ft struct snmp_dependency * 79f06ca4afSHartmut Brandt.Fn snmp_dep_lookup "struct snmp_context *ctx" "const struct asn_oid *base" "const struct asn_oid *idx" "size_t alloc" "snmp_depop_t func" 80f06ca4afSHartmut Brandt.Ft struct snmp_context * 81f06ca4afSHartmut Brandt.Fn snmp_init_context "void" 82f06ca4afSHartmut Brandt.Ft int 83f06ca4afSHartmut Brandt.Fn snmp_dep_commit "struct snmp_context *ctx" 84f06ca4afSHartmut Brandt.Ft int 85f06ca4afSHartmut Brandt.Fn snmp_dep_rollback "struct snmp_context *ctx" 868eecd77aSHartmut Brandt.Ft void 878eecd77aSHartmut Brandt.Fn snmp_dep_finish "struct snmp_context *ctx" 88f06ca4afSHartmut Brandt.Sh DESCRIPTION 89f06ca4afSHartmut BrandtThe SNMP library contains routines to easily build SNMP agent applications 90f06ca4afSHartmut Brandtthat use SNMP versions 1 or 2. Note, however, that it may be even easier to 91f06ca4afSHartmut Brandtbuild an 92f06ca4afSHartmut Brandt.Xr snmpd 1 93f06ca4afSHartmut Brandtloadable module, that handles the new MIB (see 94f06ca4afSHartmut Brandt.Xr snmpmod 3 ). 95f06ca4afSHartmut Brandt.Pp 96f06ca4afSHartmut BrandtMost of the agent routines operate on a global array that the describes the 97f06ca4afSHartmut Brandtcomplete MIB served by the agent. This array is held in the two variables: 98f06ca4afSHartmut Brandt.Bd -literal -offset indent 99f06ca4afSHartmut Brandtextern struct snmp_node *tree; 100f06ca4afSHartmut Brandtextern u_int tree_size; 101f06ca4afSHartmut Brandt.Ed 102f06ca4afSHartmut Brandt.Pp 103f06ca4afSHartmut BrandtThe elements of the array are of type 104f06ca4afSHartmut Brandt.Vt struct snmp_node : 105f06ca4afSHartmut Brandt.Bd -literal -offset indent 106f06ca4afSHartmut Brandttypedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *, 107f06ca4afSHartmut Brandt u_int, u_int, enum snmp_op); 108f06ca4afSHartmut Brandt 109f06ca4afSHartmut Brandtstruct snmp_node { 110f06ca4afSHartmut Brandt struct asn_oid oid; 111f06ca4afSHartmut Brandt const char *name; /* name of the leaf */ 112f06ca4afSHartmut Brandt enum snmp_node_type type; /* type of this node */ 113f06ca4afSHartmut Brandt enum snmp_syntax syntax; 114f06ca4afSHartmut Brandt snmp_op_t op; 115f06ca4afSHartmut Brandt u_int flags; 116f06ca4afSHartmut Brandt u_int32_t index; /* index data */ 117f06ca4afSHartmut Brandt void *data; /* application data */ 1188eecd77aSHartmut Brandt void *tree_data; /* application data */ 119f06ca4afSHartmut Brandt}; 120f06ca4afSHartmut Brandt.Ed 121f06ca4afSHartmut Brandt.Pp 122f06ca4afSHartmut BrandtThe fields of this structure are described below. 123f06ca4afSHartmut Brandt.Bl -tag -width "syntax" 124f06ca4afSHartmut Brandt.It Va oid 125f06ca4afSHartmut BrandtBase OID of the scalar or table column. 126f06ca4afSHartmut Brandt.It Va name 127f06ca4afSHartmut BrandtName of this variable. 128f06ca4afSHartmut Brandt.It Va type 129f06ca4afSHartmut BrandtType of this variable. One of: 130f06ca4afSHartmut Brandt.Bd -literal -offset indent 131f06ca4afSHartmut Brandtenum snmp_node_type { 132f06ca4afSHartmut Brandt SNMP_NODE_LEAF = 1, 133f06ca4afSHartmut Brandt SNMP_NODE_COLUMN 134f06ca4afSHartmut Brandt}; 135f06ca4afSHartmut Brandt.Ed 136f06ca4afSHartmut Brandt.It Va syntax 137f06ca4afSHartmut BrandtThe SNMP syntax of this variable. 138f06ca4afSHartmut Brandt.It Va op 139f06ca4afSHartmut BrandtThe user supplied handler for this variable. The handler is called with 140f06ca4afSHartmut Brandtthe following arguments: 141f06ca4afSHartmut Brandt.Bl -tag -width "ctx" 142f06ca4afSHartmut Brandt.It Fa ctx 143f06ca4afSHartmut BrandtA pointer to the context (see below). 144f06ca4afSHartmut Brandt.Li NULL . 145f06ca4afSHartmut Brandt.It Fa val 146f06ca4afSHartmut BrandtThe value to be set or retrieved. For GETNEXT and GETBULK operations the oid in 147f06ca4afSHartmut Brandtthis value is the current OID. The function (called in this case only for 148f06ca4afSHartmut Brandttable rows) must find the lexically next existing OID within the same column and 149f06ca4afSHartmut Brandtset the oid and value subfields accordingly. If the table column is exhausted the 150f06ca4afSHartmut Brandtfunction must return 151f06ca4afSHartmut Brandt.Li SNMP_ERR_NOSUCHNAME . 152f06ca4afSHartmut BrandtFor all other operations the oid in 153f06ca4afSHartmut Brandt.Fa val 154f06ca4afSHartmut Brandtis the oid to fetch or set. 155f06ca4afSHartmut Brandt.It Fa len 156f06ca4afSHartmut BrandtThe length of the base oid without index. 157f06ca4afSHartmut Brandt.It Fa idx 158f06ca4afSHartmut BrandtFor table columns this is the index expression from the node (see below). 159f06ca4afSHartmut Brandt.It Fa op 160f06ca4afSHartmut BrandtThis is the operation to execute, one of: 161f06ca4afSHartmut Brandt.Bd -literal -offset indent 162f06ca4afSHartmut Brandtenum snmp_op { 163f06ca4afSHartmut Brandt SNMP_OP_GET = 1, 164f06ca4afSHartmut Brandt SNMP_OP_GETNEXT, 165f06ca4afSHartmut Brandt SNMP_OP_SET, 166f06ca4afSHartmut Brandt SNMP_OP_COMMIT, 167f06ca4afSHartmut Brandt SNMP_OP_ROLLBACK, 168f06ca4afSHartmut Brandt}; 169f06ca4afSHartmut Brandt.Ed 170f06ca4afSHartmut Brandt.El 171f06ca4afSHartmut Brandt.Pp 172f06ca4afSHartmut BrandtThe user handler must return an appropiate SNMP v2 error code. If the original 173f06ca4afSHartmut BrandtPDU was a version 1 PDU, the error code is mapped automatically. 174f06ca4afSHartmut Brandt.It Va flags 175f06ca4afSHartmut BrandtCurrently only the flag 176f06ca4afSHartmut Brandt.Li SNMP_NODE_CANSET is defined and set for nodes, that can be written or 177f06ca4afSHartmut Brandtcreated. 178f06ca4afSHartmut Brandt.It Va index 179f06ca4afSHartmut BrandtThis word describes the index for table columns. Each part of the index 180f06ca4afSHartmut Brandttakes 4 bits starting at bit 4. Bits 0 to 3 hold the number of index parts. 181f06ca4afSHartmut BrandtThis arrangment allows for tables with up to seven indexes. Each bit group 182f06ca4afSHartmut Brandtcontains the syntax for the index part. There are a number of macros to 183f06ca4afSHartmut Brandthelp in parsing this field: 184f06ca4afSHartmut Brandt.Bd -literal -offset indent 185f06ca4afSHartmut Brandt#define SNMP_INDEXES_MAX 7 186f06ca4afSHartmut Brandt#define SNMP_INDEX_SHIFT 4 187f06ca4afSHartmut Brandt#define SNMP_INDEX_MASK 0xf 188f06ca4afSHartmut Brandt#define SNMP_INDEX_COUNT(V) ((V) & SNMP_INDEX_MASK) 189f06ca4afSHartmut Brandt#define SNMP_INDEX(V,I) \e 190f06ca4afSHartmut Brandt (((V) >> (((I) + 1) * SNMP_INDEX_SHIFT)) & \e 191f06ca4afSHartmut Brandt SNMP_INDEX_MASK) 192f06ca4afSHartmut Brandt.Ed 193f06ca4afSHartmut Brandt.It Va data 194f06ca4afSHartmut BrandtThis field may contain arbitrary data and is not used by the library. 195f06ca4afSHartmut Brandt.El 196f06ca4afSHartmut Brandt.Pp 197f06ca4afSHartmut BrandtThe easiest way to construct the node table is 198f06ca4afSHartmut Brandt.Xr gensnmptree 1 . 199f06ca4afSHartmut BrandtNote, that one must be careful when changing the tree while executing a SET 200f06ca4afSHartmut Brandtoperation. Consult the sources for 201f06ca4afSHartmut Brandt.Xr snmpd 1 . 202f06ca4afSHartmut Brandt.Pp 203f06ca4afSHartmut BrandtThe global variable 204f06ca4afSHartmut Brandt.Va snmp_trace 205f06ca4afSHartmut Brandttogether with the function pointed to by 206f06ca4afSHartmut Brandt.Va snmp_debug 207f06ca4afSHartmut Brandthelp in debugging the library and the agent. 208f06ca4afSHartmut Brandt.Va snmp_trace is a bit mask with the following bits: 209f06ca4afSHartmut Brandt.Bd -literal -offset indent 210f06ca4afSHartmut Brandtenum { 211f06ca4afSHartmut Brandt SNMP_TRACE_GET, 212f06ca4afSHartmut Brandt SNMP_TRACE_GETNEXT, 213f06ca4afSHartmut Brandt SNMP_TRACE_SET, 214f06ca4afSHartmut Brandt SNMP_TRACE_DEPEND, 215f06ca4afSHartmut Brandt SNMP_TRACE_FIND, 216f06ca4afSHartmut Brandt}; 217f06ca4afSHartmut Brandt.Ed 218f06ca4afSHartmut Brandt.Pp 219f06ca4afSHartmut BrandtSetting a bit to true causes the library to call 220f06ca4afSHartmut Brandt.Fn snmp_debug 221f06ca4afSHartmut Brandtin strategic places with a debug string. The library contains a default 222f06ca4afSHartmut Brandtimplementation for the debug function that prints a message to standard error. 223f06ca4afSHartmut Brandt.Pp 224f06ca4afSHartmut BrandtMany of the functions use a so called context: 225f06ca4afSHartmut Brandt.Bd -literal -offset indent 226f06ca4afSHartmut Brandtstruct snmp_context { 227f06ca4afSHartmut Brandt u_int var_index; 228f06ca4afSHartmut Brandt struct snmp_scratch *scratch; 229f06ca4afSHartmut Brandt struct snmp_dependency *dep; 230f06ca4afSHartmut Brandt void *data; /* user data */ 2318eecd77aSHartmut Brandt enum snmp_ret code; /* return code */ 232f06ca4afSHartmut Brandt}; 233f06ca4afSHartmut Brandt 234f06ca4afSHartmut Brandtstruct snmp_scratch { 235f06ca4afSHartmut Brandt void *ptr1; 236f06ca4afSHartmut Brandt void *ptr2; 237f06ca4afSHartmut Brandt u_int32_t int1; 238f06ca4afSHartmut Brandt u_int32_t int2; 239f06ca4afSHartmut Brandt}; 240f06ca4afSHartmut Brandt.Ed 241f06ca4afSHartmut Brandt.Pp 242f06ca4afSHartmut BrandtThe fields are used as follows: 243f06ca4afSHartmut Brandt.Bl -tag -width ".It Va var_index" 244f06ca4afSHartmut Brandt.It Va va_index 245f06ca4afSHartmut BrandtFor the node operation callback this is the 246f06ca4afSHartmut Brandtindex of the variable binding that should be returned if an error occures. 247f06ca4afSHartmut BrandtSet by the library. In all other functions this is undefined. 248f06ca4afSHartmut Brandt.It Va scratch 249f06ca4afSHartmut BrandtFor the node operation callback this is a pointer to a per variable binding 250f06ca4afSHartmut Brandtscratch area that can be used to implement the commit and rollback. Set 251f06ca4afSHartmut Brandtby the library. 252f06ca4afSHartmut Brandt.It Va dep 253f06ca4afSHartmut BrandtIn the dependency callback function (see below) this is a pointer to the 254f06ca4afSHartmut Brandtcurrent dependency. Set by the library. 255f06ca4afSHartmut Brandt.It Va data 256f06ca4afSHartmut BrandtThis is the 257f06ca4afSHartmut Brandt.Fa data 258f06ca4afSHartmut Brandtargument from the call to the library and is not used by the library. 259f06ca4afSHartmut Brandt.El 260f06ca4afSHartmut Brandt.Pp 261f06ca4afSHartmut BrandtThe next three functions execute different kinds of GET requests. 262f06ca4afSHartmut BrandtThe function 263f06ca4afSHartmut Brandt.Fn snmp_get 264f06ca4afSHartmut Brandtexecutes an SNMP GET operation, the function 265f06ca4afSHartmut Brandt.Fn snmp_getnext 266f06ca4afSHartmut Brandtexecutes an SNMP GETNEXT operation and the function 267f06ca4afSHartmut Brandt.Fn snmp_getbulk 268f06ca4afSHartmut Brandtexecutes an SNMP GETBULK operation. 269f06ca4afSHartmut BrandtFor all three functions the response PDU is constructed and encoded 270f06ca4afSHartmut Brandton the fly. If everything is ok, the response PDU is returned in 271f06ca4afSHartmut Brandt.Fa resp 272f06ca4afSHartmut Brandtand 273f06ca4afSHartmut Brandt.Fa resp_b . 274f06ca4afSHartmut BrandtThe caller must call 275f06ca4afSHartmut Brandt.Fn snmp_pdu_free 276f06ca4afSHartmut Brandtto free the response PDU in this case. One of the following values may be 277f06ca4afSHartmut Brandtreturned: 278f06ca4afSHartmut Brandt.Bl -tag -width ".It Li SNMP_RET_ERR" 279f06ca4afSHartmut Brandt.It Li SNMP_RET_OK 280f06ca4afSHartmut BrandtOperation successful, response PDU may be sent. 281f06ca4afSHartmut Brandt.It Li SNMP_RET_IGN 282f06ca4afSHartmut BrandtOperation failed, no response PDU constructed. Request is ignored. 283f06ca4afSHartmut Brandt.It Li SNMP_RET_ERR 284f06ca4afSHartmut BrandtError in operation. The error code and index have been set in 285f06ca4afSHartmut Brandt.Fa pdu . 286f06ca4afSHartmut BrandtNo response PDU has been constructed. 287f06ca4afSHartmut BrandtThe caller may construct an error response PDU via 288f06ca4afSHartmut Brandt.Fn snmp_make_errresp . 289f06ca4afSHartmut Brandt.El 290f06ca4afSHartmut Brandt.Pp 291f06ca4afSHartmut BrandtThe function 292f06ca4afSHartmut Brandt.Fn snmp_set 293f06ca4afSHartmut Brandtexecutes an SNMP SET operation. The arguments are the same as for the previous 294f06ca4afSHartmut Brandtthree functions. The operation of this functions is, however, much more complex. 295f06ca4afSHartmut Brandt.Pp 296f06ca4afSHartmut BrandtThe SET operation occures in several stages: 297f06ca4afSHartmut Brandt.Bl -enum -offset indent 298f06ca4afSHartmut Brandt.It 299f06ca4afSHartmut BrandtFor each binding search the corresponding nodes, check that the 300f06ca4afSHartmut Brandtvariable is writeable and the syntax is ok. The writeable check can be done 301f06ca4afSHartmut Brandtonly for scalars. For columns it must be done in the node's operation callback 302f06ca4afSHartmut Brandtfunction. 303f06ca4afSHartmut Brandt.It 304f06ca4afSHartmut BrandtFor each binding call the node's operation callback with function SNMP_OP_SET. 305f06ca4afSHartmut BrandtThe callback may create dependencies or finalizers (see below). For simple 306f06ca4afSHartmut Brandtscalars the scratch area may be enough to handle commit and rollback, for 307f06ca4afSHartmut Brandtinterdependend table columns dependencies may be necessary. 308f06ca4afSHartmut Brandt.It 309f06ca4afSHartmut BrandtIf the previous step fails at any point, the node's operation callback 310f06ca4afSHartmut Brandtfunctions are called for all bindings for which SNMP_OP_SET was executed 311f06ca4afSHartmut Brandtwith SNMP_OP_ROLLBACK, in the opposite order. This allows all variables to 312f06ca4afSHartmut Brandtundo the effect of the SET operation. After this all the dependencies 313f06ca4afSHartmut Brandtare freed 314f06ca4afSHartmut Brandtand the finalizers are executed with a fail flag of 1. Then the function 315f06ca4afSHartmut Brandtreturns to the caller with an appropriate error indication. 316f06ca4afSHartmut Brandt.It 317f06ca4afSHartmut BrandtIf the SET step was successful for all bindings, the dependency callbacks 318f06ca4afSHartmut Brandtare executed in the order in which the dependencies were created with an 319f06ca4afSHartmut Brandtoperation of SNMP_DEPOP_COMMIT. If any of the dependencies fails, all the 320f06ca4afSHartmut Brandtcommitted dependencies are called again in the opposite order 321f06ca4afSHartmut Brandtwith SNMP_DEPOP_ROLLBACK. Than for all bindings from the last to the first 322f06ca4afSHartmut Brandtthe node's operation callback is called with SNMP_OP_ROLLBACK to undo 323f06ca4afSHartmut Brandtthe effect of SNMP_OP_SET. At the end the dependencies are freed 324f06ca4afSHartmut Brandtand the finalizers are called with a fail flag 325f06ca4afSHartmut Brandtof 1 and the function returns to the caller with an appropriate error indication. 326f06ca4afSHartmut Brandt.It 327f06ca4afSHartmut BrandtIf the dependency commits were successful, for each binding the node's 328f06ca4afSHartmut Brandtoperation callback is called with SNMP_OP_COMMIT. Any error returned from 329f06ca4afSHartmut Brandtthe callbacks is ignored (an error message is generated via 330f06ca4afSHartmut Brandt.Fn snmp_error ). 331f06ca4afSHartmut Brandt.It 332f06ca4afSHartmut BrandtNow the dependencies are freed and the finalizers are called 3338eecd77aSHartmut Brandtwith a fail flag of 0. For each dependency just before freeing it 3348eecd77aSHartmut Brandtits callback is called with 3358eecd77aSHartmut Brandt.Li SNMP_DEPOP_FINISH. 3368eecd77aSHartmut BrandtThen the function returns 337f06ca4afSHartmut Brandt.Li SNMP_ERR_OK . 338f06ca4afSHartmut Brandt.El 339f06ca4afSHartmut Brandt.Pp 340f06ca4afSHartmut BrandtThere are to mechanisms to help in complex SET operations: dependencies and 341f06ca4afSHartmut Brandtfinalizers. A dependency is used if several bindings depend on each other. 342f06ca4afSHartmut BrandtA typical example is the creation of a conceptual row, which requires 343f06ca4afSHartmut Brandtthe setting of several columns to succeed. A dependency is identified by 344f06ca4afSHartmut Brandttwo OIDs. In the table case, the first oid is typically the table's base OID 345f06ca4afSHartmut Brandtand the second one the index. Both of these can easily be generated from the 346f06ca4afSHartmut Brandtvariables OID with 347f06ca4afSHartmut Brandt.Fn asn_slice_oid . 348f06ca4afSHartmut BrandtThe function 349f06ca4afSHartmut Brandt.Fn snmp_dep_lookup 350f06ca4afSHartmut Brandttries to find a dependency based on these two OIDs and, if it cannot find one 351f06ca4afSHartmut Brandtcreates a new one. This means for the table example, that the function 352f06ca4afSHartmut Brandtreturns the same dependency for each of the columns of the same table row. 353f06ca4afSHartmut BrandtThis allows during the SNMP_OP_SET processing to collect all information 354f06ca4afSHartmut Brandtabout the row into the dependency. The arguments to 355f06ca4afSHartmut Brandt.Fn snmp_dep_lookup 356f06ca4afSHartmut Brandtare: the two OIDs to identify the dependency (they are copied into newly 357f06ca4afSHartmut Brandtcreated dependencies), the size of the structure to allocate and 358f06ca4afSHartmut Brandtthe dependency callback. 359f06ca4afSHartmut Brandt.Pp 360f06ca4afSHartmut BrandtWhen all SNMP_OP_SET operations have succeeded the dependencies are executed. 361f06ca4afSHartmut BrandtAt this stage the dependency callback has all information about the given 362f06ca4afSHartmut Brandttable row that was available in this SET PDU and can operate accordingly. 363f06ca4afSHartmut Brandt.Pp 3648eecd77aSHartmut BrandtIt is guaranteed that each dependency callback is executed at minimum once 3658eecd77aSHartmut Brandt- with an operation of 3668eecd77aSHartmut Brandt.Li SNMP_OP_ROLLBACK . 3678eecd77aSHartmut BrandtThis ensures that all dynamically allocated resources in a callback can be 3688eecd77aSHartmut Brandtfreed correctly. 369f06ca4afSHartmut Brandt.Pp 370f06ca4afSHartmut BrandtThe function 371f06ca4afSHartmut Brandt.Fn snmp_make_errresp 372f06ca4afSHartmut Brandtmakes an error response if an operation has failed. It takes the original 373f06ca4afSHartmut Brandtrequest PDU (it will look only on the error code and index fields), the 374f06ca4afSHartmut Brandtbuffer containing the original PDU and a buffer for the error PDU. It copies 375f06ca4afSHartmut Brandtthe bindings field from the original PDUs buffer directly to the response 376f06ca4afSHartmut BrandtPDU and thus does not depend on the decodability of this field. It may return 377f06ca4afSHartmut Brandtthe same values as the operation functions. 378f06ca4afSHartmut Brandt.Pp 3798eecd77aSHartmut BrandtThe next four functions allow some parts of the SET operation to be executed. 380f06ca4afSHartmut BrandtThis is only used in 381f06ca4afSHartmut Brandt.Xr snmpd 1 382f06ca4afSHartmut Brandtto implement the configuration as a single transaction. 383f06ca4afSHartmut BrandtThe function 384f06ca4afSHartmut Brandt.Fn snmp_init_context 385f06ca4afSHartmut Brandtcreates and initializes a context. 386f06ca4afSHartmut BrandtThe function 387f06ca4afSHartmut Brandt.Fn snmp_dep_commit 388f06ca4afSHartmut Brandtexecutes SNMP_DEPOP_COMMIT for all dependencies in the context stopping at 389f06ca4afSHartmut Brandtthe first error. 390f06ca4afSHartmut BrandtThe function 391f06ca4afSHartmut Brandt.Fn snmp_dep_rollback 392f06ca4afSHartmut Brandtexecutes SNMP_DEPOP_ROLLBACK starting at the previous of the current 393f06ca4afSHartmut Brandtdependency in the context. 3948eecd77aSHartmut BrandtThe function 3958eecd77aSHartmut Brandt.Fn snmp_dep_finish 3968eecd77aSHartmut Brandtexecutes SNMP_DEPOP_FINISH for all dependencies. 397f06ca4afSHartmut Brandt.Sh DIAGNOSTICS 398f06ca4afSHartmut BrandtIf an error occures in any of the function an error indication as described 399f06ca4afSHartmut Brandtabove is returned. Additionally the functions may call snmp_error on unexected 400f06ca4afSHartmut Brandterrors. 401f06ca4afSHartmut Brandt.Sh SEE ALSO 402f06ca4afSHartmut Brandt.Xr snmpd 1 , 403f06ca4afSHartmut Brandt.Xr gensnmptree 1 , 404f06ca4afSHartmut Brandt.Xr bsnmplib 3 405f06ca4afSHartmut Brandt.Xr bsnmpclient 3 , 406f06ca4afSHartmut Brandt.Xr snmpmod 3 407f06ca4afSHartmut Brandt.Sh STANDARDS 408f06ca4afSHartmut BrandtThis implementation conforms to the applicable IETF RFCs and ITU-T 409f06ca4afSHartmut Brandtrecommendations. 410f06ca4afSHartmut Brandt.Sh AUTHORS 4118eecd77aSHartmut Brandt.An Hartmut Brandt Aq harti@freebsd.org 412