aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Brown <mcb30@ipxe.org>2022-09-06 13:02:17 +0100
committerMichael Brown <mcb30@ipxe.org>2022-09-06 13:04:19 +0100
commitbc19aeca5f6c695ad3db0196057d155e4f64584e (patch)
tree6b9ef11f7b57fce16818f0fd7b1f43ae05ff7057
parent131daf1aaec117b73026b34f6673c7aeba7fead3 (diff)
downloadipxe-bc19aeca5f6c695ad3db0196057d155e4f64584e.zip
ipxe-bc19aeca5f6c695ad3db0196057d155e4f64584e.tar.gz
ipxe-bc19aeca5f6c695ad3db0196057d155e4f64584e.tar.bz2
[ipv6] Fix mask calculation when prefix length is not a multiple of 8
Signed-off-by: Michael Brown <mcb30@ipxe.org>
-rw-r--r--src/net/ipv6.c2
-rw-r--r--src/tests/ipv6_test.c37
2 files changed, 38 insertions, 1 deletions
diff --git a/src/net/ipv6.c b/src/net/ipv6.c
index 4b2c33e..901203c 100644
--- a/src/net/ipv6.c
+++ b/src/net/ipv6.c
@@ -251,7 +251,7 @@ int ipv6_add_miniroute ( struct net_device *netdev, struct in6_addr *address,
*prefix_mask = 0xff;
}
if ( remaining )
- *prefix_mask <<= ( 8 - remaining );
+ *prefix_mask = ( 0xff << ( 8 - remaining ) );
}
/* Add to start of routing table */
diff --git a/src/tests/ipv6_test.c b/src/tests/ipv6_test.c
index 0a8467d..de8edc8 100644
--- a/src/tests/ipv6_test.c
+++ b/src/tests/ipv6_test.c
@@ -131,9 +131,21 @@ static struct net_device ipv6_test_netdev = {
.state = NETDEV_OPEN,
};
+/** /48 prefix */
+PREFIX ( prefix48, 48, "ffff:ffff:ffff::" );
+
/** /64 prefix */
PREFIX ( prefix64, 64, "ffff:ffff:ffff:ffff::" );
+/** /126 prefix */
+PREFIX ( prefix126, 126, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffc" );
+
+/** /127 prefix */
+PREFIX ( prefix127, 127, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:fffe" );
+
+/** /128 prefix */
+PREFIX ( prefix128, 128, "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff" );
+
/** Routing table with only a link-local address */
TABLE ( table_link_local,
{ "fe80::69ff:fe50:5845", &prefix64, NULL } );
@@ -152,6 +164,13 @@ TABLE ( table_multi,
{ "fd44:9112:6442::69ff:fe50:5845", &prefix64, "fe80::1" },
{ "fd70:6ba9:50ae::69ff:fe50:5845", &prefix64, "fe80::3" } );
+/** Routing table with unusual prefix lengths */
+TABLE ( table_unusual,
+ { "2001:db8:1::1", &prefix48, "fe80::1" },
+ { "2001:db8:2::1", &prefix126, NULL },
+ { "2001:db8:3::1", &prefix127, NULL },
+ { "2001:db8:4::1", &prefix128, NULL } );
+
/**
* Report an inet6_ntoa() test result
*
@@ -502,6 +521,7 @@ static void ipv6_test_exec ( void ) {
ipv6_table_ok ( &table_link_local );
ipv6_table_ok ( &table_normal );
ipv6_table_ok ( &table_multi );
+ ipv6_table_ok ( &table_unusual );
/* Routing table with only a link-local address */
ipv6_route_ok ( &table_link_local, "fe80::1",
@@ -545,10 +565,27 @@ static void ipv6_test_exec ( void ) {
ipv6_route_ok ( &table_multi, "ff02::1",
"fe80::69ff:fe50:5845", NULL );
+ /* Routing table with unusual prefix lengths */
+ ipv6_route_ok ( &table_unusual, "2001:db8:2::1",
+ "2001:db8:2::1", NULL );
+ ipv6_route_ok ( &table_unusual, "2001:db8:2::3",
+ "2001:db8:2::1", NULL );
+ ipv6_route_ok ( &table_unusual, "2001:db8:3::1",
+ "2001:db8:3::1", NULL );
+ ipv6_route_ok ( &table_unusual, "2001:db8:3::2",
+ "2001:db8:1::1", "fe80::1" );
+ ipv6_route_ok ( &table_unusual, "2001:db8:4::1",
+ "2001:db8:4::1", NULL );
+ ipv6_route_ok ( &table_unusual, "2001:db8:4::0",
+ "2001:db8:1::1", "fe80::1" );
+ ipv6_route_ok ( &table_unusual, "2001:db8:4::2",
+ "2001:db8:1::1", "fe80::1" );
+
/* Destroy test routing tables */
ipv6_table_del ( &table_link_local );
ipv6_table_del ( &table_normal );
ipv6_table_del ( &table_multi );
+ ipv6_table_del ( &table_unusual );
}
/** IPv6 self-test */