summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorReyk Floeter <reyk@cvs.openbsd.org>2007-12-28 17:22:33 +0000
committerReyk Floeter <reyk@cvs.openbsd.org>2007-12-28 17:22:33 +0000
commit543fde3e85cb19f3ac50ab9242d83bcc57291cfd (patch)
tree1e9c839cdab193b2a26a4efc0f9e2449208fc157
parente67798564e2c2f16e166c1dd27c68911097be333 (diff)
add "show mib" command to dump compiled-in MIB names
-rw-r--r--usr.sbin/snmpctl/Makefile4
-rw-r--r--usr.sbin/snmpctl/parser.c8
-rw-r--r--usr.sbin/snmpctl/parser.h5
-rw-r--r--usr.sbin/snmpctl/snmpctl.814
-rw-r--r--usr.sbin/snmpctl/snmpctl.c56
5 files changed, 72 insertions, 15 deletions
diff --git a/usr.sbin/snmpctl/Makefile b/usr.sbin/snmpctl/Makefile
index dedb04dd6e7..da2c34289d9 100644
--- a/usr.sbin/snmpctl/Makefile
+++ b/usr.sbin/snmpctl/Makefile
@@ -1,9 +1,9 @@
-# $Id: Makefile,v 1.1 2007/12/05 09:22:44 reyk Exp $
+# $Id: Makefile,v 1.2 2007/12/28 17:22:32 reyk Exp $
.PATH: ${.CURDIR}/../snmpd
PROG= snmpctl
-SRCS= buffer.c imsg.c log.c snmpctl.c parser.c
+SRCS= buffer.c imsg.c log.c smi.c snmpctl.c parser.c
MAN= snmpctl.8
diff --git a/usr.sbin/snmpctl/parser.c b/usr.sbin/snmpctl/parser.c
index 612c1fe36d5..60175a81079 100644
--- a/usr.sbin/snmpctl/parser.c
+++ b/usr.sbin/snmpctl/parser.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.c,v 1.2 2007/12/28 15:57:06 thib Exp $ */
+/* $OpenBSD: parser.c,v 1.3 2007/12/28 17:22:32 reyk Exp $ */
/*
* Copyright (c) 2004 Esben Norby <norby@openbsd.org>
@@ -55,6 +55,12 @@ static const struct token t_show[];
static const struct token t_main[] = {
{KEYWORD, "monitor", MONITOR, NULL},
+ {KEYWORD, "show", NONE, t_show},
+ {ENDTOKEN, "", NONE, NULL}
+};
+
+static const struct token t_show[] = {
+ {KEYWORD, "mib" , SHOW_MIB, NULL},
{ENDTOKEN, "", NONE, NULL}
};
diff --git a/usr.sbin/snmpctl/parser.h b/usr.sbin/snmpctl/parser.h
index 41202685b9d..3268e21b15b 100644
--- a/usr.sbin/snmpctl/parser.h
+++ b/usr.sbin/snmpctl/parser.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: parser.h,v 1.1 2007/12/05 09:22:44 reyk Exp $ */
+/* $OpenBSD: parser.h,v 1.2 2007/12/28 17:22:32 reyk Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net>
@@ -18,7 +18,8 @@
enum actions {
NONE,
- MONITOR
+ MONITOR,
+ SHOW_MIB
};
struct parse_result {
diff --git a/usr.sbin/snmpctl/snmpctl.8 b/usr.sbin/snmpctl/snmpctl.8
index c83747ffe1c..2823cd5f123 100644
--- a/usr.sbin/snmpctl/snmpctl.8
+++ b/usr.sbin/snmpctl/snmpctl.8
@@ -1,6 +1,6 @@
-.\" $OpenBSD: snmpctl.8,v 1.1 2007/12/05 09:22:44 reyk Exp $
+.\" $OpenBSD: snmpctl.8,v 1.2 2007/12/28 17:22:32 reyk Exp $
.\"
-.\" Copyright (c) 2006 Reyk Floeter <reyk@vantronix.net>
+.\" Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net>
.\"
.\" Permission to use, copy, modify, and distribute this software for any
.\" purpose with or without fee is hereby granted, provided that the above
@@ -14,7 +14,7 @@
.\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
.\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
.\"
-.Dd $Mdocdate: December 5 2007 $
+.Dd $Mdocdate: December 28 2007 $
.Dt SNMPCTL 8
.Os
.Sh NAME
@@ -33,8 +33,12 @@ daemon.
.Pp
The following commands are available:
.Bl -tag -width Ds
-.It Cm something
-Do something
+.It Cm monitor
+Monitor internal messages of the
+.Xr snmpd 8
+subsystems and engines.
+.It Cm show mib
+Dump the tree of compiled-in MIB objects.
.El
.Sh FILES
.Bl -tag -width "/var/run/snmpd.sockXX" -compact
diff --git a/usr.sbin/snmpctl/snmpctl.c b/usr.sbin/snmpctl/snmpctl.c
index f20e5036cc8..126871a52fa 100644
--- a/usr.sbin/snmpctl/snmpctl.c
+++ b/usr.sbin/snmpctl/snmpctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpctl.c,v 1.3 2007/12/28 15:57:06 thib Exp $ */
+/* $OpenBSD: snmpctl.c,v 1.4 2007/12/28 17:22:32 reyk Exp $ */
/*
* Copyright (c) 2007 Reyk Floeter <reyk@vantronix.net>
@@ -41,6 +41,7 @@
#include "snmpd.h"
#include "parser.h"
+#include "mib.h"
__dead void usage(void);
@@ -50,6 +51,7 @@ struct imsgname {
void (*func)(struct imsg *);
};
+void show_mib(void);
struct imsgname *monitor_lookup(u_int8_t);
void monitor_host_status(struct imsg *);
void monitor_id(struct imsg *);
@@ -63,6 +65,8 @@ struct imsgname imsgunknown = {
};
struct imsgbuf *ibuf;
+struct snmpd *env;
+struct oid mib_tree[] = MIB_TREE;
__dead void
usage(void)
@@ -90,10 +94,30 @@ main(int argc, char *argv[])
int done = 0;
int n;
+ if ((env = calloc(1, sizeof(struct snmpd *))) == NULL)
+ err(1, "calloc");
+ gettimeofday(&env->sc_starttime, NULL);
+ smi_init();
+
/* parse options */
if ((res = parse(argc - 1, argv + 1)) == NULL)
exit(1);
+ switch (res->action) {
+ case NONE:
+ usage();
+ break;
+ case SHOW_MIB:
+ show_mib();
+ break;
+ default:
+ goto connect;
+ }
+
+ free(env);
+ return (0);
+
+ connect:
/* connect to snmpd control socket */
if ((ctl_sock = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
err(1, "socket");
@@ -113,18 +137,18 @@ main(int argc, char *argv[])
}
if ((ibuf = malloc(sizeof(struct imsgbuf))) == NULL)
- err(1, NULL);
+ err(1, "malloc");
imsg_init(ibuf, ctl_sock, NULL);
done = 0;
/* process user request */
switch (res->action) {
- case NONE:
- usage();
- /* not reached */
case MONITOR:
imsg_compose(ibuf, IMSG_CTL_NOTIFY, 0, 0, -1, NULL, 0);
break;
+ case NONE:
+ case SHOW_MIB:
+ break;
}
while (ibuf->w.queued)
@@ -147,6 +171,7 @@ main(int argc, char *argv[])
done = monitor(&imsg);
break;
case NONE:
+ case SHOW_MIB:
break;
}
imsg_free(&imsg);
@@ -158,6 +183,27 @@ main(int argc, char *argv[])
return (0);
}
+void
+mib_init(void)
+{
+ /*
+ * MIB declarations (to register the OID names)
+ */
+ smi_mibtree(mib_tree);
+}
+
+void
+show_mib(void)
+{
+ struct oid *oid;
+
+ for (oid = NULL; (oid = smi_foreach(oid, 0)) != NULL;) {
+ char buf[BUFSIZ];
+ smi_oidstring(&oid->o_id, buf, sizeof(buf));
+ printf("%s\n", buf);
+ }
+}
+
struct imsgname *
monitor_lookup(u_int8_t type)
{