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