10f74e101Schristos /* NetBSD: ip6.h,v 1.9 2000/07/13 05:34:21 itojun Exp */ 20f74e101Schristos /* $KAME: ip6.h,v 1.9 2000/07/02 21:01:32 itojun Exp $ */ 30f74e101Schristos 40f74e101Schristos /* 50f74e101Schristos * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 60f74e101Schristos * All rights reserved. 70f74e101Schristos * 80f74e101Schristos * Redistribution and use in source and binary forms, with or without 90f74e101Schristos * modification, are permitted provided that the following conditions 100f74e101Schristos * are met: 110f74e101Schristos * 1. Redistributions of source code must retain the above copyright 120f74e101Schristos * notice, this list of conditions and the following disclaimer. 130f74e101Schristos * 2. Redistributions in binary form must reproduce the above copyright 140f74e101Schristos * notice, this list of conditions and the following disclaimer in the 150f74e101Schristos * documentation and/or other materials provided with the distribution. 160f74e101Schristos * 3. Neither the name of the project nor the names of its contributors 170f74e101Schristos * may be used to endorse or promote products derived from this software 180f74e101Schristos * without specific prior written permission. 190f74e101Schristos * 200f74e101Schristos * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 210f74e101Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 220f74e101Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 230f74e101Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 240f74e101Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 250f74e101Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 260f74e101Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 270f74e101Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 280f74e101Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 290f74e101Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 300f74e101Schristos * SUCH DAMAGE. 310f74e101Schristos */ 320f74e101Schristos 330f74e101Schristos /* 340f74e101Schristos * Copyright (c) 1982, 1986, 1993 350f74e101Schristos * The Regents of the University of California. All rights reserved. 360f74e101Schristos * 370f74e101Schristos * Redistribution and use in source and binary forms, with or without 380f74e101Schristos * modification, are permitted provided that the following conditions 390f74e101Schristos * are met: 400f74e101Schristos * 1. Redistributions of source code must retain the above copyright 410f74e101Schristos * notice, this list of conditions and the following disclaimer. 420f74e101Schristos * 2. Redistributions in binary form must reproduce the above copyright 430f74e101Schristos * notice, this list of conditions and the following disclaimer in the 440f74e101Schristos * documentation and/or other materials provided with the distribution. 4511b3aaa1Schristos * 3. Neither the name of the University nor the names of its contributors 460f74e101Schristos * may be used to endorse or promote products derived from this software 470f74e101Schristos * without specific prior written permission. 480f74e101Schristos * 490f74e101Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 500f74e101Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 510f74e101Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 520f74e101Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 530f74e101Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 540f74e101Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 550f74e101Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 560f74e101Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 570f74e101Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 580f74e101Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 590f74e101Schristos * SUCH DAMAGE. 600f74e101Schristos * 610f74e101Schristos * @(#)ip.h 8.1 (Berkeley) 6/10/93 620f74e101Schristos */ 630f74e101Schristos 64*c74ad251Schristos #ifndef ND_IP6_H_ 65*c74ad251Schristos #define ND_IP6_H_ 660f74e101Schristos 670f74e101Schristos /* 680f74e101Schristos * Definition for internet protocol version 6. 690f74e101Schristos * RFC 2460 700f74e101Schristos */ 710f74e101Schristos 720f74e101Schristos struct ip6_hdr { 730f74e101Schristos union { 740f74e101Schristos struct ip6_hdrctl { 75*c74ad251Schristos nd_uint32_t ip6_un1_flow; /* 20 bits of flow-ID */ 76*c74ad251Schristos nd_uint16_t ip6_un1_plen; /* payload length */ 77*c74ad251Schristos nd_uint8_t ip6_un1_nxt; /* next header */ 78*c74ad251Schristos nd_uint8_t ip6_un1_hlim; /* hop limit */ 790f74e101Schristos } ip6_un1; 80*c74ad251Schristos nd_uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */ 810f74e101Schristos } ip6_ctlun; 82*c74ad251Schristos nd_ipv6 ip6_src; /* source address */ 83*c74ad251Schristos nd_ipv6 ip6_dst; /* destination address */ 84*c74ad251Schristos }; 850f74e101Schristos 860f74e101Schristos #define ip6_vfc ip6_ctlun.ip6_un2_vfc 87*c74ad251Schristos #define IP6_VERSION(ip6_hdr) ((GET_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4) 880f74e101Schristos #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow 890f74e101Schristos #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen 900f74e101Schristos #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt 910f74e101Schristos #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim 920f74e101Schristos #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim 930f74e101Schristos 940f74e101Schristos /* in network endian */ 95b3a00663Schristos #define IPV6_FLOWINFO_MASK ((uint32_t)htonl(0x0fffffff)) /* flow info (28 bits) */ 96b3a00663Schristos #define IPV6_FLOWLABEL_MASK ((uint32_t)htonl(0x000fffff)) /* flow label (20 bits) */ 970f74e101Schristos 980f74e101Schristos /* 990f74e101Schristos * Extension Headers 1000f74e101Schristos */ 1010f74e101Schristos 1020f74e101Schristos struct ip6_ext { 103*c74ad251Schristos nd_uint8_t ip6e_nxt; 104*c74ad251Schristos nd_uint8_t ip6e_len; 105*c74ad251Schristos }; 1060f74e101Schristos 1070f74e101Schristos /* Hop-by-Hop options header */ 1080f74e101Schristos struct ip6_hbh { 109*c74ad251Schristos nd_uint8_t ip6h_nxt; /* next header */ 110*c74ad251Schristos nd_uint8_t ip6h_len; /* length in units of 8 octets */ 1110f74e101Schristos /* followed by options */ 112*c74ad251Schristos }; 1130f74e101Schristos 1140f74e101Schristos /* Destination options header */ 1150f74e101Schristos struct ip6_dest { 116*c74ad251Schristos nd_uint8_t ip6d_nxt; /* next header */ 117*c74ad251Schristos nd_uint8_t ip6d_len; /* length in units of 8 octets */ 1180f74e101Schristos /* followed by options */ 119*c74ad251Schristos }; 1200f74e101Schristos 121*c74ad251Schristos /* https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */ 122b3a00663Schristos 1230f74e101Schristos /* Option types and related macros */ 1240f74e101Schristos #define IP6OPT_PAD1 0x00 /* 00 0 00000 */ 1250f74e101Schristos #define IP6OPT_PADN 0x01 /* 00 0 00001 */ 1260f74e101Schristos #define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ 1270f74e101Schristos #define IP6OPT_JUMBO_LEN 6 128b3a00663Schristos #define IP6OPT_RPL 0x63 /* 01 1 00011 */ 129b3a00663Schristos #define IP6OPT_TUN_ENC_LIMIT 0x04 /* 00 0 00100 */ 1300f74e101Schristos #define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */ 1310f74e101Schristos 1320f74e101Schristos #define IP6OPT_RTALERT_LEN 4 1330f74e101Schristos #define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ 1340f74e101Schristos #define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ 1350f74e101Schristos #define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ 1360f74e101Schristos #define IP6OPT_MINLEN 2 1370f74e101Schristos 138b3a00663Schristos #define IP6OPT_QUICK_START 0x26 /* 00 1 00110 */ 139b3a00663Schristos #define IP6OPT_CALIPSO 0x07 /* 00 0 00111 */ 140b3a00663Schristos #define IP6OPT_SMF_DPD 0x08 /* 00 0 01000 */ 1410f74e101Schristos #define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */ 142b3a00663Schristos #define IP6OPT_HOMEADDR_MINLEN 18 1430f74e101Schristos #define IP6OPT_EID 0x8a /* 10 0 01010 */ 144b3a00663Schristos #define IP6OPT_ILNP_NOTICE 0x8b /* 10 0 01011 */ 145b3a00663Schristos #define IP6OPT_LINE_ID 0x8c /* 10 0 01100 */ 146b3a00663Schristos #define IP6OPT_MPL 0x6d /* 01 1 01101 */ 147b3a00663Schristos #define IP6OPT_IP_DFF 0xee /* 11 1 01110 */ 1480f74e101Schristos 1490f74e101Schristos #define IP6OPT_TYPE(o) ((o) & 0xC0) 1500f74e101Schristos #define IP6OPT_TYPE_SKIP 0x00 1510f74e101Schristos #define IP6OPT_TYPE_DISCARD 0x40 1520f74e101Schristos #define IP6OPT_TYPE_FORCEICMP 0x80 1530f74e101Schristos #define IP6OPT_TYPE_ICMP 0xC0 1540f74e101Schristos 1550f74e101Schristos #define IP6OPT_MUTABLE 0x20 1560f74e101Schristos 1570f74e101Schristos /* Routing header */ 1580f74e101Schristos struct ip6_rthdr { 159*c74ad251Schristos nd_uint8_t ip6r_nxt; /* next header */ 160*c74ad251Schristos nd_uint8_t ip6r_len; /* length in units of 8 octets */ 161*c74ad251Schristos nd_uint8_t ip6r_type; /* routing type */ 162*c74ad251Schristos nd_uint8_t ip6r_segleft; /* segments left */ 1630f74e101Schristos /* followed by routing type specific data */ 164*c74ad251Schristos }; 1650f74e101Schristos 166fdccd7e4Schristos #define IPV6_RTHDR_TYPE_0 0 167fdccd7e4Schristos #define IPV6_RTHDR_TYPE_2 2 168*c74ad251Schristos #define IPV6_RTHDR_TYPE_4 4 169fdccd7e4Schristos 1700f74e101Schristos /* Type 0 Routing header */ 171fdccd7e4Schristos /* Also used for Type 2 */ 1720f74e101Schristos struct ip6_rthdr0 { 17372c96ff3Schristos nd_uint8_t ip6r0_nxt; /* next header */ 17472c96ff3Schristos nd_uint8_t ip6r0_len; /* length in units of 8 octets */ 17572c96ff3Schristos nd_uint8_t ip6r0_type; /* always zero */ 17672c96ff3Schristos nd_uint8_t ip6r0_segleft; /* segments left */ 17772c96ff3Schristos nd_uint32_t ip6r0_reserved; /* reserved field */ 178*c74ad251Schristos nd_ipv6 ip6r0_addr[1]; /* up to 23 addresses */ 179*c74ad251Schristos }; 180*c74ad251Schristos 181*c74ad251Schristos /** 182*c74ad251Schristos * Type 4 Routing header 183*c74ad251Schristos * known as Segment Routing Header 'SRH' 184*c74ad251Schristos */ 185*c74ad251Schristos struct ip6_srh { 186*c74ad251Schristos nd_uint8_t srh_nxt; /* next header */ 187*c74ad251Schristos nd_uint8_t srh_len; /* length in units of 8 octets */ 188*c74ad251Schristos nd_uint8_t srh_type; /* Routing Type 4 */ 189*c74ad251Schristos nd_uint8_t srh_segleft; /* segments left */ 190*c74ad251Schristos nd_uint8_t srh_last_ent; /* Last Entry*/ 191*c74ad251Schristos nd_uint8_t srh_flags; /* Flags */ 192*c74ad251Schristos nd_uint16_t srh_tag; /* Tag */ 193*c74ad251Schristos nd_ipv6 srh_segments[1]; /* SRH segments list*/ 19472c96ff3Schristos }; 1950f74e101Schristos 1960f74e101Schristos /* Fragment header */ 1970f74e101Schristos struct ip6_frag { 198*c74ad251Schristos nd_uint8_t ip6f_nxt; /* next header */ 199*c74ad251Schristos nd_uint8_t ip6f_reserved; /* reserved field */ 200*c74ad251Schristos nd_uint16_t ip6f_offlg; /* offset, reserved, and flag */ 201*c74ad251Schristos nd_uint32_t ip6f_ident; /* identification */ 202*c74ad251Schristos }; 2030f74e101Schristos 2040f74e101Schristos #define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */ 2050f74e101Schristos #define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */ 2060f74e101Schristos #define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */ 2070f74e101Schristos 208*c74ad251Schristos #endif /* not ND_IP6_H_ */ 209