From owner-freebsd-pf@freebsd.org Mon Dec 23 16:43:23 2019 Return-Path: Delivered-To: freebsd-pf@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 239961CBAE1 for ; Mon, 23 Dec 2019 16:43:23 +0000 (UTC) (envelope-from longwitz@incore.de) Received: from dss.incore.de (dss.incore.de [195.145.1.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 47hQCG1Fyvz3Lnm for ; Mon, 23 Dec 2019 16:43:21 +0000 (UTC) (envelope-from longwitz@incore.de) Received: from inetmail.dmz (inetmail.dmz [10.3.0.3]) by dss.incore.de (Postfix) with ESMTP id 9BD0F28E10 for ; Mon, 23 Dec 2019 17:43:20 +0100 (CET) X-Virus-Scanned: amavisd-new at incore.de Received: from dss.incore.de ([10.3.0.3]) by inetmail.dmz (inetmail.dmz [10.3.0.3]) (amavisd-new, port 10024) with LMTP id yia5HrIb5ed1 for ; Mon, 23 Dec 2019 17:43:19 +0100 (CET) Received: from mail.local.incore (fwintern.dmz [10.0.0.253]) by dss.incore.de (Postfix) with ESMTP id 77F7D28E0A for ; Mon, 23 Dec 2019 17:43:19 +0100 (CET) Received: from bsdmhs.longwitz (unknown [192.168.99.6]) by mail.local.incore (Postfix) with ESMTP id 58EA3102 for ; Mon, 23 Dec 2019 17:43:19 +0100 (CET) Message-ID: <5E00EEA7.1070205@incore.de> Date: Mon, 23 Dec 2019 17:43:19 +0100 From: Andreas Longwitz User-Agent: Thunderbird 2.0.0.19 (X11/20090113) MIME-Version: 1.0 To: freebsd-pf@freebsd.org Subject: Flow of broadcast/multicast packets in pf when a bridge is present Content-Type: text/plain; charset=ISO-8859-15 Content-Transfer-Encoding: 7bit X-Rspamd-Queue-Id: 47hQCG1Fyvz3Lnm X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=none; spf=pass (mx1.freebsd.org: domain of longwitz@incore.de designates 195.145.1.138 as permitted sender) smtp.mailfrom=longwitz@incore.de X-Spamd-Result: default: False [-4.58 / 15.00]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; RCVD_COUNT_FIVE(0.00)[5]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+mx:c]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[freebsd-pf@freebsd.org]; RCPT_COUNT_ONE(0.00)[1]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; RCVD_TLS_LAST(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[138.1.145.195.list.dnswl.org : 127.0.10.0]; IP_SCORE(-2.28)[ip: (-8.73), ipnet: 195.145.0.0/16(-3.22), asn: 3320(0.55), country: DE(-0.02)]; DMARC_NA(0.00)[incore.de]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:3320, ipnet:195.145.0.0/16, country:DE]; MID_RHS_MATCH_FROM(0.00)[] X-BeenThere: freebsd-pf@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Technical discussion and general questions about packet filter \(pf\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Dec 2019 16:43:23 -0000 On a server with a bridge running FreeBSD 12.1-STABLE r354175 I try to understand the flow of broadcast/multicast packets in pf. The bridge interface is defined with ifconfig_bridge0="inet 192.168.0.125/24 addm em0 addm em1 up, further I use net.link.bridge.inherit_mac=1, the other net.link.bridge sysctls are default. For an incoming broadcast packet on em0 I would expect that pf_test() is called with dir=PF_IN two times: for if=em0 and for if=bridge0. Indeed this happens: ether_input --> bridge_input --> bridge_forward --> bridge_pfil and bridge_pfil calls pfil_run_hooks first for em0 and second for bridge0. This is not done with the original packet but a clone (mbuf mc) created by bridge_input before bridge_forward is called. Next bridge_input does reinject another copy of the original packet truncated to length max_protohdr to the bridge: /* * Reinject the mbuf as arriving on the bridge so we have a * chance at claiming multicast packets. We can not loop back * here from ether_input as a bridge is never a member of a * bridge. */ KASSERT(bifp->if_bridge == NULL, ("loop created in bridge_input")); mc2 = m_dup(m, M_NOWAIT); if (mc2 != NULL) { /* Keep the layer3 header aligned */ int i = min(mc2->m_pkthdr.len, max_protohdr); mc2 = m_copyup(mc2, i, ETHER_ALIGN); } if (mc2 != NULL) { mc2->m_pkthdr.rcvif = bifp; (*bifp->if_input)(bifp, mc2); } This coding was committed in rev 150099, 150551 and 153622. pf_test() sees and counts this shortened packet for if=bridge0 and I really do not understand the reason why this reinject is done. At last pf_test() is called once more (for if=em0) when bridge_input finishes with /* Return the original packet for local processing. */ return (m); This time pf_test() sees the original packet on if=em0, but I do not see a way in the pf rules to distinguish this packet from the packet pf has seen first. Andreas