From nobody Wed Mar 02 16:00:53 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 7613419E1009; Wed, 2 Mar 2022 16:00:56 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4K7zP30fGYz3NW6; Wed, 2 Mar 2022 16:00:54 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646236856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K4blWfkhy+yxAG8IT84F7l3pMGxYbj92YcxM7rMp/bE=; b=BHrvXyRjpePhpt3tL+GLk35abUCvwDZmNPs6jhlCOaD4Pv5sWVCtzdo76fVGDhyIpusLtI ztusIpoHxQJjsbQg1i/+Lk56/mOID/gBCII+qPpCdPD+WTRZMWipCwBtHM1O4HuJwmRHGe 89AKTvU3OrdDFt/EmX9uE6/MA8HERl7944aMhCNJRtDUawrzvTVsBmwd75Aw8TwbODlvqp rwJE418dCBAoL1F0tNFvc6YR0guqJd+DscScyGNxMo4NrKgLrIXPEUuxERRToazZaCuXF+ SbqRQo7w8em+Ofeg7EgVJACz2ulW8N5hZD5MtFXyO41qaLYQeRvmi8yWBEj0xg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id C253D26342; Wed, 2 Mar 2022 16:00:53 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 222G0rZ7091229; Wed, 2 Mar 2022 16:00:53 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 222G0rtt091228; Wed, 2 Mar 2022 16:00:53 GMT (envelope-from git) Date: Wed, 2 Mar 2022 16:00:53 GMT Message-Id: <202203021600.222G0rtt091228@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: c696d5c72fe1 - main - pfctl: Don't print (ether) to / from if they're not set List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: c696d5c72fe1426f26f798260f8cdc97e6f8cee5 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1646236856; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=K4blWfkhy+yxAG8IT84F7l3pMGxYbj92YcxM7rMp/bE=; b=cIW7tP9JWXZs22Rl0FMXZIp+uIZM3Mzn/uihfrKeLX1ga6nWH8zxdXC8MdXBn8BllHxIhs jQhQIBoxqg4xG5o4z29yCDOcnExHftq25ffbWZsGAi/N2Lfe9KElZzc+DAJxQcKHKI576c JYK42twbEMbkcTksR7RIhsVZaQCcg12dGF/a7QlHF8GX1gDNNPRNYwoClzmjCDPOYqnQKT byv6N1tDufNHFQuhHR0iXDbVcwZSYj4hCeUm2+gXgnR1eBEbfPQoPbOQVVeSuVrH+OTCHo wz3jU/IYfdaMJ/9vuG1kzeWz4YcWaOPrHNAd3ZEk99hEqSDeGjUhdMu9Wt+eZw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1646236856; a=rsa-sha256; cv=none; b=H9dBVJsaTGee3Njvw6BsErL4qdfEU4zUvN6YPbunZesFAP9dtBtI5/mm0vJAsISNIyZkCA AHAu9BvMldOqLeCWmDna367EJF+HnfN+OUHC+KfEnSfuG9IZ7sYsbD6fYNnT+IkJ1nAfna FzIJo7oOb2yicWM/h0u89+g0leGDeGaeO1luEQYw8lo5nzqVZ045cqP7gF5CrEOPpn5TRn 1wS00b2NIO9NWfT54WRfhNi784x98m0Jz0gJcD6gaKRwOEcp/HIuH1QFVZnmV8EPGuZtMl 8DsPOh9yGg3wADrpeE2wgLeOg6Ox/2Pn0VSB4qCPUUwq9VXaxjCme87II9PAww== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=c696d5c72fe1426f26f798260f8cdc97e6f8cee5 commit c696d5c72fe1426f26f798260f8cdc97e6f8cee5 Author: Kristof Provost AuthorDate: 2021-02-17 16:38:04 +0000 Commit: Kristof Provost CommitDate: 2022-03-02 16:00:05 +0000 pfctl: Don't print (ether) to / from if they're not set If we're not filtering on a specific MAC address don't print it at all, rather than showing an all-zero address. Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D31749 --- lib/libpfctl/libpfctl.c | 4 ++++ lib/libpfctl/libpfctl.h | 1 + sbin/pfctl/pfctl_parser.c | 22 ++++++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/lib/libpfctl/libpfctl.c b/lib/libpfctl/libpfctl.c index e158faf317c1..7255d18410a8 100644 --- a/lib/libpfctl/libpfctl.c +++ b/lib/libpfctl/libpfctl.c @@ -549,6 +549,7 @@ pf_nvrule_to_rule(const nvlist_t *nvl, struct pfctl_rule *rule) static void pfctl_nveth_addr_to_eth_addr(const nvlist_t *nvl, struct pfctl_eth_addr *addr) { + static const u_int8_t EMPTY_MAC[ETHER_ADDR_LEN] = { 0 }; size_t len; const void *data; @@ -557,6 +558,9 @@ pfctl_nveth_addr_to_eth_addr(const nvlist_t *nvl, struct pfctl_eth_addr *addr) memcpy(addr->addr, data, sizeof(addr->addr)); addr->neg = nvlist_get_bool(nvl, "neg"); + + /* To make checks for 'is this address set?' easier. */ + addr->isset = memcmp(addr->addr, EMPTY_MAC, ETHER_ADDR_LEN) != 0; } static nvlist_t * diff --git a/lib/libpfctl/libpfctl.h b/lib/libpfctl/libpfctl.h index e2b3711f9ffd..b44200e00ad9 100644 --- a/lib/libpfctl/libpfctl.h +++ b/lib/libpfctl/libpfctl.h @@ -73,6 +73,7 @@ struct pfctl_eth_rules_info { struct pfctl_eth_addr { uint8_t addr[ETHER_ADDR_LEN]; bool neg; + bool isset; }; struct pfctl_eth_rule { diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 8814dc38b23c..c7e980103fad 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -694,6 +694,16 @@ print_src_node(struct pf_src_node *sn, int opts) static void print_eth_addr(const struct pfctl_eth_addr *a) { + int i; + for (i = 0; i < ETHER_ADDR_LEN; i++) { + if (a->addr[i] != 0) + break; + } + + /* Unset, so don't print anything. */ + if (i == ETHER_ADDR_LEN) + return; + printf("%s%02x:%02x:%02x:%02x:%02x:%02x", a->neg ? "! " : "", a->addr[0], a->addr[1], a->addr[2], a->addr[3], a->addr[4], a->addr[5]); @@ -724,10 +734,14 @@ print_eth_rule(struct pfctl_eth_rule *r, int rule_numbers) if (r->proto) printf(" proto 0x%04x", r->proto); - printf(" from "); - print_eth_addr(&r->src); - printf(" to "); - print_eth_addr(&r->dst); + if (r->src.isset) { + printf(" from "); + print_eth_addr(&r->src); + } + if (r->dst.isset) { + printf(" to "); + print_eth_addr(&r->dst); + } if (r->qname[0]) printf(" queue %s", r->qname);