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 FILE_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 */
36 struct 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 */
60 struct ipv6_option {
61  /** Type */
63  /** Length */
65  /** Value */
67 } __attribute__ (( packed ));
68 
69 /** IPv6 option types */
71  /** Pad1 */
72  IPV6_OPT_PAD1 = 0x00,
73  /** PadN */
74  IPV6_OPT_PADN = 0x01,
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 */
85  struct ipv6_option options[0];
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 */
153  struct in6_addr dest;
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 */
183  struct list_head list;
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 */
195  struct in6_addr router;
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 */
207  IPV6_HAS_ROUTER = 0x0002,
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  */
217 static inline int ipv6_eui64 ( struct in6_addr *addr,
218  struct net_device *netdev ) {
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  */
236 static 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  */
249 static 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  */
263 static 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  */
274 static inline unsigned int
275 ipv6_multicast_scope ( const struct in6_addr *addr ) {
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 
295 extern struct list_head ipv6_miniroutes;
296 
297 extern struct net_protocol ipv6_protocol __net_protocol;
298 
299 extern int ipv6_has_addr ( struct net_device *netdev, struct in6_addr *addr );
300 extern int ipv6_add_miniroute ( struct net_device *netdev,
301  struct in6_addr *address,
302  unsigned int prefix_len,
303  struct in6_addr *router );
304 extern void ipv6_del_miniroute ( struct ipv6_miniroute *miniroute );
305 extern struct ipv6_miniroute * ipv6_route ( unsigned int scope_id,
306  struct in6_addr **dest );
307 extern int parse_ipv6_setting ( const struct setting_type *type,
308  const char *value, void *buf, size_t len );
309 extern 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 */
#define __attribute__(x)
Definition: compiler.h:10
PadN.
Definition: ipv6.h:74
uint8_t next_header
Next header type.
Definition: ipv6.h:42
ipv6_header_type
IPv6 header types.
Definition: ipv6.h:135
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
IPv6 header.
Definition: ipv6.h:36
struct ipv6_options_header options
Generic options header.
Definition: ipv6.h:123
Admin-local address scope.
Definition: ipv6.h:169
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:218
struct in6_addr src
Source address.
Definition: ipv6.h:151
Link-local address.
Definition: ipv6.h:285
Global address scope.
Definition: ipv6.h:175
struct ipv6_miniroute * ipv6_route(unsigned int scope_id, struct in6_addr **dest)
Perform IPv6 routing.
Definition: ipv6.c:308
struct ipv6_options_header hopbyhop
Hop-by-hop options header.
Definition: ipv6.h:125
struct ipv6_extension_header_common common
Extension header common fields.
Definition: ipv6.h:119
IPv6 option-based extension header.
Definition: ipv6.h:81
IPv6 hop-by-hop options header type.
Definition: ipv6.h:137
ipv6_address_scope
IPv6 address scopes.
Definition: ipv6.h:163
A fragment reassembly buffer.
Definition: fragment.h:22
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:249
uint32_t type
Operating system type.
Definition: ena.h:12
Link-local address scope.
Definition: ipv6.h:167
IPv6 type-length-value options.
Definition: ipv6.h:60
FILE_SECBOOT(PERMITTED)
struct ipv6_option options[0]
Options.
Definition: ipv6.h:85
IPv6 destination options header type.
Definition: ipv6.h:145
struct ipv6_extension_header_common common
Extension header common fields.
Definition: ipv6.h:83
Pad1.
Definition: ipv6.h:72
IPv6 fragment header.
Definition: ipv6.h:101
Address assigned via DHCPv6.
Definition: ipv6.h:289
unsigned int flags
Flags.
Definition: ipv6.h:199
Organisation-local address scope.
Definition: ipv6.h:173
A link-layer protocol.
Definition: netdevice.h:115
void ipv6_del_miniroute(struct ipv6_miniroute *miniroute)
Delete IPv6 minirouting table entry.
Definition: ipv6.c:293
A doubly-linked list entry (or list head)
Definition: list.h:19
uint32_t len
Upper-layer packet length.
Definition: ipv6.h:155
An IPv6 address/routing table entry.
Definition: ipv6.h:181
struct in6_addr router
Router address.
Definition: ipv6.h:195
uint8_t value[0]
Value.
Definition: ipv6.h:66
struct ipv6_extension_header_common common
Extension header common fields.
Definition: ipv6.h:103
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:197
static void ipv6_all_routers(struct in6_addr *addr)
Construct all-routers multicast address.
Definition: ipv6.h:263
IPv6 fragment header type.
Definition: ipv6.h:141
IPv6 extension header.
Definition: ipv6.h:117
pseudo_bit_t value[0x00020]
Definition: arbel.h:13
struct in6_addr dest
Destination address.
Definition: ipv6.h:153
ring len
Length.
Definition: dwmac.h:231
struct ipv6_options_header destination
Destination options header.
Definition: ipv6.h:131
IPv6 pseudo-header.
Definition: ipv6.h:149
static struct net_device * netdev
Definition: gdbudp.c:53
Address assigned via SLAAC.
Definition: ipv6.h:287
struct list_head list
List of miniroutes.
Definition: ipv6.h:183
IP6 address structure.
Definition: in.h:51
IPv6 routing header type.
Definition: ipv6.h:139
uint8_t len
Header extension length (excluding first 8 bytes)
Definition: ipv6.h:56
IPv6 routing header.
Definition: ipv6.h:89
Linked lists.
static size_t raw_len
Definition: base16.h:54
uint8_t hop_limit
Hop limit.
Definition: ipv6.h:44
uint32_t ver_tc_label
Version (4 bits), Traffic class (8 bits), Flow label (20 bits)
Definition: ipv6.h:38
uint8_t len
Length.
Definition: ipv6.h:64
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: netdevice.h:190
int parse_ipv6_setting(const struct setting_type *type, const char *value, void *buf, size_t len)
uint32_t addr
Buffer address.
Definition: dwmac.h:20
A network device.
Definition: netdevice.h:353
unsigned char uint8_t
Definition: stdint.h:10
Interface-local address scope.
Definition: ipv6.h:165
IPv6 extension header common fields.
Definition: ipv6.h:52
struct net_device * netdev
Network device.
Definition: ipv6.h:186
unsigned int uint32_t
Definition: stdint.h:12
Site-local address scope.
Definition: ipv6.h:171
uint8_t pad[8]
Minimum size padding.
Definition: ipv6.h:121
A network-layer protocol.
Definition: netdevice.h:65
Network device management.
struct net_protocol ipv6_protocol __net_protocol
AoE protocol.
Definition: aoe.c:56
ipv6_miniroute_flags
IPv6 address/routing table entry flags.
Definition: ipv6.h:203
uint8_t data[0]
Type-specific data.
Definition: ipv6.h:97
struct in6_addr dest
Destination address.
Definition: ipv6.h:48
uint8_t next_header
Next header type.
Definition: ipv6.h:54
IPv6 no next header type.
Definition: ipv6.h:143
ipv6_settings_order
IPv6 settings sibling order.
Definition: ipv6.h:281
No address.
Definition: ipv6.h:283
uint8_t remaining
Segments left.
Definition: ipv6.h:95
struct in6_addr src
Source address.
Definition: ipv6.h:46
Routing table entry address is valid.
Definition: ipv6.h:205
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" return dest
Definition: string.h:151
static int ipv6_eui64(struct in6_addr *addr, struct net_device *netdev)
Construct local IPv6 address via EUI-64.
Definition: ipv6.h:217
static int ipv6_link_local(struct in6_addr *addr, struct net_device *netdev)
Construct link-local address via EUI-64.
Definition: ipv6.h:236
__be32 raw[7]
Definition: CIB_PRM.h:28
Routing table entry router address is valid.
Definition: ipv6.h:207
Maximum scope.
Definition: ipv6.h:177
ipv6_option_type
IPv6 option types.
Definition: ipv6.h:70
struct ipv6_routing_header routing
Routing header.
Definition: ipv6.h:127
unsigned int prefix_len
Prefix length.
Definition: ipv6.h:191
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:388
uint8_t zero[3]
Zero padding.
Definition: ipv6.h:157
struct ipv6_extension_header_common common
Extension header common fields.
Definition: ipv6.h:91
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
uint8_t next_header
Next header.
Definition: ipv6.h:159
struct in6_addr address
IPv6 address (or prefix if no address is defined)
Definition: ipv6.h:189
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
#define htons(value)
Definition: byteswap.h:136
uint8_t type
Routing type.
Definition: ipv6.h:93
struct in6_addr prefix_mask
IPv6 prefix mask (derived from prefix length)
Definition: ipv6.h:193
A setting type.
Definition: settings.h:192
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:373
uint8_t type
Type.
Definition: ipv6.h:62
String functions.
static unsigned int ipv6_multicast_scope(const struct in6_addr *addr)
Get multicast address scope.
Definition: ipv6.h:275
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:61
uint16_t len
Payload length, including any extension headers.
Definition: ipv6.h:40