iPXE
ipv6.h
Go to the documentation of this file.
1#ifndef _IPXE_IPV6_H
2#define _IPXE_IPV6_H
3
4/** @file
5 *
6 * IPv6 protocol
7 *
8 */
9
10FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
11FILE_SECBOOT ( PERMITTED );
12
13#include <stdint.h>
14#include <string.h>
15#include <byteswap.h>
16#include <ipxe/in.h>
17#include <ipxe/list.h>
18#include <ipxe/netdevice.h>
19
20/** IPv6 version */
21#define IPV6_VER 0x60000000UL
22
23/** IPv6 version mask */
24#define IPV6_MASK_VER 0xf0000000UL
25
26/** IPv6 maximum hop limit */
27#define IPV6_HOP_LIMIT 0xff
28
29/** IPv6 default prefix length */
30#define IPV6_DEFAULT_PREFIX_LEN 64
31
32/** IPv6 maximum prefix length */
33#define IPV6_MAX_PREFIX_LEN 128
34
35/** IPv6 header */
37 /** Version (4 bits), Traffic class (8 bits), Flow label (20 bits) */
39 /** Payload length, including any extension headers */
41 /** Next header type */
43 /** Hop limit */
45 /** Source address */
46 struct in6_addr src;
47 /** Destination address */
48 struct in6_addr dest;
49} __attribute__ (( packed ));
50
51/** IPv6 extension header common fields */
53 /** Next header type */
55 /** Header extension length (excluding first 8 bytes) */
57} __attribute__ (( packed ));
58
59/** IPv6 type-length-value options */
61 /** Type */
63 /** Length */
65 /** Value */
67} __attribute__ (( packed ));
68
69/** IPv6 option types */
71 /** Pad1 */
73 /** PadN */
75};
76
77/** Test if IPv6 option can be safely ignored */
78#define IPV6_CAN_IGNORE_OPT( type ) ( ( (type) & 0xc0 ) == 0x00 )
79
80/** IPv6 option-based extension header */
82 /** Extension header common fields */
84 /** Options */
86} __attribute__ (( packed ));
87
88/** IPv6 routing header */
90 /** Extension header common fields */
92 /** Routing type */
94 /** Segments left */
96 /** Type-specific data */
98} __attribute__ (( packed ));
99
100/** IPv6 fragment header */
102 /** Extension header common fields */
104 /** Fragment offset (13 bits), reserved, more fragments (1 bit) */
106 /** Identification */
108} __attribute__ (( packed ));
109
110/** Fragment offset mask */
111#define IPV6_MASK_OFFSET 0xfff8
112
113/** More fragments */
114#define IPV6_MASK_MOREFRAGS 0x0001
115
116/** IPv6 extension header */
118 /** Extension header common fields */
120 /** Minimum size padding */
122 /** Generic options header */
124 /** Hop-by-hop options header */
126 /** Routing header */
128 /** Fragment header */
130 /** Destination options header */
132};
133
134/** IPv6 header types */
136 /** IPv6 hop-by-hop options header type */
138 /** IPv6 routing header type */
140 /** IPv6 fragment header type */
142 /** IPv6 no next header type */
144 /** IPv6 destination options header type */
146};
147
148/** IPv6 pseudo-header */
150 /** Source address */
151 struct in6_addr src;
152 /** Destination address */
154 /** Upper-layer packet length */
156 /** Zero padding */
158 /** Next header */
160} __attribute__ (( packed ));
161
162/** IPv6 address scopes */
164 /** Interface-local address scope */
166 /** Link-local address scope */
168 /** Admin-local address scope */
170 /** Site-local address scope */
172 /** Organisation-local address scope */
174 /** Global address scope */
176 /** Maximum scope */
178};
179
180/** An IPv6 address/routing table entry */
182 /** List of miniroutes */
184
185 /** Network device */
187
188 /** IPv6 address (or prefix if no address is defined) */
190 /** Prefix length */
191 unsigned int prefix_len;
192 /** IPv6 prefix mask (derived from prefix length) */
194 /** Router address */
196 /** Scope */
197 unsigned int scope;
198 /** Flags */
199 unsigned int flags;
200};
201
202/** IPv6 address/routing table entry flags */
204 /** Routing table entry address is valid */
206 /** Routing table entry router address is valid */
208};
209
210/**
211 * Construct local IPv6 address via EUI-64
212 *
213 * @v addr Prefix to be completed
214 * @v netdev Network device
215 * @ret prefix_len Prefix length, or negative error
216 */
217static inline int ipv6_eui64 ( struct in6_addr *addr,
218 struct net_device *netdev ) {
219 struct ll_protocol *ll_protocol = netdev->ll_protocol;
220 const void *ll_addr = netdev->ll_addr;
221 int rc;
222
223 if ( ( rc = ll_protocol->eui64 ( ll_addr, &addr->s6_addr[8] ) ) != 0 )
224 return rc;
225 addr->s6_addr[8] ^= 0x02;
226 return 64;
227}
228
229/**
230 * Construct link-local address via EUI-64
231 *
232 * @v addr Zeroed address to construct
233 * @v netdev Network device
234 * @ret prefix_len Prefix length, or negative error
235 */
236static inline int ipv6_link_local ( struct in6_addr *addr,
237 struct net_device *netdev ) {
238
239 addr->s6_addr16[0] = htons ( 0xfe80 );
240 return ipv6_eui64 ( addr, netdev );
241}
242
243/**
244 * Construct solicited-node multicast address
245 *
246 * @v addr Zeroed address to construct
247 * @v unicast Unicast address
248 */
249static inline void ipv6_solicited_node ( struct in6_addr *addr,
250 const struct in6_addr *unicast ) {
251
252 addr->s6_addr16[0] = htons ( 0xff02 );
253 addr->s6_addr[11] = 1;
254 addr->s6_addr[12] = 0xff;
255 memcpy ( &addr->s6_addr[13], &unicast->s6_addr[13], 3 );
256}
257
258/**
259 * Construct all-routers multicast address
260 *
261 * @v addr Zeroed address to construct
262 */
263static inline void ipv6_all_routers ( struct in6_addr *addr ) {
264 addr->s6_addr16[0] = htons ( 0xff02 );
265 addr->s6_addr[15] = 2;
266}
267
268/**
269 * Get multicast address scope
270 *
271 * @v addr Multicast address
272 * @ret scope Address scope
273 */
274static inline unsigned int
276
277 return ( addr->s6_addr[1] & 0x0f );
278}
279
280/** IPv6 settings sibling order */
282 /** No address */
284 /** Link-local address */
286 /** Address assigned via SLAAC */
288 /** Address assigned via DHCPv6 */
290};
291
292/** IPv6 link-local address settings block name */
293#define IPV6_SETTINGS_NAME "link"
294
295extern struct list_head ipv6_miniroutes;
296
297extern struct net_protocol ipv6_protocol __net_protocol;
298
299extern int ipv6_has_addr ( struct net_device *netdev, struct in6_addr *addr );
300extern int ipv6_add_miniroute ( struct net_device *netdev,
301 struct in6_addr *address,
302 unsigned int prefix_len,
303 struct in6_addr *router );
304extern void ipv6_del_miniroute ( struct ipv6_miniroute *miniroute );
305extern struct ipv6_miniroute * ipv6_route ( unsigned int scope_id,
306 struct in6_addr **dest );
307extern int parse_ipv6_setting ( const struct setting_type *type,
308 const char *value, void *buf, size_t len );
309extern int format_ipv6_setting ( const struct setting_type *type,
310 const void *raw, size_t raw_len, char *buf,
311 size_t len );
312
313#endif /* _IPXE_IPV6_H */
__be32 raw[7]
Definition CIB_PRM.h:0
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
pseudo_bit_t value[0x00020]
Definition arbel.h:2
unsigned short uint16_t
Definition stdint.h:11
unsigned int uint32_t
Definition stdint.h:12
unsigned char uint8_t
Definition stdint.h:10
if(len >=6 *4) __asm__ __volatile__("movsl" if(len >=5 *4) __asm__ __volatile__("movsl" if(len >=4 *4) __asm__ __volatile__("movsl" if(len >=3 *4) __asm__ __volatile__("movsl" if(len >=2 *4) __asm__ __volatile__("movsl" if(len >=1 *4) __asm__ __volatile__("movsl" if((len % 4) >=2) __asm__ __volatile__("movsw" if((len % 2) >=1) __asm__ __volatile__("movsb" retur dest)
Definition string.h:151
static size_t raw_len
Definition base16.h:54
ring len
Length.
Definition dwmac.h:226
uint32_t addr
Buffer address.
Definition dwmac.h:9
uint32_t type
Operating system type.
Definition ena.h:1
uint64_t address
Base address.
Definition ena.h:13
static struct net_device * netdev
Definition gdbudp.c:53
#define FILE_LICENCE(_licence)
Declare a particular licence as applying to a file.
Definition compiler.h:896
#define FILE_SECBOOT(_status)
Declare a file's UEFI Secure Boot permission status.
Definition compiler.h:926
#define htons(value)
Definition byteswap.h:136
#define __attribute__(x)
Definition compiler.h:10
String functions.
void * memcpy(void *dest, const void *src, size_t len) __nonnull
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition ipv6.c:61
static int ipv6_eui64(struct in6_addr *addr, struct net_device *netdev)
Construct local IPv6 address via EUI-64.
Definition ipv6.h:217
void ipv6_del_miniroute(struct ipv6_miniroute *miniroute)
Delete IPv6 minirouting table entry.
Definition ipv6.c:293
static unsigned int ipv6_multicast_scope(const struct in6_addr *addr)
Get multicast address scope.
Definition ipv6.h:275
ipv6_option_type
IPv6 option types.
Definition ipv6.h:70
@ IPV6_OPT_PAD1
Pad1.
Definition ipv6.h:72
@ IPV6_OPT_PADN
PadN.
Definition ipv6.h:74
int parse_ipv6_setting(const struct setting_type *type, const char *value, void *buf, size_t len)
static void ipv6_solicited_node(struct in6_addr *addr, const struct in6_addr *unicast)
Construct solicited-node multicast address.
Definition ipv6.h:249
static void ipv6_all_routers(struct in6_addr *addr)
Construct all-routers multicast address.
Definition ipv6.h:263
int format_ipv6_setting(const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
struct ipv6_miniroute * ipv6_route(unsigned int scope_id, struct in6_addr **dest)
Perform IPv6 routing.
Definition ipv6.c:308
ipv6_header_type
IPv6 header types.
Definition ipv6.h:135
@ IPV6_NO_HEADER
IPv6 no next header type.
Definition ipv6.h:143
@ IPV6_HOPBYHOP
IPv6 hop-by-hop options header type.
Definition ipv6.h:137
@ IPV6_FRAGMENT
IPv6 fragment header type.
Definition ipv6.h:141
@ IPV6_DESTINATION
IPv6 destination options header type.
Definition ipv6.h:145
@ IPV6_ROUTING
IPv6 routing header type.
Definition ipv6.h:139
ipv6_miniroute_flags
IPv6 address/routing table entry flags.
Definition ipv6.h:203
@ IPV6_HAS_ROUTER
Routing table entry router address is valid.
Definition ipv6.h:207
@ IPV6_HAS_ADDRESS
Routing table entry address is valid.
Definition ipv6.h:205
int ipv6_has_addr(struct net_device *netdev, struct in6_addr *addr)
Check if network device has a specific IPv6 address.
Definition ipv6.c:142
ipv6_settings_order
IPv6 settings sibling order.
Definition ipv6.h:281
@ IPV6_ORDER_PREFIX_ONLY
No address.
Definition ipv6.h:283
@ IPV6_ORDER_SLAAC
Address assigned via SLAAC.
Definition ipv6.h:287
@ IPV6_ORDER_DHCPV6
Address assigned via DHCPv6.
Definition ipv6.h:289
@ IPV6_ORDER_LINK_LOCAL
Link-local address.
Definition ipv6.h:285
ipv6_address_scope
IPv6 address scopes.
Definition ipv6.h:163
@ IPV6_SCOPE_SITE_LOCAL
Site-local address scope.
Definition ipv6.h:171
@ IPV6_SCOPE_GLOBAL
Global address scope.
Definition ipv6.h:175
@ IPV6_SCOPE_MAX
Maximum scope.
Definition ipv6.h:177
@ IPV6_SCOPE_ORGANISATION_LOCAL
Organisation-local address scope.
Definition ipv6.h:173
@ IPV6_SCOPE_LINK_LOCAL
Link-local address scope.
Definition ipv6.h:167
@ INV6_SCOPE_ADMIN_LOCAL
Admin-local address scope.
Definition ipv6.h:169
@ IPV6_SCOPE_INTERFACE_LOCAL
Interface-local address scope.
Definition ipv6.h:165
static int ipv6_link_local(struct in6_addr *addr, struct net_device *netdev)
Construct link-local address via EUI-64.
Definition ipv6.h:236
int ipv6_add_miniroute(struct net_device *netdev, struct in6_addr *address, unsigned int prefix_len, struct in6_addr *router)
Add IPv6 routing table entry.
Definition ipv6.c:218
Linked lists.
Network device management.
#define __net_protocol
Declare a network-layer protocol.
Definition netdevice.h:474
IP6 address structure.
Definition in.h:51
IPv6 extension header common fields.
Definition ipv6.h:52
uint8_t len
Header extension length (excluding first 8 bytes)
Definition ipv6.h:56
uint8_t next_header
Next header type.
Definition ipv6.h:54
IPv6 fragment header.
Definition ipv6.h:101
uint32_t ident
Identification.
Definition ipv6.h:107
uint16_t offset_more
Fragment offset (13 bits), reserved, more fragments (1 bit)
Definition ipv6.h:105
struct ipv6_extension_header_common common
Extension header common fields.
Definition ipv6.h:103
IPv6 header.
Definition ipv6.h:36
struct in6_addr dest
Destination address.
Definition ipv6.h:48
uint8_t hop_limit
Hop limit.
Definition ipv6.h:44
struct in6_addr src
Source address.
Definition ipv6.h:46
uint32_t ver_tc_label
Version (4 bits), Traffic class (8 bits), Flow label (20 bits)
Definition ipv6.h:38
uint16_t len
Payload length, including any extension headers.
Definition ipv6.h:40
uint8_t next_header
Next header type.
Definition ipv6.h:42
An IPv6 address/routing table entry.
Definition ipv6.h:181
struct net_device * netdev
Network device.
Definition ipv6.h:186
struct list_head list
List of miniroutes.
Definition ipv6.h:183
unsigned int scope
Scope.
Definition ipv6.h:197
unsigned int prefix_len
Prefix length.
Definition ipv6.h:191
unsigned int flags
Flags.
Definition ipv6.h:199
struct in6_addr router
Router address.
Definition ipv6.h:195
struct in6_addr address
IPv6 address (or prefix if no address is defined)
Definition ipv6.h:189
struct in6_addr prefix_mask
IPv6 prefix mask (derived from prefix length)
Definition ipv6.h:193
IPv6 type-length-value options.
Definition ipv6.h:60
uint8_t type
Type.
Definition ipv6.h:62
uint8_t len
Length.
Definition ipv6.h:64
uint8_t value[0]
Value.
Definition ipv6.h:66
IPv6 option-based extension header.
Definition ipv6.h:81
struct ipv6_extension_header_common common
Extension header common fields.
Definition ipv6.h:83
struct ipv6_option options[0]
Options.
Definition ipv6.h:85
IPv6 pseudo-header.
Definition ipv6.h:149
uint8_t next_header
Next header.
Definition ipv6.h:159
uint8_t zero[3]
Zero padding.
Definition ipv6.h:157
struct in6_addr dest
Destination address.
Definition ipv6.h:153
uint32_t len
Upper-layer packet length.
Definition ipv6.h:155
struct in6_addr src
Source address.
Definition ipv6.h:151
IPv6 routing header.
Definition ipv6.h:89
uint8_t data[0]
Type-specific data.
Definition ipv6.h:97
uint8_t remaining
Segments left.
Definition ipv6.h:95
struct ipv6_extension_header_common common
Extension header common fields.
Definition ipv6.h:91
uint8_t type
Routing type.
Definition ipv6.h:93
A doubly-linked list entry (or list head)
Definition list.h:19
A link-layer protocol.
Definition netdevice.h:115
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition netdevice.h:190
A network device.
Definition netdevice.h:353
A network-layer protocol.
Definition netdevice.h:65
A setting type.
Definition settings.h:192
IPv6 extension header.
Definition ipv6.h:117
uint8_t pad[8]
Minimum size padding.
Definition ipv6.h:121
struct ipv6_options_header destination
Destination options header.
Definition ipv6.h:131
struct ipv6_options_header hopbyhop
Hop-by-hop options header.
Definition ipv6.h:125
struct ipv6_routing_header routing
Routing header.
Definition ipv6.h:127
struct ipv6_options_header options
Generic options header.
Definition ipv6.h:123
struct ipv6_extension_header_common common
Extension header common fields.
Definition ipv6.h:119
struct ipv6_fragment_header fragment
Fragment header.
Definition ipv6.h:129