From owner-freebsd-pf@FreeBSD.ORG Wed Jun 15 22:57:37 2005 Return-Path: X-Original-To: freebsd-pf@freebsd.org Delivered-To: freebsd-pf@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5479516A41C; Wed, 15 Jun 2005 22:57:37 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from ns1.xcllnt.net (209-128-86-226.BAYAREA.NET [209.128.86.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id 0970F43D4C; Wed, 15 Jun 2005 22:57:36 +0000 (GMT) (envelope-from marcel@xcllnt.net) Received: from [192.168.4.250] (dhcp50.pn.xcllnt.net [192.168.4.250]) by ns1.xcllnt.net (8.13.3/8.13.3) with ESMTP id j5FMvNCc009334; Wed, 15 Jun 2005 15:57:23 -0700 (PDT) (envelope-from marcel@xcllnt.net) In-Reply-To: <20050615223450.GY8526@insomnia.benzedrine.cx> References: <200506132123.j5DLNove069255@freefall.freebsd.org> <20050615204232.GX8526@insomnia.benzedrine.cx> <20050615223450.GY8526@insomnia.benzedrine.cx> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Marcel Moolenaar Date: Wed, 15 Jun 2005 15:57:20 -0700 To: Daniel Hartmeier X-Mailer: Apple Mail (2.622) Cc: freebsd-net@freebsd.org, Marcel Moolenaar , freebsd-pf@freebsd.org Subject: Re: ia64/81284: Unaligned Reference with pf on 5.4/IA64 X-BeenThere: freebsd-pf@freebsd.org X-Mailman-Version: 2.1.5 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: Wed, 15 Jun 2005 22:57:37 -0000 On Jun 15, 2005, at 3:34 PM, Daniel Hartmeier wrote: > On Wed, Jun 15, 2005 at 02:23:24PM -0700, Marcel Moolenaar wrote: > >> That entirely depends. If a struct ip pointer is constructed without >> any form of casting, then one can assume that alignment is guaranteed. >> The compiler guarantees to do so, except of course in this case: >> the structure is defined as a packed structure. We, as the developers, >> have told the compiler to *NOT* guarantee alignment of fields. We're >> on our own and we miserably fail being on our own. > > 'packed', as I understand it, prohibits the compiler from inserting any > padding anywhere in the struct. That is, it guarantees that the total > size of a struct object equals the sum of the sizes of its members. > > As a consequence, individual members can't be aligned properly if that > would require padding in front of them. The compiler can (and must?) > still align the first member, i.e. the beginning of the struct object, > though, no? No, it can't guarantee alignment of the first field and consequently will not bother trying. The best way to picture this is with an array. Alignment guarantees has to come from the implementation, the compiler will not guarantee alignment. > So, are you really sure we should do differently in pf, instead of > looking for a bridge problem, where bridge constructs an mbuf with the > IP header not properly aligned? I've not been sure to begin with. I forwarded this PR because I have no clue as to where the root problem is. If you say that pf(4) is not at fault and it's the bridge code then fine, fix the bridge code. All I see is an unaligned memory access and plenty of yellow flags in the source code. > I.e. if the IP header is properly aligned within the mbuf (on 32-bit > boundaries, I presume), wouldn't ip_src/dst have to be properly aligned > as well, even though __packed is used, because the layout of struct ip > is chosen like that? Yes. -- Marcel Moolenaar USPA: A-39004 marcel@xcllnt.net