summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sbin/pfctl/pf_print_state.c30
-rw-r--r--sbin/pfctl/pfctl.h4
-rw-r--r--usr.sbin/tcpdump/pf_print_state.c23
3 files changed, 36 insertions, 21 deletions
diff --git a/sbin/pfctl/pf_print_state.c b/sbin/pfctl/pf_print_state.c
index e0ba940413f..6a6c5378c8a 100644
--- a/sbin/pfctl/pf_print_state.c
+++ b/sbin/pfctl/pf_print_state.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_print_state.c,v 1.61 2012/06/01 08:35:45 jsg Exp $ */
+/* $OpenBSD: pf_print_state.c,v 1.62 2012/07/08 17:48:37 lteo Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -166,8 +166,11 @@ print_name(struct pf_addr *addr, sa_family_t af)
void
print_host(struct pf_addr *addr, u_int16_t port, sa_family_t af, u_int16_t rdom,
- int opts)
+ const char *proto, int opts)
{
+ struct servent *s = NULL;
+ char ps[6];
+
if (rdom)
printf("(%u) ", ntohs(rdom));
@@ -188,10 +191,13 @@ print_host(struct pf_addr *addr, u_int16_t port, sa_family_t af, u_int16_t rdom,
}
if (port) {
+ snprintf(ps, sizeof(ps), "%u", ntohs(port));
+ if (opts & PF_OPT_PORTNAMES)
+ s = getservbyport(port, proto);
if (af == AF_INET)
- printf(":%u", ntohs(port));
+ printf(":%s", s ? s->s_name : ps);
else
- printf("[%u]", ntohs(port));
+ printf("[%s]", s ? s->s_name : ps);
}
}
@@ -212,6 +218,7 @@ print_state(struct pfsync_state *s, int opts)
struct pfsync_state_peer *src, *dst;
struct pfsync_state_key *sk, *nk;
struct protoent *p;
+ char *pn = NULL;
int min, sec;
int afto = (s->key[PF_SK_STACK].af != s->key[PF_SK_WIRE].af);
int idx;
@@ -232,33 +239,34 @@ print_state(struct pfsync_state *s, int opts)
sk->port[1] = nk->port[1];
}
printf("%s ", s->ifname);
- if ((p = getprotobynumber(s->proto)) != NULL)
- printf("%s ", p->p_name);
- else
+ if ((p = getprotobynumber(s->proto)) != NULL) {
+ pn = p->p_name;
+ printf("%s ", pn);
+ } else
printf("%u ", s->proto);
- print_host(&nk->addr[1], nk->port[1], nk->af, nk->rdomain, opts);
+ print_host(&nk->addr[1], nk->port[1], nk->af, nk->rdomain, pn, opts);
if (nk->af != sk->af || PF_ANEQ(&nk->addr[1], &sk->addr[1], nk->af) ||
nk->port[1] != sk->port[1] ||
nk->rdomain != sk->rdomain) {
idx = afto ? 0 : 1;
printf(" (");
print_host(&sk->addr[idx], sk->port[idx], sk->af,
- sk->rdomain, opts);
+ sk->rdomain, pn, opts);
printf(")");
}
if (s->direction == PF_OUT || (afto && s->direction == PF_IN))
printf(" -> ");
else
printf(" <- ");
- print_host(&nk->addr[0], nk->port[0], nk->af, nk->rdomain, opts);
+ print_host(&nk->addr[0], nk->port[0], nk->af, nk->rdomain, pn, opts);
if (nk->af != sk->af || PF_ANEQ(&nk->addr[0], &sk->addr[0], nk->af) ||
nk->port[0] != sk->port[0] ||
nk->rdomain != sk->rdomain) {
idx = afto ? 1 : 0;
printf(" (");
print_host(&sk->addr[idx], sk->port[idx], sk->af,
- sk->rdomain, opts);
+ sk->rdomain, pn, opts);
printf(")");
}
diff --git a/sbin/pfctl/pfctl.h b/sbin/pfctl/pfctl.h
index b1864235a62..0b99cb56b4f 100644
--- a/sbin/pfctl/pfctl.h
+++ b/sbin/pfctl/pfctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pfctl.h,v 1.49 2012/06/01 08:35:45 jsg Exp $ */
+/* $OpenBSD: pfctl.h,v 1.50 2012/07/08 17:48:37 lteo Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -106,7 +106,7 @@ struct pf_altq *pfaltq_lookup(const char *);
char *rate2str(double);
void print_addr(struct pf_addr_wrap *, sa_family_t, int);
-void print_host(struct pf_addr *, u_int16_t p, sa_family_t, u_int16_t, int);
+void print_host(struct pf_addr *, u_int16_t p, sa_family_t, u_int16_t, const char *, int);
void print_seq(struct pfsync_state_peer *);
void print_state(struct pfsync_state *, int);
int unmask(struct pf_addr *, sa_family_t);
diff --git a/usr.sbin/tcpdump/pf_print_state.c b/usr.sbin/tcpdump/pf_print_state.c
index 08b54985b9c..c6971fcdba5 100644
--- a/usr.sbin/tcpdump/pf_print_state.c
+++ b/usr.sbin/tcpdump/pf_print_state.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: pf_print_state.c,v 1.10 2011/10/13 18:32:30 claudio Exp $ */
+/* $OpenBSD: pf_print_state.c,v 1.11 2012/07/08 17:48:37 lteo Exp $ */
/*
* Copyright (c) 2001 Daniel Hartmeier
@@ -130,8 +130,11 @@ print_name(struct pf_addr *addr, sa_family_t af)
void
print_host(struct pf_addr *addr, u_int16_t port, sa_family_t af, u_int16_t rdom,
- int opts)
+ const char *proto, int opts)
{
+ struct servent *s = NULL;
+ char ps[6];
+
if (rdom)
printf("(%u) ", ntohs(rdom));
@@ -152,10 +155,13 @@ print_host(struct pf_addr *addr, u_int16_t port, sa_family_t af, u_int16_t rdom,
}
if (port) {
+ snprintf(ps, sizeof(ps), "%u", ntohs(port));
+ if (opts & PF_OPT_PORTNAMES)
+ s = getservbyport(port, proto);
if (af == AF_INET)
- printf(":%u", ntohs(port));
+ printf(":%s", s ? s->s_name : ps);
else
- printf("[%u]", ntohs(port));
+ printf("[%s]", s ? s->s_name : ps);
}
}
@@ -200,23 +206,24 @@ print_state(struct pfsync_state *s, int opts)
else
sidx = 0, didx = 1;
- print_host(&nk->addr[didx], nk->port[didx], nk->af, nk->rdomain, opts);
+ print_host(&nk->addr[didx], nk->port[didx], nk->af, nk->rdomain, NULL, opts);
if (nk->af != sk->af || PF_ANEQ(&nk->addr[1], &sk->addr[1], nk->af) ||
nk->port[1] != sk->port[1]) {
printf(" (");
print_host(&sk->addr[1], sk->port[1], sk->af, sk->rdomain,
- opts);
+ NULL, opts);
printf(")");
}
if (s->direction == PF_OUT)
printf(" -> ");
else
printf(" <- ");
- print_host(&nk->addr[sidx], nk->port[sidx], nk->af, nk->rdomain, opts);
+ print_host(&nk->addr[sidx], nk->port[sidx], nk->af, nk->rdomain, NULL,
+ opts);
if (nk->af != sk->af || PF_ANEQ(&nk->addr[0], &sk->addr[0], nk->af) ||
nk->port[0] != sk->port[0]) {
printf(" (");
- print_host(&sk->addr[0], sk->port[0], sk->af, sk->rdomain,
+ print_host(&sk->addr[0], sk->port[0], sk->af, sk->rdomain, NULL,
opts);
printf(")");
}