iPXE
Data Structures | Macros | Enumerations | Functions | Variables
ipv6.h File Reference

IPv6 protocol. More...

#include <stdint.h>
#include <string.h>
#include <byteswap.h>
#include <ipxe/in.h>
#include <ipxe/list.h>
#include <ipxe/netdevice.h>

Go to the source code of this file.

Data Structures

struct  ipv6_header
 IPv6 header. More...
 
struct  ipv6_extension_header_common
 IPv6 extension header common fields. More...
 
struct  ipv6_option
 IPv6 type-length-value options. More...
 
struct  ipv6_options_header
 IPv6 option-based extension header. More...
 
struct  ipv6_routing_header
 IPv6 routing header. More...
 
struct  ipv6_fragment_header
 IPv6 fragment header. More...
 
union  ipv6_extension_header
 IPv6 extension header. More...
 
struct  ipv6_pseudo_header
 IPv6 pseudo-header. More...
 
struct  ipv6_miniroute
 An IPv6 address/routing table entry. More...
 

Macros

#define IPV6_VER   0x60000000UL
 IPv6 version. More...
 
#define IPV6_MASK_VER   0xf0000000UL
 IPv6 version mask. More...
 
#define IPV6_HOP_LIMIT   0xff
 IPv6 maximum hop limit. More...
 
#define IPV6_DEFAULT_PREFIX_LEN   64
 IPv6 default prefix length. More...
 
#define IPV6_MAX_PREFIX_LEN   128
 IPv6 maximum prefix length. More...
 
#define IPV6_CAN_IGNORE_OPT(type)   ( ( (type) & 0xc0 ) == 0x00 )
 Test if IPv6 option can be safely ignored. More...
 
#define IPV6_MASK_OFFSET   0xfff8
 Fragment offset mask. More...
 
#define IPV6_MASK_MOREFRAGS   0x0001
 More fragments. More...
 
#define IPV6_SETTINGS_NAME   "link"
 IPv6 link-local address settings block name. More...
 

Enumerations

enum  ipv6_option_type { IPV6_OPT_PAD1 = 0x00, IPV6_OPT_PADN = 0x01 }
 IPv6 option types. More...
 
enum  ipv6_header_type {
  IPV6_HOPBYHOP = 0, IPV6_ROUTING = 43, IPV6_FRAGMENT = 44, IPV6_NO_HEADER = 59,
  IPV6_DESTINATION = 60
}
 IPv6 header types. More...
 
enum  ipv6_address_scope {
  IPV6_SCOPE_INTERFACE_LOCAL = 0x1, IPV6_SCOPE_LINK_LOCAL = 0x2, INV6_SCOPE_ADMIN_LOCAL = 0x4, IPV6_SCOPE_SITE_LOCAL = 0x5,
  IPV6_SCOPE_ORGANISATION_LOCAL = 0x8, IPV6_SCOPE_GLOBAL = 0xe, IPV6_SCOPE_MAX = 0xf
}
 IPv6 address scopes. More...
 
enum  ipv6_miniroute_flags { IPV6_HAS_ADDRESS = 0x0001, IPV6_HAS_ROUTER = 0x0002 }
 IPv6 address/routing table entry flags. More...
 
enum  ipv6_settings_order { IPV6_ORDER_PREFIX_ONLY = -4, IPV6_ORDER_LINK_LOCAL = -3, IPV6_ORDER_SLAAC = -2, IPV6_ORDER_DHCPV6 = -1 }
 IPv6 settings sibling order. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
static int ipv6_eui64 (struct in6_addr *addr, struct net_device *netdev)
 Construct local IPv6 address via EUI-64. More...
 
static int ipv6_link_local (struct in6_addr *addr, struct net_device *netdev)
 Construct link-local address via EUI-64. More...
 
static void ipv6_solicited_node (struct in6_addr *addr, const struct in6_addr *unicast)
 Construct solicited-node multicast address. More...
 
static void ipv6_all_routers (struct in6_addr *addr)
 Construct all-routers multicast address. More...
 
static unsigned int ipv6_multicast_scope (const struct in6_addr *addr)
 Get multicast address scope. More...
 
int ipv6_has_addr (struct net_device *netdev, struct in6_addr *addr)
 Check if network device has a specific IPv6 address. More...
 
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. More...
 
void ipv6_del_miniroute (struct ipv6_miniroute *miniroute)
 Delete IPv6 minirouting table entry. More...
 
struct ipv6_minirouteipv6_route (unsigned int scope_id, struct in6_addr **dest)
 Perform IPv6 routing. More...
 
int parse_ipv6_setting (const struct setting_type *type, const char *value, void *buf, size_t len)
 
int format_ipv6_setting (const struct setting_type *type, const void *raw, size_t raw_len, char *buf, size_t len)
 

Variables

struct list_head ipv6_miniroutes
 List of IPv6 miniroutes. More...
 
struct net_protocol ipv6_protocol __net_protocol
 AoE protocol. More...
 

Detailed Description

IPv6 protocol.

Definition in file ipv6.h.

Macro Definition Documentation

◆ IPV6_VER

#define IPV6_VER   0x60000000UL

IPv6 version.

Definition at line 20 of file ipv6.h.

◆ IPV6_MASK_VER

#define IPV6_MASK_VER   0xf0000000UL

IPv6 version mask.

Definition at line 23 of file ipv6.h.

◆ IPV6_HOP_LIMIT

#define IPV6_HOP_LIMIT   0xff

IPv6 maximum hop limit.

Definition at line 26 of file ipv6.h.

◆ IPV6_DEFAULT_PREFIX_LEN

#define IPV6_DEFAULT_PREFIX_LEN   64

IPv6 default prefix length.

Definition at line 29 of file ipv6.h.

◆ IPV6_MAX_PREFIX_LEN

#define IPV6_MAX_PREFIX_LEN   128

IPv6 maximum prefix length.

Definition at line 32 of file ipv6.h.

◆ IPV6_CAN_IGNORE_OPT

#define IPV6_CAN_IGNORE_OPT (   type)    ( ( (type) & 0xc0 ) == 0x00 )

Test if IPv6 option can be safely ignored.

Definition at line 77 of file ipv6.h.

◆ IPV6_MASK_OFFSET

#define IPV6_MASK_OFFSET   0xfff8

Fragment offset mask.

Definition at line 110 of file ipv6.h.

◆ IPV6_MASK_MOREFRAGS

#define IPV6_MASK_MOREFRAGS   0x0001

More fragments.

Definition at line 113 of file ipv6.h.

◆ IPV6_SETTINGS_NAME

#define IPV6_SETTINGS_NAME   "link"

IPv6 link-local address settings block name.

Definition at line 292 of file ipv6.h.

Enumeration Type Documentation

◆ ipv6_option_type

IPv6 option types.

Enumerator
IPV6_OPT_PAD1 

Pad1.

IPV6_OPT_PADN 

PadN.

Definition at line 69 of file ipv6.h.

69  {
70  /** Pad1 */
71  IPV6_OPT_PAD1 = 0x00,
72  /** PadN */
73  IPV6_OPT_PADN = 0x01,
74 };
PadN.
Definition: ipv6.h:73
Pad1.
Definition: ipv6.h:71

◆ ipv6_header_type

IPv6 header types.

Enumerator
IPV6_HOPBYHOP 

IPv6 hop-by-hop options header type.

IPV6_ROUTING 

IPv6 routing header type.

IPV6_FRAGMENT 

IPv6 fragment header type.

IPV6_NO_HEADER 

IPv6 no next header type.

IPV6_DESTINATION 

IPv6 destination options header type.

Definition at line 134 of file ipv6.h.

134  {
135  /** IPv6 hop-by-hop options header type */
136  IPV6_HOPBYHOP = 0,
137  /** IPv6 routing header type */
138  IPV6_ROUTING = 43,
139  /** IPv6 fragment header type */
140  IPV6_FRAGMENT = 44,
141  /** IPv6 no next header type */
142  IPV6_NO_HEADER = 59,
143  /** IPv6 destination options header type */
144  IPV6_DESTINATION = 60,
145 };
IPv6 hop-by-hop options header type.
Definition: ipv6.h:136
IPv6 destination options header type.
Definition: ipv6.h:144
IPv6 fragment header type.
Definition: ipv6.h:140
IPv6 routing header type.
Definition: ipv6.h:138
IPv6 no next header type.
Definition: ipv6.h:142

◆ ipv6_address_scope

IPv6 address scopes.

Enumerator
IPV6_SCOPE_INTERFACE_LOCAL 

Interface-local address scope.

IPV6_SCOPE_LINK_LOCAL 

Link-local address scope.

INV6_SCOPE_ADMIN_LOCAL 

Admin-local address scope.

IPV6_SCOPE_SITE_LOCAL 

Site-local address scope.

IPV6_SCOPE_ORGANISATION_LOCAL 

Organisation-local address scope.

IPV6_SCOPE_GLOBAL 

Global address scope.

IPV6_SCOPE_MAX 

Maximum scope.

Definition at line 162 of file ipv6.h.

162  {
163  /** Interface-local address scope */
165  /** Link-local address scope */
166  IPV6_SCOPE_LINK_LOCAL = 0x2,
167  /** Admin-local address scope */
169  /** Site-local address scope */
170  IPV6_SCOPE_SITE_LOCAL = 0x5,
171  /** Organisation-local address scope */
173  /** Global address scope */
174  IPV6_SCOPE_GLOBAL = 0xe,
175  /** Maximum scope */
176  IPV6_SCOPE_MAX = 0xf,
177 };
Admin-local address scope.
Definition: ipv6.h:168
Global address scope.
Definition: ipv6.h:174
Link-local address scope.
Definition: ipv6.h:166
Organisation-local address scope.
Definition: ipv6.h:172
Interface-local address scope.
Definition: ipv6.h:164
Site-local address scope.
Definition: ipv6.h:170
Maximum scope.
Definition: ipv6.h:176

◆ ipv6_miniroute_flags

IPv6 address/routing table entry flags.

Enumerator
IPV6_HAS_ADDRESS 

Routing table entry address is valid.

IPV6_HAS_ROUTER 

Routing table entry router address is valid.

Definition at line 202 of file ipv6.h.

202  {
203  /** Routing table entry address is valid */
204  IPV6_HAS_ADDRESS = 0x0001,
205  /** Routing table entry router address is valid */
206  IPV6_HAS_ROUTER = 0x0002,
207 };
Routing table entry address is valid.
Definition: ipv6.h:204
Routing table entry router address is valid.
Definition: ipv6.h:206

◆ ipv6_settings_order

IPv6 settings sibling order.

Enumerator
IPV6_ORDER_PREFIX_ONLY 

No address.

IPV6_ORDER_LINK_LOCAL 

Link-local address.

IPV6_ORDER_SLAAC 

Address assigned via SLAAC.

IPV6_ORDER_DHCPV6 

Address assigned via DHCPv6.

Definition at line 280 of file ipv6.h.

280  {
281  /** No address */
283  /** Link-local address */
285  /** Address assigned via SLAAC */
286  IPV6_ORDER_SLAAC = -2,
287  /** Address assigned via DHCPv6 */
288  IPV6_ORDER_DHCPV6 = -1,
289 };
Link-local address.
Definition: ipv6.h:284
Address assigned via DHCPv6.
Definition: ipv6.h:288
Address assigned via SLAAC.
Definition: ipv6.h:286
No address.
Definition: ipv6.h:282

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ ipv6_eui64()

static int ipv6_eui64 ( struct in6_addr addr,
struct net_device netdev 
)
inlinestatic

Construct local IPv6 address via EUI-64.

Parameters
addrPrefix to be completed
netdevNetwork device
Return values
prefix_lenPrefix length, or negative error

Definition at line 216 of file ipv6.h.

217  {
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 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
A link-layer protocol.
Definition: netdevice.h:114
static struct net_device * netdev
Definition: gdbudp.c:52
int(* eui64)(const void *ll_addr, void *eui64)
Generate EUI-64 address.
Definition: netdevice.h:189
u32 addr
Definition: sky2.h:8
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366

References addr, ll_protocol::eui64, net_device::ll_addr, net_device::ll_protocol, netdev, and rc.

Referenced by ipv6_link_local(), and ndp_prefix_fetch_ip6().

◆ ipv6_link_local()

static int ipv6_link_local ( struct in6_addr addr,
struct net_device netdev 
)
inlinestatic

Construct link-local address via EUI-64.

Parameters
addrZeroed address to construct
netdevNetwork device
Return values
prefix_lenPrefix length, or negative error

Definition at line 235 of file ipv6.h.

236  {
237 
238  addr->s6_addr16[0] = htons ( 0xfe80 );
239  return ipv6_eui64 ( addr, netdev );
240 }
static struct net_device * netdev
Definition: gdbudp.c:52
u32 addr
Definition: sky2.h:8
static int ipv6_eui64(struct in6_addr *addr, struct net_device *netdev)
Construct local IPv6 address via EUI-64.
Definition: ipv6.h:216
#define htons(value)
Definition: byteswap.h:135

References addr, htons, ipv6_eui64(), and netdev.

Referenced by ipv6_fetch().

◆ ipv6_solicited_node()

static void ipv6_solicited_node ( struct in6_addr addr,
const struct in6_addr unicast 
)
inlinestatic

Construct solicited-node multicast address.

Parameters
addrZeroed address to construct
unicastUnicast address

Definition at line 248 of file ipv6.h.

249  {
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 }
void * memcpy(void *dest, const void *src, size_t len) __nonnull
u32 addr
Definition: sky2.h:8
#define htons(value)
Definition: byteswap.h:135

References addr, htons, and memcpy().

Referenced by ndp_tx_request().

◆ ipv6_all_routers()

static void ipv6_all_routers ( struct in6_addr addr)
inlinestatic

Construct all-routers multicast address.

Parameters
addrZeroed address to construct

Definition at line 262 of file ipv6.h.

262  {
263  addr->s6_addr16[0] = htons ( 0xff02 );
264  addr->s6_addr[15] = 2;
265 }
u32 addr
Definition: sky2.h:8
#define htons(value)
Definition: byteswap.h:135

References addr, and htons.

Referenced by ndp_tx_router_solicitation().

◆ ipv6_multicast_scope()

static unsigned int ipv6_multicast_scope ( const struct in6_addr addr)
inlinestatic

Get multicast address scope.

Parameters
addrMulticast address
Return values
scopeAddress scope

Definition at line 274 of file ipv6.h.

274  {
275 
276  return ( addr->s6_addr[1] & 0x0f );
277 }
u32 addr
Definition: sky2.h:8

References addr.

Referenced by ipv6_scope().

◆ ipv6_has_addr()

int ipv6_has_addr ( struct net_device netdev,
struct in6_addr addr 
)

Check if network device has a specific IPv6 address.

Parameters
netdevNetwork device
addrIPv6 address
Return values
has_addrNetwork device has this IPv6 address

Definition at line 141 of file ipv6.c.

141  {
142  struct ipv6_miniroute *miniroute;
143 
144  list_for_each_entry ( miniroute, &ipv6_miniroutes, list ) {
145  if ( ( miniroute->netdev == netdev ) &&
146  ( miniroute->flags & IPV6_HAS_ADDRESS ) &&
147  ( memcmp ( &miniroute->address, addr,
148  sizeof ( miniroute->address ) ) == 0 ) ) {
149  /* Found matching address */
150  return 1;
151  }
152  }
153  return 0;
154 }
unsigned int flags
Flags.
Definition: ipv6.h:198
An IPv6 address/routing table entry.
Definition: ipv6.h:180
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head list
List of miniroutes.
Definition: ipv6.h:182
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:60
u32 addr
Definition: sky2.h:8
struct net_device * netdev
Network device.
Definition: ipv6.h:185
Routing table entry address is valid.
Definition: ipv6.h:204
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:98
struct in6_addr address
IPv6 address (or prefix if no address is defined)
Definition: ipv6.h:188

References addr, ipv6_miniroute::address, ipv6_miniroute::flags, IPV6_HAS_ADDRESS, ipv6_miniroutes, ipv6_miniroute::list, list_for_each_entry, memcmp(), netdev, and ipv6_miniroute::netdev.

Referenced by ipv6_rx(), and ndp_rx_neighbour_solicitation_ll_source().

◆ ipv6_add_miniroute()

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.

Parameters
netdevNetwork device
addressIPv6 address (or prefix)
prefix_lenPrefix length
routerRouter address (if any)
Return values
rcReturn status code

Definition at line 217 of file ipv6.c.

218  {
219  struct ipv6_miniroute *miniroute;
221  unsigned int remaining;
222  unsigned int i;
223 
224  /* Find or create routing table entry */
225  miniroute = ipv6_miniroute ( netdev, address );
226  if ( miniroute ) {
227 
228  /* Remove from existing position in routing table */
229  list_del ( &miniroute->list );
230 
231  } else {
232 
233  /* Create new routing table entry */
234  miniroute = zalloc ( sizeof ( *miniroute ) );
235  if ( ! miniroute )
236  return -ENOMEM;
237  miniroute->netdev = netdev_get ( netdev );
238  memcpy ( &miniroute->address, address,
239  sizeof ( miniroute->address ) );
240 
241  /* Default to prefix length of 64 if none specified */
242  if ( ! prefix_len )
244  miniroute->prefix_len = prefix_len;
246 
247  /* Construct prefix mask */
248  remaining = prefix_len;
249  for ( prefix_mask = miniroute->prefix_mask.s6_addr ;
250  remaining >= 8 ; prefix_mask++, remaining -= 8 ) {
251  *prefix_mask = 0xff;
252  }
253  if ( remaining )
254  *prefix_mask <<= ( 8 - remaining );
255  }
256 
257  /* Add to start of routing table */
258  list_add ( &miniroute->list, &ipv6_miniroutes );
259 
260  /* Set or update address, if applicable */
261  for ( i = 0 ; i < ( sizeof ( address->s6_addr32 ) /
262  sizeof ( address->s6_addr32[0] ) ) ; i++ ) {
263  if ( ( address->s6_addr32[i] &
264  ~miniroute->prefix_mask.s6_addr32[i] ) != 0 ) {
265  memcpy ( &miniroute->address, address,
266  sizeof ( miniroute->address ) );
267  miniroute->flags |= IPV6_HAS_ADDRESS;
268  }
269  }
270  if ( miniroute->prefix_len == IPV6_MAX_PREFIX_LEN )
271  miniroute->flags |= IPV6_HAS_ADDRESS;
272 
273  /* Update scope */
274  miniroute->scope = ipv6_scope ( &miniroute->address );
275 
276  /* Set or update router, if applicable */
277  if ( router ) {
278  memcpy ( &miniroute->router, router,
279  sizeof ( miniroute->router ) );
280  miniroute->flags |= IPV6_HAS_ROUTER;
281  }
282 
283  ipv6_dump_miniroute ( miniroute );
284  return 0;
285 }
#define IPV6_DEFAULT_PREFIX_LEN
IPv6 default prefix length.
Definition: ipv6.h:29
#define list_add(new, head)
Add a new entry to the head of a list.
Definition: list.h:69
#define IPV6_MAX_PREFIX_LEN
IPv6 maximum prefix length.
Definition: ipv6.h:32
static unsigned int ipv6_scope(const struct in6_addr *addr)
Determine IPv6 address scope.
Definition: ipv6.c:88
uint64_t address
Base address.
Definition: ena.h:24
unsigned int flags
Flags.
Definition: ipv6.h:198
An IPv6 address/routing table entry.
Definition: ipv6.h:180
struct in6_addr router
Router address.
Definition: ipv6.h:194
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
unsigned int scope
Scope.
Definition: ipv6.h:196
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
static struct net_device * netdev
Definition: gdbudp.c:52
struct list_head list
List of miniroutes.
Definition: ipv6.h:182
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:60
unsigned char uint8_t
Definition: stdint.h:10
struct net_device * netdev
Network device.
Definition: ipv6.h:185
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:544
static void ipv6_dump_miniroute(struct ipv6_miniroute *miniroute)
Dump IPv6 routing table entry.
Definition: ipv6.c:122
Routing table entry address is valid.
Definition: ipv6.h:204
Routing table entry router address is valid.
Definition: ipv6.h:206
unsigned int prefix_len
Prefix length.
Definition: ipv6.h:190
struct in6_addr address
IPv6 address (or prefix if no address is defined)
Definition: ipv6.h:188
static struct ipv6_miniroute * ipv6_miniroute(struct net_device *netdev, struct in6_addr *address)
Find IPv6 routing table entry for a given address.
Definition: ipv6.c:192
struct in6_addr prefix_mask
IPv6 prefix mask (derived from prefix length)
Definition: ipv6.h:192

References address, ipv6_miniroute::address, assert(), ENOMEM, ipv6_miniroute::flags, IPV6_DEFAULT_PREFIX_LEN, ipv6_dump_miniroute(), IPV6_HAS_ADDRESS, IPV6_HAS_ROUTER, IPV6_MAX_PREFIX_LEN, ipv6_miniroute(), ipv6_miniroutes, ipv6_scope(), ipv6_miniroute::list, list_add, list_del, memcpy(), netdev, ipv6_miniroute::netdev, netdev_get(), ipv6_miniroute::prefix_len, ipv6_miniroute::prefix_mask, ipv6_miniroute::router, ipv6_miniroute::scope, and zalloc().

Referenced by ipv6_create_routes(), and ipv6_table_okx().

◆ ipv6_del_miniroute()

void ipv6_del_miniroute ( struct ipv6_miniroute miniroute)

Delete IPv6 minirouting table entry.

Parameters
minirouteRouting table entry

Definition at line 292 of file ipv6.c.

292  {
293 
294  netdev_put ( miniroute->netdev );
295  list_del ( &miniroute->list );
296  free ( miniroute );
297 }
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
struct list_head list
List of miniroutes.
Definition: ipv6.h:182
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
struct net_device * netdev
Network device.
Definition: ipv6.h:185

References free, ipv6_miniroute::list, list_del, ipv6_miniroute::netdev, and netdev_put().

Referenced by ipv6_create_all_routes(), and ipv6_table_del().

◆ ipv6_route()

struct ipv6_miniroute* ipv6_route ( unsigned int  scope_id,
struct in6_addr **  dest 
)

Perform IPv6 routing.

Parameters
scope_idDestination address scope ID (for link-local addresses)
destFinal destination address
Return values
destNext hop destination address
minirouteRouting table entry to use, or NULL if no route

Definition at line 307 of file ipv6.c.

308  {
309  struct ipv6_miniroute *miniroute;
310  struct ipv6_miniroute *chosen = NULL;
311  unsigned int best = 0;
312  unsigned int match_len;
313  unsigned int score;
314  unsigned int scope;
315 
316  /* Calculate destination address scope */
317  scope = ipv6_scope ( *dest );
318 
319  /* Find first usable route in routing table */
320  list_for_each_entry ( miniroute, &ipv6_miniroutes, list ) {
321 
322  /* Skip closed network devices */
323  if ( ! netdev_is_open ( miniroute->netdev ) )
324  continue;
325 
326  /* Skip entries with no usable source address */
327  if ( ! ( miniroute->flags & IPV6_HAS_ADDRESS ) )
328  continue;
329 
330  /* Skip entries with a non-matching scope ID, if
331  * destination specifies a scope ID.
332  */
333  if ( scope_id && ( miniroute->netdev->index != scope_id ) )
334  continue;
335 
336  /* Skip entries that are out of scope */
337  if ( miniroute->scope < scope )
338  continue;
339 
340  /* Calculate match length */
341  match_len = ipv6_match_len ( miniroute, *dest );
342 
343  /* If destination is on-link, then use this route */
344  if ( match_len >= miniroute->prefix_len )
345  return miniroute;
346 
347  /* If destination is unicast, then skip off-link
348  * entries with no router.
349  */
350  if ( ! ( IN6_IS_ADDR_MULTICAST ( *dest ) ||
351  ( miniroute->flags & IPV6_HAS_ROUTER ) ) )
352  continue;
353 
354  /* Choose best route, defined as being the route with
355  * the smallest viable scope. If two routes both have
356  * the same scope, then prefer the route with the
357  * longest match length.
358  */
359  score = ( ( ( IPV6_SCOPE_MAX + 1 - miniroute->scope ) << 8 )
360  + match_len );
361  if ( score > best ) {
362  chosen = miniroute;
363  best = score;
364  }
365  }
366 
367  /* Return chosen route, if any */
368  if ( chosen ) {
369  if ( ! IN6_IS_ADDR_MULTICAST ( *dest ) )
370  *dest = &chosen->router;
371  return chosen;
372  }
373 
374  return NULL;
375 }
uint8_t scope
Scope.
Definition: ena.h:18
static unsigned int ipv6_scope(const struct in6_addr *addr)
Determine IPv6 address scope.
Definition: ipv6.c:88
unsigned int flags
Flags.
Definition: ipv6.h:198
An IPv6 address/routing table entry.
Definition: ipv6.h:180
struct in6_addr router
Router address.
Definition: ipv6.h:194
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
unsigned int scope
Scope.
Definition: ipv6.h:196
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
struct list_head list
List of miniroutes.
Definition: ipv6.h:182
static void * dest
Definition: strings.h:176
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:60
struct net_device * netdev
Network device.
Definition: ipv6.h:185
static unsigned int ipv6_match_len(struct ipv6_miniroute *miniroute, struct in6_addr *address)
Count matching bits of an IPv6 routing table entry prefix.
Definition: ipv6.c:163
unsigned int index
Index of this network device.
Definition: netdevice.h:356
Routing table entry address is valid.
Definition: ipv6.h:204
#define IN6_IS_ADDR_MULTICAST(addr)
Definition: in.h:65
Routing table entry router address is valid.
Definition: ipv6.h:206
Maximum scope.
Definition: ipv6.h:176
unsigned int prefix_len
Prefix length.
Definition: ipv6.h:190
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References dest, ipv6_miniroute::flags, IN6_IS_ADDR_MULTICAST, net_device::index, IPV6_HAS_ADDRESS, IPV6_HAS_ROUTER, ipv6_match_len(), ipv6_miniroutes, ipv6_scope(), IPV6_SCOPE_MAX, ipv6_miniroute::list, list_for_each_entry, ipv6_miniroute::netdev, netdev_is_open(), NULL, ipv6_miniroute::prefix_len, ipv6_miniroute::router, scope, and ipv6_miniroute::scope.

Referenced by ipv6_netdev(), ipv6_route_okx(), and ipv6_tx().

◆ parse_ipv6_setting()

int parse_ipv6_setting ( const struct setting_type type,
const char *  value,
void *  buf,
size_t  len 
)

◆ format_ipv6_setting()

int format_ipv6_setting ( const struct setting_type type,
const void *  raw,
size_t  raw_len,
char *  buf,
size_t  len 
)

Variable Documentation

◆ ipv6_miniroutes

struct list_head ipv6_miniroutes

◆ __net_protocol

struct net_protocol ipv6_protocol __net_protocol

AoE protocol.

AoE protocol.

AoE protocol.

FIP protocol.

Definition at line 55 of file aoe.c.