summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip/tcpip_test.go
diff options
context:
space:
mode:
authorGhanan Gowripalan <ghanan@google.com>2020-12-21 22:23:18 -0800
committergVisor bot <gvisor-bot@google.com>2020-12-21 22:26:10 -0800
commit620de250a48ac6a0f1c46b6ea22eb94e4c907a8e (patch)
tree33927c23fc2de19015fa9bbc98ea3726bac2fa66 /pkg/tcpip/tcpip_test.go
parent946cb909e62e0aaca9e3bbb7cf059dd6b0eab2ce (diff)
Prefer matching labels and longest matching prefix
...when performing source address selection for IPv6. These are defined in RFC 6724 section 5 rule 6 (prefer matching label) and rule 8 (use longest matching prefix). This change also considers ULA of global scope instead of its own scope, as per RFC 6724 section 3.1: Also, note that ULAs are considered as global, not site-local, scope but are handled via the prefix policy table as discussed in Section 10.6. Test: stack_test.TestIPv6SourceAddressSelectionScope Startblock: has LGTM from peterjohnston and then add reviewer brunodalbo PiperOrigin-RevId: 348580996
Diffstat (limited to 'pkg/tcpip/tcpip_test.go')
-rw-r--r--pkg/tcpip/tcpip_test.go40
1 files changed, 40 insertions, 0 deletions
diff --git a/pkg/tcpip/tcpip_test.go b/pkg/tcpip/tcpip_test.go
index c461da137..9bd563c46 100644
--- a/pkg/tcpip/tcpip_test.go
+++ b/pkg/tcpip/tcpip_test.go
@@ -270,3 +270,43 @@ func TestAddressUnspecified(t *testing.T) {
})
}
}
+
+func TestAddressMatchingPrefix(t *testing.T) {
+ tests := []struct {
+ addrA Address
+ addrB Address
+ prefix uint8
+ }{
+ {
+ addrA: "\x01\x01",
+ addrB: "\x01\x01",
+ prefix: 16,
+ },
+ {
+ addrA: "\x01\x01",
+ addrB: "\x01\x00",
+ prefix: 15,
+ },
+ {
+ addrA: "\x01\x01",
+ addrB: "\x81\x00",
+ prefix: 0,
+ },
+ {
+ addrA: "\x01\x01",
+ addrB: "\x01\x80",
+ prefix: 8,
+ },
+ {
+ addrA: "\x01\x01",
+ addrB: "\x02\x80",
+ prefix: 6,
+ },
+ }
+
+ for _, test := range tests {
+ if got := test.addrA.MatchingPrefix(test.addrB); got != test.prefix {
+ t.Errorf("got (%s).MatchingPrefix(%s) = %d, want = %d", test.addrA, test.addrB, got, test.prefix)
+ }
+ }
+}