]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
ipfilter: Print protocol when listing NAT table mappings
authorCy Schubert <cy@FreeBSD.org>
Mon, 28 Feb 2022 19:43:33 +0000 (11:43 -0800)
committerCy Schubert <cy@FreeBSD.org>
Mon, 7 Mar 2022 13:32:58 +0000 (05:32 -0800)
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 9291d079d54b828b43d3714a5f19f0ffe92837b8)

sbin/ipf/libipf/printactivenat.c

index fcef19a4efa7909780dea3770082ff96acdcdaf9..3a6337ab0f7b8c29b0c556fc858d241b97effb87 100644 (file)
 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));
 
@@ -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]);
@@ -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]);
@@ -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,