summaryrefslogtreecommitdiffstats
path: root/contrib/bsnmp/lib
diff options
context:
space:
mode:
authorharti <harti@FreeBSD.org>2004-04-14 16:20:14 +0000
committerharti <harti@FreeBSD.org>2004-04-14 16:20:14 +0000
commit2dce00c891322ea0439dacc8b83fa1965ba5c2dc (patch)
tree4ab07393a68643de15ecd9eb3d4baa678839c746 /contrib/bsnmp/lib
parentc1b6f5303fde40ed2a5a4dfd652664a790b6d77d (diff)
downloadFreeBSD-src-2dce00c891322ea0439dacc8b83fa1965ba5c2dc.zip
FreeBSD-src-2dce00c891322ea0439dacc8b83fa1965ba5c2dc.tar.gz
Import of bsnmpd 1.6
Diffstat (limited to 'contrib/bsnmp/lib')
-rw-r--r--contrib/bsnmp/lib/asn1.34
-rw-r--r--contrib/bsnmp/lib/bsnmpagent.346
-rw-r--r--contrib/bsnmp/lib/bsnmpclient.34
-rw-r--r--contrib/bsnmp/lib/bsnmplib.34
-rw-r--r--contrib/bsnmp/lib/snmpagent.c78
-rw-r--r--contrib/bsnmp/lib/snmpagent.h33
6 files changed, 65 insertions, 104 deletions
diff --git a/contrib/bsnmp/lib/asn1.3 b/contrib/bsnmp/lib/asn1.3
index ec01b9a..aa63bdf 100644
--- a/contrib/bsnmp/lib/asn1.3
+++ b/contrib/bsnmp/lib/asn1.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/asn1.3,v 1.3 2003/12/02 15:45:48 hbb Exp $
+.\" $Begemot: bsnmp/lib/asn1.3,v 1.4 2004/04/13 17:01:31 novo Exp $
.\"
.Dd August 15, 2002
.Dt asn1 3
@@ -481,4 +481,4 @@ followed by the error message and an optional dump of the buffer.
This implementation conforms to the applicable IETF RFCs and ITU-T
recommendations.
.Sh AUTHORS
-.An Hartmut Brandt Aq brandt@fokus.gmd.de
+.An Hartmut Brandt Aq harti@freebsd.org
diff --git a/contrib/bsnmp/lib/bsnmpagent.3 b/contrib/bsnmp/lib/bsnmpagent.3
index ad2f628..7afedcb 100644
--- a/contrib/bsnmp/lib/bsnmpagent.3
+++ b/contrib/bsnmp/lib/bsnmpagent.3
@@ -30,14 +30,14 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.2 2003/12/02 16:13:45 hbb Exp $
+.\" $Begemot: bsnmp/lib/bsnmpagent.3,v 1.5 2004/04/13 17:01:31 novo Exp $
.\"
.Dd August 16, 2002
.Dt bsnmpagent 3
.Os
.Sh NAME
+.Nm bsnmpagent
.Nm snmp_depop_t ,
-.Nm snmp_set_finish_t ,
.Nm snmp_op_t ,
.Nm tree ,
.Nm tree_size ,
@@ -49,10 +49,10 @@
.Nm snmp_set ,
.Nm snmp_make_errresp ,
.Nm snmp_dep_lookup ,
-.Nm snmp_set_atfinish ,
.Nm snmp_init_context ,
.Nm snmp_dep_commit ,
-.Nm snmp_dep_rollback
+.Nm snmp_dep_rollback ,
+.Nm snmp_dep_finish
.Nd "SNMP agent library"
.Sh LIBRARY
Begemot SNMP library
@@ -63,8 +63,6 @@ Begemot SNMP library
.In snmpagent.h
.Ft typedef int
.Fn (*snmp_depop_t) "struct snmp_context *ctx" "struct snmp_dependency *dep" "enum snmp_depop op"
-.Ft typedef void
-.Fn (*snmp_set_finish_t) "struct snmp_context *ctx" "int fail" "void *uarg"
.Ft typedef int
.Fn (*snmp_op_t) "struct snmp_context *ctx" "struct snmp_value *val" "u_int len" "u_int idx" "enum snmp_op op"
.Vt extern struct snmp_node *tree ;
@@ -83,14 +81,14 @@ Begemot SNMP library
.Fn snmp_make_errresp "const struct snmp_pdu *pdu" "struct asn_buf *req_b" "struct asn_buf *resp_b"
.Ft struct snmp_dependency *
.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"
-.Ft int
-.Fn snmp_set_atfinish "struct snmp_context *ctx" "snmp_set_finish_t func" "void *uarg"
.Ft struct snmp_context *
.Fn snmp_init_context "void"
.Ft int
.Fn snmp_dep_commit "struct snmp_context *ctx"
.Ft int
.Fn snmp_dep_rollback "struct snmp_context *ctx"
+.Ft void
+.Fn snmp_dep_finish "struct snmp_context *ctx"
.Sh DESCRIPTION
The SNMP library contains routines to easily build SNMP agent applications
that use SNMP versions 1 or 2. Note, however, that it may be even easier to
@@ -121,6 +119,7 @@ struct snmp_node {
u_int flags;
u_int32_t index; /* index data */
void *data; /* application data */
+ void *tree_data; /* application data */
};
.Ed
.Pp
@@ -233,6 +232,7 @@ struct snmp_context {
struct snmp_scratch *scratch;
struct snmp_dependency *dep;
void *data; /* user data */
+ enum snmp_ret code; /* return code */
};
struct snmp_scratch {
@@ -334,7 +334,10 @@ the callbacks is ignored (an error message is generated via
.Fn snmp_error ).
.It
Now the dependencies are freed and the finalizers are called
-with a fail flag of 0. Then the function returns
+with a fail flag of 0. For each dependency just before freeing it
+its callback is called with
+.Li SNMP_DEPOP_FINISH.
+Then the function returns
.Li SNMP_ERR_OK .
.El
.Pp
@@ -362,19 +365,11 @@ When all SNMP_OP_SET operations have succeeded the dependencies are executed.
At this stage the dependency callback has all information about the given
table row that was available in this SET PDU and can operate accordingly.
.Pp
-If a SNMP_OP_SET operation fails, the dependency callbacks are never
-called. The nodes SNMP_OP_ROLLBACK operations have to ensure, that
-any dynamically allocated data is freed.
-.Pp
-Finalizers are a
-.Sq last change
-to do processing.
-They are called after everything has been done, just before returning to the
-user. They get a flag, that tells them, whether the return to the user is a good
-one or not. The typical use is to finally remove deleted table elements.
-Finalizers are created with
-.Fn snmp_set_atfinish
-which takes the callback function and a user data pointer as argument.
+It is guaranteed that each dependency callback is executed at minimum once
+- with an operation of
+.Li SNMP_OP_ROLLBACK .
+This ensures that all dynamically allocated resources in a callback can be
+freed correctly.
.Pp
The function
.Fn snmp_make_errresp
@@ -385,7 +380,7 @@ the bindings field from the original PDUs buffer directly to the response
PDU and thus does not depend on the decodability of this field. It may return
the same values as the operation functions.
.Pp
-The next three functions allow some parts of the SET operation to be executed.
+The next four functions allow some parts of the SET operation to be executed.
This is only used in
.Xr snmpd 1
to implement the configuration as a single transaction.
@@ -400,6 +395,9 @@ The function
.Fn snmp_dep_rollback
executes SNMP_DEPOP_ROLLBACK starting at the previous of the current
dependency in the context.
+The function
+.Fn snmp_dep_finish
+executes SNMP_DEPOP_FINISH for all dependencies.
.Sh DIAGNOSTICS
If an error occures in any of the function an error indication as described
above is returned. Additionally the functions may call snmp_error on unexected
@@ -414,4 +412,4 @@ errors.
This implementation conforms to the applicable IETF RFCs and ITU-T
recommendations.
.Sh AUTHORS
-.An Hartmut Brandt Aq brandt@fokus.gmd.de
+.An Hartmut Brandt Aq harti@freebsd.org
diff --git a/contrib/bsnmp/lib/bsnmpclient.3 b/contrib/bsnmp/lib/bsnmpclient.3
index a4996c4..0120a53 100644
--- a/contrib/bsnmp/lib/bsnmpclient.3
+++ b/contrib/bsnmp/lib/bsnmpclient.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.5 2003/12/08 17:11:58 hbb Exp $
+.\" $Begemot: bsnmp/lib/bsnmpclient.3,v 1.6 2004/04/13 17:01:31 novo Exp $
.\"
.Dd August 15, 2002
.Dt bsnmpclient 3
@@ -592,5 +592,5 @@ filed of
This implementation conforms to the applicable IETF RFCs and ITU-T
recommendations.
.Sh AUTHORS
-.An Hartmut Brandt Aq brandt@fokus.gmd.de
+.An Hartmut Brandt Aq harti@freebsd.org
.An Kendy Kutzner Aq kutzner@fokus.gmd.de
diff --git a/contrib/bsnmp/lib/bsnmplib.3 b/contrib/bsnmp/lib/bsnmplib.3
index 8f7fcb4..6af381d 100644
--- a/contrib/bsnmp/lib/bsnmplib.3
+++ b/contrib/bsnmp/lib/bsnmplib.3
@@ -30,7 +30,7 @@
.\" NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
-.\" $Begemot: bsnmp/lib/bsnmplib.3,v 1.3 2003/12/02 16:14:28 hbb Exp $
+.\" $Begemot: bsnmp/lib/bsnmplib.3,v 1.4 2004/04/13 17:01:31 novo Exp $
.\"
.Dd August 15, 2002
.Dt bsnmplib 3
@@ -303,4 +303,4 @@ Encoding failed.
This implementation conforms to the applicable IETF RFCs and ITU-T
recommendations.
.Sh AUTHORS
-.An Hartmut Brandt Aq brandt@fokus.gmd.de
+.An Hartmut Brandt Aq harti@freebsd.org
diff --git a/contrib/bsnmp/lib/snmpagent.c b/contrib/bsnmp/lib/snmpagent.c
index c03b606..965c043 100644
--- a/contrib/bsnmp/lib/snmpagent.c
+++ b/contrib/bsnmp/lib/snmpagent.c
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmpagent.c,v 1.16 2003/12/03 09:55:58 hbb Exp $
+ * $Begemot: bsnmp/lib/snmpagent.c,v 1.17 2004/04/13 14:58:46 novo Exp $
*
* SNMP Agent functions
*/
@@ -69,22 +69,11 @@ struct depend {
TAILQ_HEAD(depend_list, depend);
/*
- * Structure to hold atfinish functions during SET processing.
- */
-struct finish {
- STAILQ_ENTRY(finish) link;
- snmp_set_finish_t func;
- void *arg;
-};
-STAILQ_HEAD(finish_list, finish);
-
-/*
* Set context
*/
struct context {
struct snmp_context ctx;
struct depend_list dlist;
- struct finish_list flist;
const struct snmp_node *node[SNMP_MAX_BINDINGS];
struct snmp_scratch scratch[SNMP_MAX_BINDINGS];
struct depend *depend;
@@ -108,7 +97,6 @@ snmp_init_context(void)
memset(context, 0, sizeof(*context));
TAILQ_INIT(&context->dlist);
- STAILQ_INIT(&context->flist);
return (&context->ctx);
}
@@ -621,6 +609,20 @@ snmp_dep_rollback(struct snmp_context *ctx)
return (ret1);
}
+void
+snmp_dep_finish(struct snmp_context *ctx)
+{
+ struct context *context = (struct context *)ctx;
+ struct depend *d;
+
+ while ((d = TAILQ_FIRST(&context->dlist)) != NULL) {
+ ctx->dep = &d->dep;
+ (void)d->func(ctx, ctx->dep, SNMP_DEPOP_FINISH);
+ TAILQ_REMOVE(&context->dlist, d, link);
+ free(d);
+ }
+}
+
/*
* Do a SET operation.
*/
@@ -630,18 +632,14 @@ snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
{
int ret;
u_int i;
- enum snmp_ret code;
enum asn_err asnerr;
struct context context;
const struct snmp_node *np;
- struct finish *f;
- struct depend *d;
struct snmp_value *b;
enum snmp_syntax except;
memset(&context, 0, sizeof(context));
TAILQ_INIT(&context.dlist);
- STAILQ_INIT(&context.flist);
context.ctx.data = data;
memset(resp, 0, sizeof(*resp));
@@ -739,7 +737,7 @@ snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
resp->nbindings++;
}
- code = SNMP_RET_OK;
+ context.ctx.code = SNMP_RET_OK;
/*
* 2. Call the SET method for each node. If a SET fails, rollback
@@ -811,7 +809,7 @@ snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
rollback(&context, pdu, i);
snmp_pdu_free(resp);
- code = SNMP_RET_ERR;
+ context.ctx.code = SNMP_RET_ERR;
goto errout;
}
@@ -836,7 +834,7 @@ snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
rollback(&context, pdu, i);
snmp_pdu_free(resp);
- code = SNMP_RET_ERR;
+ context.ctx.code = SNMP_RET_ERR;
goto errout;
}
@@ -868,31 +866,19 @@ snmp_set(struct snmp_pdu *pdu, struct asn_buf *resp_b,
if (snmp_fix_encoding(resp_b, resp) != SNMP_CODE_OK) {
snmp_error("set: fix_encoding failed");
snmp_pdu_free(resp);
- code = SNMP_RET_IGN;
+ context.ctx.code = SNMP_RET_IGN;
}
/*
* Done
*/
errout:
- while ((d = TAILQ_FIRST(&context.dlist)) != NULL) {
- TAILQ_REMOVE(&context.dlist, d, link);
- free(d);
- }
-
- /*
- * call finish function
- */
- while ((f = STAILQ_FIRST(&context.flist)) != NULL) {
- STAILQ_REMOVE_HEAD(&context.flist, link);
- (*f->func)(&context.ctx, code != SNMP_RET_OK, f->arg);
- free(f);
- }
+ snmp_dep_finish(&context.ctx);
if (TR(SET))
- snmp_debug("set: returning %d", code);
+ snmp_debug("set: returning %d", context.ctx.code);
- return (code);
+ return (context.ctx.code);
}
/*
* Lookup a dependency. If it doesn't exist, create one
@@ -941,26 +927,6 @@ snmp_dep_lookup(struct snmp_context *ctx, const struct asn_oid *obj,
}
/*
- * Register a finish function.
- */
-int
-snmp_set_atfinish(struct snmp_context *ctx, snmp_set_finish_t func, void *arg)
-{
- struct context *context;
- struct finish *f;
-
- context = (struct context *)(void *)
- ((char *)ctx - offsetof(struct context, ctx));
- if ((f = malloc(sizeof(struct finish))) == NULL)
- return (-1);
- f->func = func;
- f->arg = arg;
- STAILQ_INSERT_TAIL(&context->flist, f, link);
-
- return (0);
-}
-
-/*
* Make an error response from a PDU. We do this without decoding the
* variable bindings. This means we can sent the junk back to a caller
* that has sent us junk in the first place.
diff --git a/contrib/bsnmp/lib/snmpagent.h b/contrib/bsnmp/lib/snmpagent.h
index cd89456..1a26935 100644
--- a/contrib/bsnmp/lib/snmpagent.h
+++ b/contrib/bsnmp/lib/snmpagent.h
@@ -30,7 +30,7 @@
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Begemot: bsnmp/lib/snmpagent.h,v 1.10 2003/12/03 09:55:58 hbb Exp $
+ * $Begemot: bsnmp/lib/snmpagent.h,v 1.12 2004/04/13 15:18:15 novo Exp $
*
* Header file for SNMP functions. This requires snmp.h to be included.
*/
@@ -39,12 +39,22 @@
struct snmp_dependency;
+enum snmp_ret {
+ /* OK, generate a response */
+ SNMP_RET_OK = 0,
+ /* Error, ignore packet (no response) */
+ SNMP_RET_IGN = 1,
+ /* Error, generate response from original packet */
+ SNMP_RET_ERR = 2
+};
+
/* Semi-Opaque object for SET operations */
struct snmp_context {
u_int var_index;
struct snmp_scratch *scratch;
struct snmp_dependency *dep;
void *data; /* user data */
+ enum snmp_ret code; /* return code */
};
struct snmp_scratch {
@@ -56,7 +66,8 @@ struct snmp_scratch {
enum snmp_depop {
SNMP_DEPOP_COMMIT,
- SNMP_DEPOP_ROLLBACK
+ SNMP_DEPOP_ROLLBACK,
+ SNMP_DEPOP_FINISH
};
typedef int (*snmp_depop_t)(struct snmp_context *, struct snmp_dependency *,
@@ -68,11 +79,6 @@ struct snmp_dependency {
};
/*
- * Functions to be called at the end of a SET operation.
- */
-typedef void (*snmp_set_finish_t)(struct snmp_context *, int fail, void *);
-
-/*
* The TREE
*/
enum snmp_node_type {
@@ -88,15 +94,6 @@ enum snmp_op {
SNMP_OP_ROLLBACK,
};
-enum snmp_ret {
- /* OK, generate a response */
- SNMP_RET_OK = 0,
- /* Error, ignore packet (no response) */
- SNMP_RET_IGN = 1,
- /* Error, generate response from original packet */
- SNMP_RET_ERR = 2
-};
-
typedef int (*snmp_op_t)(struct snmp_context *, struct snmp_value *,
u_int, u_int, enum snmp_op);
@@ -109,6 +106,7 @@ struct snmp_node {
u_int flags;
u_int32_t index; /* index data */
void *data; /* application data */
+ void *tree_data; /* application data */
};
extern struct snmp_node *tree;
extern u_int tree_size;
@@ -150,10 +148,9 @@ enum snmp_ret snmp_make_errresp(const struct snmp_pdu *, struct asn_buf *,
struct snmp_dependency *snmp_dep_lookup(struct snmp_context *,
const struct asn_oid *, const struct asn_oid *, size_t, snmp_depop_t);
-int snmp_set_atfinish(struct snmp_context *, snmp_set_finish_t func, void *arg);
-
struct snmp_context *snmp_init_context(void);
int snmp_dep_commit(struct snmp_context *);
int snmp_dep_rollback(struct snmp_context *);
+void snmp_dep_finish(struct snmp_context *);
#endif
OpenPOWER on IntegriCloud