svn commit: r295086 - head/sbin/pfctl

Ian Lepore ian at FreeBSD.org
Sat Jan 30 22:03:16 UTC 2016


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 at 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];
 	}


More information about the svn-src-head mailing list