be friendly with gcc-3.1.1 -O2, which takes advantage of ANSI C

pointer aliasing rule (gcc optimization/7427).  from tsubai, sync w/kame
This commit is contained in:
itojun 2002-07-29 09:14:36 +00:00
parent 6dbfb914a2
commit f8e5e9c295
3 changed files with 34 additions and 26 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_cksum.c,v 1.8 2002/06/01 11:41:33 simonb Exp $ */
/* $NetBSD: in_cksum.c,v 1.9 2002/07/29 09:14:36 itojun Exp $ */
/*
* Copyright (c) 1993 Regents of the University of California.
@ -284,15 +284,18 @@ in4_cksum(struct mbuf *m, uint8_t nxt, int off, int len)
if (nxt != 0) {
uint16_t *w;
union {
struct ipovly ipov;
u_int16_t w[10];
} u;
/* pseudo header */
memset(&ipov, 0, sizeof(ipov));
ipov.ih_len = htons(len);
ipov.ih_pr = nxt;
ipov.ih_src = mtod(m, struct ip *)->ip_src;
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = (uint16_t *)&ipov;
memset(&u.ipov, 0, sizeof(u.ipov));
u.ipov.ih_len = htons(len);
u.ipov.ih_pr = nxt;
u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = u.w;
/* assumes sizeof(ipov) == 20 */
sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];

View File

@ -1,4 +1,4 @@
/* $NetBSD: in_cksum.c,v 1.3 2001/06/13 06:01:50 simonb Exp $ */
/* $NetBSD: in_cksum.c,v 1.4 2002/07/29 09:14:37 itojun Exp $ */
/*
* Copyright 2001 Wasabi Systems, Inc.
@ -237,16 +237,19 @@ in4_cksum(struct mbuf *m, uint8_t nxt, int off, int len)
{
uint16_t *w;
u_int sum = 0;
union {
struct ipovly ipov;
u_int16_t w[10];
} u;
if (nxt != 0) {
/* pseudo header */
memset(&ipov, 0, sizeof(ipov));
ipov.ih_len = htons(len);
ipov.ih_pr = nxt;
ipov.ih_src = mtod(m, struct ip *)->ip_src;
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = (uint16_t *)&ipov;
memset(&u.ipov, 0, sizeof(u.ipov));
u.ipov.ih_len = htons(len);
u.ipov.ih_pr = nxt;
u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = u.w;
/* assumes sizeof(ipov) == 20 */
sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];

View File

@ -1,4 +1,4 @@
/* $NetBSD: in4_cksum.c,v 1.8 2001/12/21 02:50:28 itojun Exp $ */
/* $NetBSD: in4_cksum.c,v 1.9 2002/07/29 09:14:37 itojun Exp $ */
/*
* Copyright (C) 1999 WIDE Project.
@ -65,7 +65,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.8 2001/12/21 02:50:28 itojun Exp $");
__KERNEL_RCSID(0, "$NetBSD: in4_cksum.c,v 1.9 2002/07/29 09:14:37 itojun Exp $");
#include <sys/param.h>
#include <sys/mbuf.h>
@ -101,8 +101,10 @@ in4_cksum(m, nxt, off, len)
int sum = 0;
int mlen = 0;
int byte_swapped = 0;
union {
struct ipovly ipov;
u_int16_t w[10];
} u;
union {
u_int8_t c[2];
u_int16_t s;
@ -118,12 +120,12 @@ in4_cksum(m, nxt, off, len)
panic("in4_cksum: offset too short");
if (m->m_len < sizeof(struct ip))
panic("in4_cksum: bad mbuf chain");
bzero(&ipov, sizeof(ipov));
ipov.ih_len = htons(len);
ipov.ih_pr = nxt;
ipov.ih_src = mtod(m, struct ip *)->ip_src;
ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = (u_int16_t *)&ipov;
bzero(&u.ipov, sizeof(u.ipov));
u.ipov.ih_len = htons(len);
u.ipov.ih_pr = nxt;
u.ipov.ih_src = mtod(m, struct ip *)->ip_src;
u.ipov.ih_dst = mtod(m, struct ip *)->ip_dst;
w = u.w;
/* assumes sizeof(ipov) == 20 */
sum += w[0]; sum += w[1]; sum += w[2]; sum += w[3]; sum += w[4];
sum += w[5]; sum += w[6]; sum += w[7]; sum += w[8]; sum += w[9];