Mistake on this page?
Report an issue in GitHub or email us
prot/ip6.h
Go to the documentation of this file.
1 /**
2  * @file
3  * IPv6 protocol definitions
4  */
5 
6 /*
7  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without modification,
11  * are permitted provided that the following conditions are met:
12  *
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.
20  *
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
30  * OF SUCH DAMAGE.
31  *
32  * This file is part of the lwIP TCP/IP stack.
33  *
34  * Author: Adam Dunkels <adam@sics.se>
35  *
36  */
37 #ifndef LWIP_HDR_PROT_IP6_H
38 #define LWIP_HDR_PROT_IP6_H
39 
40 #include "lwip/arch.h"
41 #include "lwip/ip6_addr.h"
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /** This is the packed version of ip6_addr_t,
48  used in network headers that are itself packed */
49 #ifdef PACK_STRUCT_USE_INCLUDES
50 # include "arch/bpstruct.h"
51 #endif
54  PACK_STRUCT_FIELD(u32_t addr[4]);
57 #ifdef PACK_STRUCT_USE_INCLUDES
58 # include "arch/epstruct.h"
59 #endif
60 typedef struct ip6_addr_packed ip6_addr_p_t;
61 
62 #define IP6_HLEN 40
63 
64 #define IP6_NEXTH_HOPBYHOP 0
65 #define IP6_NEXTH_TCP 6
66 #define IP6_NEXTH_UDP 17
67 #define IP6_NEXTH_ENCAPS 41
68 #define IP6_NEXTH_ROUTING 43
69 #define IP6_NEXTH_FRAGMENT 44
70 #define IP6_NEXTH_ICMP6 58
71 #define IP6_NEXTH_NONE 59
72 #define IP6_NEXTH_DESTOPTS 60
73 #define IP6_NEXTH_UDPLITE 136
74 
75 /** The IPv6 header. */
76 #ifdef PACK_STRUCT_USE_INCLUDES
77 # include "arch/bpstruct.h"
78 #endif
80 struct ip6_hdr {
81  /** version / traffic class / flow label */
82  PACK_STRUCT_FIELD(u32_t _v_tc_fl);
83  /** payload length */
84  PACK_STRUCT_FIELD(u16_t _plen);
85  /** next header */
86  PACK_STRUCT_FLD_8(u8_t _nexth);
87  /** hop limit */
88  PACK_STRUCT_FLD_8(u8_t _hoplim);
89  /** source and destination IP addresses */
90  PACK_STRUCT_FLD_S(ip6_addr_p_t src);
91  PACK_STRUCT_FLD_S(ip6_addr_p_t dest);
94 #ifdef PACK_STRUCT_USE_INCLUDES
95 # include "arch/epstruct.h"
96 #endif
97 #define IP6H_V(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f)
98 #define IP6H_TC(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 20) & 0xff)
99 #define IP6H_FL(hdr) (lwip_ntohl((hdr)->_v_tc_fl) & 0x000fffff)
100 #define IP6H_PLEN(hdr) (lwip_ntohs((hdr)->_plen))
101 #define IP6H_NEXTH(hdr) ((hdr)->_nexth)
102 #define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6)
103 #define IP6H_HOPLIM(hdr) ((hdr)->_hoplim)
104 #define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (lwip_htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl)))
105 #define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = lwip_htons(plen)
106 #define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth)
107 #define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl)
108 
109 /* ipv6 extended options header */
110 #define IP6_PAD1_OPTION 0
111 #define IP6_PADN_OPTION 1
112 #define IP6_ROUTER_ALERT_OPTION 5
113 #define IP6_JUMBO_OPTION 194
114 #define IP6_HOME_ADDRESS_OPTION 201
115 #define IP6_ROUTER_ALERT_DLEN 2
116 #define IP6_ROUTER_ALERT_VALUE_MLD 0
117 
118 #ifdef PACK_STRUCT_USE_INCLUDES
119 # include "arch/bpstruct.h"
120 #endif
122 struct ip6_opt_hdr {
123  /* router alert option type */
124  PACK_STRUCT_FLD_8(u8_t _opt_type);
125  /* router alert option data len */
126  PACK_STRUCT_FLD_8(u8_t _opt_dlen);
129 #ifdef PACK_STRUCT_USE_INCLUDES
130 # include "arch/epstruct.h"
131 #endif
132 #define IP6_OPT_HLEN 2
133 #define IP6_OPT_TYPE_ACTION(hdr) ((((hdr)->_opt_type) >> 6) & 0x3)
134 #define IP6_OPT_TYPE_CHANGE(hdr) ((((hdr)->_opt_type) >> 5) & 0x1)
135 #define IP6_OPT_TYPE(hdr) ((hdr)->_opt_type)
136 #define IP6_OPT_DLEN(hdr) ((hdr)->_opt_dlen)
137 
138 /* Hop-by-Hop header. */
139 #define IP6_HBH_HLEN 2
140 
141 #ifdef PACK_STRUCT_USE_INCLUDES
142 # include "arch/bpstruct.h"
143 #endif
145 struct ip6_hbh_hdr {
146  /* next header */
147  PACK_STRUCT_FLD_8(u8_t _nexth);
148  /* header length in 8-octet units */
149  PACK_STRUCT_FLD_8(u8_t _hlen);
152 #ifdef PACK_STRUCT_USE_INCLUDES
153 # include "arch/epstruct.h"
154 #endif
155 #define IP6_HBH_NEXTH(hdr) ((hdr)->_nexth)
156 
157 /* Destination header. */
158 #define IP6_DEST_HLEN 2
159 
160 #ifdef PACK_STRUCT_USE_INCLUDES
161 # include "arch/bpstruct.h"
162 #endif
164 struct ip6_dest_hdr {
165  /* next header */
166  PACK_STRUCT_FLD_8(u8_t _nexth);
167  /* header length in 8-octet units */
168  PACK_STRUCT_FLD_8(u8_t _hlen);
171 #ifdef PACK_STRUCT_USE_INCLUDES
172 # include "arch/epstruct.h"
173 #endif
174 #define IP6_DEST_NEXTH(hdr) ((hdr)->_nexth)
175 
176 /* Routing header */
177 #define IP6_ROUT_TYPE2 2
178 #define IP6_ROUT_RPL 3
179 
180 #ifdef PACK_STRUCT_USE_INCLUDES
181 # include "arch/bpstruct.h"
182 #endif
184 struct ip6_rout_hdr {
185  /* next header */
186  PACK_STRUCT_FLD_8(u8_t _nexth);
187  /* reserved */
188  PACK_STRUCT_FLD_8(u8_t _hlen);
189  /* fragment offset */
190  PACK_STRUCT_FIELD(u8_t _routing_type);
191  /* fragmented packet identification */
192  PACK_STRUCT_FIELD(u8_t _segments_left);
195 #ifdef PACK_STRUCT_USE_INCLUDES
196 # include "arch/epstruct.h"
197 #endif
198 #define IP6_ROUT_NEXTH(hdr) ((hdr)->_nexth)
199 #define IP6_ROUT_TYPE(hdr) ((hdr)->_routing_type)
200 #define IP6_ROUT_SEG_LEFT(hdr) ((hdr)->_segments_left)
201 
202 /* Fragment header. */
203 #define IP6_FRAG_HLEN 8
204 #define IP6_FRAG_OFFSET_MASK 0xfff8
205 #define IP6_FRAG_MORE_FLAG 0x0001
206 
207 #ifdef PACK_STRUCT_USE_INCLUDES
208 # include "arch/bpstruct.h"
209 #endif
211 struct ip6_frag_hdr {
212  /* next header */
213  PACK_STRUCT_FLD_8(u8_t _nexth);
214  /* reserved */
215  PACK_STRUCT_FLD_8(u8_t reserved);
216  /* fragment offset */
217  PACK_STRUCT_FIELD(u16_t _fragment_offset);
218  /* fragmented packet identification */
219  PACK_STRUCT_FIELD(u32_t _identification);
222 #ifdef PACK_STRUCT_USE_INCLUDES
223 # include "arch/epstruct.h"
224 #endif
225 #define IP6_FRAG_NEXTH(hdr) ((hdr)->_nexth)
226 #define IP6_FRAG_MBIT(hdr) (lwip_ntohs((hdr)->_fragment_offset) & 0x1)
227 #define IP6_FRAG_ID(hdr) (lwip_ntohl((hdr)->_identification))
228 
229 #ifdef __cplusplus
230 }
231 #endif
232 
233 #endif /* LWIP_HDR_PROT_IP6_H */
#define PACK_STRUCT_BEGIN
Packed structs support.
Definition: arch.h:307
This is the packed version of ip6_addr_t, used in network headers that are itself packed...
Definition: prot/ip6.h:53
IPv6 addresses.
#define PACK_STRUCT_FLD_S(x)
Packed structs support.
Definition: arch.h:356
#define PACK_STRUCT_STRUCT
Packed structs support.
Definition: arch.h:328
#define PACK_STRUCT_END
Packed structs support.
Definition: arch.h:316
#define PACK_STRUCT_FLD_8(x)
Packed structs support.
Definition: arch.h:347
Support for different processor and compiler architectures.
The IPv6 header.
Definition: prot/ip6.h:80
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.