Skip to content

Commit

Permalink
ipfilter: Print protocol when listing NAT table mappings
Browse files Browse the repository at this point in the history
NAT table mappings list only the source and destination IP, the source
and destinaion port numbers, and their mappings. But the protocol is not
listed. Now that Facebook and Google use QUIC, seeing port 443 in in a
list of active NAT sessions could mean 443/tcp or 443/udp. This patch
adds the protocol to the listing to aid in determining whether HTTPS is
TCP or QUIC in a NAT mapping listing. This also helps differentiatinete
between other protocols such as ICMP, ESP, and AH in ipnat list of active
sessions.

(cherry picked from commit 9291d07)
  • Loading branch information
cschuber committed Mar 7, 2022
1 parent 6b3a14c commit d1f3afc
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions sbin/ipf/libipf/printactivenat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@
static const char rcsid[] = "@(#)$Id$";
#endif

static int proto_opened = 0;

void
printactivenat(nat_t *nat, int opts, u_long ticks)
{
struct protoent *pproto;

if (proto_opened == 0) {
proto_opened = 1;
setprotoent(1);
}

PRINTF("%s", getnattype(nat));

Expand Down Expand Up @@ -55,6 +62,9 @@ printactivenat(nat_t *nat, int opts, u_long ticks)
if ((nat->nat_flags & IPN_TCPUDP) != 0)
PRINTF(" %-5hu", ntohs(nat->nat_ndport));

pproto = getprotobynumber(nat->nat_pr[0]);
PRINTF(" %s", pproto->p_name);

} else if (nat->nat_dir == NAT_OUTBOUND) {
printactiveaddress(nat->nat_v[0], "%-15s", &nat->nat_osrc6,
nat->nat_ifnames[0]);
Expand All @@ -76,6 +86,9 @@ printactivenat(nat_t *nat, int opts, u_long ticks)
if ((nat->nat_flags & IPN_TCPUDP) != 0)
PRINTF(" %hu", ntohs(nat->nat_odport));
PRINTF("]");

pproto = getprotobynumber(nat->nat_pr[1]);
PRINTF(" %s", pproto->p_name);
} else {
printactiveaddress(nat->nat_v[1], "%-15s", &nat->nat_ndst6,
nat->nat_ifnames[0]);
Expand All @@ -97,8 +110,12 @@ printactivenat(nat_t *nat, int opts, u_long ticks)
if ((nat->nat_flags & IPN_TCPUDP) != 0)
PRINTF(" %hu", ntohs(nat->nat_osport));
PRINTF("]");

pproto = getprotobynumber(nat->nat_pr[0]);
PRINTF(" %s", pproto->p_name);
}


if (opts & OPT_VERBOSE) {
PRINTF("\n\tttl %lu use %hu sumd %s/",
nat->nat_age - ticks, nat->nat_use,
Expand Down

0 comments on commit d1f3afc

Please sign in to comment.