diff options
author | Michael Brown <mcb30@ipxe.org> | 2022-09-06 13:02:17 +0100 |
---|---|---|
committer | Michael Brown <mcb30@ipxe.org> | 2022-09-06 13:04:19 +0100 |
commit | bc19aeca5f6c695ad3db0196057d155e4f64584e (patch) | |
tree | 6b9ef11f7b57fce16818f0fd7b1f43ae05ff7057 | |
parent | 131daf1aaec117b73026b34f6673c7aeba7fead3 (diff) | |
download | ipxe-bc19aeca5f6c695ad3db0196057d155e4f64584e.tar.gz |
[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.c | 2 | ||||
-rw-r--r-- | src/tests/ipv6_test.c | 37 |
2 files changed, 38 insertions, 1 deletions
diff --git a/src/net/ipv6.c b/src/net/ipv6.c index 4b2c33eb4..901203c40 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 0a8467d67..de8edc8ad 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 */ |