summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorCedric Berger <cedric@cvs.openbsd.org>2004-02-19 21:37:02 +0000
committerCedric Berger <cedric@cvs.openbsd.org>2004-02-19 21:37:02 +0000
commitcba11930f1479033cbdbfa570fcd627f4b450f19 (patch)
tree6ed3bd79a86443cffd0d351c222cec40a99b5c47 /sbin
parentf85d92bb0ed3beb219c0adc523c25c97b12a4da8 (diff)
Makes pfctl -ss and pfctl -sq use optional -i argument.
ok dhartmei@ markus@ mcbride@
Diffstat (limited to 'sbin')
-rw-r--r--sbin/pfctl/pfctl.c31
-rw-r--r--sbin/pfctl/pfctl.h4
-rw-r--r--sbin/pfctl/pfctl_qstats.c22
-rw-r--r--sbin/pfctl/pfctl_table.c9
4 files changed, 39 insertions, 27 deletions
diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c
index 5e5e3cb6739..3baa00fc5ed 100644
--- a/sbin/pfctl/pfctl.c
+++ b/sbin/pfctl/pfctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.c,v 1.206 2004/02/19 21:29:51 cedric Exp $ */
+/* $OpenBSD: pfctl.c,v 1.207 2004/02/19 21:37:01 cedric Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -70,7 +70,7 @@ void pfctl_print_rule_counters(struct pf_rule *, int);
int pfctl_show_rules(int, int, int, char *, char *);
int pfctl_show_nat(int, int, char *, char *);
int pfctl_show_src_nodes(int, int);
-int pfctl_show_states(int, u_int8_t, int);
+int pfctl_show_states(int, const char *, int);
int pfctl_show_status(int, int);
int pfctl_show_timeouts(int, int);
int pfctl_show_limits(int, int);
@@ -819,13 +819,13 @@ pfctl_show_src_nodes(int dev, int opts)
}
int
-pfctl_show_states(int dev, u_int8_t proto, int opts)
+pfctl_show_states(int dev, const char *iface, int opts)
{
struct pfioc_states ps;
struct pf_state *p;
char *inbuf = NULL, *newinbuf = NULL;
unsigned len = 0;
- int i;
+ int i, dotitle = (opts & PF_OPT_SHOWALL);
memset(&ps, 0, sizeof(ps));
for (;;) {
@@ -848,15 +848,17 @@ pfctl_show_states(int dev, u_int8_t proto, int opts)
len = ps.ps_len;
if (ps.ps_len == 0)
return (0); /* no states */
- else if (opts && PF_OPT_SHOWALL)
- pfctl_print_title("STATES:");
len *= 2;
}
p = ps.ps_states;
- for (i = 0; i < ps.ps_len; i += sizeof(*p)) {
- if (!proto || (p->proto == proto))
- print_state(p, opts);
- p++;
+ for (i = 0; i < ps.ps_len; i += sizeof(*p), p++) {
+ if (iface != NULL && strcmp(p->u.ifname, iface))
+ continue;
+ if (dotitle) {
+ pfctl_print_title("STATES:");
+ dotitle = 0;
+ }
+ print_state(p, opts);
}
return (0);
}
@@ -1658,10 +1660,11 @@ main(int argc, char *argv[])
pfctl_show_nat(dev, opts, anchorname, rulesetname);
break;
case 'q':
- pfctl_show_altq(dev, opts, opts & PF_OPT_VERBOSE2);
+ pfctl_show_altq(dev, ifaceopt, opts,
+ opts & PF_OPT_VERBOSE2);
break;
case 's':
- pfctl_show_states(dev, 0, opts);
+ pfctl_show_states(dev, ifaceopt, opts);
break;
case 'S':
pfctl_show_src_nodes(dev, opts);
@@ -1682,8 +1685,8 @@ main(int argc, char *argv[])
pfctl_show_nat(dev, opts, anchorname, rulesetname);
pfctl_show_rules(dev, opts, 0, anchorname,
rulesetname);
- pfctl_show_altq(dev, opts, 0);
- pfctl_show_states(dev, 0, opts);
+ pfctl_show_altq(dev, ifaceopt, opts, 0);
+ pfctl_show_states(dev, ifaceopt, opts);
pfctl_show_src_nodes(dev, opts);
pfctl_show_status(dev, opts);
pfctl_show_rules(dev, opts, 1, anchorname, rulesetname);
diff --git a/sbin/pfctl/pfctl.h b/sbin/pfctl/pfctl.h
index a577e1d324e..dd39abab319 100644
--- a/sbin/pfctl/pfctl.h
+++ b/sbin/pfctl/pfctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.h,v 1.32 2004/02/17 08:48:29 cedric Exp $ */
+/* $OpenBSD: pfctl.h,v 1.33 2004/02/19 21:37:01 cedric Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -83,7 +83,7 @@ int pfctl_clear_tables(const char *, const char *, int);
int pfctl_show_tables(const char *, const char *, int);
int pfctl_command_tables(int, char *[], char *, const char *, char *,
const char *, const char *, int);
-int pfctl_show_altq(int, int, int);
+int pfctl_show_altq(int, const char *, int, int);
void warn_namespace_collision(const char *);
int pfctl_show_ifaces(const char *, int);
diff --git a/sbin/pfctl/pfctl_qstats.c b/sbin/pfctl/pfctl_qstats.c
index 776c36a47c6..b5f0903950d 100644
--- a/sbin/pfctl/pfctl_qstats.c
+++ b/sbin/pfctl/pfctl_qstats.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl_qstats.c,v 1.27 2004/02/10 17:53:37 henning Exp $ */
+/* $OpenBSD: pfctl_qstats.c,v 1.28 2004/02/19 21:37:01 cedric Exp $ */
/*
* Copyright (c) Henning Brauer <henning@openbsd.org>
@@ -81,19 +81,24 @@ void pfctl_print_altq_nodestat(int,
void update_avg(struct pf_altq_node *);
int
-pfctl_show_altq(int dev, int opts, int verbose2)
+pfctl_show_altq(int dev, const char *iface, int opts, int verbose2)
{
struct pf_altq_node *root = NULL, *node;
- int nodes;
+ int nodes, dotitle = (opts & PF_OPT_SHOWALL);
if ((nodes = pfctl_update_qstats(dev, &root)) < 0)
return (-1);
- if (opts & PF_OPT_SHOWALL && nodes > 0)
- pfctl_print_title("ALTQ:");
- for (node = root; node != NULL; node = node->next)
+ for (node = root; node != NULL; node = node->next) {
+ if (iface != NULL && strcmp(node->altq.ifname, iface))
+ continue;
+ if (dotitle) {
+ pfctl_print_title("ALTQ:");
+ dotitle = 0;
+ }
pfctl_print_altq_node(dev, node, 0, opts);
+ }
while (verbose2) {
printf("\n");
@@ -101,8 +106,11 @@ pfctl_show_altq(int dev, int opts, int verbose2)
sleep(STAT_INTERVAL);
if (pfctl_update_qstats(dev, &root) == -1)
return (-1);
- for (node = root; node != NULL; node = node->next)
+ for (node = root; node != NULL; node = node->next) {
+ if (iface != NULL && strcmp(node->altq.ifname, iface))
+ continue;
pfctl_print_altq_node(dev, node, 0, opts);
+ }
}
pfctl_free_altq_node(root);
return (0);
diff --git a/sbin/pfctl/pfctl_table.c b/sbin/pfctl/pfctl_table.c
index 8a790283f61..9daa0b646a7 100644
--- a/sbin/pfctl/pfctl_table.c
+++ b/sbin/pfctl/pfctl_table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl_table.c,v 1.56 2004/02/17 08:48:29 cedric Exp $ */
+/* $OpenBSD: pfctl_table.c,v 1.57 2004/02/19 21:37:01 cedric Exp $ */
/*
* Copyright (c) 2002 Cedric Berger
@@ -541,15 +541,16 @@ pfctl_show_ifaces(const char *filter, int opts)
{
struct pfr_buffer b;
struct pfi_if *p;
- int i = 0;
+ int i = 0, f = PFI_FLAG_GROUP|PFI_FLAG_INSTANCE;
+ if (filter != NULL && *filter && !isdigit(filter[strlen(filter)-1]))
+ f &= ~PFI_FLAG_INSTANCE;
bzero(&b, sizeof(b));
b.pfrb_type = PFRB_IFACES;
for (;;) {
pfr_buf_grow(&b, b.pfrb_size);
b.pfrb_size = b.pfrb_msize;
- if (pfi_get_ifaces(filter, b.pfrb_caddr, &b.pfrb_size,
- PFI_FLAG_GROUP|PFI_FLAG_INSTANCE)) {
+ if (pfi_get_ifaces(filter, b.pfrb_caddr, &b.pfrb_size, f)) {
radix_perror();
return (1);
}