Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 30 Jan 2016 22:03:15 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r295086 - head/sbin/pfctl
Message-ID:  <201601302203.u0UM3FCG089464@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Sat Jan 30 22:03:14 2016
New Revision: 295086
URL: https://svnweb.freebsd.org/changeset/base/295086

Log:
  Make pfctl(8) work on strict-alignment platforms, by copying a pair of
  embedded structures out of a packed, unaligned struct into local copies
  on the stack which are aligned.
  
  The original patch to do this was submitted by Guy Yur <guyyur@gmail.com>,
  and this is conceptually the same change, but restructured with the
  #ifndef __NO_STRICT_ALIGNMENT wrapper, similar to how the same issue is
  handled in the kernel pf code.
  
  PR:		185617
  PR:		206658

Modified:
  head/sbin/pfctl/pf_print_state.c

Modified: head/sbin/pfctl/pf_print_state.c
==============================================================================
--- head/sbin/pfctl/pf_print_state.c	Sat Jan 30 21:21:25 2016	(r295085)
+++ head/sbin/pfctl/pf_print_state.c	Sat Jan 30 22:03:14 2016	(r295086)
@@ -208,22 +208,30 @@ void
 print_state(struct pfsync_state *s, int opts)
 {
 	struct pfsync_state_peer *src, *dst;
-	struct pfsync_state_key *sk, *nk;
+	struct pfsync_state_key *key, *sk, *nk;
 	struct protoent *p;
 	int min, sec;
+#ifndef __NO_STRICT_ALIGNMENT
+	struct pfsync_state_key aligned_key[2];
+
+	bcopy(&s->key, aligned_key, sizeof(aligned_key));
+	key = aligned_key;
+#else
+	key = s->key;
+#endif
 
 	if (s->direction == PF_OUT) {
 		src = &s->src;
 		dst = &s->dst;
-		sk = &s->key[PF_SK_STACK];
-		nk = &s->key[PF_SK_WIRE];
+		sk = &key[PF_SK_STACK];
+		nk = &key[PF_SK_WIRE];
 		if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) 
 			sk->port[0] = nk->port[0];
 	} else {
 		src = &s->dst;
 		dst = &s->src;
-		sk = &s->key[PF_SK_WIRE];
-		nk = &s->key[PF_SK_STACK];
+		sk = &key[PF_SK_WIRE];
+		nk = &key[PF_SK_STACK];
 		if (s->proto == IPPROTO_ICMP || s->proto == IPPROTO_ICMPV6) 
 			sk->port[1] = nk->port[1];
 	}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201601302203.u0UM3FCG089464>