From f103f9aee9309153f9959f468e01a2e02ab8eb9b Mon Sep 17 00:00:00 2001 From: itojun Date: Mon, 26 Apr 2004 05:15:47 +0000 Subject: [PATCH] declare ip6_hdr_pseudo (for kernel only) and use it for TCP MD5 signature --- sys/netinet/ip6.h | 16 +++++++++++++++- sys/netinet/tcp_subr.c | 24 ++++++++++-------------- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/sys/netinet/ip6.h b/sys/netinet/ip6.h index 1f45b9bd759b..e04760357f17 100644 --- a/sys/netinet/ip6.h +++ b/sys/netinet/ip6.h @@ -1,4 +1,4 @@ -/* $NetBSD: ip6.h,v 1.16 2003/08/07 16:33:11 agc Exp $ */ +/* $NetBSD: ip6.h,v 1.17 2004/04/26 05:15:47 itojun Exp $ */ /* $KAME: ip6.h,v 1.45 2003/06/05 04:46:38 keiichi Exp $ */ /* @@ -108,6 +108,20 @@ struct ip6_hdr { #define IP6TOS_ECT 0x02 /* ECN-capable transport */ #endif +#ifdef _KERNEL +/* + * for IPv6 pseudo header checksum + * XXX nonstandard + */ +struct ip6_hdr_pseudo { + struct in6_addr ip6ph_src; + struct in6_addr ip6ph_dst; + u_int32_t ip6ph_len; + u_int8_t ip6ph_zero[3]; + u_int8_t ip6ph_nxt; +} __attribute__((__packed__)); +#endif + /* * Extension Headers */ diff --git a/sys/netinet/tcp_subr.c b/sys/netinet/tcp_subr.c index cb8a92535d4f..0be1aaf58eb2 100644 --- a/sys/netinet/tcp_subr.c +++ b/sys/netinet/tcp_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: tcp_subr.c,v 1.168 2004/04/26 05:05:49 itojun Exp $ */ +/* $NetBSD: tcp_subr.c,v 1.169 2004/04/26 05:15:47 itojun Exp $ */ /* * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. @@ -98,7 +98,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.168 2004/04/26 05:05:49 itojun Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tcp_subr.c,v 1.169 2004/04/26 05:15:47 itojun Exp $"); #include "opt_inet.h" #include "opt_ipsec.h" @@ -1666,12 +1666,7 @@ tcp_signature_compute(struct mbuf *m, struct tcphdr *th, int thoff, u_int16_t savecsum; struct ippseudo ippseudo; struct ip6_ext ip6e; - struct { - struct in6_addr src, dst; - u_int32_t len; - u_int8_t zero[3]; - u_int8_t nxt; - } ip6pseudo; + struct ip6_hdr_pseudo ip6pseudo; u_int8_t nxt; KASSERT(m != NULL /*, ("NULL mbuf chain")*/); @@ -1761,12 +1756,13 @@ found: htons(len + sizeof(struct tcphdr) + optlen); MD5Update(&ctx, (char *)&ippseudo, sizeof(ippseudo)); } else { - ip6pseudo.src = ip6->ip6_src; - in6_clearscope(&ip6pseudo.src); - ip6pseudo.dst = ip6->ip6_dst; - in6_clearscope(&ip6pseudo.dst); - ip6pseudo.len = htonl(len + sizeof(struct tcphdr) + optlen); - ip6pseudo.nxt = IPPROTO_TCP; + ip6pseudo.ip6ph_src = ip6->ip6_src; + in6_clearscope(&ip6pseudo.ip6ph_src); + ip6pseudo.ip6ph_dst = ip6->ip6_dst; + in6_clearscope(&ip6pseudo.ip6ph_dst); + ip6pseudo.ip6ph_len = + htonl(len + sizeof(struct tcphdr) + optlen); + ip6pseudo.ip6ph_nxt = IPPROTO_TCP; MD5Update(&ctx, (char *)&ip6pseudo, sizeof(ip6pseudo)); }