1686cdd19SJun-ichiro itojun Hagino /* $FreeBSD$ */ 233841545SHajimu UMEMOTO /* $KAME: ip6.h,v 1.18 2001/03/29 05:34:30 itojun Exp $ */ 3686cdd19SJun-ichiro itojun Hagino 482cd038dSYoshinobu Inoue /* 5686cdd19SJun-ichiro itojun Hagino * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 682cd038dSYoshinobu Inoue * All rights reserved. 782cd038dSYoshinobu Inoue * 882cd038dSYoshinobu Inoue * Redistribution and use in source and binary forms, with or without 982cd038dSYoshinobu Inoue * modification, are permitted provided that the following conditions 1082cd038dSYoshinobu Inoue * are met: 1182cd038dSYoshinobu Inoue * 1. Redistributions of source code must retain the above copyright 1282cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer. 1382cd038dSYoshinobu Inoue * 2. Redistributions in binary form must reproduce the above copyright 1482cd038dSYoshinobu Inoue * notice, this list of conditions and the following disclaimer in the 1582cd038dSYoshinobu Inoue * documentation and/or other materials provided with the distribution. 1682cd038dSYoshinobu Inoue * 3. Neither the name of the project nor the names of its contributors 1782cd038dSYoshinobu Inoue * may be used to endorse or promote products derived from this software 1882cd038dSYoshinobu Inoue * without specific prior written permission. 1982cd038dSYoshinobu Inoue * 2082cd038dSYoshinobu Inoue * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 2182cd038dSYoshinobu Inoue * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2282cd038dSYoshinobu Inoue * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2382cd038dSYoshinobu Inoue * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 2482cd038dSYoshinobu Inoue * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2582cd038dSYoshinobu Inoue * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2682cd038dSYoshinobu Inoue * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2782cd038dSYoshinobu Inoue * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2882cd038dSYoshinobu Inoue * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2982cd038dSYoshinobu Inoue * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3082cd038dSYoshinobu Inoue * SUCH DAMAGE. 3182cd038dSYoshinobu Inoue */ 3282cd038dSYoshinobu Inoue 33686cdd19SJun-ichiro itojun Hagino /* 34686cdd19SJun-ichiro itojun Hagino * Copyright (c) 1982, 1986, 1993 35686cdd19SJun-ichiro itojun Hagino * The Regents of the University of California. All rights reserved. 36686cdd19SJun-ichiro itojun Hagino * 37686cdd19SJun-ichiro itojun Hagino * Redistribution and use in source and binary forms, with or without 38686cdd19SJun-ichiro itojun Hagino * modification, are permitted provided that the following conditions 39686cdd19SJun-ichiro itojun Hagino * are met: 40686cdd19SJun-ichiro itojun Hagino * 1. Redistributions of source code must retain the above copyright 41686cdd19SJun-ichiro itojun Hagino * notice, this list of conditions and the following disclaimer. 42686cdd19SJun-ichiro itojun Hagino * 2. Redistributions in binary form must reproduce the above copyright 43686cdd19SJun-ichiro itojun Hagino * notice, this list of conditions and the following disclaimer in the 44686cdd19SJun-ichiro itojun Hagino * documentation and/or other materials provided with the distribution. 45686cdd19SJun-ichiro itojun Hagino * 3. All advertising materials mentioning features or use of this software 46686cdd19SJun-ichiro itojun Hagino * must display the following acknowledgement: 47686cdd19SJun-ichiro itojun Hagino * This product includes software developed by the University of 48686cdd19SJun-ichiro itojun Hagino * California, Berkeley and its contributors. 49686cdd19SJun-ichiro itojun Hagino * 4. Neither the name of the University nor the names of its contributors 50686cdd19SJun-ichiro itojun Hagino * may be used to endorse or promote products derived from this software 51686cdd19SJun-ichiro itojun Hagino * without specific prior written permission. 52686cdd19SJun-ichiro itojun Hagino * 53686cdd19SJun-ichiro itojun Hagino * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 54686cdd19SJun-ichiro itojun Hagino * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 55686cdd19SJun-ichiro itojun Hagino * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 56686cdd19SJun-ichiro itojun Hagino * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 57686cdd19SJun-ichiro itojun Hagino * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 58686cdd19SJun-ichiro itojun Hagino * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 59686cdd19SJun-ichiro itojun Hagino * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 60686cdd19SJun-ichiro itojun Hagino * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 61686cdd19SJun-ichiro itojun Hagino * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 62686cdd19SJun-ichiro itojun Hagino * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 63686cdd19SJun-ichiro itojun Hagino * SUCH DAMAGE. 64686cdd19SJun-ichiro itojun Hagino * 65686cdd19SJun-ichiro itojun Hagino * @(#)ip.h 8.1 (Berkeley) 6/10/93 66686cdd19SJun-ichiro itojun Hagino */ 67686cdd19SJun-ichiro itojun Hagino 68686cdd19SJun-ichiro itojun Hagino #ifndef _NETINET_IP6_H_ 69686cdd19SJun-ichiro itojun Hagino #define _NETINET_IP6_H_ 70686cdd19SJun-ichiro itojun Hagino 71686cdd19SJun-ichiro itojun Hagino /* 72686cdd19SJun-ichiro itojun Hagino * Definition for internet protocol version 6. 73686cdd19SJun-ichiro itojun Hagino * RFC 2460 74686cdd19SJun-ichiro itojun Hagino */ 75686cdd19SJun-ichiro itojun Hagino 76686cdd19SJun-ichiro itojun Hagino struct ip6_hdr { 77686cdd19SJun-ichiro itojun Hagino union { 78686cdd19SJun-ichiro itojun Hagino struct ip6_hdrctl { 79686cdd19SJun-ichiro itojun Hagino u_int32_t ip6_un1_flow; /* 20 bits of flow-ID */ 80686cdd19SJun-ichiro itojun Hagino u_int16_t ip6_un1_plen; /* payload length */ 81686cdd19SJun-ichiro itojun Hagino u_int8_t ip6_un1_nxt; /* next header */ 82686cdd19SJun-ichiro itojun Hagino u_int8_t ip6_un1_hlim; /* hop limit */ 83686cdd19SJun-ichiro itojun Hagino } ip6_un1; 84686cdd19SJun-ichiro itojun Hagino u_int8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */ 85686cdd19SJun-ichiro itojun Hagino } ip6_ctlun; 86686cdd19SJun-ichiro itojun Hagino struct in6_addr ip6_src; /* source address */ 87686cdd19SJun-ichiro itojun Hagino struct in6_addr ip6_dst; /* destination address */ 88618d51bbSHajimu UMEMOTO } __packed; 89686cdd19SJun-ichiro itojun Hagino 90686cdd19SJun-ichiro itojun Hagino #define ip6_vfc ip6_ctlun.ip6_un2_vfc 91686cdd19SJun-ichiro itojun Hagino #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow 92686cdd19SJun-ichiro itojun Hagino #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen 93686cdd19SJun-ichiro itojun Hagino #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt 94686cdd19SJun-ichiro itojun Hagino #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim 95686cdd19SJun-ichiro itojun Hagino #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim 96686cdd19SJun-ichiro itojun Hagino 97686cdd19SJun-ichiro itojun Hagino #define IPV6_VERSION 0x60 98686cdd19SJun-ichiro itojun Hagino #define IPV6_VERSION_MASK 0xf0 99686cdd19SJun-ichiro itojun Hagino 100686cdd19SJun-ichiro itojun Hagino #if BYTE_ORDER == BIG_ENDIAN 101686cdd19SJun-ichiro itojun Hagino #define IPV6_FLOWINFO_MASK 0x0fffffff /* flow info (28 bits) */ 102686cdd19SJun-ichiro itojun Hagino #define IPV6_FLOWLABEL_MASK 0x000fffff /* flow label (20 bits) */ 103686cdd19SJun-ichiro itojun Hagino #else 104686cdd19SJun-ichiro itojun Hagino #if BYTE_ORDER == LITTLE_ENDIAN 105686cdd19SJun-ichiro itojun Hagino #define IPV6_FLOWINFO_MASK 0xffffff0f /* flow info (28 bits) */ 106686cdd19SJun-ichiro itojun Hagino #define IPV6_FLOWLABEL_MASK 0xffff0f00 /* flow label (20 bits) */ 107686cdd19SJun-ichiro itojun Hagino #endif /* LITTLE_ENDIAN */ 108686cdd19SJun-ichiro itojun Hagino #endif 10933841545SHajimu UMEMOTO #if 1 110686cdd19SJun-ichiro itojun Hagino /* ECN bits proposed by Sally Floyd */ 111686cdd19SJun-ichiro itojun Hagino #define IP6TOS_CE 0x01 /* congestion experienced */ 112686cdd19SJun-ichiro itojun Hagino #define IP6TOS_ECT 0x02 /* ECN-capable transport */ 11333841545SHajimu UMEMOTO #endif 114686cdd19SJun-ichiro itojun Hagino 115686cdd19SJun-ichiro itojun Hagino /* 116686cdd19SJun-ichiro itojun Hagino * Extension Headers 117686cdd19SJun-ichiro itojun Hagino */ 118686cdd19SJun-ichiro itojun Hagino 119686cdd19SJun-ichiro itojun Hagino struct ip6_ext { 12033841545SHajimu UMEMOTO u_int8_t ip6e_nxt; 12133841545SHajimu UMEMOTO u_int8_t ip6e_len; 122618d51bbSHajimu UMEMOTO } __packed; 123686cdd19SJun-ichiro itojun Hagino 124686cdd19SJun-ichiro itojun Hagino /* Hop-by-Hop options header */ 125686cdd19SJun-ichiro itojun Hagino /* XXX should we pad it to force alignment on an 8-byte boundary? */ 126686cdd19SJun-ichiro itojun Hagino struct ip6_hbh { 127686cdd19SJun-ichiro itojun Hagino u_int8_t ip6h_nxt; /* next header */ 128686cdd19SJun-ichiro itojun Hagino u_int8_t ip6h_len; /* length in units of 8 octets */ 129686cdd19SJun-ichiro itojun Hagino /* followed by options */ 130618d51bbSHajimu UMEMOTO } __packed; 131686cdd19SJun-ichiro itojun Hagino 132686cdd19SJun-ichiro itojun Hagino /* Destination options header */ 133686cdd19SJun-ichiro itojun Hagino /* XXX should we pad it to force alignment on an 8-byte boundary? */ 134686cdd19SJun-ichiro itojun Hagino struct ip6_dest { 135686cdd19SJun-ichiro itojun Hagino u_int8_t ip6d_nxt; /* next header */ 136686cdd19SJun-ichiro itojun Hagino u_int8_t ip6d_len; /* length in units of 8 octets */ 137686cdd19SJun-ichiro itojun Hagino /* followed by options */ 138618d51bbSHajimu UMEMOTO } __packed; 139686cdd19SJun-ichiro itojun Hagino 140686cdd19SJun-ichiro itojun Hagino /* Option types and related macros */ 141686cdd19SJun-ichiro itojun Hagino #define IP6OPT_PAD1 0x00 /* 00 0 00000 */ 142686cdd19SJun-ichiro itojun Hagino #define IP6OPT_PADN 0x01 /* 00 0 00001 */ 143686cdd19SJun-ichiro itojun Hagino #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ 14433841545SHajimu UMEMOTO #define IP6OPT_NSAP_ADDR 0xC3 /* 11 0 00011 */ 14533841545SHajimu UMEMOTO #define IP6OPT_TUNNEL_LIMIT 0x04 /* 00 0 00100 */ 146f95d4633SHajimu UMEMOTO #ifndef _KERNEL 14733841545SHajimu UMEMOTO #define IP6OPT_RTALERT 0x05 /* 00 0 00101 (KAME definition) */ 148f95d4633SHajimu UMEMOTO #endif 149f95d4633SHajimu UMEMOTO #define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 (2292bis, recommended) */ 15033841545SHajimu UMEMOTO 151686cdd19SJun-ichiro itojun Hagino #define IP6OPT_RTALERT_LEN 4 152686cdd19SJun-ichiro itojun Hagino #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ 153686cdd19SJun-ichiro itojun Hagino #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ 154686cdd19SJun-ichiro itojun Hagino #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ 155686cdd19SJun-ichiro itojun Hagino #define IP6OPT_MINLEN 2 156686cdd19SJun-ichiro itojun Hagino 15733841545SHajimu UMEMOTO #define IP6OPT_EID 0x8a /* 10 0 01010 */ 15833841545SHajimu UMEMOTO 159686cdd19SJun-ichiro itojun Hagino #define IP6OPT_TYPE(o) ((o) & 0xC0) 160686cdd19SJun-ichiro itojun Hagino #define IP6OPT_TYPE_SKIP 0x00 161686cdd19SJun-ichiro itojun Hagino #define IP6OPT_TYPE_DISCARD 0x40 162686cdd19SJun-ichiro itojun Hagino #define IP6OPT_TYPE_FORCEICMP 0x80 163686cdd19SJun-ichiro itojun Hagino #define IP6OPT_TYPE_ICMP 0xC0 164686cdd19SJun-ichiro itojun Hagino 165686cdd19SJun-ichiro itojun Hagino #define IP6OPT_MUTABLE 0x20 166686cdd19SJun-ichiro itojun Hagino 16733841545SHajimu UMEMOTO #define IP6OPT_JUMBO_LEN 6 16833841545SHajimu UMEMOTO 169686cdd19SJun-ichiro itojun Hagino /* Routing header */ 170686cdd19SJun-ichiro itojun Hagino struct ip6_rthdr { 171686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r_nxt; /* next header */ 172686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r_len; /* length in units of 8 octets */ 173686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r_type; /* routing type */ 174686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r_segleft; /* segments left */ 175686cdd19SJun-ichiro itojun Hagino /* followed by routing type specific data */ 176618d51bbSHajimu UMEMOTO } __packed; 177686cdd19SJun-ichiro itojun Hagino 178686cdd19SJun-ichiro itojun Hagino /* Type 0 Routing header */ 179686cdd19SJun-ichiro itojun Hagino struct ip6_rthdr0 { 180686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r0_nxt; /* next header */ 181686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r0_len; /* length in units of 8 octets */ 182686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r0_type; /* always zero */ 183686cdd19SJun-ichiro itojun Hagino u_int8_t ip6r0_segleft; /* segments left */ 184c302f5bcSHajimu UMEMOTO u_int32_t ip6r0_reserved; /* reserved field */ 185c302f5bcSHajimu UMEMOTO /* followed by up to 127 struct in6_addr */ 186618d51bbSHajimu UMEMOTO } __packed; 187686cdd19SJun-ichiro itojun Hagino 188686cdd19SJun-ichiro itojun Hagino /* Fragment header */ 189686cdd19SJun-ichiro itojun Hagino struct ip6_frag { 190686cdd19SJun-ichiro itojun Hagino u_int8_t ip6f_nxt; /* next header */ 191686cdd19SJun-ichiro itojun Hagino u_int8_t ip6f_reserved; /* reserved field */ 192686cdd19SJun-ichiro itojun Hagino u_int16_t ip6f_offlg; /* offset, reserved, and flag */ 193686cdd19SJun-ichiro itojun Hagino u_int32_t ip6f_ident; /* identification */ 194618d51bbSHajimu UMEMOTO } __packed; 195686cdd19SJun-ichiro itojun Hagino 196686cdd19SJun-ichiro itojun Hagino #if BYTE_ORDER == BIG_ENDIAN 197686cdd19SJun-ichiro itojun Hagino #define IP6F_OFF_MASK 0xfff8 /* mask out offset from _offlg */ 198686cdd19SJun-ichiro itojun Hagino #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */ 199686cdd19SJun-ichiro itojun Hagino #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */ 200686cdd19SJun-ichiro itojun Hagino #else /* BYTE_ORDER == LITTLE_ENDIAN */ 201686cdd19SJun-ichiro itojun Hagino #define IP6F_OFF_MASK 0xf8ff /* mask out offset from _offlg */ 202686cdd19SJun-ichiro itojun Hagino #define IP6F_RESERVED_MASK 0x0600 /* reserved bits in ip6f_offlg */ 203686cdd19SJun-ichiro itojun Hagino #define IP6F_MORE_FRAG 0x0100 /* more-fragments flag */ 204686cdd19SJun-ichiro itojun Hagino #endif /* BYTE_ORDER == LITTLE_ENDIAN */ 205686cdd19SJun-ichiro itojun Hagino 206686cdd19SJun-ichiro itojun Hagino /* 207686cdd19SJun-ichiro itojun Hagino * Internet implementation parameters. 208686cdd19SJun-ichiro itojun Hagino */ 209686cdd19SJun-ichiro itojun Hagino #define IPV6_MAXHLIM 255 /* maximun hoplimit */ 210686cdd19SJun-ichiro itojun Hagino #define IPV6_DEFHLIM 64 /* default hlim */ 211686cdd19SJun-ichiro itojun Hagino #define IPV6_FRAGTTL 120 /* ttl for fragment packets, in slowtimo tick */ 212686cdd19SJun-ichiro itojun Hagino #define IPV6_HLIMDEC 1 /* subtracted when forwaeding */ 213686cdd19SJun-ichiro itojun Hagino 214686cdd19SJun-ichiro itojun Hagino #define IPV6_MMTU 1280 /* minimal MTU and reassembly. 1024 + 256 */ 215686cdd19SJun-ichiro itojun Hagino #define IPV6_MAXPACKET 65535 /* ip6 max packet size without Jumbo payload*/ 216686cdd19SJun-ichiro itojun Hagino 217686cdd19SJun-ichiro itojun Hagino #ifdef _KERNEL 218686cdd19SJun-ichiro itojun Hagino /* 219686cdd19SJun-ichiro itojun Hagino * IP6_EXTHDR_CHECK ensures that region between the IP6 header and the 220686cdd19SJun-ichiro itojun Hagino * target header (including IPv6 itself, extension headers and 221686cdd19SJun-ichiro itojun Hagino * TCP/UDP/ICMP6 headers) are continuous. KAME requires drivers 222686cdd19SJun-ichiro itojun Hagino * to store incoming data into one internal mbuf or one or more external 223686cdd19SJun-ichiro itojun Hagino * mbufs(never into two or more internal mbufs). Thus, the third case is 224686cdd19SJun-ichiro itojun Hagino * supposed to never be matched but is prepared just in case. 225686cdd19SJun-ichiro itojun Hagino */ 226686cdd19SJun-ichiro itojun Hagino 227686cdd19SJun-ichiro itojun Hagino #define IP6_EXTHDR_CHECK(m, off, hlen, ret) \ 228686cdd19SJun-ichiro itojun Hagino do { \ 229686cdd19SJun-ichiro itojun Hagino if ((m)->m_next != NULL) { \ 230686cdd19SJun-ichiro itojun Hagino if (((m)->m_flags & M_LOOP) && \ 231686cdd19SJun-ichiro itojun Hagino ((m)->m_len < (off) + (hlen)) && \ 232686cdd19SJun-ichiro itojun Hagino (((m) = m_pullup((m), (off) + (hlen))) == NULL)) { \ 233f3821164SJun-ichiro itojun Hagino ip6stat.ip6s_exthdrtoolong++; \ 234686cdd19SJun-ichiro itojun Hagino return ret; \ 235686cdd19SJun-ichiro itojun Hagino } else if ((m)->m_flags & M_EXT) { \ 236686cdd19SJun-ichiro itojun Hagino if ((m)->m_len < (off) + (hlen)) { \ 237f3821164SJun-ichiro itojun Hagino ip6stat.ip6s_exthdrtoolong++; \ 238686cdd19SJun-ichiro itojun Hagino m_freem(m); \ 239686cdd19SJun-ichiro itojun Hagino return ret; \ 240686cdd19SJun-ichiro itojun Hagino } \ 241686cdd19SJun-ichiro itojun Hagino } else { \ 242686cdd19SJun-ichiro itojun Hagino if ((m)->m_len < (off) + (hlen)) { \ 243f3821164SJun-ichiro itojun Hagino ip6stat.ip6s_exthdrtoolong++; \ 244686cdd19SJun-ichiro itojun Hagino m_freem(m); \ 245686cdd19SJun-ichiro itojun Hagino return ret; \ 246686cdd19SJun-ichiro itojun Hagino } \ 247686cdd19SJun-ichiro itojun Hagino } \ 248686cdd19SJun-ichiro itojun Hagino } else { \ 249686cdd19SJun-ichiro itojun Hagino if ((m)->m_len < (off) + (hlen)) { \ 250f3821164SJun-ichiro itojun Hagino ip6stat.ip6s_tooshort++; \ 251686cdd19SJun-ichiro itojun Hagino in6_ifstat_inc(m->m_pkthdr.rcvif, ifs6_in_truncated); \ 252686cdd19SJun-ichiro itojun Hagino m_freem(m); \ 253686cdd19SJun-ichiro itojun Hagino return ret; \ 254686cdd19SJun-ichiro itojun Hagino } \ 255686cdd19SJun-ichiro itojun Hagino } \ 2565c6ebad8SHajimu UMEMOTO } while (/*CONSTCOND*/ 0) 257686cdd19SJun-ichiro itojun Hagino 258686cdd19SJun-ichiro itojun Hagino /* 259686cdd19SJun-ichiro itojun Hagino * IP6_EXTHDR_GET ensures that intermediate protocol header (from "off" to 260686cdd19SJun-ichiro itojun Hagino * "len") is located in single mbuf, on contiguous memory region. 261686cdd19SJun-ichiro itojun Hagino * The pointer to the region will be returned to pointer variable "val", 262686cdd19SJun-ichiro itojun Hagino * with type "typ". 263686cdd19SJun-ichiro itojun Hagino * IP6_EXTHDR_GET0 does the same, except that it aligns the structure at the 264686cdd19SJun-ichiro itojun Hagino * very top of mbuf. GET0 is likely to make memory copy than GET. 265686cdd19SJun-ichiro itojun Hagino * 266686cdd19SJun-ichiro itojun Hagino * XXX we're now testing this, needs m_pulldown() 267686cdd19SJun-ichiro itojun Hagino */ 268686cdd19SJun-ichiro itojun Hagino #define IP6_EXTHDR_GET(val, typ, m, off, len) \ 269686cdd19SJun-ichiro itojun Hagino do { \ 270686cdd19SJun-ichiro itojun Hagino struct mbuf *t; \ 271686cdd19SJun-ichiro itojun Hagino int tmp; \ 272686cdd19SJun-ichiro itojun Hagino if ((m)->m_len >= (off) + (len)) \ 273686cdd19SJun-ichiro itojun Hagino (val) = (typ)(mtod((m), caddr_t) + (off)); \ 274686cdd19SJun-ichiro itojun Hagino else { \ 275686cdd19SJun-ichiro itojun Hagino t = m_pulldown((m), (off), (len), &tmp); \ 276686cdd19SJun-ichiro itojun Hagino if (t) { \ 277686cdd19SJun-ichiro itojun Hagino if (t->m_len < tmp + (len)) \ 278686cdd19SJun-ichiro itojun Hagino panic("m_pulldown malfunction"); \ 279686cdd19SJun-ichiro itojun Hagino (val) = (typ)(mtod(t, caddr_t) + tmp); \ 280686cdd19SJun-ichiro itojun Hagino } else { \ 281686cdd19SJun-ichiro itojun Hagino (val) = (typ)NULL; \ 282686cdd19SJun-ichiro itojun Hagino (m) = NULL; \ 283686cdd19SJun-ichiro itojun Hagino } \ 284686cdd19SJun-ichiro itojun Hagino } \ 2855c6ebad8SHajimu UMEMOTO } while (/*CONSTCOND*/ 0) 286686cdd19SJun-ichiro itojun Hagino 287686cdd19SJun-ichiro itojun Hagino #define IP6_EXTHDR_GET0(val, typ, m, off, len) \ 288686cdd19SJun-ichiro itojun Hagino do { \ 289686cdd19SJun-ichiro itojun Hagino struct mbuf *t; \ 290686cdd19SJun-ichiro itojun Hagino if ((off) == 0) \ 291686cdd19SJun-ichiro itojun Hagino (val) = (typ)mtod(m, caddr_t); \ 292686cdd19SJun-ichiro itojun Hagino else { \ 293686cdd19SJun-ichiro itojun Hagino t = m_pulldown((m), (off), (len), NULL); \ 294686cdd19SJun-ichiro itojun Hagino if (t) { \ 295686cdd19SJun-ichiro itojun Hagino if (t->m_len < (len)) \ 296686cdd19SJun-ichiro itojun Hagino panic("m_pulldown malfunction"); \ 297686cdd19SJun-ichiro itojun Hagino (val) = (typ)mtod(t, caddr_t); \ 298686cdd19SJun-ichiro itojun Hagino } else { \ 299686cdd19SJun-ichiro itojun Hagino (val) = (typ)NULL; \ 300686cdd19SJun-ichiro itojun Hagino (m) = NULL; \ 301686cdd19SJun-ichiro itojun Hagino } \ 302686cdd19SJun-ichiro itojun Hagino } \ 3035c6ebad8SHajimu UMEMOTO } while (/*CONSTCOND*/ 0) 304686cdd19SJun-ichiro itojun Hagino #endif /*_KERNEL*/ 305686cdd19SJun-ichiro itojun Hagino 306686cdd19SJun-ichiro itojun Hagino #endif /* not _NETINET_IP6_H_ */ 307