From nobody Thu Sep 19 20:21:19 2024 X-Original-To: dev-commits-src-main@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 4X8n3N4CjSz5XKxx; Thu, 19 Sep 2024 20:21:20 +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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4X8n3N00lXz4WjD; Thu, 19 Sep 2024 20:21:20 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777280; 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=cMqizNUQkEbBEDwwo0U0Mom2fIGUJyHJ80wqZe/xZIk=; b=vNmQk2/lNzMlP+bipLUPoPHXth/ZeQELPHYl1ioC6x8F8XBboSQJ2uOn0bmVaISFDJhkAd j6qoeQ3HQHs4BgoIHOasImSnW/1demRo3WOdfkH52PJRCSwx5i9HBUeR85F/dfKnTw+5TT JtDN2LvtONkwR+7n+IODjcUR5LkEdhLWqDZxzZ4GSTf6IYtWn4v5fBdkRlFvBGPG1/2kW5 k8G9ZdBa8tPVK7t/J6ihxhixHCsa2GxuPi08t4xpTUHVWa7DsSVxbVmC+4/43soYrgNOsz YcoJOWDjBXdevSQm/EeWNnHWlSI1xfJuM1e17W2YsnUBa5v5GPuuCspxglbVRA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1726777280; a=rsa-sha256; cv=none; b=xesta6b8hQf0ziIQtYulvrPawEY2PJhbD9hPWk7ZZ44gkhl7ScEZ5AuB/6t3BV+cig82hG LoglaovYe2xsEOkQPRKLyCAYkZmB/M5vZ1Mpvd1ktONm10yxVCEIBFzHkhrtrHNqZt9bA+ 6zuUyVJVrYyu95aJGRNIY4qfCJhWgrmXUiVs2LZZPIvPqvvuI69OsVOjP3R3BWVslzfWEl oNibK0slH86ohHBdXVazCMELS4+MNue3gMd9xppRX+Ldt0SvOYLXYfYw6xSv/Qsvaa5rwe aAsLlN+l8l0m2t4J7NmPBiGcO1X9kHOLauJ8j9KS+OWIzAgZNFsraaob0KcLgA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1726777280; 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=cMqizNUQkEbBEDwwo0U0Mom2fIGUJyHJ80wqZe/xZIk=; b=Eqd/bTCxW6HnY0XVHAzHLkJYr5X2hEkFUR/m4z5BTEiKJTNsDro6OStDyrgFJsZJMsLhDX FU99aQ/iN8ZuvzIZhSTTdqiL3ufRmd4C8xDsocyA35baCvhG6d73O70vQym3fSkVsgX66O CC6XdHt13wzUdTBJQJ2gzz1qrXl91PLrFBhZyxKUw+Kt66Cz8KopaQBmMeBQE4rWkhRdvq 5P1tR290FWXXxeUkzEiD8ePMuAJ1UzA+RYm73Zaur0OX9zEyh5Uw3wVoCdNE96h9TbBN5q EP8+9hql+xdjkNg0psjmwZ9jza22dVxmktpN8Q82a2BUhZqqlLjPOOeA8R9lhA== 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 4X8n3M6jL5zKvH; Thu, 19 Sep 2024 20:21:19 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 48JKLJ9c046444; Thu, 19 Sep 2024 20:21:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 48JKLJAv046441; Thu, 19 Sep 2024 20:21:19 GMT (envelope-from git) Date: Thu, 19 Sep 2024 20:21:19 GMT Message-Id: <202409192021.48JKLJAv046441@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: f3ab00c2b607 - main - pf: add a new log opt PF_LOG_MATCHES List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@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: f3ab00c2b607f80f69963f8a38a8d1910ed4e593 Auto-Submitted: auto-generated The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=f3ab00c2b607f80f69963f8a38a8d1910ed4e593 commit f3ab00c2b607f80f69963f8a38a8d1910ed4e593 Author: Kristof Provost AuthorDate: 2024-09-03 13:32:57 +0000 Commit: Kristof Provost CommitDate: 2024-09-19 20:20:13 +0000 pf: add a new log opt PF_LOG_MATCHES forces logging on all subsequent matching rules new log opt "matches" awesome for debugging, a rule like match log(matches) from $testbox will show you exactly which subsequent rules match on that packet real ok theo assumed oks ryan & dlg bikeshedding many Obtained from: OpenBSD, henning , 1603e01ae4 Obtained from: OpenBSD, henning , f496e91672 Obtained from: OpenBSD, henning , 07481a9fee Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D46588 --- sbin/pfctl/parse.y | 4 +++- sbin/pfctl/pfctl_parser.c | 2 ++ share/man/man5/pf.conf.5 | 4 +++- sys/netpfil/pf/pf.c | 8 ++++++-- sys/netpfil/pf/pf.h | 1 + 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index cfa6c85b5c0a..9d95122f9826 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -507,7 +507,7 @@ int parseport(char *, struct range *r, int); %token REASSEMBLE ANCHOR NATANCHOR RDRANCHOR BINATANCHOR %token SET OPTIMIZATION TIMEOUT LIMIT LOGINTERFACE BLOCKPOLICY FAILPOLICY %token RANDOMID REQUIREORDER SYNPROXY FINGERPRINTS NOSYNC DEBUG SKIP HOSTID -%token ANTISPOOF FOR INCLUDE KEEPCOUNTERS SYNCOOKIES L3 +%token ANTISPOOF FOR INCLUDE KEEPCOUNTERS SYNCOOKIES L3 MATCHES %token ETHER %token BITMASK RANDOM SOURCEHASH ROUNDROBIN STATICPORT PROBABILITY MAPEPORTSET %token ALTQ CBQ CODEL PRIQ HFSC FAIRQ BANDWIDTH TBRSIZE LINKSHARE REALTIME @@ -3222,6 +3222,7 @@ logopts : logopt { $$ = $1; } ; logopt : ALL { $$.log = PF_LOG_ALL; $$.logif = 0; } + | MATCHES { $$.log = PF_LOG_MATCHES; $$.logif = 0; } | USER { $$.log = PF_LOG_SOCKET_LOOKUP; $$.logif = 0; } | GROUP { $$.log = PF_LOG_SOCKET_LOOKUP; $$.logif = 0; } | TO string { @@ -6365,6 +6366,7 @@ lookup(char *s) { "loginterface", LOGINTERFACE}, { "map-e-portset", MAPEPORTSET}, { "match", MATCH}, + { "matches", MATCHES}, { "max", MAXIMUM}, { "max-mss", MAXMSS}, { "max-src-conn", MAXSRCCONN}, diff --git a/sbin/pfctl/pfctl_parser.c b/sbin/pfctl/pfctl_parser.c index 2e6a1d1cb1c5..70c2ad42ca55 100644 --- a/sbin/pfctl/pfctl_parser.c +++ b/sbin/pfctl/pfctl_parser.c @@ -918,6 +918,8 @@ print_rule(struct pfctl_rule *r, const char *anchor_call, int verbose, int numer printf(" ("); if (r->log & PF_LOG_ALL) printf("%sall", count++ ? ", " : ""); + if (r->log & PF_LOG_MATCHES) + printf("%smatches", count++ ? ", " : ""); if (r->log & PF_LOG_SOCKET_LOOKUP) printf("%suser", count++ ? ", " : ""); if (r->logif) diff --git a/share/man/man5/pf.conf.5 b/share/man/man5/pf.conf.5 index bfa79b928b69..28cd2407b41a 100644 --- a/share/man/man5/pf.conf.5 +++ b/share/man/man5/pf.conf.5 @@ -1684,6 +1684,8 @@ As with .Ar log , packets are logged to .Xr pflog 4 . +.It Ar log (matches) +Used to force logging of this packet on all subsequent matching rules. .It Ar log (user) Logs the .Ux @@ -3217,7 +3219,7 @@ pf-rule = action [ ( "in" | "out" ) ] hosts [ filteropt-list ] logopts = logopt [ "," logopts ] -logopt = "all" | "user" | "to" interface-name +logopt = "all" | "matches" | "user" | "to" interface-name etherfilteropt-list = etherfilteropt-list etherfilteropt | etherfilteropt etherfilteropt = "tag" string | "tagged" string | "queue" ( string ) | diff --git a/sys/netpfil/pf/pf.c b/sys/netpfil/pf/pf.c index f340c76da40e..4d0cee4d0c4a 100644 --- a/sys/netpfil/pf/pf.c +++ b/sys/netpfil/pf/pf.c @@ -5198,7 +5198,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, struct pfi_kkif *kif, pf_counter_u64_add_protected(&r->bytes[pd->dir == PF_OUT], pd->tot_len); pf_counter_u64_critical_exit(); pf_rule_to_actions(r, &pd->act); - if (r->log) + if (r->log || pd->act.log & PF_LOG_MATCHES) PFLOG_PACKET(kif, m, af, r->action, PFRES_MATCH, r, a, ruleset, pd, 1); @@ -5207,6 +5207,10 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, struct pfi_kkif *kif, *rm = r; *am = a; *rsm = ruleset; + if (pd->act.log & PF_LOG_MATCHES) + PFLOG_PACKET(kif, m, af, + r->action, PFRES_MATCH, r, + a, ruleset, pd, 1); } if ((*rm)->quick) break; @@ -5229,7 +5233,7 @@ pf_test_rule(struct pf_krule **rm, struct pf_kstate **sm, struct pfi_kkif *kif, /* apply actions for last matching pass/block rule */ pf_rule_to_actions(r, &pd->act); - if (r->log) { + if (r->log || pd->act.log & PF_LOG_MATCHES) { if (rewrite) m_copyback(m, off, hdrlen, pd->hdr.any); PFLOG_PACKET(kif, m, af, r->action, reason, r, a, ruleset, pd, 1); diff --git a/sys/netpfil/pf/pf.h b/sys/netpfil/pf/pf.h index 6370164cb291..063abe83274b 100644 --- a/sys/netpfil/pf/pf.h +++ b/sys/netpfil/pf/pf.h @@ -137,6 +137,7 @@ enum { PF_ADDR_ADDRMASK, PF_ADDR_NOROUTE, PF_ADDR_DYNIFTL, #define PF_LOG_ALL 0x02 #define PF_LOG_SOCKET_LOOKUP 0x04 #define PF_LOG_FORCE 0x08 +#define PF_LOG_MATCHES 0x10 /* Reasons code for passing/dropping a packet */ #define PFRES_MATCH 0 /* Explicit match of a rule */