2 * Copyright (c) 2010 Pierre-Yves Ritschard <pyr@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 #include <sys/types.h>
18 #include <sys/ioctl.h>
19 #include <sys/socket.h>
22 #include <net/pfvar.h>
37 #include "configfile.h"
40 typedef u_int64_t counter_t;
43 #define PF_SOCKET "/dev/pf"
49 static struct pfdata pd;
51 static int pf_init(void);
52 static int pf_read(void);
53 static void submit_counter(const char *, const char *, counter_t);
56 submit_counter(const char *type, const char *inst, counter_t val)
60 value_list_t vl = VALUE_LIST_INIT;
62 values[0].counter = val;
66 sstrncpy (vl.host, hostname_g, sizeof (vl.host));
67 sstrncpy (vl.plugin, "pf", sizeof (vl.plugin));
68 sstrncpy (vl.type, type, sizeof(vl.type));
69 sstrncpy (vl.type_instance, inst, sizeof(vl.type_instance));
70 plugin_dispatch_values(&vl);
72 printf("%s.%s: %lld\n", type, inst, val);
80 struct pf_status status;
82 memset(&pd, '\0', sizeof(pd));
84 if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) {
87 if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) {
101 struct pf_status status;
103 char *cnames[] = PFRES_NAMES;
104 char *lnames[] = LCNT_NAMES;
105 char *names[] = { "searches", "inserts", "removals" };
107 if ((pd.pd_dev = open(PF_SOCKET, O_RDWR)) == -1) {
110 if (ioctl(pd.pd_dev, DIOCGETSTATUS, &status) == -1) {
114 for (i = 0; i < PFRES_MAX; i++)
115 submit_counter("pf_counters", cnames[i], status.counters[i]);
116 for (i = 0; i < LCNT_MAX; i++)
117 submit_counter("pf_limits", lnames[i], status.lcounters[i]);
118 for (i = 0; i < FCNT_MAX; i++)
119 submit_counter("pf_state", names[i], status.fcounters[i]);
120 for (i = 0; i < SCNT_MAX; i++)
121 submit_counter("pf_source", names[i], status.scounters[i]);
127 main(int argc, char *argv[])
136 void module_register(void) {
137 plugin_register_init("pf", pf_init);
138 plugin_register_read("pf", pf_read);