summaryrefslogtreecommitdiff
path: root/usr.bin/snmp
diff options
context:
space:
mode:
authorMartijn van Duren <martijn@cvs.openbsd.org>2020-01-17 09:49:48 +0000
committerMartijn van Duren <martijn@cvs.openbsd.org>2020-01-17 09:49:48 +0000
commit181e3c60a30276e04af8f3452f21bfdee95ef2df (patch)
tree2adb0abfd42b26ac319adecfeb47aaad75094bd8 /usr.bin/snmp
parent6a33073f11078e29f3e94a5753c4f60a6f6e9b9b (diff)
Implement a -Cs option for snmp walk and bulkwalk.
This option allows you to skip subsections of a tree and allows for faster walking with less (undesired) clutter on screen. OK florian@ jan@ Happy sounds from Michael W. Lucas
Diffstat (limited to 'usr.bin/snmp')
-rw-r--r--usr.bin/snmp/snmp.115
-rw-r--r--usr.bin/snmp/snmpc.c39
2 files changed, 50 insertions, 4 deletions
diff --git a/usr.bin/snmp/snmp.1 b/usr.bin/snmp/snmp.1
index 440c43f1152..b479fe1031c 100644
--- a/usr.bin/snmp/snmp.1
+++ b/usr.bin/snmp/snmp.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: snmp.1,v 1.8 2019/10/26 17:43:52 martijn Exp $
+.\" $OpenBSD: snmp.1,v 1.9 2020/01/17 09:49:47 martijn Exp $
.\"
.\" Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org>
.\"
@@ -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: October 26 2019 $
+.Dd $Mdocdate: January 17 2020 $
.Dt SNMP 1
.Os
.Sh NAME
@@ -256,6 +256,17 @@ This determines the amount of MIBs to return for each specified OID.
This value defaults to 10.
No blank is allowed before
.Ar maxrep .
+.It Cm s Ar skipoid
+For
+.Cm walk
+or
+.Cm bulkwalk
+don't include
+.Ar skipoid
+or its children in the walk output.
+The blank before
+.Ar skipoid
+is mandatory.
.It Cm t
For
.Cm walk ,
diff --git a/usr.bin/snmp/snmpc.c b/usr.bin/snmp/snmpc.c
index 95227e9a4e1..53d86574835 100644
--- a/usr.bin/snmp/snmpc.c
+++ b/usr.bin/snmp/snmpc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: snmpc.c,v 1.17 2019/10/26 19:34:15 martijn Exp $ */
+/* $OpenBSD: snmpc.c,v 1.18 2020/01/17 09:49:47 martijn Exp $ */
/*
* Copyright (c) 2019 Martijn van Duren <martijn@openbsd.org>
@@ -95,6 +95,8 @@ int smi_print_hint = 1;
int non_repeaters = 0;
int max_repetitions = 10;
struct ber_oid walk_end = {{0}, 0};
+struct ber_oid *walk_skip = NULL;
+size_t walk_skip_len = 0;
enum smi_oid_lookup oid_lookup = smi_oidl_short;
enum smi_output_string output_string = smi_os_default;
@@ -327,6 +329,23 @@ main(int argc, char *argv[])
errx(1, "-Cr invalid argument");
i = strtolp - optarg - 1;
break;
+ case 's':
+ if (strcmp(snmp_app->name, "walk") &&
+ strcmp(snmp_app->name, "bulkwalk"))
+ usage();
+ if ((walk_skip = recallocarray(
+ walk_skip, walk_skip_len,
+ walk_skip_len + 1,
+ sizeof(*walk_skip))) == NULL)
+ errx(1, "malloc");
+ if (smi_string2oid(argv[optind],
+ &(walk_skip[walk_skip_len])) != 0)
+ errx(1, "%s: %s",
+ "Unknown Object Identifier",
+ argv[optind]);
+ walk_skip_len++;
+ optind++;
+ break;
case 't':
if (strcmp(snmp_app->name, "walk"))
usage();
@@ -548,9 +567,10 @@ snmpc_walk(int argc, char *argv[])
struct timespec start, finish;
struct snmp_agent *agent;
const char *oids;
- int n = 0, prev_cmp;
+ int n = 0, prev_cmp, skip_cmp;
int errorstatus, errorindex;
int class;
+ size_t i;
unsigned type;
if (strcmp(snmp_app->name, "bulkwalk") == 0 && version < SNMP_V2C)
@@ -592,6 +612,14 @@ snmpc_walk(int argc, char *argv[])
n++;
}
while (1) {
+ for (i = 0; i < walk_skip_len; i++) {
+ skip_cmp = ober_oid_cmp(&(walk_skip[i]), &noid);
+ if (skip_cmp == 0 || skip_cmp == 2) {
+ bcopy(&(walk_skip[i]), &noid, sizeof(noid));
+ noid.bo_id[noid.bo_n -1]++;
+ break;
+ }
+ }
bcopy(&noid, &loid, sizeof(loid));
if (strcmp(snmp_app->name, "bulkwalk") == 0) {
if ((pdu = snmp_getbulk(agent, &noid, 1,
@@ -617,6 +645,13 @@ snmpc_walk(int argc, char *argv[])
if (value->be_class == BER_CLASS_CONTEXT &&
value->be_type == BER_TYPE_EOC)
break;
+ for (i = 0; i < walk_skip_len; i++) {
+ skip_cmp = ober_oid_cmp(&(walk_skip[i]), &noid);
+ if (skip_cmp == 0 || skip_cmp == 2)
+ break;
+ }
+ if (i < walk_skip_len)
+ continue;
prev_cmp = ober_oid_cmp(&loid, &noid);
if (walk_check_increase && prev_cmp == -1)
errx(1, "OID not increasing");