Add some test coverage for the IPv6 scoped address feature in netaddress
/netbase
per https://tools.ietf.org/html/rfc4007, update the member name scopeId
to m_scope_id
per doc/developer-notes.md
, and improve the code doc.
Reviewers can manually verify the test with these steps:
-
run the test:
cd src ; test/test_bitcoin -t net_tests/cnetaddr_basic -l all
0Running 1 test case...
1Entering test module "Bitcoin Core Test Suite"
2test/net_tests.cpp(85): Entering test suite "net_tests"
3test/net_tests.cpp(204): Entering test case "cnetaddr_basic"
4test/net_tests.cpp(210): info: check LookupHost("0.0.0.0", addr, false) has passed
5test/net_tests.cpp(211): info: check !addr.IsValid() has passed
6test/net_tests.cpp(212): info: check addr.IsIPv4() has passed
7test/net_tests.cpp(214): info: check addr.IsBindAny() has passed
8test/net_tests.cpp(215): info: check addr.ToString() == "0.0.0.0" has passed
9test/net_tests.cpp(218): info: check LookupHost("255.255.255.255", addr, false) has passed
10test/net_tests.cpp(219): info: check !addr.IsValid() has passed
11test/net_tests.cpp(220): info: check addr.IsIPv4() has passed
12test/net_tests.cpp(222): info: check !addr.IsBindAny() has passed
13test/net_tests.cpp(223): info: check addr.ToString() == "255.255.255.255" has passed
14test/net_tests.cpp(226): info: check LookupHost("12.34.56.78", addr, false) has passed
15test/net_tests.cpp(227): info: check addr.IsValid() has passed
16test/net_tests.cpp(228): info: check addr.IsIPv4() has passed
17test/net_tests.cpp(230): info: check !addr.IsBindAny() has passed
18test/net_tests.cpp(231): info: check addr.ToString() == "12.34.56.78" has passed
19test/net_tests.cpp(234): info: check LookupHost("::", addr, false) has passed
20test/net_tests.cpp(235): info: check !addr.IsValid() has passed
21test/net_tests.cpp(236): info: check addr.IsIPv6() has passed
22test/net_tests.cpp(238): info: check addr.IsBindAny() has passed
23test/net_tests.cpp(239): info: check addr.ToString() == "::" has passed
24test/net_tests.cpp(242): info: check LookupHost(ipv6_addr, addr, false) has passed
25test/net_tests.cpp(243): info: check addr.IsValid() has passed
26test/net_tests.cpp(244): info: check addr.IsIPv6() has passed
27test/net_tests.cpp(246): info: check !addr.IsBindAny() has passed
28test/net_tests.cpp(247): info: check addr.ToString() == ipv6_addr has passed
29test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
30test/net_tests.cpp(255): info: check addr.IsValid() has passed
31test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
32test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
33test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
34test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
35test/net_tests.cpp(255): info: check addr.IsValid() has passed
36test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
37test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
38test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
39test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
40test/net_tests.cpp(255): info: check addr.IsValid() has passed
41test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
42test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
43test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
44test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
45test/net_tests.cpp(255): info: check addr.IsValid() has passed
46test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
47test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
48test/net_tests.cpp(258): info: check addr.ToString() == scoped_addr has passed
49test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
50test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
51test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
52test/net_tests.cpp(266): info: check LookupHost(ipv6_addr + "%0", addr, false) has passed
53test/net_tests.cpp(267): info: check addr.IsValid() has passed
54test/net_tests.cpp(268): info: check addr.IsIPv6() has passed
55test/net_tests.cpp(269): info: check !addr.IsBindAny() has passed
56test/net_tests.cpp(270): info: check addr.ToString() == ipv6_addr has passed
57test/net_tests.cpp(274): info: check addr.IsValid() has passed
58test/net_tests.cpp(275): info: check addr.IsTor() has passed
59test/net_tests.cpp(277): info: check !addr.IsBindAny() has passed
60test/net_tests.cpp(278): info: check addr.ToString() == "6hzph5hv6337r6p2.onion" has passed
61test/net_tests.cpp(282): info: check !addr.IsValid() has passed
62test/net_tests.cpp(283): info: check addr.IsInternal() has passed
63test/net_tests.cpp(285): info: check !addr.IsBindAny() has passed
64test/net_tests.cpp(286): info: check addr.ToString() == "esffpvrt3wpeaygy.internal" has passed
65test/net_tests.cpp(204): Leaving test case "cnetaddr_basic"; testing time: 30933us
66test/net_tests.cpp(85): Leaving test suite "net_tests"; testing time: 30975us
67Leaving test module "Bitcoin Core Test Suite"; testing time: 31169us
68
69*** No errors detected
- change this line in the code to break the feature:
0--- a/src/netaddress.cpp
1+++ b/src/netaddress.cpp
2@@ -716,7 +716,7 @@ bool CService::GetSockAddr(struct sockaddr* paddr, socklen_t *addrlen) const
3 memset(paddrin6, 0, *addrlen);
4 if (!GetIn6Addr(&paddrin6->sin6_addr))
5 return false;
6- paddrin6->sin6_scope_id = m_scope_id;
7+ // paddrin6->sin6_scope_id = m_scope_id;
-
rebuild, e.g.
make
-
run the test:
test/test_bitcoin -t net_tests/cnetaddr_basic -l all
, verify that the added tests break
0Running 1 test case...
1Entering test module "Bitcoin Core Test Suite"
2test/net_tests.cpp(85): Entering test suite "net_tests"
3test/net_tests.cpp(204): Entering test case "cnetaddr_basic"
4test/net_tests.cpp(210): info: check LookupHost("0.0.0.0", addr, false) has passed
5test/net_tests.cpp(211): info: check !addr.IsValid() has passed
6test/net_tests.cpp(212): info: check addr.IsIPv4() has passed
7test/net_tests.cpp(214): info: check addr.IsBindAny() has passed
8test/net_tests.cpp(215): info: check addr.ToString() == "0.0.0.0" has passed
9test/net_tests.cpp(218): info: check LookupHost("255.255.255.255", addr, false) has passed
10test/net_tests.cpp(219): info: check !addr.IsValid() has passed
11test/net_tests.cpp(220): info: check addr.IsIPv4() has passed
12test/net_tests.cpp(222): info: check !addr.IsBindAny() has passed
13test/net_tests.cpp(223): info: check addr.ToString() == "255.255.255.255" has passed
14test/net_tests.cpp(226): info: check LookupHost("12.34.56.78", addr, false) has passed
15test/net_tests.cpp(227): info: check addr.IsValid() has passed
16test/net_tests.cpp(228): info: check addr.IsIPv4() has passed
17test/net_tests.cpp(230): info: check !addr.IsBindAny() has passed
18test/net_tests.cpp(231): info: check addr.ToString() == "12.34.56.78" has passed
19test/net_tests.cpp(234): info: check LookupHost("::", addr, false) has passed
20test/net_tests.cpp(235): info: check !addr.IsValid() has passed
21test/net_tests.cpp(236): info: check addr.IsIPv6() has passed
22test/net_tests.cpp(238): info: check addr.IsBindAny() has passed
23test/net_tests.cpp(239): info: check addr.ToString() == "::" has passed
24test/net_tests.cpp(242): info: check LookupHost(ipv6_addr, addr, false) has passed
25test/net_tests.cpp(243): info: check addr.IsValid() has passed
26test/net_tests.cpp(244): info: check addr.IsIPv6() has passed
27test/net_tests.cpp(246): info: check !addr.IsBindAny() has passed
28test/net_tests.cpp(247): info: check addr.ToString() == ipv6_addr has passed
29test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
30test/net_tests.cpp(255): info: check addr.IsValid() has passed
31test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
32test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
33test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%1]
34test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
35test/net_tests.cpp(255): info: check addr.IsValid() has passed
36test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
37test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
38test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%21]
39test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
40test/net_tests.cpp(255): info: check addr.IsValid() has passed
41test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
42test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
43test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%19]
44test/net_tests.cpp(254): info: check LookupHost(scoped_addr, addr, false) has passed
45test/net_tests.cpp(255): info: check addr.IsValid() has passed
46test/net_tests.cpp(256): info: check addr.IsIPv6() has passed
47test/net_tests.cpp(257): info: check !addr.IsBindAny() has passed
48test/net_tests.cpp(258): error: in "net_tests/cnetaddr_basic": check addr.ToString() == scoped_addr has failed [1122:3344:5566:7788:9900:aabb:ccdd:eeff != 1122:3344:5566:7788:9900:aabb:ccdd:eeff%3]
49test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
50test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
51test/net_tests.cpp(263): info: check !LookupHost(ipv6_addr + "%" + zone_id, addr, false) has passed
52test/net_tests.cpp(266): info: check LookupHost(ipv6_addr + "%0", addr, false) has passed
53test/net_tests.cpp(267): info: check addr.IsValid() has passed
54test/net_tests.cpp(268): info: check addr.IsIPv6() has passed
55test/net_tests.cpp(269): info: check !addr.IsBindAny() has passed
56test/net_tests.cpp(270): info: check addr.ToString() == ipv6_addr has passed
57test/net_tests.cpp(274): info: check addr.IsValid() has passed
58test/net_tests.cpp(275): info: check addr.IsTor() has passed
59test/net_tests.cpp(277): info: check !addr.IsBindAny() has passed
60test/net_tests.cpp(278): info: check addr.ToString() == "6hzph5hv6337r6p2.onion" has passed
61test/net_tests.cpp(282): info: check !addr.IsValid() has passed
62test/net_tests.cpp(283): info: check addr.IsInternal() has passed
63test/net_tests.cpp(285): info: check !addr.IsBindAny() has passed
64test/net_tests.cpp(286): info: check addr.ToString() == "esffpvrt3wpeaygy.internal" has passed
65test/net_tests.cpp(204): Leaving test case "cnetaddr_basic"; testing time: 32316us
66test/net_tests.cpp(85): Leaving test suite "net_tests"; testing time: 32354us
67Leaving test module "Bitcoin Core Test Suite"; testing time: 32522us
68
69*** 4 failures are detected in the test module "Bitcoin Core Test Suite"
- leave your review here