mirror of
https://github.com/ipxe/ipxe
synced 2025-12-19 19:49:45 +03:00
[test] Validate constructed IPv6 routing table entries
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -41,12 +41,20 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
/** Define inline IPv6 address */
|
/** Define inline IPv6 address */
|
||||||
#define IPV6(...) { __VA_ARGS__ }
|
#define IPV6(...) { __VA_ARGS__ }
|
||||||
|
|
||||||
|
/** An IPv6 test prefix */
|
||||||
|
struct ipv6_test_prefix {
|
||||||
|
/** Prefix length */
|
||||||
|
unsigned int len;
|
||||||
|
/** Prefix mask */
|
||||||
|
const char *mask;
|
||||||
|
};
|
||||||
|
|
||||||
/** An IPv6 test routing table entry */
|
/** An IPv6 test routing table entry */
|
||||||
struct ipv6_test_route {
|
struct ipv6_test_route {
|
||||||
/** Local address */
|
/** Local address */
|
||||||
const char *address;
|
const char *address;
|
||||||
/** Prefix length */
|
/** Prefix */
|
||||||
unsigned int prefix_len;
|
const struct ipv6_test_prefix *prefix;
|
||||||
/** Router address (if any) */
|
/** Router address (if any) */
|
||||||
const char *router;
|
const char *router;
|
||||||
};
|
};
|
||||||
@@ -61,6 +69,13 @@ struct ipv6_test_table {
|
|||||||
struct list_head list;
|
struct list_head list;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** Define a test prefix */
|
||||||
|
#define PREFIX( name, LEN, MASK ) \
|
||||||
|
static const struct ipv6_test_prefix name = { \
|
||||||
|
.len = LEN, \
|
||||||
|
.mask = MASK, \
|
||||||
|
};
|
||||||
|
|
||||||
/** Define a test routing table */
|
/** Define a test routing table */
|
||||||
#define TABLE( name, ... ) \
|
#define TABLE( name, ... ) \
|
||||||
static const struct ipv6_test_route name ## _routes[] = { \
|
static const struct ipv6_test_route name ## _routes[] = { \
|
||||||
@@ -116,23 +131,26 @@ static struct net_device ipv6_test_netdev = {
|
|||||||
.state = NETDEV_OPEN,
|
.state = NETDEV_OPEN,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/** /64 prefix */
|
||||||
|
PREFIX ( prefix64, 64, "ffff:ffff:ffff:ffff::" );
|
||||||
|
|
||||||
/** Routing table with only a link-local address */
|
/** Routing table with only a link-local address */
|
||||||
TABLE ( table_link_local,
|
TABLE ( table_link_local,
|
||||||
{ "fe80::69ff:fe50:5845", 64, NULL } );
|
{ "fe80::69ff:fe50:5845", &prefix64, NULL } );
|
||||||
|
|
||||||
/** Routing table with a global address */
|
/** Routing table with a global address */
|
||||||
TABLE ( table_normal,
|
TABLE ( table_normal,
|
||||||
{ "fe80::69ff:fe50:5845", 64, NULL },
|
{ "fe80::69ff:fe50:5845", &prefix64, NULL },
|
||||||
{ "2001:db8:3::1", 64, "fe80::1" } );
|
{ "2001:db8:3::1", &prefix64, "fe80::1" } );
|
||||||
|
|
||||||
/** Routing table with multiple addresses and routers */
|
/** Routing table with multiple addresses and routers */
|
||||||
TABLE ( table_multi,
|
TABLE ( table_multi,
|
||||||
{ "fe80::69ff:fe50:5845", 64, NULL },
|
{ "fe80::69ff:fe50:5845", &prefix64, NULL },
|
||||||
{ "2001:db8:3::1", 64, "fe80::1" },
|
{ "2001:db8:3::1", &prefix64, "fe80::1" },
|
||||||
{ "2001:db8:5::1", 64, NULL },
|
{ "2001:db8:5::1", &prefix64, NULL },
|
||||||
{ "2001:db8:42::1", 64, "fe80::2" },
|
{ "2001:db8:42::1", &prefix64, "fe80::2" },
|
||||||
{ "fd44:9112:6442::69ff:fe50:5845", 64, "fe80::1" },
|
{ "fd44:9112:6442::69ff:fe50:5845", &prefix64, "fe80::1" },
|
||||||
{ "fd70:6ba9:50ae::69ff:fe50:5845", 64, "fe80::3" } );
|
{ "fd70:6ba9:50ae::69ff:fe50:5845", &prefix64, "fe80::3" } );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Report an inet6_ntoa() test result
|
* Report an inet6_ntoa() test result
|
||||||
@@ -212,8 +230,10 @@ static void inet6_aton_fail_okx ( const char *text, const char *file,
|
|||||||
static void ipv6_table_okx ( struct ipv6_test_table *table, const char *file,
|
static void ipv6_table_okx ( struct ipv6_test_table *table, const char *file,
|
||||||
unsigned int line ) {
|
unsigned int line ) {
|
||||||
const struct ipv6_test_route *route;
|
const struct ipv6_test_route *route;
|
||||||
|
struct ipv6_miniroute *miniroute;
|
||||||
struct in6_addr address;
|
struct in6_addr address;
|
||||||
struct in6_addr router;
|
struct in6_addr router;
|
||||||
|
struct in6_addr mask;
|
||||||
struct list_head saved;
|
struct list_head saved;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
|
||||||
@@ -235,13 +255,33 @@ static void ipv6_table_okx ( struct ipv6_test_table *table, const char *file,
|
|||||||
okx ( inet6_aton ( route->router, &router ) == 0,
|
okx ( inet6_aton ( route->router, &router ) == 0,
|
||||||
file, line );
|
file, line );
|
||||||
}
|
}
|
||||||
|
okx ( inet6_aton ( route->prefix->mask, &mask ) == 0,
|
||||||
|
file, line );
|
||||||
|
|
||||||
/* Add routing table entry */
|
/* Add routing table entry */
|
||||||
okx ( ipv6_add_miniroute ( &ipv6_test_netdev, &address,
|
okx ( ipv6_add_miniroute ( &ipv6_test_netdev, &address,
|
||||||
route->prefix_len,
|
route->prefix->len,
|
||||||
( route->router ?
|
( route->router ?
|
||||||
&router : NULL ) ) == 0,
|
&router : NULL ) ) == 0,
|
||||||
file, line );
|
file, line );
|
||||||
|
|
||||||
|
/* Check routing table entry */
|
||||||
|
miniroute = list_first_entry ( &ipv6_miniroutes,
|
||||||
|
struct ipv6_miniroute, list );
|
||||||
|
okx ( miniroute != NULL, file, line );
|
||||||
|
okx ( memcmp ( &miniroute->address, &address,
|
||||||
|
sizeof ( address ) ) == 0, file, line );
|
||||||
|
okx ( miniroute->prefix_len == route->prefix->len,
|
||||||
|
file, line );
|
||||||
|
okx ( memcmp ( &miniroute->prefix_mask, &mask,
|
||||||
|
sizeof ( mask ) ) == 0, file, line );
|
||||||
|
if ( route->router ) {
|
||||||
|
okx ( memcmp ( &miniroute->router, &router,
|
||||||
|
sizeof ( router ) ) == 0, file, line );
|
||||||
|
} else {
|
||||||
|
okx ( IN6_IS_ADDR_UNSPECIFIED ( &miniroute->router ),
|
||||||
|
file, line );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save constructed routing table */
|
/* Save constructed routing table */
|
||||||
|
|||||||
Reference in New Issue
Block a user