diff options
author | Michael Brown | 2013-08-26 15:23:54 +0200 |
---|---|---|
committer | Michael Brown | 2013-09-03 17:30:46 +0200 |
commit | f7f3087cc542d76f19ba6362b0837dcf1baf86b8 (patch) | |
tree | 8d2a920c16a2255f9e9ac57d2b333d8d01edc556 /src/tests | |
parent | [ipv4] Abstract out protocol-specific portions of "route" command (diff) | |
download | ipxe-f7f3087cc542d76f19ba6362b0837dcf1baf86b8.tar.gz ipxe-f7f3087cc542d76f19ba6362b0837dcf1baf86b8.tar.xz ipxe-f7f3087cc542d76f19ba6362b0837dcf1baf86b8.zip |
[ipv6] Replace IPv6 stack
Replace the existing partially-implemented IPv6 stack with a fresh
implementation.
This implementation is not yet complete. The IPv6 transmit and
receive datapaths are functional (including fragment reassembly and
parsing of arbitrary extension headers). NDP neighbour solicitations
and advertisements are supported. ICMPv6 echo is supported.
At present, only link-local addresses may be used, and there is no way
to specify an IPv6 address as part of a URI (either directly or via
a DNS lookup).
Signed-off-by: Michael Brown <mcb30@ipxe.org>
Diffstat (limited to 'src/tests')
-rw-r--r-- | src/tests/ipv6_test.c | 115 | ||||
-rw-r--r-- | src/tests/tests.c | 1 |
2 files changed, 116 insertions, 0 deletions
diff --git a/src/tests/ipv6_test.c b/src/tests/ipv6_test.c new file mode 100644 index 00000000..10e964d9 --- /dev/null +++ b/src/tests/ipv6_test.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2013 Michael Brown <mbrown@fensystems.co.uk>. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + * 02110-1301, USA. + */ + +FILE_LICENCE ( GPL2_OR_LATER ); + +/** @file + * + * IPv6 tests + * + */ + +/* Forcibly enable assertions */ +#undef NDEBUG + +#include <stdint.h> +#include <string.h> +#include <byteswap.h> +#include <ipxe/ipv6.h> +#include <ipxe/test.h> + +/** Define inline IPv6 address */ +#define IPV6(...) { __VA_ARGS__ } + +/** + * Report an inet6_ntoa() test result + * + * @v addr IPv6 address + * @v text Expected textual representation + */ +#define inet6_ntoa_ok( addr, text ) do { \ + static const struct in6_addr in = { \ + .s6_addr = addr, \ + }; \ + static const char expected[] = text; \ + char *actual; \ + \ + actual = inet6_ntoa ( &in ); \ + DBG ( "inet6_ntoa ( %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x ) " \ + "= %s\n", ntohs ( in.s6_addr16[0] ), \ + ntohs ( in.s6_addr16[1] ), ntohs ( in.s6_addr16[2] ), \ + ntohs ( in.s6_addr16[3] ), ntohs ( in.s6_addr16[4] ), \ + ntohs ( in.s6_addr16[5] ), ntohs ( in.s6_addr16[6] ), \ + ntohs ( in.s6_addr16[7] ), actual ); \ + ok ( strcmp ( actual, expected ) == 0 ); \ + } while ( 0 ) + +/** + * Perform IPv6 self-tests + * + */ +static void ipv6_test_exec ( void ) { + + /* inet6_ntoa() tests */ + inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0b, 0xa8, 0x00, 0x00, 0x01, 0xd4, + 0x00, 0x00, 0x00, 0x00, 0x69, 0x50, 0x58, 0x45 ), + "2001:ba8:0:1d4::6950:5845" ); + /* No zeros */ + inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x01, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 ), + "2001:db8:1:1:1:1:1:1" ); + /* Run of zeros */ + inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + "2001:db8::1" ); + /* No "::" for single zero */ + inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x01, 0x00, 0x01, 0x00, 0x01, 0x00, 0x01 ), + "2001:db8:0:1:1:1:1:1" ); + /* Use "::" for longest run of zeros */ + inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + "2001:0:0:1::1" ); + /* Use "::" for leftmost equal-length run of zeros */ + inet6_ntoa_ok ( IPV6 ( 0x20, 0x01, 0x0d, 0xb8, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + "2001:db8::1:0:0:1" ); + /* Trailing run of zeros */ + inet6_ntoa_ok ( IPV6 ( 0xfe, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ), + "fe80::" ); + /* Leading run of zeros */ + inet6_ntoa_ok ( IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 ), + "::1" ); + /* All zeros */ + inet6_ntoa_ok ( IPV6 ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 ), + "::" ); + /* Maximum length */ + inet6_ntoa_ok ( IPV6 ( 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff ), + "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" ); +} + +/** IPv6 self-test */ +struct self_test ipv6_test __self_test = { + .name = "ipv6", + .exec = ipv6_test_exec, +}; diff --git a/src/tests/tests.c b/src/tests/tests.c index f965e6e3..17e22a3a 100644 --- a/src/tests/tests.c +++ b/src/tests/tests.c @@ -36,6 +36,7 @@ REQUIRE_OBJECT ( base16_test ); REQUIRE_OBJECT ( settings_test ); REQUIRE_OBJECT ( time_test ); REQUIRE_OBJECT ( tcpip_test ); +REQUIRE_OBJECT ( ipv6_test ); REQUIRE_OBJECT ( crc32_test ); REQUIRE_OBJECT ( md5_test ); REQUIRE_OBJECT ( sha1_test ); |