Module Name: src Committed By: christos Date: Tue Aug 16 12:49:13 UTC 2011
Modified Files: src/usr.sbin/altq/libaltq: Makefile altq_qop.h parser.c qop.c qop_conf.c Log Message: use memcpy to avoid type punning. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/altq/libaltq/Makefile cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/altq/libaltq/altq_qop.h cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/altq/libaltq/parser.c \ src/usr.sbin/altq/libaltq/qop.c cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/altq/libaltq/qop_conf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.sbin/altq/libaltq/Makefile diff -u src/usr.sbin/altq/libaltq/Makefile:1.11 src/usr.sbin/altq/libaltq/Makefile:1.12 --- src/usr.sbin/altq/libaltq/Makefile:1.11 Tue Jun 21 22:49:45 2011 +++ src/usr.sbin/altq/libaltq/Makefile Tue Aug 16 08:49:13 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.11 2011/06/22 02:49:45 mrg Exp $ +# $NetBSD: Makefile,v 1.12 2011/08/16 12:49:13 christos Exp $ LIBISPRIVATE= yes @@ -16,8 +16,3 @@ .endif .include <bsd.lib.mk> - -# XXX -.if ${HAVE_GCC} == 45 -COPTS.parser.c+= -fno-strict-aliasing -.endif Index: src/usr.sbin/altq/libaltq/altq_qop.h diff -u src/usr.sbin/altq/libaltq/altq_qop.h:1.5 src/usr.sbin/altq/libaltq/altq_qop.h:1.6 --- src/usr.sbin/altq/libaltq/altq_qop.h:1.5 Fri May 2 15:07:44 2008 +++ src/usr.sbin/altq/libaltq/altq_qop.h Tue Aug 16 08:49:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: altq_qop.h,v 1.5 2008/05/02 19:07:44 xtraeme Exp $ */ +/* $NetBSD: altq_qop.h,v 1.6 2011/08/16 12:49:13 christos Exp $ */ /* $KAME: altq_qop.h,v 1.5 2002/02/12 10:14:01 kjc Exp $ */ /* * Copyright (C) 1999-2000 @@ -246,8 +246,14 @@ #endif /* !RSVPD */ #ifdef INET6 -/* a macro to handle v6 address in 32-bit fields */ -#define IN6ADDR32(a, i) (*(u_int32_t *)(&(a)->s6_addr[(i)<<2])) +static inline uint32_t IN6ADDR32_GET(const struct in6_addr *a, size_t i) { + uint32_t ret; + memcpy(&ret, &(a)->s6_addr[i << 2], sizeof(ret)); + return ret; +} +static inline void IN6ADDR32_SET(struct in6_addr *a, size_t i, uint32_t val) { + memcpy(&(a)->s6_addr[i << 2], &val, sizeof(val)); +} #endif #endif /* _ALTQ_QOP_H_ */ Index: src/usr.sbin/altq/libaltq/parser.c diff -u src/usr.sbin/altq/libaltq/parser.c:1.10 src/usr.sbin/altq/libaltq/parser.c:1.11 --- src/usr.sbin/altq/libaltq/parser.c:1.10 Fri Oct 29 15:58:18 2004 +++ src/usr.sbin/altq/libaltq/parser.c Tue Aug 16 08:49:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: parser.c,v 1.10 2004/10/29 19:58:18 dsl Exp $ */ +/* $NetBSD: parser.c,v 1.11 2011/08/16 12:49:13 christos Exp $ */ /* $KAME: parser.c,v 1.16 2002/02/20 10:40:39 kjc Exp $ */ /* * Copyright (C) 1999-2002 @@ -843,10 +843,14 @@ if (len > 0) *cp = (0xff << (8 - len)) & 0xff; - IN6ADDR32(addr, 0) &= IN6ADDR32(mask, 0); - IN6ADDR32(addr, 1) &= IN6ADDR32(mask, 1); - IN6ADDR32(addr, 2) &= IN6ADDR32(mask, 2); - IN6ADDR32(addr, 3) &= IN6ADDR32(mask, 3); + IN6ADDR32_SET(addr, 0, IN6ADDR32_GET(mask, 0) & + IN6ADDR32_GET(addr, 0)); + IN6ADDR32_SET(addr, 1, IN6ADDR32_GET(mask, 1) & + IN6ADDR32_GET(addr, 1)); + IN6ADDR32_SET(addr, 2, IN6ADDR32_GET(mask, 2) & + IN6ADDR32_GET(addr, 2)); + IN6ADDR32_SET(addr, 3, IN6ADDR32_GET(mask, 3) & + IN6ADDR32_GET(addr, 3)); } else /* full mask */ memset(mask, 0xff, sizeof(struct in6_addr)); Index: src/usr.sbin/altq/libaltq/qop.c diff -u src/usr.sbin/altq/libaltq/qop.c:1.10 src/usr.sbin/altq/libaltq/qop.c:1.11 --- src/usr.sbin/altq/libaltq/qop.c:1.10 Tue Jan 4 04:14:42 2011 +++ src/usr.sbin/altq/libaltq/qop.c Tue Aug 16 08:49:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: qop.c,v 1.10 2011/01/04 09:14:42 wiz Exp $ */ +/* $NetBSD: qop.c,v 1.11 2011/08/16 12:49:13 christos Exp $ */ /* $KAME: qop.c,v 1.11 2001/10/26 04:57:59 kjc Exp $ */ /* * Copyright (C) 1999-2000 @@ -1196,20 +1196,20 @@ if (!IN6_IS_ADDR_UNSPECIFIED(&front6->ff_flow6.fi6_src) && !IN6_IS_ADDR_UNSPECIFIED(&back6->ff_flow6.fi6_src)) { for (i=0; i<4; i++) { - mask = IN6ADDR32(&front6->ff_mask6.mask6_src, i) - & IN6ADDR32(&back6->ff_mask6.mask6_src, i); - if ((IN6ADDR32(&front6->ff_flow6.fi6_src, i) & mask) != - (IN6ADDR32(&back6->ff_flow6.fi6_src, i) & mask)) + mask = IN6ADDR32_GET(&front6->ff_mask6.mask6_src, i) + & IN6ADDR32_GET(&back6->ff_mask6.mask6_src, i); + if ((IN6ADDR32_GET(&front6->ff_flow6.fi6_src, i) & mask) != + (IN6ADDR32_GET(&back6->ff_flow6.fi6_src, i) & mask)) return (1); } } if (!IN6_IS_ADDR_UNSPECIFIED(&front6->ff_flow6.fi6_dst) && !IN6_IS_ADDR_UNSPECIFIED(&back6->ff_flow6.fi6_dst)) { for (i=0; i<4; i++) { - mask = IN6ADDR32(&front6->ff_mask6.mask6_dst, i) - & IN6ADDR32(&back6->ff_mask6.mask6_dst, i); - if ((IN6ADDR32(&front6->ff_flow6.fi6_dst, i) & mask) != - (IN6ADDR32(&back6->ff_flow6.fi6_dst, i) & mask)) + mask = IN6ADDR32_GET(&front6->ff_mask6.mask6_dst, i) + & IN6ADDR32_GET(&back6->ff_mask6.mask6_dst, i); + if ((IN6ADDR32_GET(&front6->ff_flow6.fi6_dst, i) & mask) != + (IN6ADDR32_GET(&back6->ff_flow6.fi6_dst, i) & mask)) return (1); } } @@ -1306,16 +1306,16 @@ return (0); } else if (!IN6_IS_ADDR_UNSPECIFIED(&back6->ff_flow6.fi6_src)) for (i=0; i<4; i++) - if (~IN6ADDR32(&front6->ff_mask6.mask6_src, i) & - IN6ADDR32(&back6->ff_mask6.mask6_src, i)) + if (~IN6ADDR32_GET(&front6->ff_mask6.mask6_src, i) & + IN6ADDR32_GET(&back6->ff_mask6.mask6_src, i)) return (0); if (IN6_IS_ADDR_UNSPECIFIED(&front6->ff_flow6.fi6_dst)) { if (!IN6_IS_ADDR_UNSPECIFIED(&back6->ff_flow6.fi6_dst)) return (0); } else if (!IN6_IS_ADDR_UNSPECIFIED(&back6->ff_flow6.fi6_dst)) for (i=0; i<4; i++) - if (~IN6ADDR32(&front6->ff_mask6.mask6_dst, i) & - IN6ADDR32(&back6->ff_mask6.mask6_dst, i)) + if (~IN6ADDR32_GET(&front6->ff_mask6.mask6_dst, i) & + IN6ADDR32_GET(&back6->ff_mask6.mask6_dst, i)) return (0); if (~front6->ff_mask6.mask6_tclass & Index: src/usr.sbin/altq/libaltq/qop_conf.c diff -u src/usr.sbin/altq/libaltq/qop_conf.c:1.3 src/usr.sbin/altq/libaltq/qop_conf.c:1.4 --- src/usr.sbin/altq/libaltq/qop_conf.c:1.3 Thu Oct 12 15:59:13 2006 +++ src/usr.sbin/altq/libaltq/qop_conf.c Tue Aug 16 08:49:13 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: qop_conf.c,v 1.3 2006/10/12 19:59:13 peter Exp $ */ +/* $NetBSD: qop_conf.c,v 1.4 2011/08/16 12:49:13 christos Exp $ */ /* $KAME: qop_conf.c,v 1.3 2002/10/26 06:59:53 kjc Exp $ */ /* * Copyright (C) 1999-2000 @@ -30,6 +30,7 @@ #include <sys/socket.h> #include <net/if.h> #include <stdio.h> +#include <string.h> #include <altq/altq.h> #include "altq_qop.h"