From owner-svn-src-stable-10@FreeBSD.ORG Fri Aug 22 13:39:57 2014 Return-Path: Delivered-To: svn-src-stable-10@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D6CD977F; Fri, 22 Aug 2014 13:39:56 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (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 B6AC031E3; Fri, 22 Aug 2014 13:39:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id s7MDdu1o048563; Fri, 22 Aug 2014 13:39:56 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id s7MDduX4048562; Fri, 22 Aug 2014 13:39:56 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201408221339.s7MDduX4048562@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Fri, 22 Aug 2014 13:39:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r270328 - stable/10/sys/netpfil/pf X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable-10@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for only the 10-stable src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Aug 2014 13:39:57 -0000 Author: glebius Date: Fri Aug 22 13:39:56 2014 New Revision: 270328 URL: http://svnweb.freebsd.org/changeset/base/270328 Log: Merge r268492: On machines with strict alignment copy pfsync_state_key from packet on stack to avoid unaligned access. PR: 187381 Modified: stable/10/sys/netpfil/pf/if_pfsync.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/netpfil/pf/if_pfsync.c ============================================================================== --- stable/10/sys/netpfil/pf/if_pfsync.c Fri Aug 22 13:15:59 2014 (r270327) +++ stable/10/sys/netpfil/pf/if_pfsync.c Fri Aug 22 13:39:56 2014 (r270328) @@ -400,6 +400,10 @@ static int pfsync_state_import(struct pfsync_state *sp, u_int8_t flags) { struct pfsync_softc *sc = V_pfsyncif; +#ifndef __NO_STRICT_ALIGNMENT + struct pfsync_state_key key[2]; +#endif + struct pfsync_state_key *kw, *ks; struct pf_state *st = NULL; struct pf_state_key *skw = NULL, *sks = NULL; struct pf_rule *r = NULL; @@ -449,12 +453,19 @@ pfsync_state_import(struct pfsync_state if ((skw = uma_zalloc(V_pf_state_key_z, M_NOWAIT)) == NULL) goto cleanup; - if (PF_ANEQ(&sp->key[PF_SK_WIRE].addr[0], - &sp->key[PF_SK_STACK].addr[0], sp->af) || - PF_ANEQ(&sp->key[PF_SK_WIRE].addr[1], - &sp->key[PF_SK_STACK].addr[1], sp->af) || - sp->key[PF_SK_WIRE].port[0] != sp->key[PF_SK_STACK].port[0] || - sp->key[PF_SK_WIRE].port[1] != sp->key[PF_SK_STACK].port[1]) { +#ifndef __NO_STRICT_ALIGNMENT + bcopy(&sp->key, key, sizeof(struct pfsync_state_key) * 2); + kw = &key[PF_SK_WIRE]; + ks = &key[PF_SK_STACK]; +#else + kw = &sp->key[PF_SK_WIRE]; + ks = &sp->key[PF_SK_STACK]; +#endif + + if (PF_ANEQ(&kw->addr[0], &ks->addr[0], sp->af) || + PF_ANEQ(&kw->addr[1], &ks->addr[1], sp->af) || + kw->port[0] != ks->port[0] || + kw->port[1] != ks->port[1]) { sks = uma_zalloc(V_pf_state_key_z, M_NOWAIT); if (sks == NULL) goto cleanup; @@ -466,18 +477,18 @@ pfsync_state_import(struct pfsync_state pfsync_alloc_scrub_memory(&sp->dst, &st->dst)) goto cleanup; - /* copy to state key(s) */ - skw->addr[0] = sp->key[PF_SK_WIRE].addr[0]; - skw->addr[1] = sp->key[PF_SK_WIRE].addr[1]; - skw->port[0] = sp->key[PF_SK_WIRE].port[0]; - skw->port[1] = sp->key[PF_SK_WIRE].port[1]; + /* Copy to state key(s). */ + skw->addr[0] = kw->addr[0]; + skw->addr[1] = kw->addr[1]; + skw->port[0] = kw->port[0]; + skw->port[1] = kw->port[1]; skw->proto = sp->proto; skw->af = sp->af; if (sks != skw) { - sks->addr[0] = sp->key[PF_SK_STACK].addr[0]; - sks->addr[1] = sp->key[PF_SK_STACK].addr[1]; - sks->port[0] = sp->key[PF_SK_STACK].port[0]; - sks->port[1] = sp->key[PF_SK_STACK].port[1]; + sks->addr[0] = ks->addr[0]; + sks->addr[1] = ks->addr[1]; + sks->port[0] = ks->port[0]; + sks->port[1] = ks->port[1]; sks->proto = sp->proto; sks->af = sp->af; }