On Tue, Apr 05, 2016 at 12:35:11PM +0200, Mike Belopuhov wrote:
> On Mon, Apr 04, 2016 at 15:45 +0000, Philip Higgins wrote:
> > If I'm not mistaken this information isn't exported already.
> > 
> > I've been using this for a while to track queue usage over time in Cacti.
> > 
> > Still need to add entries in OPENBSD-PF-MIB.txt,
> > but want to make sure I'm on the right track first.
> >
> 
> Hi Philip,
> 
> Thanks for your work, you most definitely are on a right track.
> Please add MIB entries and make sure that your mail client doesn't
> change tabs to spaces.  Your diff is broken as it is now.  Please
> also respect the maximum line width (80 characters).

Have switched to a real email client, was having many issues beyond tabs
and spaces.

OPENBSD-PF-MIB updated to match implementation.

I was thinking of dropping QueueId (and ParentQueueId) fields, they were
mostly in just for debugging. 
Not sure if they will be of value to others though.

There are also plenty more fields that could be added, but these were the ones
I needed for my purpose.

> > I just added it on the end of the PF  section and used the next number in 
> > sequence, if there's a better way let me know.
> > All constructive feedback welcome.
> > 
> > Diff against 5.9.
> > 
> 
> Cheers,
> Mike

---
-Phil


Index: usr.sbin/snmpd/mib.c
===================================================================
RCS file: /cvs/src/usr.sbin/snmpd/mib.c,v
retrieving revision 1.80
diff -u -p -u -r1.80 mib.c
--- usr.sbin/snmpd/mib.c        17 Nov 2015 12:30:23 -0000      1.80
+++ usr.sbin/snmpd/mib.c        5 Apr 2016 13:55:10 -0000
@@ -42,6 +42,7 @@
 #include <net/if_types.h>
 #include <net/pfvar.h>
 #include <net/if_pfsync.h>
+#include <net/hfsc.h>
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -1415,6 +1416,8 @@ struct ber_oid *
 int     mib_pflabelnum(struct oid *, struct ber_oid *, struct ber_element **);
 int     mib_pflabels(struct oid *, struct ber_oid *, struct ber_element **);
 int     mib_pfsyncstats(struct oid *, struct ber_oid *, struct ber_element **);
+int     mib_pfqueuenum(struct oid *, struct ber_oid *, struct ber_element **);
+int     mib_pfqueues(struct oid *, struct ber_oid *, struct ber_element **);
 
 int     mib_sensornum(struct oid *, struct ber_oid *, struct ber_element **);
 int     mib_sensors(struct oid *, struct ber_oid *, struct ber_element **);
@@ -1603,6 +1606,19 @@ static struct oid openbsd_mib[] = {
        { MIB(pfsyncIp6PktsSent),       OID_RD, mib_pfsyncstats },
        { MIB(pfsyncNoMemory),          OID_RD, mib_pfsyncstats },
        { MIB(pfsyncOutputErrors),      OID_RD, mib_pfsyncstats },
+       { MIB(pfQueueNumber),           OID_RD, mib_pfqueuenum },
+       { MIB(pfQueueIndex),            OID_TRD, mib_pfqueues },
+       { MIB(pfQueueId),               OID_TRD, mib_pfqueues },
+       { MIB(pfQueueName),             OID_TRD, mib_pfqueues },
+       { MIB(pfQueueIf),               OID_TRD, mib_pfqueues },
+       { MIB(pfQueueParentId),         OID_TRD, mib_pfqueues },
+       { MIB(pfQueueParentName),       OID_TRD, mib_pfqueues },
+       { MIB(pfQueueOutPackets),       OID_TRD, mib_pfqueues },
+       { MIB(pfQueueOutBytes),         OID_TRD, mib_pfqueues },
+       { MIB(pfQueueDropPackets),      OID_TRD, mib_pfqueues },
+       { MIB(pfQueueDropBytes),        OID_TRD, mib_pfqueues },
+       { MIB(pfQueueMaxLength),        OID_TRD, mib_pfqueues },
+       { MIB(pfQueueLength),           OID_TRD, mib_pfqueues },
        { MIB(sensorsMIBObjects),       OID_MIB },
        { MIB(sensorNumber),            OID_RD, mib_sensornum },
        { MIB(sensorIndex),             OID_TRD, mib_sensors },
@@ -2501,6 +2517,98 @@ mib_pfsyncstats(struct oid *oid, struct 
        }
 
        return (-1);
+}
+
+int
+mib_pfqueuenum(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
+{
+       extern int              devpf;
+       struct pfioc_queue      pq;
+
+       memset(&pq, 0, sizeof(pq));
+
+       if (ioctl(devpf, DIOCGETQUEUES, &pq))
+               return (-1);
+
+       *elm = ber_add_integer(*elm, pq.nr);
+
+       return (0);
+}
+
+int
+mib_pfqueues(struct oid *oid, struct ber_oid *o, struct ber_element **elm)
+{
+       struct ber_element      *ber = *elm;
+       struct pfioc_queue       pq;
+       struct pfioc_qstats      pqs;
+       struct hfsc_class_stats  s;
+       u_int32_t                idx;
+       extern int               devpf;
+
+       memset(&pq, 0, sizeof(pq));
+       memset(&pqs, 0, sizeof(pqs));
+
+       idx = o->bo_id[OIDIDX_pfQueueEntry];
+
+       if (ioctl(devpf, DIOCGETQUEUES, &pq))
+               return (-1);
+
+       pqs.nr = idx-1;
+       pqs.ticket = pq.ticket;
+       pqs.buf = &s;
+       pqs.nbytes = sizeof(s);
+       if (ioctl(devpf, DIOCGETQSTATS, &pqs)) {
+               return (1);
+       }
+
+       ber = ber_add_oid(ber, o);
+
+       switch (o->bo_id[OIDIDX_pfQueue]) {
+       case 1:
+               ber = ber_add_integer(ber, idx);
+               break;
+       case 2:
+               ber = ber_add_integer(ber, pqs.queue.qid);
+               break;
+       case 3:
+               ber = ber_add_string(ber, pqs.queue.qname);
+               break;
+       case 4:
+               ber = ber_add_string(ber, pqs.queue.ifname);
+               break;
+       case 5:
+               ber = ber_add_integer(ber, pqs.queue.parent_qid);
+               break;
+       case 6:
+               ber = ber_add_string(ber, pqs.queue.parent);
+               break;
+       case 7:
+               ber = ber_add_integer(ber, s.xmit_cnt.packets);
+               ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64);
+               break;
+       case 8:
+               ber = ber_add_integer(ber, s.xmit_cnt.bytes);
+               ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64);
+               break;
+       case 9:
+               ber = ber_add_integer(ber, s.drop_cnt.packets);
+               ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64);
+               break;
+       case 10:
+               ber = ber_add_integer(ber, s.drop_cnt.bytes);
+               ber_set_header(ber, BER_CLASS_APPLICATION, SNMP_T_COUNTER64);
+               break;
+       case 11:
+               ber = ber_add_integer(ber, s.qlimit);
+               break;
+       case 12:
+               ber = ber_add_integer(ber, s.qlength);
+               break;
+       default:
+               return (1);
+       }
+
+       return (0);
 }
 
 int
Index: usr.sbin/snmpd/mib.h
===================================================================
RCS file: /cvs/src/usr.sbin/snmpd/mib.h,v
retrieving revision 1.37
diff -u -p -u -r1.37 mib.h
--- usr.sbin/snmpd/mib.h        11 Jun 2015 18:49:09 -0000      1.37
+++ usr.sbin/snmpd/mib.h        5 Apr 2016 13:55:12 -0000
@@ -651,6 +651,24 @@
 #define MIB_pfsyncIp6PktsSent          MIB_pfsyncStats, 14
 #define MIB_pfsyncNoMemory             MIB_pfsyncStats, 15
 #define MIB_pfsyncOutputErrors         MIB_pfsyncStats, 16
+#define MIB_pfQueues                   MIB_pfMIBObjects, 12
+#define MIB_pfQueueNumber              MIB_pfQueues, 1
+#define MIB_pfQueueTable               MIB_pfQueues, 128
+#define OIDIDX_pfQueue                 11
+#define OIDIDX_pfQueueEntry            12
+#define MIB_pfQueueEntry               MIB_pfQueueTable, 1
+#define MIB_pfQueueIndex               MIB_pfQueueEntry, 1
+#define MIB_pfQueueId                  MIB_pfQueueEntry, 2
+#define MIB_pfQueueName                        MIB_pfQueueEntry, 3
+#define MIB_pfQueueIf                  MIB_pfQueueEntry, 4
+#define MIB_pfQueueParentId            MIB_pfQueueEntry, 5
+#define MIB_pfQueueParentName          MIB_pfQueueEntry, 6
+#define MIB_pfQueueOutPackets          MIB_pfQueueEntry, 7
+#define MIB_pfQueueOutBytes            MIB_pfQueueEntry, 8
+#define MIB_pfQueueDropPackets         MIB_pfQueueEntry, 9
+#define MIB_pfQueueDropBytes           MIB_pfQueueEntry, 10
+#define MIB_pfQueueMaxLength           MIB_pfQueueEntry, 11
+#define MIB_pfQueueLength              MIB_pfQueueEntry, 12
 #define MIB_sensorsMIBObjects          MIB_openBSD, 2
 #define MIB_sensors                    MIB_sensorsMIBObjects, 1
 #define MIB_sensorNumber               MIB_sensors, 1
@@ -1211,6 +1229,22 @@
        { MIBDECL(pfsyncIp6PktsSent) },                 \
        { MIBDECL(pfsyncNoMemory) },                    \
        { MIBDECL(pfsyncOutputErrors) },                \
+       { MIBDECL(pfQueues) },                          \
+       { MIBDECL(pfQueueNumber) },                     \
+       { MIBDECL(pfQueueTable) },                      \
+       { MIBDECL(pfQueueEntry) },                      \
+       { MIBDECL(pfQueueIndex) },                      \
+       { MIBDECL(pfQueueId) },                         \
+       { MIBDECL(pfQueueName) },                       \
+       { MIBDECL(pfQueueIf) },                         \
+       { MIBDECL(pfQueueParentId) },                   \
+       { MIBDECL(pfQueueParentName) },                 \
+       { MIBDECL(pfQueueOutPackets) },                 \
+       { MIBDECL(pfQueueOutBytes) },                   \
+       { MIBDECL(pfQueueDropPackets) },                \
+       { MIBDECL(pfQueueDropBytes) },                  \
+       { MIBDECL(pfQueueMaxLength) },                  \
+       { MIBDECL(pfQueueLength) },                     \
        { MIBDECL(sensorsMIBObjects) },                 \
        { MIBDECL(relaydMIBObjects) },                  \
        { MIBDECL(relaydHostTrap) },                    \
Index: share/snmp/OPENBSD-PF-MIB.txt
===================================================================
RCS file: /cvs/src/share/snmp/OPENBSD-PF-MIB.txt,v
retrieving revision 1.5
diff -u -p -u -r1.5 OPENBSD-PF-MIB.txt
--- share/snmp/OPENBSD-PF-MIB.txt       10 Jun 2015 10:03:59 -0000      1.5
+++ share/snmp/OPENBSD-PF-MIB.txt       5 Apr 2016 13:55:16 -0000
@@ -67,6 +67,7 @@ pfInterfaces                  OBJECT IDENTIFIER ::= { p
 pfTables                       OBJECT IDENTIFIER ::= { pfMIBObjects 9 }
 pfLabels                       OBJECT IDENTIFIER ::= { pfMIBObjects 10 }
 pfsyncStats                    OBJECT IDENTIFIER ::= { pfMIBObjects 11 }
+pfQueues                       OBJECT IDENTIFIER ::= { pfMIBObjects 12 }
 
 
 -- pfInfo
@@ -1593,6 +1594,148 @@ pfsyncOutputErrors OBJECT-TYPE
        DESCRIPTION
        "Number of pfsync packets which could not be sent."
        ::= { pfsyncStats 16 }
+
+
+-- pfQueues
+
+pfQueueNumber OBJECT-TYPE
+       SYNTAX          Integer32
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The number of queues in the active pf ruleset."
+       ::= { pfQueues 1 }
+
+pfQueueTable OBJECT-TYPE
+       SYNTAX          SEQUENCE OF PfQueueEntry
+       MAX-ACCESS      not-accessible
+       STATUS          current
+       DESCRIPTION
+       "A list of individual queues. The number of entries is
+       given by the value of pfQueueNumber."
+       ::= { pfQueues 128 }
+
+pfQueueEntry OBJECT-TYPE
+       SYNTAX          PfQueueEntry
+       MAX-ACCESS      not-accessible
+       STATUS          current
+       DESCRIPTION
+       "An entry containing management information applicable to a
+       particular queue."
+       INDEX   { pfQueueIndex }
+       ::= { pfQueueTable 1 }
+
+PfQueueEntry ::=
+       SEQUENCE {
+               pfQueueIndex            Integer32,
+               pfQueueId               Integer32,
+               pfQueueName             OCTET STRING,
+               pfQueueIf               OCTET STRING,
+               pfQueueParentId         Integer32,
+               pfQueueParentName       OCTET STRING,
+               pfQueueOutPackets       Counter64,
+               pfQueueOutBytes         Counter64,
+               pfQueueDropPackets      Counter64,
+               pfQueueDropBtes         Counter64,
+               pfQueueMaxLength        Integer32,
+               pfQueueLength           Integer32
+       }
+
+pfQueueIndex OBJECT-TYPE
+       SYNTAX          Integer32 (1..2147483647)
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "A unique value, greater than zero, for each queue."
+       ::= { pfQueueEntry 1 }
+
+pfQueueId OBJECT-TYPE
+       SYNTAX          Integer32 (1..2147483647)
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "Kernel id of this queue."
+       ::= { pfQueueEntry 2 }
+
+pfQueueName OBJECT-TYPE
+       SYNTAX          OCTET STRING
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The name of the queue."
+       ::= { pfQueueEntry 3 }
+
+pfQueueIf OBJECT-TYPE
+       SYNTAX          OCTET STRING
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The name of parent interface of this queue."
+       ::= { pfQueueEntry 4 }
+
+pfQueueParentId OBJECT-TYPE
+       SYNTAX          Integer32 (1..2147483647)
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The id of the parent queue of this queue,"
+       ::= { pfQueueEntry 5 }
+
+pfQueueParentName OBJECT-TYPE
+       SYNTAX          OCTET STRING
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The name of parent queue of this queue."
+       ::= { pfQueueEntry 6 }
+
+pfQueueOutPackets OBJECT-TYPE
+       SYNTAX          Counter64
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The number of packets sent through this queue."
+       ::= { pfQueueEntry 7 }
+
+pfQueueOutBytes OBJECT-TYPE
+       SYNTAX          Counter64
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The number of bytes sent through this queue."
+       ::= { pfQueueEntry 8 }
+
+pfQueueDropPackets OBJECT-TYPE
+       SYNTAX          Counter64
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The number of packets dropped by this queue."
+       ::= { pfQueueEntry 9 }
+
+pfQueueDropBytes OBJECT-TYPE
+       SYNTAX          Counter64
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The number of bytes dropped by this queue."
+       ::= { pfQueueEntry 10 }
+
+pfQueueMaxLength OBJECT-TYPE
+       SYNTAX          Integer32
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The maximum number of packets held in the queue."
+       ::= { pfQueueEntry 11 }
+
+pfQueueLength OBJECT-TYPE
+       SYNTAX          Integer32
+       MAX-ACCESS      read-only
+       STATUS          current
+       DESCRIPTION
+       "The number of packets held in the queue."
+       ::= { pfQueueEntry 12 }
 
 END
 

Reply via email to