diff options
24 files changed, 704 insertions, 235 deletions
diff --git a/contrib/bsnmp/NEWS b/contrib/bsnmp/NEWS index 01281ec..f9f6a53 100644 --- a/contrib/bsnmp/NEWS +++ b/contrib/bsnmp/NEWS @@ -1,3 +1,36 @@ +1.6 + New gensnmpdef tool. Needs libsmi. + + Make build infrastructure more intelligent. + + Fix a typo in the mibII counter retrival code. + + Add a new field to struct snmp_node for snmp agents: tree_data. + This field can be used by the application. + + Fix a syntax error in the example configuration file (thanks to + David J Duchscher). + + Fix a long standing problem with the module loading code + and a memory leak. When a module could not be loaded usually + a core dump was generated. This was caused by wrong handling + of malloced memory in the module table dependency. While + fixing this problem it became obvious that dynamic allocated + data which was held in a dependency could be lost, because + there was no guarantee that the dependency handler ever was + call (in case of an error in a SET handler or an earlier + dependency in the same PDU) thus causing this memory to leak. + To fix this a third dependency operation is introduced + SNMP_DEPOP_FINISH which is invoked just before a dependency + is freed at the very end of the SET PDU handling. This + means also that finalizers (set_atfinish) can be converted + to DEPOP_FINISH handler in almost all cases. The only case + where this is not so easy is when a finializer was registered + for a simple SET operation. In this case an artifical dependency + would be needed. Because this seems to occure very seldom the + snmp_set_atfinish() call is removed. Thanks to Paul-Henning Kamp + for an initial fix for the core dump. + 09-Dec-2003 First step on factoring out the transport mapping stuff into loadable modules. diff --git a/contrib/bsnmp/VERSION b/contrib/bsnmp/VERSION index 941c596..810ee4e 100644 --- a/contrib/bsnmp/VERSION +++ b/contrib/bsnmp/VERSION @@ -1 +1 @@ -1.5a +1.6 diff --git a/contrib/bsnmp/gensnmpdef/gensnmpdef.1 b/contrib/bsnmp/gensnmpdef/gensnmpdef.1 new file mode 100644 index 0000000..2bcb440 --- /dev/null +++ b/contrib/bsnmp/gensnmpdef/gensnmpdef.1 @@ -0,0 +1,73 @@ +.\" +.\" Copyright (c) 2004 +.\" Hartmut Brandt +.\" All rights reserved. +.\" +.\" Redistribution of this software and documentation and use in source and +.\" binary forms, with or without modification, are permitted provided that +.\" the following conditions are met: +.\" +.\" 1. Redistributions of source code or documentation must retain the above +.\" copyright notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. Neither the name of the author nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE AUTHOR +.\" AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, +.\" INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND +.\" FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL +.\" THE AUTHOR OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +.\" LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, +.\" OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF +.\" LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +.\" 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/gensnmpdef/gensnmpdef.1,v 1.1 2004/04/14 09:54:51 novo Exp $ +.\" +.\" Author: Harti Brandt <harti@freebsd.org> +.\" +.Dd April 14, 2004 +.Dt gensnmpdef 1 +.Os +.Sh NAME +.Nm gensnmpdef +.Nd "generate a MIB description file from MIBs" +.Sh SYNOPSIS +.Nm +.Op Fl h +.Op Fl c Ar cut +.Ar name Op Ar ... +.Sh DESCRIPTION +The +.Nm +utility is used to create an initial MIB description file from +one or more MIBs. The description file must be edited to be actually useful +for feeding it into +.Xr gensnmptree 1 . +.Pp +The +.Fl c +option specifies the number of initial sub-oids that should be omitted +from the tree. +.Xr gensnmptree 1 +automatically adds 1.3.6 in front of all OIDs so the default value +of 3 is just correct in most cases. +.Pp +.Nm +does no attempt on sorting the OID tree so in case of complex and +non-standard MIBs it is necessay to sort the tree in the resulting definition +file by hand. +.Sh SEE ALSO +.Xr snmpd 1 +.Sh BUGS +The utility is by no means bullet-proof and may fail for complex +or non-standard MIBs. +Its output is expected to be edited by hand. +.Sh AUTHORS +.An Hartmut Brandt Aq harti@freebsd.org diff --git a/contrib/bsnmp/gensnmpdef/gensnmpdef.c b/contrib/bsnmp/gensnmpdef/gensnmpdef.c new file mode 100644 index 0000000..f1e60f2 --- /dev/null +++ b/contrib/bsnmp/gensnmpdef/gensnmpdef.c @@ -0,0 +1,433 @@ +/* + * Copyright (c) 2004 + * Hartmut Brandt. + * All rights reserved. + * + * Author: Harti Brandt <harti@freebsd.org> + * + * Redistribution of this software and documentation and use in source and + * binary forms, with or without modification, are permitted provided that + * the following conditions are met: + * + * 1. Redistributions of source code or documentation must retain the above + * copyright notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the author nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE AND DOCUMENTATION IS PROVIDED BY THE AUTHOR + * AND ITS CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL + * THE AUTHOR OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF + * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * 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/gensnmpdef/gensnmpdef.c,v 1.2 2004/04/14 09:54:51 novo Exp $ + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#include <errno.h> +#include <err.h> +#include <assert.h> +#include <smi.h> + +static const char usgtxt[] = +"Usage: gensnmpdef [-h] [-c <cut>] MIB [MIB ...]\n" +"Options:\n" +" -c specify the number of initial sub-oids to cut from the oids\n" +" -h print this help\n" +"MIBs are searched according to the libsmi(3) search rules and can\n" +"be specified either by path or module name\n"; + +static SmiNode *last_node; +static u_int cut = 3; + +static void print_node(SmiNode *n, u_int level); + +static void +save_node(SmiNode *n) +{ + if (n != NULL) + last_node = n; +} + +static void +pindent(u_int level) +{ + if (level >= cut) + printf("%*s", (level - cut) * 2, ""); +} + +static void +print_name(SmiNode *n) +{ + char *p; + + for (p = n->name; *p != '\0'; p++) { + if (*p == '-') + printf("_"); + else + printf("%c", *p); + } +} + +static u_int +close_node(u_int n, u_int level) +{ + while (n--) { + pindent(level); + level--; + if (level >= cut) + printf(")\n"); + } + return (level); +} + +static u_int +open_node(const SmiNode *n, u_int level, SmiNode **last) +{ + SmiNode *n1; + u_int i; + + if (*last != NULL) { + for (i = 0; i < (*last)->oidlen - 1; i++) { + if (i >= n->oidlen) { + level = close_node((*last)->oidlen - + n->oidlen, level); + break; + } + if ((*last)->oid[i] != n->oid[i]) + break; + } + if (i < (*last)->oidlen - 1) + level = close_node((*last)->oidlen - 1 - i, + level - 1) + 1; + } + + while (level < n->oidlen - 1) { + if (level >= cut) { + pindent(level); + printf("(%u", n->oid[level]); + n1 = smiGetNodeByOID(level + 1, n->oid); + printf(" "); + print_name(n1); + printf("\n"); + } + level++; + } + return (level); +} + +static const char *const type_names[] = { + [SMI_BASETYPE_UNKNOWN] = "UNKNOWN_TYPE", + [SMI_BASETYPE_INTEGER32] = "INTEGER", + [SMI_BASETYPE_OCTETSTRING] = "OCTETSTRING", + [SMI_BASETYPE_OBJECTIDENTIFIER] = "OID", + [SMI_BASETYPE_UNSIGNED32] = "UNSIGNED32", + [SMI_BASETYPE_INTEGER64] = "INTEGER64", + [SMI_BASETYPE_UNSIGNED64] = "UNSIGNED64", + [SMI_BASETYPE_FLOAT32] = "FLOAT32", + [SMI_BASETYPE_FLOAT64] = "FLOAT64", + [SMI_BASETYPE_FLOAT128] = "FLOAT128", + [SMI_BASETYPE_ENUM] = "INTEGER", + [SMI_BASETYPE_BITS] = "BITS", +}; + +static const char *const type_map[] = { + "Gauge32", "GAUGE", + "Gauge", "GAUGE", + "TimeTicks", "TIMETICKS", + "Counter32", "COUNTER", + "Counter", "COUNTER", + "Counter64", "COUNTER64", + "Integer32", "INTEGER32", + "IpAddress", "IPADDRESS", + NULL +}; + +static void +print_type(SmiNode *n) +{ + SmiType *type; + u_int m; + + type = smiGetNodeType(n); + assert(type != NULL); + + if (type->name != NULL) { + for (m = 0; type_map[m] != NULL; m += 2) + if (strcmp(type_map[m], type->name) == 0) { + printf("%s", type_map[m + 1]); + return; + } + } + printf("%s", type_names[type->basetype]); +} + +static void +print_access(SmiAccess a) +{ + if (a == SMI_ACCESS_READ_ONLY) + printf(" GET"); + else if (a == SMI_ACCESS_READ_WRITE) + printf(" GET SET"); +} + +static void +print_scalar(SmiNode *n, u_int level) +{ + SmiNode *p; + + assert (n->nodekind == SMI_NODEKIND_SCALAR); + + save_node(n); + + pindent(level); + printf("(%u ", n->oid[level]); + print_name(n); + printf(" "); + print_type(n); + + /* generate the operation from the parent node name */ + p = smiGetParentNode(n); + printf(" op_%s", p->name); + + print_access(n->access); + + printf(")\n"); +} + +static void +print_notification(SmiNode *n, u_int level) +{ + + assert (n->nodekind == SMI_NODEKIND_NOTIFICATION); + + save_node(n); + + pindent(level); + printf("(%u ", n->oid[level]); + print_name(n); + printf(" OID"); + + printf(" op_%s)\n", n->name); +} + +static void +print_col(SmiNode *n, u_int level) +{ + assert (n->nodekind == SMI_NODEKIND_COLUMN); + + save_node(n); + + pindent(level); + printf("(%u ", n->oid[level]); + print_name(n); + printf(" "); + print_type(n); + print_access(n->access); + printf(")\n"); +} + +static void +print_index(SmiNode *row) +{ + SmiElement *e; + + e = smiGetFirstElement(row); + while (e != NULL) { + printf(" "); + print_type(smiGetElementNode(e)); + e = smiGetNextElement(e); + } +} + +static void +print_table(SmiNode *n, u_int level) +{ + SmiNode *row, *col, *rel; + + assert (n->nodekind == SMI_NODEKIND_TABLE); + + save_node(n); + + pindent(level); + printf("(%u ", n->oid[level]); + print_name(n); + printf("\n"); + + row = smiGetFirstChildNode(n); + if (row->nodekind != SMI_NODEKIND_ROW) + errx(1, "%s: kind %u, not row", __func__, row->nodekind); + + save_node(n); + + pindent(level + 1); + printf("(%u ", row->oid[level + 1]); + print_name(row); + printf(" :"); + + /* index */ + rel = smiGetRelatedNode(row); + switch (row->indexkind) { + + case SMI_INDEX_INDEX: + print_index(row); + break; + + case SMI_INDEX_AUGMENT: + if (rel == NULL) + errx(1, "%s: cannot find augemented table", row->name); + print_index(rel); + break; + + default: + errx(1, "%s: cannot handle index kind %u", row->name, + row->indexkind); + } + + printf(" op_%s", n->name); + printf("\n"); + + col = smiGetFirstChildNode(row); + while (col != NULL) { + print_col(col, level + 2); + col = smiGetNextChildNode(col); + } + pindent(level + 1); + printf(")\n"); + + pindent(level); + printf(")\n"); +} + +static void +print_it(SmiNode *n, u_int level) +{ + switch (n->nodekind) { + + case SMI_NODEKIND_NODE: + print_node(n, level); + break; + + case SMI_NODEKIND_SCALAR: + print_scalar(n, level); + break; + + case SMI_NODEKIND_TABLE: + print_table(n, level); + break; + + case SMI_NODEKIND_COMPLIANCE: + case SMI_NODEKIND_GROUP: + save_node(n); + break; + + case SMI_NODEKIND_NOTIFICATION: + print_notification(n, level); + break; + + default: + errx(1, "cannot handle %u nodes", n->nodekind); + } +} + +static void +print_node(SmiNode *n, u_int level) +{ + assert (n->nodekind == SMI_NODEKIND_NODE); + + save_node(n); + + pindent(level); + printf("(%u ", n->oid[level]); + print_name(n); + printf("\n"); + + n = smiGetFirstChildNode(n); + while (n != NULL) { + print_it(n, level + 1); + n = smiGetNextChildNode(n); + } + pindent(level); + printf(")\n"); +} + +int +main(int argc, char *argv[]) +{ + int opt; + int flags; + SmiModule **mods; + char *name; + SmiNode *n, *last; + u_int level; + long u; + char *end; + + smiInit(NULL); + + while ((opt = getopt(argc, argv, "c:h")) != -1) + switch (opt) { + + case 'c': + errno = 0; + u = strtol(optarg, &end, 10); + if (errno != 0) + err(1, "argument to -c"); + if (*end != '\0') + err(1, "%s: not a number", optarg); + if (u < 0 || u > 5) + err(1, "%s: out of range", optarg); + cut = (u_int)u; + break; + + case 'h': + fprintf(stderr, usgtxt); + exit(0); + } + + argc -= optind; + argv += optind; + + flags = smiGetFlags(); + flags |= SMI_FLAG_ERRORS; + smiSetFlags(flags); + + mods = malloc(sizeof(mods[0]) * argc); + if (mods == NULL) + err(1, NULL); + + for (opt = 0; opt < argc; opt++) { + if ((name = smiLoadModule(argv[opt])) == NULL) + err(1, "%s: cannot load", argv[opt]); + mods[opt] = smiGetModule(name); + } + level = 0; + last = NULL; + for (opt = 0; opt < argc; opt++) { + n = smiGetFirstNode(mods[opt], SMI_NODEKIND_ANY); + for (;;) { + level = open_node(n, level, &last); + print_it(n, level); + last = n; + + if (last_node == NULL || + (n = smiGetNextNode(last_node, SMI_NODEKIND_ANY)) + == NULL) + break; + } + } + level = close_node(last->oidlen - 1, level - 1); + return (0); +} diff --git a/contrib/bsnmp/gensnmptree/gensnmptree.c b/contrib/bsnmp/gensnmptree/gensnmptree.c index 9816144..0dcb2a5 100644 --- a/contrib/bsnmp/gensnmptree/gensnmptree.c +++ b/contrib/bsnmp/gensnmptree/gensnmptree.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/gensnmptree/gensnmptree.c,v 1.36 2003/12/03 09:56:57 hbb Exp $ + * $Begemot: bsnmp/gensnmptree/gensnmptree.c,v 1.37 2004/04/13 15:18:15 novo Exp $ * * Generate OID table from table description. * @@ -522,7 +522,7 @@ gen_node(struct node *np, struct asn_oid *oid, u_int idx, const char *func) fprintf(fp, "0"); if (np->flags & FL_SET) fprintf(fp, "|SNMP_NODE_CANSET"); - fprintf(fp, ", %#x, NULL },\n", idx); + fprintf(fp, ", %#x, NULL, NULL },\n", idx); oid->len--; return; } 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 diff --git a/contrib/bsnmp/snmp_mibII/mibII.c b/contrib/bsnmp/snmp_mibII/mibII.c index ae38b6f..29b0399 100644 --- a/contrib/bsnmp/snmp_mibII/mibII.c +++ b/contrib/bsnmp/snmp_mibII/mibII.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/snmp_mibII/mibII.c,v 1.17 2003/12/03 10:01:19 hbb Exp $ + * $Begemot: bsnmp/snmp_mibII/mibII.c,v 1.18 2004/04/13 14:58:46 novo Exp $ * * Implementation of the standard interfaces and ip MIB. */ @@ -466,7 +466,7 @@ get_physaddr(struct mibif *ifp, struct sockaddr_dl *sdl, u_char *ptr) if (sdl->sdl_alen == 0) { /* no address */ - if (ifp->physaddrlen != NULL) { + if (ifp->physaddrlen != 0) { if ((rcv = mib_find_rcvaddr(ifp->index, ifp->physaddr, ifp->physaddrlen)) != NULL) mib_rcvaddr_delete(rcv); diff --git a/contrib/bsnmp/snmp_mibII/mibII_interfaces.c b/contrib/bsnmp/snmp_mibII/mibII_interfaces.c index a0023bd..38811e4 100644 --- a/contrib/bsnmp/snmp_mibII/mibII_interfaces.c +++ b/contrib/bsnmp/snmp_mibII/mibII_interfaces.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/snmp_mibII/mibII_interfaces.c,v 1.10 2003/12/03 10:01:19 hbb Exp $ + * $Begemot: bsnmp/snmp_mibII/mibII_interfaces.c,v 1.12 2004/04/13 15:19:59 novo Exp $ * * Interfaces group. */ @@ -132,6 +132,9 @@ ifchange_func(struct snmp_context *ctx __unused, struct snmp_dependency *dep, ifp->trap_enable = ifc->rb_traps; return (SNMP_ERR_NOERROR); + case SNMP_DEPOP_FINISH: + return (SNMP_ERR_NOERROR); + } abort(); } @@ -470,7 +473,7 @@ op_ifxtable(struct snmp_context *ctx, struct snmp_value *value, case LEAF_ifHCOutOctets: if (!(ifp->flags & MIBIF_HIGHSPEED)) goto again; - value->v.counter64 = ifp->hc_inoctets; + value->v.counter64 = ifp->hc_outoctets; break; case LEAF_ifHCOutUcastPkts: diff --git a/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c b/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c index a0050f6..49d14a3 100644 --- a/contrib/bsnmp/snmp_mibII/mibII_ipaddr.c +++ b/contrib/bsnmp/snmp_mibII/mibII_ipaddr.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/snmp_mibII/mibII_ipaddr.c,v 1.7 2003/12/03 10:01:19 hbb Exp $ + * $Begemot: bsnmp/snmp_mibII/mibII_ipaddr.c,v 1.8 2004/04/13 14:58:46 novo Exp $ * * IP address table. This table is writeable! * @@ -138,35 +138,16 @@ modify(struct update *upd, struct mibifa *ifa) } /* - * Remove an IP address from an interface. This is called when - * the SET finishes. - */ -static void -destroy_func(struct snmp_context *ctx __unused, int fail __unused, void *arg) -{ - struct mibifa *ifa = arg; - - if (ifa->flags & MIBIFA_DESTROYED) { - TAILQ_REMOVE(&mibifa_list, ifa, link); - free(ifa); - } -} - -/* * Destroy the given row in the table. We remove the address from the * system, but keep the structure around for the COMMIT. It's deleted - * only in the finish function. + * only in the FINISH operation. */ static int -destroy(struct snmp_context *ctx, struct update *upd, struct mibifa *ifa) +destroy(struct snmp_context *ctx __unused, struct update *upd, + struct mibifa *ifa) { if (mib_destroy_ifa(ifa)) return (SNMP_ERR_GENERR); - if (snmp_set_atfinish(ctx, destroy_func, ifa)) { - syslog(LOG_ERR, "atfinish: %m"); - mib_undestroy_ifa(ifa); - return (SNMP_ERR_GENERR); - } upd->rb |= RB_DESTROY; return (SNMP_ERR_NOERROR); } @@ -219,6 +200,15 @@ update_func(struct snmp_context *ctx, struct snmp_dependency *dep, return (SNMP_ERR_NOERROR); } return (SNMP_ERR_NOERROR); + + case SNMP_DEPOP_FINISH: + if ((upd->rb & RB_DESTROY) && + (ifa = mib_find_ifa(upd->addr)) != NULL && + (ifa->flags & MIBIFA_DESTROYED)) { + TAILQ_REMOVE(&mibifa_list, ifa, link); + free(ifa); + } + return (SNMP_ERR_NOERROR); } abort(); } diff --git a/contrib/bsnmp/snmp_mibII/snmp_mibII.3 b/contrib/bsnmp/snmp_mibII/snmp_mibII.3 index 1d7018a..981ed26 100644 --- a/contrib/bsnmp/snmp_mibII/snmp_mibII.3 +++ b/contrib/bsnmp/snmp_mibII/snmp_mibII.3 @@ -30,12 +30,13 @@ .\" 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/snmp_mibII/snmp_mibII.3,v 1.2 2003/12/03 10:01:19 hbb Exp $ +.\" $Begemot: bsnmp/snmp_mibII/snmp_mibII.3,v 1.3 2004/04/13 17:01:31 novo Exp $ .\" .Dd August 19, 2002 .Dt snmp_mibII 3 .Os .Sh NAME +.Nm mibII , .Nm mibif_notify_f , .Nm mib_netsock , .Nm mib_if_set_dyn , @@ -61,7 +62,7 @@ .Nm mibif_unnotify .Nd "mib-2 module for snmpd. .Sh LIBRARY -.Pq begemotSnmpdModulePath."mibII" = "/usr/local/lib/snmp_mibII.so" +.Pq begemotSnmpdModulePath."mibII" = "@MODPATH@snmp_mibII.so" .Sh SYNOPSIS .In bsnmp/snmpmod.h .In bsnmp/snmp_mibII.h @@ -116,7 +117,7 @@ The module implements parts of the internet standard MIB-2. Most of the relevant MIBs are implemented. Some of the tables are restricted to be read-only instead of read-write. The exact current implementation can be found in -.Pa /usr/local/include/bsnmp/mibII_tree.def . +.Pa @DEFPATH@mibII_tree.def . The module also exports a number of functions and global variables for use by other modules, that need to handle network interfaces. This man page describes these functions. @@ -333,11 +334,12 @@ Both functions need the pointers to the interfaces. Entries are automatically deleted if any of the interfaces of the entry is destroyed. The functions handle both the stack table and the reverse stack table. .Sh FILES -.Bl -tag -width ".It Pa /usr/local/include/bsnmp/mibII_tree.def" -compact -.It Pa /usr/local/include/bsnmp/mibII_tree.def +.Bl -tag -width ".It Pa @DEFPATH@mibII_tree.def" -compact +.It Pa @DEFPATH@mibII_tree.def The description of the MIB tree implemented by .Nm . .It Pa /usr/local/share/snmp/mibs +.It Pa @MIBSPATH@ The various internet MIBs. .Sh SEE ALSO .Xr snmpmod 3 , @@ -345,4 +347,4 @@ The various internet MIBs. .Sh STANDARDS This implementation conforms to the applicable IETF RFCs. .Sh AUTHORS -.An Hartmut Brandt Aq brandt@fokus.gmd.de +.An Hartmut Brandt Aq harti@freebsd.org diff --git a/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt b/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt index 76fcbd5..039b4fe 100644 --- a/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt +++ b/contrib/bsnmp/snmpd/BEGEMOT-SNMPD.txt @@ -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/snmpd/BEGEMOT-SNMPD.txt,v 1.21 2003/12/09 12:28:52 hbb Exp $ +-- $Begemot: bsnmp/snmpd/BEGEMOT-SNMPD.txt,v 1.22 2004/04/13 15:21:46 novo Exp $ -- -- Begemot Private SNMPd MIB. -- @@ -38,7 +38,7 @@ BEGEMOT-SNMPD-MIB DEFINITIONS ::= BEGIN IMPORTS MODULE-IDENTITY, OBJECT-TYPE, OBJECT-IDENTITY, Counter32, - Unsigned32 + Unsigned32, IpAddress FROM SNMPv2-SMI TEXTUAL-CONVENTION, TruthValue, RowStatus FROM SNMPv2-TC @@ -144,7 +144,7 @@ begemotSnmpdVersionEnable OBJECT-TYPE 0x00000001 - SNMPv1 0x00000002 - SNMPv2c" - DEFVAL { 0x3 } + DEFVAL { 3 } ::= { begemotSnmpdConfig 5 } -- @@ -475,7 +475,7 @@ begemotSnmpdLocalPortEntry OBJECT-TYPE BegemotSnmpdLocalPortEntry ::= SEQUENCE { begemotSnmpdLocalPortPath OCTET STRING, - begemotSnmpdLocalPortStatus INTEGER + begemotSnmpdLocalPortStatus INTEGER, begemotSnmpdLocalPortType INTEGER } @@ -536,7 +536,7 @@ begemotSnmpdTransportEntry OBJECT-TYPE BegemotSnmpdTransportEntry ::= SEQUENCE { begemotSnmpdTransportName OCTET STRING, - begemotSnmpdTransportStatus INTEGER + begemotSnmpdTransportStatus INTEGER, begemotSnmpdTransportOid OBJECT IDENTIFIER } diff --git a/contrib/bsnmp/snmpd/action.c b/contrib/bsnmp/snmpd/action.c index 0fee3b9..521a5ae 100644 --- a/contrib/bsnmp/snmpd/action.c +++ b/contrib/bsnmp/snmpd/action.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/snmpd/action.c,v 1.56 2003/12/09 12:28:52 hbb Exp $ + * $Begemot: bsnmp/snmpd/action.c,v 1.57 2004/04/13 14:58:46 novo Exp $ * * Variable access for SNMPd */ @@ -730,26 +730,6 @@ struct module_dep { struct lmodule *m; }; -static void -finish_unload(struct snmp_context *ctx __unused, int fail, void *arg) -{ - struct lmodule *m = arg; - - if (!fail) { - lm_unload(m); - } -} - -static void -finish_load(struct snmp_context *ctx __unused, int fail, void *arg) -{ - struct lmodule *m = arg; - - if (!fail) { - lm_start(m); - } -} - static int dep_modules(struct snmp_context *ctx, struct snmp_dependency *dep, enum snmp_depop op) @@ -762,31 +742,44 @@ dep_modules(struct snmp_context *ctx, struct snmp_dependency *dep, if (mdep->path == NULL) { /* unload - find the module */ TAILQ_FOREACH(mdep->m, &lmodules, link) - if (strcmp(mdep->m->section, mdep->section) == 0) + if (strcmp(mdep->m->section, + mdep->section) == 0) break; if (mdep->m == NULL) + /* no such module - that's ok */ return (SNMP_ERR_NOERROR); - if (snmp_set_atfinish(ctx, finish_unload, mdep->m)) - return (SNMP_ERR_RES_UNAVAIL); + + /* handle unloading in the finalizer */ return (SNMP_ERR_NOERROR); } /* load */ - if ((mdep->m = lm_load(mdep->path, mdep->section)) == NULL) - return (SNMP_ERR_RES_UNAVAIL); - if (snmp_set_atfinish(ctx, finish_load, mdep->m)) { - lm_unload(mdep->m); + if ((mdep->m = lm_load(mdep->path, mdep->section)) == NULL) { + /* could not load */ return (SNMP_ERR_RES_UNAVAIL); } + /* start in finalizer */ return (SNMP_ERR_NOERROR); case SNMP_DEPOP_ROLLBACK: if (mdep->path == NULL) { - /* rollback unload - the finish function takes care */ + /* rollback unload - the finalizer takes care */ return (SNMP_ERR_NOERROR); } /* rollback load */ lm_unload(mdep->m); return (SNMP_ERR_NOERROR); + + case SNMP_DEPOP_FINISH: + if (mdep->path == NULL) { + if (mdep->m != NULL && ctx->code == SNMP_RET_OK) + lm_unload(mdep->m); + } else { + if (mdep->m != NULL && ctx->code == SNMP_RET_OK && + community != COMM_INITIALIZE) + lm_start(mdep->m); + free(mdep->path); + } + return (SNMP_ERR_NOERROR); } abort(); } @@ -900,8 +893,6 @@ op_modules(struct snmp_context *ctx, struct snmp_value *value, return (SNMP_ERR_NOERROR); case SNMP_OP_ROLLBACK: - /* must be module path */ - free(ctx->scratch->ptr1); case SNMP_OP_COMMIT: return (SNMP_ERR_NOERROR); diff --git a/contrib/bsnmp/snmpd/bsnmpd.1 b/contrib/bsnmp/snmpd/bsnmpd.1 index 334ac18..81562b7 100644 --- a/contrib/bsnmp/snmpd/bsnmpd.1 +++ b/contrib/bsnmp/snmpd/bsnmpd.1 @@ -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/snmpd/bsnmpd.1,v 1.1 2003/12/03 10:08:33 hbb Exp $ +.\" $Begemot: bsnmp/snmpd/bsnmpd.1,v 1.3 2004/04/13 17:01:31 novo Exp $ .\" .Dd August 15, 2002 .Dt SNMPD 1 @@ -239,9 +239,9 @@ is Default pid file. .It Pa /etc:/usr/etc/:/usr/local/etc This is the default search path for system include files. -.It Pa /usr/local/share/snmp/mibs/FOKUS-MIB.txt -.It Pa /usr/local/share/snmp/mibs/BEGEMOT-MIB.txt -.It Pa /usr/local/share/snmp/mibs/BEGEMOT-SNMPD.txt +.It Pa @MIBSPATH@FOKUS-MIB.txt +.It Pa @MIBSPATH@BEGEMOT-MIB.txt +.It Pa @MIBSPATH@BEGEMOT-SNMPD.txt The definitions for the MIBs implemented in the daemon. .El .Sh SEE ALSO @@ -251,6 +251,6 @@ The .Nm conforms to the applicable IETF RFCs. .Sh AUTHORS -.An Hartmut Brandt Aq brandt@fokus.gmd.de +.An Hartmut Brandt Aq harti@freebsd.org .Sh BUGS Sure. diff --git a/contrib/bsnmp/snmpd/config.c b/contrib/bsnmp/snmpd/config.c index 4001156..223c675 100644 --- a/contrib/bsnmp/snmpd/config.c +++ b/contrib/bsnmp/snmpd/config.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/snmpd/config.c,v 1.19 2003/12/03 10:08:47 hbb Exp $ + * $Begemot: bsnmp/snmpd/config.c,v 1.20 2004/04/13 14:58:46 novo Exp $ * * Parse configuration file. */ @@ -1328,6 +1328,8 @@ read_config(const char *fname, struct lmodule *lodmod) } do_commit(); + snmp_dep_finish(snmp_ctx); + macro_free_all(); free(snmp_ctx); diff --git a/contrib/bsnmp/snmpd/main.c b/contrib/bsnmp/snmpd/main.c index 1a528ac..df879fe 100644 --- a/contrib/bsnmp/snmpd/main.c +++ b/contrib/bsnmp/snmpd/main.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/snmpd/main.c,v 1.82 2003/12/09 12:28:52 hbb Exp $ + * $Begemot: bsnmp/snmpd/main.c,v 1.85 2004/04/14 15:39:14 novo Exp $ * * SNMPd main stuff. */ @@ -840,7 +840,7 @@ recv_dgram(struct port_input *pi) cmsg.hdr.cmsg_type = SCM_CREDS; } else { msg.msg_control = NULL; - msg.msg_controllen = NULL; + msg.msg_controllen = 0; } msg.msg_flags = 0; @@ -2015,14 +2015,14 @@ tree_merge(const struct snmp_node *ntree, u_int nsize, struct lmodule *mod) xtree = realloc(tree, sizeof(*tree) * (tree_size + nsize)); if (xtree == NULL) { - syslog(LOG_ERR, "lm_load: %m"); + syslog(LOG_ERR, "tree_merge: %m"); return (-1); } tree = xtree; memcpy(&tree[tree_size], ntree, sizeof(*tree) * nsize); for (i = 0; i < nsize; i++) - tree[tree_size + i].data = mod; + tree[tree_size + i].tree_data = mod; tree_size += nsize; @@ -2040,7 +2040,7 @@ tree_unmerge(struct lmodule *mod) u_int s, d; for(s = d = 0; s < tree_size; s++) - if (tree[s].data != mod) { + if (tree[s].tree_data != mod) { if (s != d) tree[d] = tree[s]; d++; diff --git a/contrib/bsnmp/snmpd/snmpd.config b/contrib/bsnmp/snmpd/snmpd.config index 3b2e2f5..62bcb57 100644 --- a/contrib/bsnmp/snmpd/snmpd.config +++ b/contrib/bsnmp/snmpd/snmpd.config @@ -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/snmpd/snmpd.config,v 1.12 2003/12/03 10:08:47 hbb Exp $ +# $Begemot: bsnmp/snmpd/snmpd.config,v 1.13 2004/04/13 15:00:00 novo Exp $ # # Example configuration file. # @@ -68,9 +68,9 @@ begemotSnmpdPortStatus.127.0.0.1.161 = 1 begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1 # send traps to the traphost -begemotTrapSinkStatus[$(traphost)].$(trapport) = 4 -begemotTrapSinkVersion[$(traphost)].$(trapport) = 2 -begemotTrapSinkComm[$(traphost)].$(trapport) = $(trap) +begemotTrapSinkStatus.[$(traphost)].$(trapport) = 4 +begemotTrapSinkVersion.[$(traphost)].$(trapport) = 2 +begemotTrapSinkComm.[$(traphost)].$(trapport) = $(trap) sysContact = $(contact) sysLocation = $(location) diff --git a/contrib/bsnmp/snmpd/snmpmod.3 b/contrib/bsnmp/snmpd/snmpmod.3 index be0136c..9877673 100644 --- a/contrib/bsnmp/snmpd/snmpmod.3 +++ b/contrib/bsnmp/snmpd/snmpmod.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/snmpd/snmpmod.3,v 1.5 2003/12/08 16:55:58 hbb Exp $ +.\" $Begemot: bsnmp/snmpd/snmpmod.3,v 1.6 2004/04/13 15:22:52 novo Exp $ .\" .Dd August 16, 2002 .Dt snmpmod 3 @@ -864,4 +864,4 @@ beginning at position 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/snmpd/trans_lsock.c b/contrib/bsnmp/snmpd/trans_lsock.c index 1e0da59..ad1826b 100644 --- a/contrib/bsnmp/snmpd/trans_lsock.c +++ b/contrib/bsnmp/snmpd/trans_lsock.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/snmpd/trans_lsock.c,v 1.3 2003/12/09 12:28:53 hbb Exp $ + * $Begemot: bsnmp/snmpd/trans_lsock.c,v 1.4 2004/04/13 14:58:46 novo Exp $ * * Local domain socket transport */ @@ -90,7 +90,7 @@ lsock_stop(int force) if (my_trans != NULL) { if (!force && trans_first_port(my_trans) != NULL) return (SNMP_ERR_GENERR); - trans_iter_port(my_trans, lsock_remove, NULL); + trans_iter_port(my_trans, lsock_remove, 0); return (trans_unregister(my_trans)); } return (SNMP_ERR_NOERROR); @@ -117,10 +117,9 @@ lsock_open_port(u_char *name, size_t namelen, struct lsock_port **pp, int err; struct sockaddr_un sa; - if (namelen == 0 || namelen + 1 > sizeof(sa.sun_path)) { - free(name); + if (namelen == 0 || namelen + 1 > sizeof(sa.sun_path)) return (SNMP_ERR_BADVALUE); - } + switch (type) { case LOCP_DGRAM_UNPRIV: is_stream = 0; @@ -143,25 +142,21 @@ lsock_open_port(u_char *name, size_t namelen, struct lsock_port **pp, break; default: - free(name); return (SNMP_ERR_BADVALUE); } - if ((port = malloc(sizeof(*port))) == NULL) { - free(name); + if ((port = malloc(sizeof(*port))) == NULL) return (SNMP_ERR_GENERR); - } + memset(port, 0, sizeof(*port)); if (!is_stream) { if ((peer = malloc(sizeof(*peer))) == NULL) { - free(name); free(port); return (SNMP_ERR_GENERR); } memset(peer, 0, sizeof(*peer)); } if ((port->name = malloc(namelen + 1)) == NULL) { - free(name); free(port); if (!is_stream) free(peer); @@ -444,18 +439,7 @@ struct lsock_dep { #define LD_TYPE 0x01 #define LD_STATUS 0x02 #define LD_CREATE 0x04 /* rollback create */ - -/* - * Finish handler for deleting a port - this cannot fail :-) - */ -static void -lsock_del(struct snmp_context *ctx __unused, int fail, void *arg) -{ - struct lsock_dep *ld = (struct lsock_dep *)(void *)arg; - - if (!fail) - lsock_close_port(&ld->port->tport); -} +#define LD_DELETE 0x08 /* rollback delete */ /* * dependency handler for lsock ports @@ -484,16 +468,12 @@ lsock_func(struct snmp_context *ctx, struct snmp_dependency *dep, ld->set |= LD_CREATE; } } else if (!ld->status) { - /* delete - hard to roll back so defer to - * finish handler */ - if (snmp_set_atfinish(ctx, lsock_del, ld->port)) - err = SNMP_ERR_RES_UNAVAIL; + /* delete - hard to roll back so defer to finalizer */ + ld->set |= LD_DELETE; } else /* modify - read-only */ err = SNMP_ERR_READONLY; - free(ld->path); - ld->path = NULL; return (err); case SNMP_DEPOP_ROLLBACK: @@ -502,6 +482,12 @@ lsock_func(struct snmp_context *ctx, struct snmp_dependency *dep, lsock_close_port(&ld->port->tport); } return (SNMP_ERR_NOERROR); + + case SNMP_DEPOP_FINISH: + if ((ld->set & LD_DELETE) && ctx->code == SNMP_RET_OK) + lsock_close_port(&ld->port->tport); + free(ld->path); + return (SNMP_ERR_NOERROR); } abort(); } diff --git a/contrib/bsnmp/snmpd/trap.c b/contrib/bsnmp/snmpd/trap.c index 2dd6b82..40f7cf6 100644 --- a/contrib/bsnmp/snmpd/trap.c +++ b/contrib/bsnmp/snmpd/trap.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/snmpd/trap.c,v 1.6 2003/12/03 10:08:47 hbb Exp $ + * $Begemot: bsnmp/snmpd/trap.c,v 1.7 2004/04/13 14:58:46 novo Exp $ * * TrapSinkTable */ @@ -202,21 +202,10 @@ trapsink_unmodify(struct trapsink *t, struct trapsink_dep *tdep) return (SNMP_ERR_NOERROR); } -static void -trapsink_finish(struct snmp_context *ctx __unused, int fail, void *arg) -{ - struct trapsink *t = arg; - - if (!fail) - trapsink_free(t); -} - static int -trapsink_destroy(struct snmp_context *ctx, struct trapsink *t, +trapsink_destroy(struct snmp_context *ctx __unused, struct trapsink *t, struct trapsink_dep *tdep) { - if (snmp_set_atfinish(ctx, trapsink_finish, t)) - return (SNMP_ERR_RES_UNAVAIL); t->status = TRAPSINK_DESTROY; tdep->rb_status = t->status; tdep->rb |= TDEP_DESTROY; @@ -277,6 +266,12 @@ trapsink_dep(struct snmp_context *ctx, struct snmp_dependency *dep, if(tdep->rb & TDEP_DESTROY) return (trapsink_undestroy(t, tdep)); return (SNMP_ERR_NOERROR); + + case SNMP_DEPOP_FINISH: + if ((tdep->rb & TDEP_DESTROY) && t != NULL && + ctx->code == SNMP_RET_OK) + trapsink_free(t); + return (SNMP_ERR_NOERROR); } abort(); } |