iPXE
Data Structures | Macros | Functions | Variables
ipv6_test.c File Reference

IPv6 tests. More...

#include <stdint.h>
#include <string.h>
#include <byteswap.h>
#include <ipxe/ipv6.h>
#include <ipxe/test.h>

Go to the source code of this file.

Data Structures

struct  ipv6_test_route
 An IPv6 test routing table entry. More...
 
struct  ipv6_test_table
 An IPv6 test routing table. More...
 

Macros

#define IPV6(...)   { __VA_ARGS__ }
 Define inline IPv6 address. More...
 
#define TABLE(name, ...)
 Define a test routing table. More...
 
#define inet6_ntoa_ok(addr, text)
 
#define inet6_aton_ok(text, addr)
 
#define inet6_aton_fail_ok(text)   inet6_aton_fail_okx ( text, __FILE__, __LINE__ )
 
#define ipv6_table_ok(table)   ipv6_table_okx ( table, __FILE__, __LINE__ )
 
#define ipv6_route_ok(table, dest, src, next)   ipv6_route_okx ( table, dest, src, next, __FILE__, __LINE__ )
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 TABLE (table_link_local, { "fe80::69ff:fe50:5845", 64, NULL })
 Routing table with only a link-local address. More...
 
 TABLE (table_normal, { "fe80::69ff:fe50:5845", 64, NULL }, { "2001:db8:3::1", 64, "fe80::1" })
 Routing table with a global address. More...
 
 TABLE (table_multi, { "fe80::69ff:fe50:5845", 64, NULL }, { "2001:db8:3::1", 64, "fe80::1" }, { "2001:db8:5::1", 64, NULL }, { "2001:db8:42::1", 64, "fe80::2" }, { "fd44:9112:6442::69ff:fe50:5845", 64, "fe80::1" }, { "fd70:6ba9:50ae::69ff:fe50:5845", 64, "fe80::3" })
 Routing table with multiple addresses and routers. More...
 
static void inet6_ntoa_okx (const struct in6_addr *addr, const char *text, const char *file, unsigned int line)
 Report an inet6_ntoa() test result. More...
 
static void inet6_aton_okx (const char *text, const struct in6_addr *addr, const char *file, unsigned int line)
 Report an inet6_aton() test result. More...
 
static void inet6_aton_fail_okx (const char *text, const char *file, unsigned int line)
 Report an inet6_aton() failure test result. More...
 
static void ipv6_table_okx (struct ipv6_test_table *table, const char *file, unsigned int line)
 Create test routing table. More...
 
static void ipv6_route_okx (struct ipv6_test_table *table, const char *dest, const char *src, const char *next, const char *file, unsigned int line)
 Report an ipv6_route() test result. More...
 
static void ipv6_table_del (struct ipv6_test_table *table)
 Destroy test routing table. More...
 
static void ipv6_test_exec (void)
 Perform IPv6 self-tests. More...
 

Variables

static const struct in6_addr sample_unspecified
 The unspecified IPv6 address. More...
 
static const struct in6_addr sample_link_local
 A sample link-local IPv6 address. More...
 
static const struct in6_addr sample_site_local
 A sample site-local IPv6 address. More...
 
static const struct in6_addr sample_ula
 A sample ULA IPv6 address. More...
 
static const struct in6_addr sample_global
 A sample global IPv6 address. More...
 
static const struct in6_addr sample_multicast
 A sample multicast IPv6 address. More...
 
static struct net_device ipv6_test_netdev
 Dummy network device used for routing tests. More...
 
struct self_test ipv6_test __self_test
 IPv6 self-test. More...
 

Detailed Description

IPv6 tests.

Definition in file ipv6_test.c.

Macro Definition Documentation

◆ IPV6

#define IPV6 (   ...)    { __VA_ARGS__ }

Define inline IPv6 address.

Definition at line 42 of file ipv6_test.c.

◆ TABLE

#define TABLE (   name,
  ... 
)
Value:
static const struct ipv6_test_route name ## _routes[] = { \
__VA_ARGS__ \
}; \
static struct ipv6_test_table name = { \
.routes = name ## _routes, \
.count = ( sizeof ( name ## _routes ) / \
sizeof ( name ## _routes[0] ) ), \
.list = LIST_HEAD_INIT ( name.list ), \
};
const char * name
Definition: ath9k_hw.c:1984
struct list_head list
Constructed routing table.
Definition: ipv6_test.c:61
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
An IPv6 test routing table.
Definition: ipv6_test.c:55
An IPv6 test routing table entry.
Definition: ipv6_test.c:45

Define a test routing table.

Definition at line 65 of file ipv6_test.c.

◆ inet6_ntoa_ok

#define inet6_ntoa_ok (   addr,
  text 
)
Value:
do { \
static const struct in6_addr in = { \
.s6_addr = addr, \
}; \
inet6_ntoa_okx ( &in, text, __FILE__, __LINE__ ); \
} while ( 0 )
__be32 in[4]
Definition: CIB_PRM.h:35
IP6 address structure.
Definition: in.h:48
u32 addr
Definition: sky2.h:8

Definition at line 158 of file ipv6_test.c.

◆ inet6_aton_ok

#define inet6_aton_ok (   text,
  addr 
)
Value:
do { \
static const struct in6_addr in = { \
.s6_addr = addr, \
}; \
inet6_aton_okx ( text, &in, __FILE__, __LINE__ ); \
} while ( 0 )
__be32 in[4]
Definition: CIB_PRM.h:35
IP6 address structure.
Definition: in.h:48
u32 addr
Definition: sky2.h:8

Definition at line 182 of file ipv6_test.c.

◆ inet6_aton_fail_ok

#define inet6_aton_fail_ok (   text)    inet6_aton_fail_okx ( text, __FILE__, __LINE__ )

Definition at line 202 of file ipv6_test.c.

◆ ipv6_table_ok

#define ipv6_table_ok (   table)    ipv6_table_okx ( table, __FILE__, __LINE__ )

Definition at line 253 of file ipv6_test.c.

◆ ipv6_route_ok

#define ipv6_route_ok (   table,
  dest,
  src,
  next 
)    ipv6_route_okx ( table, dest, src, next, __FILE__, __LINE__ )

Definition at line 321 of file ipv6_test.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ TABLE() [1/3]

TABLE ( table_link_local  ,
{ "fe80::69ff:fe50:5845", 64, NULL }   
)

Routing table with only a link-local address.

◆ TABLE() [2/3]

TABLE ( table_normal  ,
{ "fe80::69ff:fe50:5845", 64, NULL }  ,
{ "2001:db8:3::1", 64, "fe80::1" }   
)

Routing table with a global address.

◆ TABLE() [3/3]

TABLE ( table_multi  ,
{ "fe80::69ff:fe50:5845", 64, NULL }  ,
{ "2001:db8:3::1", 64, "fe80::1" }  ,
{ "2001:db8:5::1", 64, NULL }  ,
{ "2001:db8:42::1", 64, "fe80::2" }  ,
{ "fd44:9112:6442::69ff:fe50:5845", 64, "fe80::1" }  ,
{ "fd70:6ba9:50ae::69ff:fe50:5845", 64, "fe80::3" }   
)

Routing table with multiple addresses and routers.

◆ inet6_ntoa_okx()

static void inet6_ntoa_okx ( const struct in6_addr addr,
const char *  text,
const char *  file,
unsigned int  line 
)
static

Report an inet6_ntoa() test result.

Parameters
addrIPv6 address
textExpected textual representation
fileTest code file
lineTest code line

Definition at line 145 of file ipv6_test.c.

146  {
147  char *actual;
148 
149  actual = inet6_ntoa ( addr );
150  DBG ( "inet6_ntoa ( %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ) "
151  "= %s\n", ntohs ( addr->s6_addr16[0] ),
152  ntohs ( addr->s6_addr16[1] ), ntohs ( addr->s6_addr16[2] ),
153  ntohs ( addr->s6_addr16[3] ), ntohs ( addr->s6_addr16[4] ),
154  ntohs ( addr->s6_addr16[5] ), ntohs ( addr->s6_addr16[6] ),
155  ntohs ( addr->s6_addr16[7] ), actual );
156  okx ( strcmp ( actual, text ) == 0, file, line );
157 }
char * inet6_ntoa(const struct in6_addr *in)
Convert IPv6 address to standard notation.
Definition: ipv6.c:894
#define ntohs(value)
Definition: byteswap.h:136
#define okx(success, file, line)
Report test result.
Definition: test.h:44
u32 addr
Definition: sky2.h:8
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:172
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498

References addr, DBG, inet6_ntoa(), ntohs, okx, and strcmp().

◆ inet6_aton_okx()

static void inet6_aton_okx ( const char *  text,
const struct in6_addr addr,
const char *  file,
unsigned int  line 
)
static

Report an inet6_aton() test result.

Parameters
textTextual representation
addrExpected IPv6 address
fileTest code file
lineTest code line

Definition at line 173 of file ipv6_test.c.

174  {
175  struct in6_addr actual;
176 
177  okx ( inet6_aton ( text, &actual ) == 0, file, line );
178  DBG ( "inet6_aton ( \"%s\" ) = %s\n", text, inet6_ntoa ( &actual ) );
179  okx ( memcmp ( &actual, addr, sizeof ( actual ) ) == 0,
180  file, line );
181 }
char * inet6_ntoa(const struct in6_addr *in)
Convert IPv6 address to standard notation.
Definition: ipv6.c:894
int inet6_aton(const char *string, struct in6_addr *in)
Parse IPv6 address.
Definition: ipv6.c:824
#define okx(success, file, line)
Report test result.
Definition: test.h:44
IP6 address structure.
Definition: in.h:48
u32 addr
Definition: sky2.h:8
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113

References addr, DBG, inet6_aton(), inet6_ntoa(), memcmp(), and okx.

◆ inet6_aton_fail_okx()

static void inet6_aton_fail_okx ( const char *  text,
const char *  file,
unsigned int  line 
)
static

Report an inet6_aton() failure test result.

Parameters
textTextual representation
fileTest code file
lineTest code line

Definition at line 196 of file ipv6_test.c.

197  {
198  struct in6_addr dummy;
199 
200  okx ( inet6_aton ( text, &dummy ) != 0, file, line );
201 }
int inet6_aton(const char *string, struct in6_addr *in)
Parse IPv6 address.
Definition: ipv6.c:824
#define okx(success, file, line)
Report test result.
Definition: test.h:44
IP6 address structure.
Definition: in.h:48

References inet6_aton(), and okx.

◆ ipv6_table_okx()

static void ipv6_table_okx ( struct ipv6_test_table table,
const char *  file,
unsigned int  line 
)
static

Create test routing table.

Parameters
tableTest routing table
fileTest code file
lineTest code line

Definition at line 212 of file ipv6_test.c.

213  {
214  const struct ipv6_test_route *route;
215  struct in6_addr address;
216  struct in6_addr router;
217  struct list_head saved;
218  unsigned int i;
219 
220  /* Sanity check */
221  okx ( list_empty ( &table->list ), file, line );
222 
223  /* Save existing routing table */
224  INIT_LIST_HEAD ( &saved );
225  list_splice_init ( &ipv6_miniroutes, &saved );
226 
227  /* Construct routing table */
228  for ( i = 0 ; i < table->count ; i++ ) {
229 
230  /* Parse address and router (if applicable) */
231  route = &table->routes[i];
232  okx ( inet6_aton ( route->address, &address ) == 0,
233  file, line );
234  if ( route->router ) {
235  okx ( inet6_aton ( route->router, &router ) == 0,
236  file, line );
237  }
238 
239  /* Add routing table entry */
241  route->prefix_len,
242  ( route->router ?
243  &router : NULL ) ) == 0,
244  file, line );
245  }
246 
247  /* Save constructed routing table */
248  list_splice_init ( &ipv6_miniroutes, &table->list );
249 
250  /* Restore original routing table */
251  list_splice ( &saved, &ipv6_miniroutes );
252 }
const struct ipv6_test_route * routes
Test routing table entries.
Definition: ipv6_test.c:57
uint64_t address
Base address.
Definition: ena.h:24
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
int inet6_aton(const char *string, struct in6_addr *in)
Parse IPv6 address.
Definition: ipv6.c:824
A doubly-linked list entry (or list head)
Definition: list.h:18
#define list_empty(list)
Test whether a list is empty.
Definition: list.h:136
#define okx(success, file, line)
Report test result.
Definition: test.h:44
void route(void)
Print routing table.
Definition: route.c:39
unsigned int count
Number of table entries.
Definition: ipv6_test.c:59
#define list_splice_init(list, entry)
Move all entries from one list into another list and reinitialise empty list.
Definition: list.h:278
IP6 address structure.
Definition: in.h:48
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:60
struct list_head list
Constructed routing table.
Definition: ipv6_test.c:61
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
static struct net_device ipv6_test_netdev
Dummy network device used for routing tests.
Definition: ipv6_test.c:113
#define list_splice(list, entry)
Move all entries from one list into another list.
Definition: list.h:220
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
An IPv6 test routing table entry.
Definition: ipv6_test.c:45

References address, ipv6_test_table::count, inet6_aton(), INIT_LIST_HEAD, ipv6_add_miniroute(), ipv6_miniroutes, ipv6_test_netdev, ipv6_test_table::list, list_empty, list_splice, list_splice_init, NULL, okx, route(), and ipv6_test_table::routes.

◆ ipv6_route_okx()

static void ipv6_route_okx ( struct ipv6_test_table table,
const char *  dest,
const char *  src,
const char *  next,
const char *  file,
unsigned int  line 
)
static

Report an ipv6_route() test result.

Parameters
tableTest routing table
destDestination address
srcExpected source address, or NULL to expect failure
nextExpected next hop address, or NULL to expect destination
fileTest code file
lineTest code line

Definition at line 266 of file ipv6_test.c.

268  {
269  struct in6_addr in_dest;
270  struct in6_addr in_src;
271  struct in6_addr in_next;
272  struct in6_addr *actual;
273  struct ipv6_miniroute *miniroute;
274  struct list_head saved;
275 
276  /* Switch to test routing table */
277  INIT_LIST_HEAD ( &saved );
278  list_splice_init ( &ipv6_miniroutes, &saved );
279  list_splice_init ( &table->list, &ipv6_miniroutes );
280 
281  /* Parse addresses */
282  okx ( inet6_aton ( dest, &in_dest ) == 0, file, line );
283  if ( src )
284  okx ( inet6_aton ( src, &in_src ) == 0, file, line );
285  if ( next ) {
286  okx ( inet6_aton ( next, &in_next ) == 0, file, line );
287  } else {
288  memcpy ( &in_next, &in_dest, sizeof ( in_next ) );
289  }
290 
291  /* Perform routing */
292  actual = &in_dest;
293  miniroute = ipv6_route ( ipv6_test_netdev.index, &actual );
294 
295  /* Validate result */
296  if ( src ) {
297 
298  /* Check that a route was found */
299  okx ( miniroute != NULL, file, line );
300  DBG ( "ipv6_route ( %s ) = %s", dest, inet6_ntoa ( actual ) );
301  DBG ( " from %s\n", inet6_ntoa ( &miniroute->address ) );
302 
303  /* Check that expected source address was used */
304  okx ( memcmp ( &miniroute->address, &in_src,
305  sizeof ( in_src ) ) == 0, file, line );
306 
307  /* Check that expected next hop address was used */
308  okx ( memcmp ( actual, &in_next, sizeof ( *actual ) ) == 0,
309  file, line );
310 
311  } else {
312 
313  /* Routing is expected to fail */
314  okx ( miniroute == NULL, file, line );
315  }
316 
317  /* Restore original routing table */
318  list_splice_init ( &ipv6_miniroutes, &table->list );
319  list_splice ( &saved, &ipv6_miniroutes );
320 }
char * inet6_ntoa(const struct in6_addr *in)
Convert IPv6 address to standard notation.
Definition: ipv6.c:894
uint32_t next
Next descriptor address.
Definition: myson.h:18
struct ipv6_miniroute * ipv6_route(unsigned int scope_id, struct in6_addr **dest)
Perform IPv6 routing.
Definition: ipv6.c:307
int inet6_aton(const char *string, struct in6_addr *in)
Parse IPv6 address.
Definition: ipv6.c:824
A doubly-linked list entry (or list head)
Definition: list.h:18
An IPv6 address/routing table entry.
Definition: ipv6.h:180
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define okx(success, file, line)
Report test result.
Definition: test.h:44
#define list_splice_init(list, entry)
Move all entries from one list into another list and reinitialise empty list.
Definition: list.h:278
IP6 address structure.
Definition: in.h:48
static void * dest
Definition: strings.h:176
static __always_inline void off_t userptr_t src
Definition: efi_uaccess.h:66
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:60
struct list_head list
Constructed routing table.
Definition: ipv6_test.c:61
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
unsigned int index
Index of this network device.
Definition: netdevice.h:356
static struct net_device ipv6_test_netdev
Dummy network device used for routing tests.
Definition: ipv6_test.c:113
#define list_splice(list, entry)
Move all entries from one list into another list.
Definition: list.h:220
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:113
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
struct in6_addr address
IPv6 address (or prefix if no address is defined)
Definition: ipv6.h:188

References ipv6_miniroute::address, DBG, dest, net_device::index, inet6_aton(), inet6_ntoa(), INIT_LIST_HEAD, ipv6_miniroutes, ipv6_route(), ipv6_test_netdev, ipv6_test_table::list, list_splice, list_splice_init, memcmp(), memcpy(), next, NULL, okx, and src.

◆ ipv6_table_del()

static void ipv6_table_del ( struct ipv6_test_table table)
static

Destroy test routing table.

Parameters
tableTest routing table

Definition at line 329 of file ipv6_test.c.

329  {
330  struct ipv6_miniroute *miniroute;
331  struct ipv6_miniroute *tmp;
332  struct list_head saved;
333 
334  /* Switch to test routing table */
335  INIT_LIST_HEAD ( &saved );
336  list_splice_init ( &ipv6_miniroutes, &saved );
337  list_splice_init ( &table->list, &ipv6_miniroutes );
338 
339  /* Delete all existing routes */
340  list_for_each_entry_safe ( miniroute, tmp, &ipv6_miniroutes, list )
341  ipv6_del_miniroute ( miniroute );
342 
343  /* Restore original routing table */
344  list_splice ( &saved, &ipv6_miniroutes );
345 }
A doubly-linked list entry (or list head)
Definition: list.h:18
An IPv6 address/routing table entry.
Definition: ipv6.h:180
void ipv6_del_miniroute(struct ipv6_miniroute *miniroute)
Delete IPv6 minirouting table entry.
Definition: ipv6.c:292
#define list_splice_init(list, entry)
Move all entries from one list into another list and reinitialise empty list.
Definition: list.h:278
#define list_for_each_entry_safe(pos, tmp, head, member)
Iterate over entries in a list, safe against deletion of the current entry.
Definition: list.h:447
uint8_t * tmp
Definition: entropy.h:156
struct list_head ipv6_miniroutes
List of IPv6 miniroutes.
Definition: ipv6.c:60
struct list_head list
Constructed routing table.
Definition: ipv6_test.c:61
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition: list.h:45
#define list_splice(list, entry)
Move all entries from one list into another list.
Definition: list.h:220

References INIT_LIST_HEAD, ipv6_del_miniroute(), ipv6_miniroutes, ipv6_test_table::list, list_for_each_entry_safe, list_splice, list_splice_init, and tmp.

Referenced by ipv6_test_exec().

◆ ipv6_test_exec()

static void ipv6_test_exec ( void  )
static

Perform IPv6 self-tests.

Routing table with a global address

Routing table with multiple addresses and routers

Definition at line 351 of file ipv6_test.c.

351  {
352 
353  /* Address testing macros */
381  ok ( IN6_IS_ADDR_ULA ( &sample_ula ) );
382  ok ( ! IN6_IS_ADDR_ULA ( &sample_global ) );
384 
385  /* inet6_ntoa() tests */
386  inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
387  0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ),
388  "2001:ba8:0:1d4::6950:5845" );
389  /* No zeros */
390  inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0x00, 0x01,
391  0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 ),
392  "2001:db8:1:1:1:1:1:1" );
393  /* Run of zeros */
394  inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
395  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
396  "2001:db8::1" );
397  /* No "::" for single zero */
398  inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x01,
399  0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 ),
400  "2001:db8:0:1:1:1:1:1" );
401  /* Use "::" for longest run of zeros */
402  inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
403  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
404  "2001:0:0:1::1" );
405  /* Use "::" for leftmost equal-length run of zeros */
406  inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00,
407  0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
408  "2001:db8::1:0:0:1" );
409  /* Trailing run of zeros */
410  inet6_ntoa_ok ( IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
411  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
412  "fe80::" );
413  /* Leading run of zeros */
414  inet6_ntoa_ok ( IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
415  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
416  "::1" );
417  /* All zeros */
418  inet6_ntoa_ok ( IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
419  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
420  "::" );
421  /* Maximum length */
422  inet6_ntoa_ok ( IPV6 ( 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
423  0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ),
424  "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" );
425 
426  /* inet6_aton() tests */
427  inet6_aton_ok ( "2001:ba8:0:1d4::6950:5845",
428  IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
429  0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45));
430  /* No zeros */
431  inet6_aton_ok ( "2001:db8:1:1:1:1:1:1",
432  IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0x00, 0x01,
433  0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01));
434  /* All intervening zeros */
435  inet6_aton_ok ( "fe80::1",
436  IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
437  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01));
438  /* Trailing run of zeros */
439  inet6_aton_ok ( "fe80::",
440  IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
441  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
442  /* Leading run of zeros */
443  inet6_aton_ok ( "::1",
444  IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
445  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01));
446  /* All zeros */
447  inet6_aton_ok ( "::",
448  IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
449  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00));
450 
451  /* inet6_aton() failure tests */
452  inet6_aton_fail_ok ( "20012:ba8:0:1d4::6950:5845" );
453  inet6_aton_fail_ok ( "200z:ba8:0:1d4::6950:5845" );
454  inet6_aton_fail_ok ( "2001.ba8:0:1d4::6950:5845" );
455  inet6_aton_fail_ok ( "2001:db8:1:1:1:1:1" );
456  inet6_aton_fail_ok ( "2001:db8:1:1:1:1:1:1:2" );
457  inet6_aton_fail_ok ( "2001:db8::1::2" );
458  inet6_aton_fail_ok ( "2001:ba8:0:1d4:::6950:5845" );
459  inet6_aton_fail_ok ( ":::" );
460 
461  /* Create test routing tables */
462  ipv6_table_ok ( &table_link_local );
463  ipv6_table_ok ( &table_normal );
464  ipv6_table_ok ( &table_multi );
465 
466  /* Routing table with only a link-local address */
467  ipv6_route_ok ( &table_link_local, "fe80::1",
468  "fe80::69ff:fe50:5845", NULL );
469  ipv6_route_ok ( &table_link_local, "2001:db8:1::1",
470  NULL, NULL );
471  ipv6_route_ok ( &table_link_local, "ff02::1",
472  "fe80::69ff:fe50:5845", NULL );
473 
474  /** Routing table with a global address */
475  ipv6_route_ok ( &table_normal, "fe80::1",
476  "fe80::69ff:fe50:5845", NULL );
477  ipv6_route_ok ( &table_normal, "2001:db8:3::42",
478  "2001:db8:3::1", NULL );
479  ipv6_route_ok ( &table_normal, "2001:ba8:0:1d4::6950:5845",
480  "2001:db8:3::1", "fe80::1" );
481  ipv6_route_ok ( &table_normal, "ff02::1",
482  "fe80::69ff:fe50:5845", NULL );
483  ipv6_route_ok ( &table_normal, "ff0e::1",
484  "2001:db8:3::1", NULL );
485 
486  /** Routing table with multiple addresses and routers */
487  ipv6_route_ok ( &table_multi, "fe80::1",
488  "fe80::69ff:fe50:5845", NULL );
489  ipv6_route_ok ( &table_multi, "2001:db8:3::17",
490  "2001:db8:3::1", NULL );
491  ipv6_route_ok ( &table_multi, "2001:db8:5::92",
492  "2001:db8:5::1", NULL );
493  ipv6_route_ok ( &table_multi, "2001:db8:42::17",
494  "2001:db8:42::1", NULL );
495  ipv6_route_ok ( &table_multi, "2001:db8:5:1::17",
496  "2001:db8:3::1", "fe80::1" );
497  ipv6_route_ok ( &table_multi, "fd44:9112:6442::1",
498  "fd44:9112:6442::69ff:fe50:5845", NULL );
499  ipv6_route_ok ( &table_multi, "fd70:6ba9:50ae::1",
500  "fd70:6ba9:50ae::69ff:fe50:5845", NULL );
501  ipv6_route_ok ( &table_multi, "fd40::3",
502  "fd44:9112:6442::69ff:fe50:5845", "fe80::1" );
503  ipv6_route_ok ( &table_multi, "fd70::2",
504  "fd70:6ba9:50ae::69ff:fe50:5845", "fe80::3" );
505  ipv6_route_ok ( &table_multi, "ff02::1",
506  "fe80::69ff:fe50:5845", NULL );
507 
508  /* Destroy test routing tables */
509  ipv6_table_del ( &table_link_local );
510  ipv6_table_del ( &table_normal );
511  ipv6_table_del ( &table_multi );
512 }
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42
#define inet6_aton_fail_ok(text)
Definition: ipv6_test.c:202
static const struct in6_addr sample_link_local
A sample link-local IPv6 address.
Definition: ipv6_test.c:83
#define IN6_IS_ADDR_SITELOCAL(addr)
Definition: in.h:72
static const struct in6_addr sample_ula
A sample ULA IPv6 address.
Definition: ipv6_test.c:95
static const struct in6_addr sample_unspecified
The unspecified IPv6 address.
Definition: ipv6_test.c:77
static void ipv6_table_del(struct ipv6_test_table *table)
Destroy test routing table.
Definition: ipv6_test.c:329
static const struct in6_addr sample_multicast
A sample multicast IPv6 address.
Definition: ipv6_test.c:107
#define IN6_IS_ADDR_LINKLOCAL(addr)
Definition: in.h:68
#define IN6_IS_ADDR_UNSPECIFIED(addr)
Definition: in.h:59
#define ipv6_route_ok(table, dest, src, next)
Definition: ipv6_test.c:321
#define inet6_aton_ok(text, addr)
Definition: ipv6_test.c:182
#define IN6_IS_ADDR_MULTICAST(addr)
Definition: in.h:65
#define ipv6_table_ok(table)
Definition: ipv6_test.c:253
#define IN6_IS_ADDR_ULA(addr)
Definition: in.h:76
static const struct in6_addr sample_site_local
A sample site-local IPv6 address.
Definition: ipv6_test.c:89
#define ok(success)
Definition: test.h:46
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
#define inet6_ntoa_ok(addr, text)
Definition: ipv6_test.c:158
static const struct in6_addr sample_global
A sample global IPv6 address.
Definition: ipv6_test.c:101

References IN6_IS_ADDR_LINKLOCAL, IN6_IS_ADDR_MULTICAST, IN6_IS_ADDR_SITELOCAL, IN6_IS_ADDR_ULA, IN6_IS_ADDR_UNSPECIFIED, inet6_aton_fail_ok, inet6_aton_ok, inet6_ntoa_ok, IPV6, ipv6_route_ok, ipv6_table_del(), ipv6_table_ok, NULL, ok, sample_global, sample_link_local, sample_multicast, sample_site_local, sample_ula, and sample_unspecified.

Variable Documentation

◆ sample_unspecified

const struct in6_addr sample_unspecified
static
Initial value:
= {
.s6_addr = IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ),
}
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42

The unspecified IPv6 address.

Definition at line 77 of file ipv6_test.c.

Referenced by ipv6_test_exec().

◆ sample_link_local

const struct in6_addr sample_link_local
static
Initial value:
= {
.s6_addr = IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x69, 0xff, 0xfe, 0x50, 0x58, 0x45 ),
}
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42

A sample link-local IPv6 address.

Definition at line 83 of file ipv6_test.c.

Referenced by ipv6_test_exec().

◆ sample_site_local

const struct in6_addr sample_site_local
static
Initial value:
= {
.s6_addr = IPV6 ( 0xfe, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 ),
}
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42

A sample site-local IPv6 address.

Definition at line 89 of file ipv6_test.c.

Referenced by ipv6_test_exec().

◆ sample_ula

const struct in6_addr sample_ula
static
Initial value:
= {
.s6_addr = IPV6 ( 0xfd, 0x44, 0x91, 0x12, 0x64, 0x42, 0x00, 0x00,
0x00, 0x00, 0x69, 0xff, 0xfe, 0x50, 0x58, 0x45 ),
}
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42

A sample ULA IPv6 address.

Definition at line 95 of file ipv6_test.c.

Referenced by ipv6_test_exec().

◆ sample_global

const struct in6_addr sample_global
static
Initial value:
= {
.s6_addr = IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4,
0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ),
}
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42

A sample global IPv6 address.

Definition at line 101 of file ipv6_test.c.

Referenced by ipv6_test_exec().

◆ sample_multicast

const struct in6_addr sample_multicast
static
Initial value:
= {
.s6_addr = IPV6 ( 0xff, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ),
}
#define IPV6(...)
Define inline IPv6 address.
Definition: ipv6_test.c:42

A sample multicast IPv6 address.

Definition at line 107 of file ipv6_test.c.

Referenced by ipv6_test_exec().

◆ ipv6_test_netdev

struct net_device ipv6_test_netdev
static
Initial value:
= {
.refcnt = REF_INIT ( ref_no_free ),
.index = 42,
.state = NETDEV_OPEN,
}
#define NETDEV_OPEN
Network device is open.
Definition: netdevice.h:432
#define REF_INIT(free_fn)
Initialise a static reference counter.
Definition: refcnt.h:77
void ref_no_free(struct refcnt *refcnt __unused)
Do not free reference-counted object.
Definition: refcnt.c:101

Dummy network device used for routing tests.

Definition at line 113 of file ipv6_test.c.

Referenced by ipv6_route_okx(), and ipv6_table_okx().

◆ __self_test

struct self_test ipv6_test __self_test
Initial value:
= {
.name = "ipv6",
.exec = ipv6_test_exec,
}
static void ipv6_test_exec(void)
Perform IPv6 self-tests.
Definition: ipv6_test.c:351

IPv6 self-test.

Definition at line 515 of file ipv6_test.c.