3 * IPv6 protocol definitions
7 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
13 * 1. Redistributions of source code must retain the above copyright notice,
14 * this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright notice,
16 * this list of conditions and the following disclaimer in the documentation
17 * and/or other materials provided with the distribution.
18 * 3. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
22 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
23 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
24 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
26 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
29 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * This file is part of the lwIP TCP/IP stack.
34 * Author: Adam Dunkels <adam@sics.se>
37 #ifndef LWIP_HDR_PROT_IP6_H
38 #define LWIP_HDR_PROT_IP6_H
40 #include "lwip/arch.h"
41 #include "lwip/ip6_addr.h"
47 #define IP6_MIN_MTU 1280
49 /** This is the packed version of ip6_addr_t,
50 used in network headers that are itself packed */
51 #ifdef PACK_STRUCT_USE_INCLUDES
52 # include "arch/bpstruct.h"
55 struct ip6_addr_packed {
56 PACK_STRUCT_FIELD(u32_t addr[4]);
59 #ifdef PACK_STRUCT_USE_INCLUDES
60 # include "arch/epstruct.h"
62 typedef struct ip6_addr_packed ip6_addr_p_t;
66 #define IP6_NEXTH_HOPBYHOP 0
67 #define IP6_NEXTH_TCP 6
68 #define IP6_NEXTH_UDP 17
69 #define IP6_NEXTH_ENCAPS 41
70 #define IP6_NEXTH_ROUTING 43
71 #define IP6_NEXTH_FRAGMENT 44
72 #define IP6_NEXTH_ICMP6 58
73 #define IP6_NEXTH_NONE 59
74 #define IP6_NEXTH_DESTOPTS 60
75 #define IP6_NEXTH_UDPLITE 136
77 /** The IPv6 header. */
78 #ifdef PACK_STRUCT_USE_INCLUDES
79 # include "arch/bpstruct.h"
83 /** version / traffic class / flow label */
84 PACK_STRUCT_FIELD(u32_t _v_tc_fl);
86 PACK_STRUCT_FIELD(u16_t _plen);
88 PACK_STRUCT_FLD_8(u8_t _nexth);
90 PACK_STRUCT_FLD_8(u8_t _hoplim);
91 /** source and destination IP addresses */
92 PACK_STRUCT_FLD_S(ip6_addr_p_t src);
93 PACK_STRUCT_FLD_S(ip6_addr_p_t dest);
96 #ifdef PACK_STRUCT_USE_INCLUDES
97 # include "arch/epstruct.h"
100 /* Hop-by-hop router alert option. */
101 #define IP6_HBH_HLEN 8
102 #define IP6_PAD1_OPTION 0
103 #define IP6_PADN_ALERT_OPTION 1
104 #define IP6_ROUTER_ALERT_OPTION 5
105 #define IP6_ROUTER_ALERT_VALUE_MLD 0
106 #ifdef PACK_STRUCT_USE_INCLUDES
107 # include "arch/bpstruct.h"
112 PACK_STRUCT_FLD_8(u8_t _nexth);
114 PACK_STRUCT_FLD_8(u8_t _hlen);
115 /* router alert option type */
116 PACK_STRUCT_FLD_8(u8_t _ra_opt_type);
117 /* router alert option data len */
118 PACK_STRUCT_FLD_8(u8_t _ra_opt_dlen);
119 /* router alert option data */
120 PACK_STRUCT_FIELD(u16_t _ra_opt_data);
121 /* PadN option type */
122 PACK_STRUCT_FLD_8(u8_t _padn_opt_type);
123 /* PadN option data len */
124 PACK_STRUCT_FLD_8(u8_t _padn_opt_dlen);
125 } PACK_STRUCT_STRUCT;
127 #ifdef PACK_STRUCT_USE_INCLUDES
128 # include "arch/epstruct.h"
131 /* Fragment header. */
132 #define IP6_FRAG_HLEN 8
133 #define IP6_FRAG_OFFSET_MASK 0xfff8
134 #define IP6_FRAG_MORE_FLAG 0x0001
135 #ifdef PACK_STRUCT_USE_INCLUDES
136 # include "arch/bpstruct.h"
139 struct ip6_frag_hdr {
141 PACK_STRUCT_FLD_8(u8_t _nexth);
143 PACK_STRUCT_FLD_8(u8_t reserved);
144 /* fragment offset */
145 PACK_STRUCT_FIELD(u16_t _fragment_offset);
146 /* fragmented packet identification */
147 PACK_STRUCT_FIELD(u32_t _identification);
148 } PACK_STRUCT_STRUCT;
150 #ifdef PACK_STRUCT_USE_INCLUDES
151 # include "arch/epstruct.h"
154 #define IP6H_V(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f)
155 #define IP6H_TC(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 20) & 0xff)
156 #define IP6H_FL(hdr) (lwip_ntohl((hdr)->_v_tc_fl) & 0x000fffff)
157 #define IP6H_PLEN(hdr) (lwip_ntohs((hdr)->_plen))
158 #define IP6H_NEXTH(hdr) ((hdr)->_nexth)
159 #define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6)
160 #define IP6H_HOPLIM(hdr) ((hdr)->_hoplim)
162 #define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (lwip_htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl)))
163 #define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = lwip_htons(plen)
164 #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth)
165 #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl)
171 #endif /* LWIP_HDR_PROT_IP6_H */