The Pedigree Project 0.1
prot/ip6.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2014, Pedigree Developers
3 *
4 * Please see the CONTRIB file in the root of the source tree for a full
5 * list of contributors.
6 *
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
25/*
26 * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without modification,
30 * are permitted provided that the following conditions are met:
31 *
32 * 1. Redistributions of source code must retain the above copyright notice,
33 * this list of conditions and the following disclaimer.
34 * 2. Redistributions in binary form must reproduce the above copyright notice,
35 * this list of conditions and the following disclaimer in the documentation
36 * and/or other materials provided with the distribution.
37 * 3. The name of the author may not be used to endorse or promote products
38 * derived from this software without specific prior written permission.
39 *
40 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49 * OF SUCH DAMAGE.
50 *
51 * This file is part of the lwIP TCP/IP stack.
52 *
53 * Author: Adam Dunkels <adam@sics.se>
54 *
55 */
56#ifndef LWIP_HDR_PROT_IP6_H
57#define LWIP_HDR_PROT_IP6_H
58
59#include "lwip/arch.h"
60#include "lwip/ip6_addr.h"
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
68#ifdef PACK_STRUCT_USE_INCLUDES
69# include "arch/bpstruct.h"
70#endif
73 PACK_STRUCT_FIELD(u32_t addr[4]);
74} PACK_STRUCT_STRUCT;
76#ifdef PACK_STRUCT_USE_INCLUDES
77# include "arch/epstruct.h"
78#endif
79typedef struct ip6_addr_packed ip6_addr_p_t;
80
81#define IP6_HLEN 40
82
83#define IP6_NEXTH_HOPBYHOP 0
84#define IP6_NEXTH_TCP 6
85#define IP6_NEXTH_UDP 17
86#define IP6_NEXTH_ENCAPS 41
87#define IP6_NEXTH_ROUTING 43
88#define IP6_NEXTH_FRAGMENT 44
89#define IP6_NEXTH_ICMP6 58
90#define IP6_NEXTH_NONE 59
91#define IP6_NEXTH_DESTOPTS 60
92#define IP6_NEXTH_UDPLITE 136
93
95#ifdef PACK_STRUCT_USE_INCLUDES
96# include "arch/bpstruct.h"
97#endif
99struct ip6_hdr {
101 PACK_STRUCT_FIELD(u32_t _v_tc_fl);
103 PACK_STRUCT_FIELD(u16_t _plen);
105 PACK_STRUCT_FLD_8(u8_t _nexth);
107 PACK_STRUCT_FLD_8(u8_t _hoplim);
109 PACK_STRUCT_FLD_S(ip6_addr_p_t src);
110 PACK_STRUCT_FLD_S(ip6_addr_p_t dest);
111} PACK_STRUCT_STRUCT;
113#ifdef PACK_STRUCT_USE_INCLUDES
114# include "arch/epstruct.h"
115#endif
116
117/* Hop-by-hop router alert option. */
118#define IP6_HBH_HLEN 8
119#define IP6_PAD1_OPTION 0
120#define IP6_PADN_ALERT_OPTION 1
121#define IP6_ROUTER_ALERT_OPTION 5
122#define IP6_ROUTER_ALERT_VALUE_MLD 0
123#ifdef PACK_STRUCT_USE_INCLUDES
124# include "arch/bpstruct.h"
125#endif
128 /* next header */
129 PACK_STRUCT_FLD_8(u8_t _nexth);
130 /* header length */
131 PACK_STRUCT_FLD_8(u8_t _hlen);
132 /* router alert option type */
133 PACK_STRUCT_FLD_8(u8_t _ra_opt_type);
134 /* router alert option data len */
135 PACK_STRUCT_FLD_8(u8_t _ra_opt_dlen);
136 /* router alert option data */
137 PACK_STRUCT_FIELD(u16_t _ra_opt_data);
138 /* PadN option type */
139 PACK_STRUCT_FLD_8(u8_t _padn_opt_type);
140 /* PadN option data len */
141 PACK_STRUCT_FLD_8(u8_t _padn_opt_dlen);
142} PACK_STRUCT_STRUCT;
144#ifdef PACK_STRUCT_USE_INCLUDES
145# include "arch/epstruct.h"
146#endif
147
148/* Fragment header. */
149#define IP6_FRAG_HLEN 8
150#define IP6_FRAG_OFFSET_MASK 0xfff8
151#define IP6_FRAG_MORE_FLAG 0x0001
152#ifdef PACK_STRUCT_USE_INCLUDES
153# include "arch/bpstruct.h"
154#endif
157 /* next header */
158 PACK_STRUCT_FLD_8(u8_t _nexth);
159 /* reserved */
160 PACK_STRUCT_FLD_8(u8_t reserved);
161 /* fragment offset */
162 PACK_STRUCT_FIELD(u16_t _fragment_offset);
163 /* fragmented packet identification */
164 PACK_STRUCT_FIELD(u32_t _identification);
165} PACK_STRUCT_STRUCT;
167#ifdef PACK_STRUCT_USE_INCLUDES
168# include "arch/epstruct.h"
169#endif
170
171#define IP6H_V(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 28) & 0x0f)
172#define IP6H_TC(hdr) ((lwip_ntohl((hdr)->_v_tc_fl) >> 20) & 0xff)
173#define IP6H_FL(hdr) (lwip_ntohl((hdr)->_v_tc_fl) & 0x000fffff)
174#define IP6H_PLEN(hdr) (lwip_ntohs((hdr)->_plen))
175#define IP6H_NEXTH(hdr) ((hdr)->_nexth)
176#define IP6H_NEXTH_P(hdr) ((u8_t *)(hdr) + 6)
177#define IP6H_HOPLIM(hdr) ((hdr)->_hoplim)
178
179#define IP6H_VTCFL_SET(hdr, v, tc, fl) (hdr)->_v_tc_fl = (lwip_htonl((((u32_t)(v)) << 28) | (((u32_t)(tc)) << 20) | (fl)))
180#define IP6H_PLEN_SET(hdr, plen) (hdr)->_plen = lwip_htons(plen)
181#define IP6H_NEXTH_SET(hdr, nexth) (hdr)->_nexth = (nexth)
182#define IP6H_HOPLIM_SET(hdr, hl) (hdr)->_hoplim = (u8_t)(hl)
183
184#ifdef __cplusplus
185}
186#endif
187
188#endif /* LWIP_HDR_PROT_IP6_H */
#define PACK_STRUCT_END
Definition arch.h:270
#define PACK_STRUCT_BEGIN
Definition arch.h:261
#define PACK_STRUCT_FLD_8(x)
Definition arch.h:301
#define PACK_STRUCT_FIELD(x)
Definition arch.h:292
#define PACK_STRUCT_FLD_S(x)
Definition arch.h:310
PACK_STRUCT_FIELD(u16_t _plen)
PACK_STRUCT_FLD_S(ip6_addr_p_t src)
PACK_STRUCT_FLD_8(u8_t _nexth)
PACK_STRUCT_FIELD(u32_t _v_tc_fl)
PACK_STRUCT_FLD_8(u8_t _hoplim)