From c310081011c49acebf12b5e9216fe0378df11f3a Mon Sep 17 00:00:00 2001 From: martijn Date: Tue, 6 Feb 2024 12:39:13 +0000 Subject: [PATCH] Load MIB files during startup. The default directory is /usr/share/snmp/mibs, but one or more directories can be configured via the "mib directory" option. OK tb@ --- usr.sbin/snmpd/parse.y | 17 ++++++++++++++++- usr.sbin/snmpd/snmpd.conf.5 | 9 +++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y index ab78c2bde29..dd2456c1bf0 100644 --- a/usr.sbin/snmpd/parse.y +++ b/usr.sbin/snmpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.86 2023/12/21 12:43:31 martijn Exp $ */ +/* $OpenBSD: parse.y,v 1.87 2024/02/06 12:39:13 martijn Exp $ */ /* * Copyright (c) 2007, 2008, 2012 Reyk Floeter @@ -100,6 +100,7 @@ char *symget(const char *); struct snmpd *conf = NULL; static int errors = 0; static struct usmuser *user = NULL; +static int mibparsed = 0; static struct ber_oid *smi_object; static uint8_t engineid[SNMPD_MAXENGINEIDLEN]; @@ -145,6 +146,7 @@ typedef struct { %token READONLY READWRITE OCTETSTRING INTEGER COMMUNITY TRAP RECEIVER %token SECLEVEL NONE AUTH ENC USER AUTHKEY ENCKEY ERROR %token HANDLE DEFAULT SRCADDR TCP UDP BLOCKLIST PORT +%token MIB DIRECTORY %token STRING %token NUMBER %type usmuser community optcommunity @@ -166,6 +168,7 @@ grammar : /* empty */ | grammar main '\n' | grammar system '\n' | grammar object '\n' + | grammar mib '\n' | grammar error '\n' { file->errors++; } ; @@ -1188,6 +1191,12 @@ cmd : STRING { } ; +mib : MIB DIRECTORY STRING { + mib_parsedir($3); + mibparsed = 1; + } + ; + %% struct keywords { @@ -1231,6 +1240,7 @@ lookup(char *s) { "contact", CONTACT }, { "default", DEFAULT }, { "description", DESCR }, + { "directory", DIRECTORY }, { "enc", ENC }, { "enckey", ENCKEY }, { "engineid", ENGINEID }, @@ -1245,6 +1255,7 @@ lookup(char *s) { "listen", LISTEN }, { "location", LOCATION }, { "mac", MAC }, + { "mib", MIB }, { "mode", MODE }, { "name", NAME }, { "none", NONE }, @@ -1670,6 +1681,10 @@ parse_config(const char *filename, u_int flags) endservent(); + if (!mibparsed) + mib_parsedir("/usr/share/snmp/mibs"); + mib_resolve(); + if (uname(&u) == -1) fatal("uname"); diff --git a/usr.sbin/snmpd/snmpd.conf.5 b/usr.sbin/snmpd/snmpd.conf.5 index f4fd21d8f84..7e40c3e7fa5 100644 --- a/usr.sbin/snmpd/snmpd.conf.5 +++ b/usr.sbin/snmpd/snmpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: snmpd.conf.5,v 1.63 2023/04/25 13:36:01 op Exp $ +.\" $OpenBSD: snmpd.conf.5,v 1.64 2024/02/06 12:39:13 martijn Exp $ .\" .\" Copyright (c) 2007, 2008, 2012 Reyk Floeter .\" @@ -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: April 25 2023 $ +.Dd $Mdocdate: February 6 2024 $ .Dt SNMPD.CONF 5 .Os .Sh NAME @@ -231,6 +231,11 @@ RFC1910 legacy format. must be 8 bytes .Pq or 16 characters in hexadecimal format . .El +.It Ic mib directory Ar path +Specify which directories to recursively search for MIB files. +Multiple directories can be specified. +If no directory is specified it defaults to +.Pa /usr/share/snmp/mibs . .It Ic read-only community Ar string Specify the name of the read-only community. There is no default value. -- 2.20.1