diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2011-04-21 14:55:23 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2011-04-21 14:55:23 +0000 |
commit | 75b72345e279c79d30c6ab7a75d8c0ec9aa6e159 (patch) | |
tree | f0f5a91223049701fbe6645a291c49521c17fd69 /usr.sbin/snmpd | |
parent | f3821124272adcb26767e6549f92338963aacc63 (diff) |
Add a "filter-routes" option; when set, snmpd asks the kernel not to
send route updates. If you aren't interested in examining routing tables
over SNMP (e.g. if you only use it for sensors or interface stats) this
reduces cpu use during heavy route updates. Makes my full-table bgp
routers happier when a major peer bounces. ok reyk@
Diffstat (limited to 'usr.sbin/snmpd')
-rw-r--r-- | usr.sbin/snmpd/kroute.c | 8 | ||||
-rw-r--r-- | usr.sbin/snmpd/parse.y | 31 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.conf.5 | 16 | ||||
-rw-r--r-- | usr.sbin/snmpd/snmpd.h | 3 |
4 files changed, 51 insertions, 7 deletions
diff --git a/usr.sbin/snmpd/kroute.c b/usr.sbin/snmpd/kroute.c index 006453c6ac4..d5e3b100cf6 100644 --- a/usr.sbin/snmpd/kroute.c +++ b/usr.sbin/snmpd/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.16 2011/03/07 07:43:02 henning Exp $ */ +/* $OpenBSD: kroute.c,v 1.17 2011/04/21 14:55:22 sthen Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net> @@ -45,6 +45,8 @@ #include "snmpd.h" +extern struct snmpd *env; + struct { struct event ks_ev; u_long ks_iflastchange; @@ -160,6 +162,10 @@ kr_init(void) &opt, sizeof(opt)) == -1) log_warn("kr_init: setsockopt"); /* not fatal */ + if (env->sc_rtfilter && setsockopt(kr_state.ks_fd, PF_ROUTE, + ROUTE_MSGFILTER, &env->sc_rtfilter, sizeof(env->sc_rtfilter)) == -1) + log_warn("kr_init: setsockopt(ROUTE_MSGFILTER)"); + /* grow receive buffer, don't wanna miss messages */ optlen = sizeof(default_rcvbuf); if (getsockopt(kr_state.ks_fd, SOL_SOCKET, SO_RCVBUF, diff --git a/usr.sbin/snmpd/parse.y b/usr.sbin/snmpd/parse.y index 6982519d778..b6503233529 100644 --- a/usr.sbin/snmpd/parse.y +++ b/usr.sbin/snmpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.19 2010/10/18 13:29:49 sthen Exp $ */ +/* $OpenBSD: parse.y,v 1.20 2011/04/21 14:55:22 sthen Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net> @@ -112,13 +112,13 @@ typedef struct { %token INCLUDE %token LISTEN ON -%token SYSTEM CONTACT DESCR LOCATION NAME OBJECTID SERVICES +%token SYSTEM CONTACT DESCR LOCATION NAME OBJECTID SERVICES RTFILTER %token READONLY READWRITE OCTETSTRING INTEGER COMMUNITY TRAP RECEIVER %token ERROR %token <v.string> STRING %token <v.number> NUMBER %type <v.string> hostcmn -%type <v.number> optwrite +%type <v.number> optwrite yesno %type <v.data> objtype %type <v.oid> oid hostoid @@ -157,6 +157,21 @@ varset : STRING '=' STRING { } ; +yesno : STRING { + if (!strcmp($1, "yes")) + $$ = 1; + else if (!strcmp($1, "no")) + $$ = 0; + else { + yyerror("syntax error, " + "either yes or no expected"); + free($1); + YYERROR; + } + free($1); + } + ; + main : LISTEN ON STRING { struct addresslist al; struct address *h; @@ -212,6 +227,15 @@ main : LISTEN ON STRING { } host { hlist = NULL; } + | RTFILTER yesno { + if ($2 == 1) + conf->sc_rtfilter = ROUTE_FILTER(RTM_NEWADDR) | + ROUTE_FILTER(RTM_DELADDR) | + ROUTE_FILTER(RTM_IFINFO) | + ROUTE_FILTER(RTM_IFANNOUNCE); + else + conf->sc_rtfilter = 0; + } ; system : SYSTEM sysmib @@ -378,6 +402,7 @@ lookup(char *s) { "community", COMMUNITY }, { "contact", CONTACT }, { "description", DESCR }, + { "filter-routes", RTFILTER }, { "include", INCLUDE }, { "integer", INTEGER }, { "listen", LISTEN }, diff --git a/usr.sbin/snmpd/snmpd.conf.5 b/usr.sbin/snmpd/snmpd.conf.5 index 9026e1cf78a..44c034f440d 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.13 2010/07/18 08:03:04 jmc Exp $ +.\" $OpenBSD: snmpd.conf.5,v 1.14 2011/04/21 14:55:22 sthen Exp $ .\" .\" Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net> .\" @@ -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: July 18 2010 $ +.Dd $Mdocdate: April 21 2011 $ .Dt SNMPD.CONF 5 .Os .Sh NAME @@ -85,6 +85,18 @@ Specify the name of the read-write community. The default value is .Ar private . .Pp +.It Xo +.Ic filter-routes +.Pq Ic yes Ns \&| Ns Ic no +.Xc +If set to +.Ic yes , +ask the kernel to filter route update messages on the routing socket. +Routing table information will not be available, but CPU use will be +reduced during bulk updates. +The default is +.Ic no . +.Pp .It Ic system contact Ar string Specify the name or description of the system contact, typically a name or an e-mail address. diff --git a/usr.sbin/snmpd/snmpd.h b/usr.sbin/snmpd/snmpd.h index 293a9b420b8..5a0b388fa80 100644 --- a/usr.sbin/snmpd/snmpd.h +++ b/usr.sbin/snmpd/snmpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: snmpd.h,v 1.30 2010/09/20 08:56:16 martinh Exp $ */ +/* $OpenBSD: snmpd.h,v 1.31 2011/04/21 14:55:22 sthen Exp $ */ /* * Copyright (c) 2007, 2008 Reyk Floeter <reyk@vantronix.net> @@ -303,6 +303,7 @@ struct snmpd { int sc_ncpu; int64_t *sc_cpustates; + int sc_rtfilter; }; /* control.c */ |