Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/altq/libaltq use memcpy to avoid type punning.



details:   https://anonhg.NetBSD.org/src/rev/33bd33f508e4
branches:  trunk
changeset: 768423:33bd33f508e4
user:      christos <christos%NetBSD.org@localhost>
date:      Tue Aug 16 12:49:13 2011 +0000

description:
use memcpy to avoid type punning.

diffstat:

 usr.sbin/altq/libaltq/Makefile   |   7 +------
 usr.sbin/altq/libaltq/altq_qop.h |  12 +++++++++---
 usr.sbin/altq/libaltq/parser.c   |  14 +++++++++-----
 usr.sbin/altq/libaltq/qop.c      |  26 +++++++++++++-------------
 usr.sbin/altq/libaltq/qop_conf.c |   3 ++-
 5 files changed, 34 insertions(+), 28 deletions(-)

diffs (148 lines):

diff -r 3bb87de6ee18 -r 33bd33f508e4 usr.sbin/altq/libaltq/Makefile
--- a/usr.sbin/altq/libaltq/Makefile    Tue Aug 16 12:39:29 2011 +0000
+++ b/usr.sbin/altq/libaltq/Makefile    Tue Aug 16 12:49:13 2011 +0000
@@ -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
diff -r 3bb87de6ee18 -r 33bd33f508e4 usr.sbin/altq/libaltq/altq_qop.h
--- a/usr.sbin/altq/libaltq/altq_qop.h  Tue Aug 16 12:39:29 2011 +0000
+++ b/usr.sbin/altq/libaltq/altq_qop.h  Tue Aug 16 12:49:13 2011 +0000
@@ -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_ */
diff -r 3bb87de6ee18 -r 33bd33f508e4 usr.sbin/altq/libaltq/parser.c
--- a/usr.sbin/altq/libaltq/parser.c    Tue Aug 16 12:39:29 2011 +0000
+++ b/usr.sbin/altq/libaltq/parser.c    Tue Aug 16 12:49:13 2011 +0000
@@ -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));
diff -r 3bb87de6ee18 -r 33bd33f508e4 usr.sbin/altq/libaltq/qop.c
--- a/usr.sbin/altq/libaltq/qop.c       Tue Aug 16 12:39:29 2011 +0000
+++ b/usr.sbin/altq/libaltq/qop.c       Tue Aug 16 12:49:13 2011 +0000
@@ -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 &
diff -r 3bb87de6ee18 -r 33bd33f508e4 usr.sbin/altq/libaltq/qop_conf.c
--- a/usr.sbin/altq/libaltq/qop_conf.c  Tue Aug 16 12:39:29 2011 +0000
+++ b/usr.sbin/altq/libaltq/qop_conf.c  Tue Aug 16 12:49:13 2011 +0000
@@ -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"



Home | Main Index | Thread Index | Old Index