diff options
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | COPYING | 14 | ||||
-rw-r--r-- | ChangeLog | 0 | ||||
-rw-r--r-- | Makefile.am | 4 | ||||
-rw-r--r-- | NEWS | 1 | ||||
-rw-r--r-- | README | 0 | ||||
-rw-r--r-- | configure.in | 42 | ||||
-rw-r--r-- | src/.deps/bsnmp-regex.Po | 93 | ||||
-rw-r--r-- | src/.deps/regex_tree.Po | 45 | ||||
-rw-r--r-- | src/.deps/regextree.Po | 45 | ||||
-rw-r--r-- | src/Makefile.am | 12 | ||||
-rw-r--r-- | src/bsnmp-regex.c | 171 | ||||
-rw-r--r-- | src/regex-tree.def | 15 | ||||
-rw-r--r-- | src/regex_oid.h | 3 | ||||
-rw-r--r-- | src/usuals.h | 32 |
15 files changed, 478 insertions, 0 deletions
@@ -0,0 +1 @@ +nielsen@memberwebs.com
\ No newline at end of file @@ -0,0 +1,14 @@ +LICENSE +This software is in the public domain. + +The software is provided "as is", without warranty of any kind, +express or implied, including but not limited to the warranties +of merchantability, fitness for a particular purpose, and +noninfringement. In no event shall the author(s) be liable for any +claim, damages, or other liability, whether in an action of +contract, tort, or otherwise, arising from, out of, or in connection +with the software or the use or other dealings in the software. + +SUPPORT +Send bug reports to: <nielsen@memberwebs.com> + diff --git a/ChangeLog b/ChangeLog new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/ChangeLog diff --git a/Makefile.am b/Makefile.am new file mode 100644 index 0000000..941939e --- /dev/null +++ b/Makefile.am @@ -0,0 +1,4 @@ +# EXTRA_DIST = BUGS +SUBDIRS = src + + @@ -0,0 +1 @@ +See ChangeLog
\ No newline at end of file diff --git a/configure.in b/configure.in new file mode 100644 index 0000000..fb24345 --- /dev/null +++ b/configure.in @@ -0,0 +1,42 @@ +# Process this file with autoconf to produce a configure script. +AC_INIT(bsnmp-regex, 0.1, nielsen@memberwebs.com) +AM_INIT_AUTOMAKE(bsnmp-regex, 0.1) + +AC_CONFIG_SRCDIR([src/bsnmp-regex.c]) +AM_CONFIG_HEADER([config.h]) + +# Checks for programs. +AC_PROG_CC +AC_PROG_INSTALL +AC_PROG_LIBTOOL + +# Debug mode +AC_ARG_ENABLE(debug, + AC_HELP_STRING([--enable-debug], + [Compile binaries in debug mode])) + +if test "$enable_debug" = "yes"; then + CFLAGS="$CFLAGS -g -O0 -Wall" + AC_DEFINE_UNQUOTED(_DEBUG, 1, [In debug mode]) + echo "enabling debug compile mode" +fi + +# Some checks for BSNMP libraries +AC_CHECK_LIB(bsnmp, snmp_close, , + [echo "Couldn't find the bsnmp module library"; exit 1]) + +# Checks for header files. +AC_HEADER_STDC +dnl AC_CHECK_HEADERS() + +# Checks for typedefs, structures, and compiler characteristics. +AC_C_CONST +AC_TYPE_SIZE_T + +# Checks for library functions. +AC_FUNC_MALLOC +AC_FUNC_MEMCMP +dnl TODO AC_CHECK_FUNCS([atexit inet_ntoa inet_pton memset strerror strspn strtol]) + +AC_CONFIG_FILES([Makefile src/Makefile]) +AC_OUTPUT diff --git a/src/.deps/bsnmp-regex.Po b/src/.deps/bsnmp-regex.Po new file mode 100644 index 0000000..6d1d5f1 --- /dev/null +++ b/src/.deps/bsnmp-regex.Po @@ -0,0 +1,93 @@ +bsnmp-regex.o bsnmp-regex.o: bsnmp-regex.c usuals.h \ + /usr/include/sys/types.h /usr/include/sys/cdefs.h \ + /usr/include/machine/endian.h /usr/include/sys/_types.h \ + /usr/include/machine/_types.h /usr/include/sys/_pthreadtypes.h \ + /usr/include/sys/select.h /usr/include/sys/_sigset.h \ + /usr/include/sys/_timeval.h /usr/include/sys/timespec.h ../config.h \ + /usr/include/errno.h /usr/include/stdint.h \ + /usr/include/machine/_stdint.h /usr/include/stdio.h \ + /usr/include/sys/_null.h /usr/include/stdlib.h /usr/include/string.h \ + /usr/include/strings.h /usr/include/sys/queue.h /usr/include/syslog.h \ + /usr/include/unistd.h /usr/include/sys/unistd.h \ + /usr/include/bsnmp/snmpmod.h /usr/include/sys/socket.h \ + /usr/include/sys/_iovec.h /usr/include/machine/param.h \ + /usr/include/net/if.h /usr/include/sys/time.h /usr/include/time.h \ + /usr/include/netinet/in.h /usr/include/netinet6/in6.h \ + /usr/include/bsnmp/asn1.h /usr/include/bsnmp/snmp.h \ + /usr/include/bsnmp/snmpagent.h regex_tree.h regex_oid.h + +usuals.h: + +/usr/include/sys/types.h: + +/usr/include/sys/cdefs.h: + +/usr/include/machine/endian.h: + +/usr/include/sys/_types.h: + +/usr/include/machine/_types.h: + +/usr/include/sys/_pthreadtypes.h: + +/usr/include/sys/select.h: + +/usr/include/sys/_sigset.h: + +/usr/include/sys/_timeval.h: + +/usr/include/sys/timespec.h: + +../config.h: + +/usr/include/errno.h: + +/usr/include/stdint.h: + +/usr/include/machine/_stdint.h: + +/usr/include/stdio.h: + +/usr/include/sys/_null.h: + +/usr/include/stdlib.h: + +/usr/include/string.h: + +/usr/include/strings.h: + +/usr/include/sys/queue.h: + +/usr/include/syslog.h: + +/usr/include/unistd.h: + +/usr/include/sys/unistd.h: + +/usr/include/bsnmp/snmpmod.h: + +/usr/include/sys/socket.h: + +/usr/include/sys/_iovec.h: + +/usr/include/machine/param.h: + +/usr/include/net/if.h: + +/usr/include/sys/time.h: + +/usr/include/time.h: + +/usr/include/netinet/in.h: + +/usr/include/netinet6/in6.h: + +/usr/include/bsnmp/asn1.h: + +/usr/include/bsnmp/snmp.h: + +/usr/include/bsnmp/snmpagent.h: + +regex_tree.h: + +regex_oid.h: diff --git a/src/.deps/regex_tree.Po b/src/.deps/regex_tree.Po new file mode 100644 index 0000000..eaaa64e --- /dev/null +++ b/src/.deps/regex_tree.Po @@ -0,0 +1,45 @@ +regex_tree.o regex_tree.o: regex_tree.c /usr/include/sys/types.h \ + /usr/include/sys/cdefs.h /usr/include/machine/endian.h \ + /usr/include/sys/_types.h /usr/include/machine/_types.h \ + /usr/include/sys/_pthreadtypes.h /usr/include/sys/select.h \ + /usr/include/sys/_sigset.h /usr/include/sys/_timeval.h \ + /usr/include/sys/timespec.h /usr/include/stdio.h \ + /usr/include/sys/_null.h /usr/include/stdint.h \ + /usr/include/machine/_stdint.h /usr/include/bsnmp/asn1.h \ + /usr/include/bsnmp/snmp.h /usr/include/bsnmp/snmpagent.h regex_tree.h + +/usr/include/sys/types.h: + +/usr/include/sys/cdefs.h: + +/usr/include/machine/endian.h: + +/usr/include/sys/_types.h: + +/usr/include/machine/_types.h: + +/usr/include/sys/_pthreadtypes.h: + +/usr/include/sys/select.h: + +/usr/include/sys/_sigset.h: + +/usr/include/sys/_timeval.h: + +/usr/include/sys/timespec.h: + +/usr/include/stdio.h: + +/usr/include/sys/_null.h: + +/usr/include/stdint.h: + +/usr/include/machine/_stdint.h: + +/usr/include/bsnmp/asn1.h: + +/usr/include/bsnmp/snmp.h: + +/usr/include/bsnmp/snmpagent.h: + +regex_tree.h: diff --git a/src/.deps/regextree.Po b/src/.deps/regextree.Po new file mode 100644 index 0000000..a399d57 --- /dev/null +++ b/src/.deps/regextree.Po @@ -0,0 +1,45 @@ +regextree.o regextree.o: regextree.c /usr/include/sys/types.h \ + /usr/include/sys/cdefs.h /usr/include/machine/endian.h \ + /usr/include/sys/_types.h /usr/include/machine/_types.h \ + /usr/include/sys/_pthreadtypes.h /usr/include/sys/select.h \ + /usr/include/sys/_sigset.h /usr/include/sys/_timeval.h \ + /usr/include/sys/timespec.h /usr/include/stdio.h \ + /usr/include/sys/_null.h /usr/include/stdint.h \ + /usr/include/machine/_stdint.h /usr/include/bsnmp/asn1.h \ + /usr/include/bsnmp/snmp.h /usr/include/bsnmp/snmpagent.h regextree.h + +/usr/include/sys/types.h: + +/usr/include/sys/cdefs.h: + +/usr/include/machine/endian.h: + +/usr/include/sys/_types.h: + +/usr/include/machine/_types.h: + +/usr/include/sys/_pthreadtypes.h: + +/usr/include/sys/select.h: + +/usr/include/sys/_sigset.h: + +/usr/include/sys/_timeval.h: + +/usr/include/sys/timespec.h: + +/usr/include/stdio.h: + +/usr/include/sys/_null.h: + +/usr/include/stdint.h: + +/usr/include/machine/_stdint.h: + +/usr/include/bsnmp/asn1.h: + +/usr/include/bsnmp/snmp.h: + +/usr/include/bsnmp/snmpagent.h: + +regextree.h: diff --git a/src/Makefile.am b/src/Makefile.am new file mode 100644 index 0000000..9758f1a --- /dev/null +++ b/src/Makefile.am @@ -0,0 +1,12 @@ + +lib_LTLIBRARIES = libsnmp_regex.la +libsnmp_regex_la_LDFLAGS = +libsnmp_regex_la_SOURCES = regex_tree.c regex_tree.h regex_oid.h \ + bsnmp-regex.c + +regex_tree.c: regex-tree.def + gensnmptree -p regex_ < regex-tree.def + gensnmptree -e regexData > regex_oid.h < regex-tree.def + +CLEANFILES = regex_tree.* \ + regex_oid.h diff --git a/src/bsnmp-regex.c b/src/bsnmp-regex.c new file mode 100644 index 0000000..a3a7385 --- /dev/null +++ b/src/bsnmp-regex.c @@ -0,0 +1,171 @@ + +#include "usuals.h" + +#include <sys/queue.h> +#include <sys/select.h> +#include <syslog.h> +#include <unistd.h> + +#include <bsnmp/snmpmod.h> + +#include "regex_tree.h" +#include "regex_oid.h" + +/* our module handle */ +static struct lmodule *module; + +/* OIDs */ +static const struct asn_oid oid_regex = OIDX_regexData; + +/* the Object Resource registration index */ +static u_int reg_index; + +/* last time we've fetch the peer list */ +static uint64_t peers_tick; + +/* request sequence number generator */ +static uint16_t seqno; + +struct data_entry { + uint32_t index; + TAILQ_ENTRY(data_entry) link; + + char *descr; + uint64_t last_update; + uint64_t value; +}; + +TAILQ_HEAD(data_entry_list, data_entry); + +/* list of peers */ +static struct data_entry_list entries = TAILQ_HEAD_INITIALIZER(entries); +static uint32_t entry_count = 0; + +/* the initialisation function */ +static int +module_init(struct lmodule *mod, int argc, char *argv[]) +{ + module = mod; + + if (argc != 0) { + syslog(LOG_ERR, "bad number of arguments for %s", __func__); + return (EINVAL); + } + + return 0; +} + +/* Module is started */ +static void +module_start(void) +{ + reg_index = or_register(&oid_regex, "The MIB for regex data.", module); +} + +/* Called, when the module is to be unloaded after it was successfully loaded */ +static int +module_fini(void) +{ + or_unregister(reg_index); + return 0; +} + +const struct snmp_module config = { + .comment = "This module implements SNMP listing of data from regular expressions", + .init = module_init, + .start = module_start, + .fini = module_fini, + .tree = regex_ctree, + .tree_size = regex_CTREE_SIZE, +}; + +/* System variables - read-only scalars only. */ +int +op_data (struct snmp_context *ctx, struct snmp_value *value, + u_int sub, u_int iidx, enum snmp_op op) +{ + asn_subid_t which = value->var.subs[sub - 1]; + + switch (op) { + case SNMP_OP_GET: + break; + + case SNMP_OP_SET: + return SNMP_ERR_NOT_WRITEABLE; + + default: + ASSERT(0); + break; + } + + switch (which) { + case LEAF_dataCount: + value->v.integer = entry_count; + break; + + default: + ASSERT(0); + break; + } + + return SNMP_ERR_NOERROR; +} + +int +op_dataentry (struct snmp_context *ctx, struct snmp_value *value, + u_int sub, u_int iidx, enum snmp_op op) +{ + asn_subid_t which = value->var.subs[sub - 1]; + struct data_entry *data; + + switch (op) { + case SNMP_OP_GETNEXT: + data = NEXT_OBJECT_INT (&entries, &value->var, sub); + if (data == NULL) + return SNMP_ERR_NOSUCHNAME; + value->var.len = sub + 1; + value->var.subs[sub] = data->index; + break; + + case SNMP_OP_GET: + data = FIND_OBJECT_INT (&entries, &value->var, sub); + if (data == NULL) + return SNMP_ERR_NOSUCHNAME; + break; + + case SNMP_OP_SET: + if (index_decode (&value->var, sub, iidx, &data)) + return SNMP_ERR_NO_CREATION; + data = FIND_OBJECT_INT (&entries, &value->var, sub); + if (data != NULL) + return SNMP_ERR_NOT_WRITEABLE; + return SNMP_ERR_NO_CREATION; + + default: + ASSERT(0); + break; + } + + switch (which) { + case LEAF_dataIndex: + value->v.integer = data->index; + break; + + case LEAF_dataDescr: + return (string_get (value, data->descr, -1)); + + case LEAF_dataLast: + value->v.uint32 = data->last_update; + break; + + case LEAF_dataValue: + value->v.uint32 = data->value; + break; + + default: + ASSERT(0); + break; + }; + + return SNMP_ERR_NOERROR; +} diff --git a/src/regex-tree.def b/src/regex-tree.def new file mode 100644 index 0000000..8a631b9 --- /dev/null +++ b/src/regex-tree.def @@ -0,0 +1,15 @@ +(1 internet + (4 private + (1 enterprises + (10277 regexData + (1 dataCount INTEGER op_data GET) + (2 dataEntry : INTEGER op_dataentry + (1 dataIndex INTEGER GET) + (2 dataDescr OCTETSTRING GET) + (3 dataLast TIMETICKS GET) + (4 dataValue INTEGER GET) + ) + ) + ) + ) +) diff --git a/src/regex_oid.h b/src/regex_oid.h new file mode 100644 index 0000000..221f029 --- /dev/null +++ b/src/regex_oid.h @@ -0,0 +1,3 @@ +#define OID_regexData 10277 +#define OIDLEN_regexData 7 +#define OIDX_regexData { 7, { 1, 3, 6, 1, 4, 1, 10277, } } diff --git a/src/usuals.h b/src/usuals.h new file mode 100644 index 0000000..6dc7b08 --- /dev/null +++ b/src/usuals.h @@ -0,0 +1,32 @@ + +#ifndef __USUALS_H__ +#define __USUALS_H__ + +#include <sys/types.h> + +#include "config.h" + +#include <errno.h> +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> + +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#define countof(x) (sizeof(x) / sizeof(x[0])) + +#ifdef _DEBUG + #include "assert.h" + #define ASSERT(x) assert(x) +#else + #define ASSERT(x) +#endif + +#endif /* __USUALS_H__ */ |