summaryrefslogtreecommitdiffstats
path: root/usr.sbin/bsnmpd
diff options
context:
space:
mode:
authorphilip <philip@FreeBSD.org>2005-11-30 21:08:04 +0000
committerphilip <philip@FreeBSD.org>2005-11-30 21:08:04 +0000
commit59488a6d95a7da1b09575c8053c4ee8edd096b53 (patch)
treeb9e197b6cd9621e8773a6100676014a9034d6724 /usr.sbin/bsnmpd
parentf243cd906e715a43fad19bdf09a9458e0b0b6509 (diff)
downloadFreeBSD-src-59488a6d95a7da1b09575c8053c4ee8edd096b53.zip
FreeBSD-src-59488a6d95a7da1b09575c8053c4ee8edd096b53.tar.gz
Check for altq presence during module init, and allow module to work even if
altq is not present (just disable the altq bits in that case). PR: 89601 Submitted by: Juraj Lutter <otis -at- sk.freebsd.org> MFC after: 3 days
Diffstat (limited to 'usr.sbin/bsnmpd')
-rw-r--r--usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
index 5f65cde..226394f 100644
--- a/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
+++ b/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
@@ -96,6 +96,8 @@ static struct pfq_table pfq_table;
static time_t pfq_table_age;
static int pfq_table_count;
+static int altq_enabled = 0;
+
#define PFQ_TABLE_MAXAGE 5
/* Forward declarations */
@@ -107,6 +109,8 @@ static struct pfi_entry * pfi_table_find(u_int idx);
static struct pfq_entry * pfq_table_find(u_int idx);
static struct pft_entry * pft_table_find(u_int idx);
+static int altq_is_enabled(int pfdevice);
+
int
pf_status(struct snmp_context __unused *ctx, struct snmp_value *val,
u_int sub, u_int __unused vindex, enum snmp_op op)
@@ -781,6 +785,10 @@ pf_altq(struct snmp_context __unused *ctx, struct snmp_value *val,
{
asn_subid_t which = val->var.subs[sub - 1];
+ if (!altq_enabled) {
+ return (SNMP_ERR_NOERROR);
+ }
+
if (op == SNMP_OP_SET)
return (SNMP_ERR_NOT_WRITEABLE);
@@ -812,6 +820,10 @@ pf_altqq(struct snmp_context __unused *ctx, struct snmp_value *val,
asn_subid_t which = val->var.subs[sub - 1];
struct pfq_entry *e = NULL;
+ if (!altq_enabled) {
+ return (SNMP_ERR_NOERROR);
+ }
+
switch (op) {
case SNMP_OP_SET:
return (SNMP_ERR_NOT_WRITEABLE);
@@ -1119,6 +1131,29 @@ err2:
}
/*
+ * check whether altq support is enabled in kernel
+ */
+
+static int
+altq_is_enabled(int pfdev)
+{
+ struct pfioc_altq pa;
+
+ errno = 0;
+ if (ioctl(pfdev, DIOCGETALTQS, &pa)) {
+ if (errno == ENODEV) {
+ syslog(LOG_INFO, "No ALTQ support in kernel\n"
+ "ALTQ related functions disabled\n");
+ return (0);
+ } else
+ syslog(LOG_ERR, "DIOCGETALTQS returned an error: %s",
+ strerror(errno));
+ return (-1);
+ }
+ return (1);
+}
+
+/*
* Implement the bsnmpd module interface
*/
static int
@@ -1132,13 +1167,21 @@ pf_init(struct lmodule *mod, int __unused argc, char __unused *argv[])
return (-1);
}
+ if ((altq_enabled = altq_is_enabled(dev)) == -1) {
+ syslog(LOG_ERR, "pf_init(): altq test failed");
+ return (-1);
+ }
+
/* Prepare internal state */
TAILQ_INIT(&pfi_table);
TAILQ_INIT(&pfq_table);
TAILQ_INIT(&pft_table);
pfi_refresh();
- pfq_refresh();
+ if (altq_enabled) {
+ pfq_refresh();
+ }
+
pfs_refresh();
pft_refresh();
@@ -1186,7 +1229,9 @@ static void
pf_dump(void)
{
pfi_refresh();
- pfq_refresh();
+ if (altq_enabled) {
+ pfq_refresh();
+ }
pft_refresh();
syslog(LOG_ERR, "Dump: pfi_table_age = %jd",
OpenPOWER on IntegriCloud