1205417Sluigi/* NetBSD: ip6.h,v 1.9 2000/07/13 05:34:21 itojun Exp */ 2205417Sluigi/* $KAME: ip6.h,v 1.9 2000/07/02 21:01:32 itojun Exp $ */ 3205417Sluigi 4205417Sluigi/* 5205417Sluigi * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project. 6205417Sluigi * All rights reserved. 7205417Sluigi * 8205417Sluigi * Redistribution and use in source and binary forms, with or without 9205417Sluigi * modification, are permitted provided that the following conditions 10205417Sluigi * are met: 11205417Sluigi * 1. Redistributions of source code must retain the above copyright 12205417Sluigi * notice, this list of conditions and the following disclaimer. 13205417Sluigi * 2. Redistributions in binary form must reproduce the above copyright 14205417Sluigi * notice, this list of conditions and the following disclaimer in the 15205417Sluigi * documentation and/or other materials provided with the distribution. 16205417Sluigi * 3. Neither the name of the project nor the names of its contributors 17205417Sluigi * may be used to endorse or promote products derived from this software 18205417Sluigi * without specific prior written permission. 19205417Sluigi * 20205417Sluigi * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND 21205417Sluigi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22205417Sluigi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23205417Sluigi * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE 24205417Sluigi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25205417Sluigi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26205417Sluigi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27205417Sluigi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28205417Sluigi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29205417Sluigi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30205417Sluigi * SUCH DAMAGE. 31205417Sluigi */ 32205417Sluigi 33205417Sluigi/* 34205417Sluigi * Copyright (c) 1982, 1986, 1993 35205417Sluigi * The Regents of the University of California. All rights reserved. 36205417Sluigi * 37205417Sluigi * Redistribution and use in source and binary forms, with or without 38205417Sluigi * modification, are permitted provided that the following conditions 39205417Sluigi * are met: 40205417Sluigi * 1. Redistributions of source code must retain the above copyright 41205417Sluigi * notice, this list of conditions and the following disclaimer. 42240494Sglebius * 2. Redistributions in binary form must reproduce the above copyright 43240494Sglebius * notice, this list of conditions and the following disclaimer in the 44240494Sglebius * documentation and/or other materials provided with the distribution. 45205417Sluigi * 3. Neither the name of the University nor the names of its contributors 46205417Sluigi * may be used to endorse or promote products derived from this software 47205417Sluigi * without specific prior written permission. 48205417Sluigi * 49205417Sluigi * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 50205417Sluigi * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 51205417Sluigi * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 52205417Sluigi * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 53205417Sluigi * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 54205417Sluigi * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 55205417Sluigi * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56205417Sluigi * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 57205417Sluigi * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 58205417Sluigi * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 59205417Sluigi * SUCH DAMAGE. 60205417Sluigi * 61205417Sluigi * @(#)ip.h 8.1 (Berkeley) 6/10/93 62205417Sluigi */ 63205417Sluigi 64205417Sluigi#ifndef ND_IP6_H_ 65205417Sluigi#define ND_IP6_H_ 66205417Sluigi 67205417Sluigi/* 68205417Sluigi * Definition for internet protocol version 6. 69205417Sluigi * RFC 2460 70205417Sluigi */ 71205417Sluigi 72205417Sluigistruct ip6_hdr { 73205417Sluigi union { 74205417Sluigi struct ip6_hdrctl { 75205417Sluigi nd_uint32_t ip6_un1_flow; /* 20 bits of flow-ID */ 76205417Sluigi nd_uint16_t ip6_un1_plen; /* payload length */ 77205417Sluigi nd_uint8_t ip6_un1_nxt; /* next header */ 78205417Sluigi nd_uint8_t ip6_un1_hlim; /* hop limit */ 79205417Sluigi } ip6_un1; 80205417Sluigi nd_uint8_t ip6_un2_vfc; /* 4 bits version, top 4 bits class */ 81205417Sluigi } ip6_ctlun; 82205417Sluigi nd_ipv6 ip6_src; /* source address */ 83205417Sluigi nd_ipv6 ip6_dst; /* destination address */ 84205417Sluigi}; 85205417Sluigi 86205417Sluigi#define ip6_vfc ip6_ctlun.ip6_un2_vfc 87205417Sluigi#define IP6_VERSION(ip6_hdr) ((GET_U_1((ip6_hdr)->ip6_vfc) & 0xf0) >> 4) 88205417Sluigi#define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow 89205417Sluigi#define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen 90205417Sluigi#define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt 91205417Sluigi#define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim 92205417Sluigi#define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim 93205417Sluigi 94205417Sluigi/* in network endian */ 95205417Sluigi#define IPV6_FLOWINFO_MASK ((uint32_t)htonl(0x0fffffff)) /* flow info (28 bits) */ 96205417Sluigi#define IPV6_FLOWLABEL_MASK ((uint32_t)htonl(0x000fffff)) /* flow label (20 bits) */ 97205417Sluigi 98205417Sluigi/* 99205417Sluigi * Extension Headers 100205417Sluigi */ 101205417Sluigi 102205417Sluigistruct ip6_ext { 103205417Sluigi nd_uint8_t ip6e_nxt; 104205417Sluigi nd_uint8_t ip6e_len; 105205417Sluigi}; 106205417Sluigi 107205417Sluigi/* Hop-by-Hop options header */ 108205417Sluigistruct ip6_hbh { 109205417Sluigi nd_uint8_t ip6h_nxt; /* next header */ 110205417Sluigi nd_uint8_t ip6h_len; /* length in units of 8 octets */ 111205417Sluigi /* followed by options */ 112205417Sluigi}; 113205417Sluigi 114205417Sluigi/* Destination options header */ 115205417Sluigistruct ip6_dest { 116205417Sluigi nd_uint8_t ip6d_nxt; /* next header */ 117205417Sluigi nd_uint8_t ip6d_len; /* length in units of 8 octets */ 118205417Sluigi /* followed by options */ 119205417Sluigi}; 120205417Sluigi 121205417Sluigi/* https://www.iana.org/assignments/ipv6-parameters/ipv6-parameters.xhtml */ 122205417Sluigi 123205417Sluigi/* Option types and related macros */ 124205417Sluigi#define IP6OPT_PAD1 0x00 /* 00 0 00000 */ 125205417Sluigi#define IP6OPT_PADN 0x01 /* 00 0 00001 */ 126205417Sluigi#define IP6OPT_JUMBO 0xC2 /* 11 0 00010 = 194 */ 127205417Sluigi#define IP6OPT_JUMBO_LEN 6 128205417Sluigi#define IP6OPT_RPL 0x63 /* 01 1 00011 */ 129205417Sluigi#define IP6OPT_TUN_ENC_LIMIT 0x04 /* 00 0 00100 */ 130205417Sluigi#define IP6OPT_ROUTER_ALERT 0x05 /* 00 0 00101 */ 131205417Sluigi 132205417Sluigi#define IP6OPT_RTALERT_LEN 4 133205417Sluigi#define IP6OPT_RTALERT_MLD 0 /* Datagram contains an MLD message */ 134205417Sluigi#define IP6OPT_RTALERT_RSVP 1 /* Datagram contains an RSVP message */ 135205417Sluigi#define IP6OPT_RTALERT_ACTNET 2 /* contains an Active Networks msg */ 136205417Sluigi#define IP6OPT_MINLEN 2 137205417Sluigi 138205417Sluigi#define IP6OPT_QUICK_START 0x26 /* 00 1 00110 */ 139205417Sluigi#define IP6OPT_CALIPSO 0x07 /* 00 0 00111 */ 140205417Sluigi#define IP6OPT_SMF_DPD 0x08 /* 00 0 01000 */ 141205417Sluigi#define IP6OPT_HOME_ADDRESS 0xc9 /* 11 0 01001 */ 142205417Sluigi#define IP6OPT_HOMEADDR_MINLEN 18 143205417Sluigi#define IP6OPT_EID 0x8a /* 10 0 01010 */ 144205417Sluigi#define IP6OPT_ILNP_NOTICE 0x8b /* 10 0 01011 */ 145205417Sluigi#define IP6OPT_LINE_ID 0x8c /* 10 0 01100 */ 146205417Sluigi#define IP6OPT_MPL 0x6d /* 01 1 01101 */ 147205417Sluigi#define IP6OPT_IP_DFF 0xee /* 11 1 01110 */ 148205417Sluigi 149205417Sluigi#define IP6OPT_TYPE(o) ((o) & 0xC0) 150205417Sluigi#define IP6OPT_TYPE_SKIP 0x00 151205417Sluigi#define IP6OPT_TYPE_DISCARD 0x40 152205417Sluigi#define IP6OPT_TYPE_FORCEICMP 0x80 153205417Sluigi#define IP6OPT_TYPE_ICMP 0xC0 154205417Sluigi 155205417Sluigi#define IP6OPT_MUTABLE 0x20 156205417Sluigi 157205417Sluigi/* Routing header */ 158205417Sluigistruct ip6_rthdr { 159205417Sluigi nd_uint8_t ip6r_nxt; /* next header */ 160205417Sluigi nd_uint8_t ip6r_len; /* length in units of 8 octets */ 161205417Sluigi nd_uint8_t ip6r_type; /* routing type */ 162205417Sluigi nd_uint8_t ip6r_segleft; /* segments left */ 163205417Sluigi /* followed by routing type specific data */ 164205417Sluigi}; 165205417Sluigi 166205417Sluigi#define IPV6_RTHDR_TYPE_0 0 167205417Sluigi#define IPV6_RTHDR_TYPE_2 2 168205417Sluigi#define IPV6_RTHDR_TYPE_4 4 169205417Sluigi 170205417Sluigi/* Type 0 Routing header */ 171205417Sluigi/* Also used for Type 2 */ 172205417Sluigistruct ip6_rthdr0 { 173205417Sluigi nd_uint8_t ip6r0_nxt; /* next header */ 174205417Sluigi nd_uint8_t ip6r0_len; /* length in units of 8 octets */ 175205417Sluigi nd_uint8_t ip6r0_type; /* always zero */ 176205417Sluigi nd_uint8_t ip6r0_segleft; /* segments left */ 177205417Sluigi nd_uint32_t ip6r0_reserved; /* reserved field */ 178205417Sluigi nd_ipv6 ip6r0_addr[1]; /* up to 23 addresses */ 179205417Sluigi}; 180205417Sluigi 181205417Sluigi/** 182205417Sluigi * Type 4 Routing header 183205417Sluigi * known as Segment Routing Header 'SRH' 184205417Sluigi */ 185205417Sluigistruct ip6_srh { 186205417Sluigi nd_uint8_t srh_nxt; /* next header */ 187205417Sluigi nd_uint8_t srh_len; /* length in units of 8 octets */ 188205417Sluigi nd_uint8_t srh_type; /* Routing Type 4 */ 189205417Sluigi nd_uint8_t srh_segleft; /* segments left */ 190205417Sluigi nd_uint8_t srh_last_ent; /* Last Entry*/ 191205417Sluigi nd_uint8_t srh_flags; /* Flags */ 192205417Sluigi nd_uint16_t srh_tag; /* Tag */ 193205417Sluigi nd_ipv6 srh_segments[1]; /* SRH segments list*/ 194205417Sluigi}; 195205417Sluigi 196205417Sluigi/* Fragment header */ 197205417Sluigistruct ip6_frag { 198205417Sluigi nd_uint8_t ip6f_nxt; /* next header */ 199205417Sluigi nd_uint8_t ip6f_reserved; /* reserved field */ 200205417Sluigi nd_uint16_t ip6f_offlg; /* offset, reserved, and flag */ 201205417Sluigi nd_uint32_t ip6f_ident; /* identification */ 202205417Sluigi}; 203205417Sluigi 204205417Sluigi#define IP6F_OFF_MASK 0xfff8 /* mask out offset from ip6f_offlg */ 205205417Sluigi#define IP6F_RESERVED_MASK 0x0006 /* reserved bits in ip6f_offlg */ 206205417Sluigi#define IP6F_MORE_FRAG 0x0001 /* more-fragments flag */ 207205417Sluigi 208205417Sluigi#endif /* not ND_IP6_H_ */ 209205417Sluigi