diff options
Diffstat (limited to 'pkg/tcpip/header')
-rw-r--r-- | pkg/tcpip/header/ndp_options.go | 134 | ||||
-rw-r--r-- | pkg/tcpip/header/ndp_test.go | 52 | ||||
-rw-r--r-- | pkg/tcpip/header/ndpoptionidentifier_string.go | 36 |
3 files changed, 111 insertions, 111 deletions
diff --git a/pkg/tcpip/header/ndp_options.go b/pkg/tcpip/header/ndp_options.go index 5deae465c..3d1bccd15 100644 --- a/pkg/tcpip/header/ndp_options.go +++ b/pkg/tcpip/header/ndp_options.go @@ -26,33 +26,33 @@ import ( "gvisor.dev/gvisor/pkg/tcpip" ) -// NDPOptionIdentifier is an NDP option type identifier. -type NDPOptionIdentifier uint8 +// ndpOptionIdentifier is an NDP option type identifier. +type ndpOptionIdentifier uint8 const ( - // NDPSourceLinkLayerAddressOptionType is the type of the Source Link Layer + // ndpSourceLinkLayerAddressOptionType is the type of the Source Link Layer // Address option, as per RFC 4861 section 4.6.1. - NDPSourceLinkLayerAddressOptionType NDPOptionIdentifier = 1 + ndpSourceLinkLayerAddressOptionType ndpOptionIdentifier = 1 - // NDPTargetLinkLayerAddressOptionType is the type of the Target Link Layer + // ndpTargetLinkLayerAddressOptionType is the type of the Target Link Layer // Address option, as per RFC 4861 section 4.6.1. - NDPTargetLinkLayerAddressOptionType NDPOptionIdentifier = 2 + ndpTargetLinkLayerAddressOptionType ndpOptionIdentifier = 2 - // NDPPrefixInformationType is the type of the Prefix Information + // ndpPrefixInformationType is the type of the Prefix Information // option, as per RFC 4861 section 4.6.2. - NDPPrefixInformationType NDPOptionIdentifier = 3 + ndpPrefixInformationType ndpOptionIdentifier = 3 - // NDPNonceOptionType is the type of the Nonce option, as per + // ndpNonceOptionType is the type of the Nonce option, as per // RFC 3971 section 5.3.2. - NDPNonceOptionType NDPOptionIdentifier = 14 + ndpNonceOptionType ndpOptionIdentifier = 14 - // NDPRecursiveDNSServerOptionType is the type of the Recursive DNS + // ndpRecursiveDNSServerOptionType is the type of the Recursive DNS // Server option, as per RFC 8106 section 5.1. - NDPRecursiveDNSServerOptionType NDPOptionIdentifier = 25 + ndpRecursiveDNSServerOptionType ndpOptionIdentifier = 25 - // NDPDNSSearchListOptionType is the type of the DNS Search List option, + // ndpDNSSearchListOptionType is the type of the DNS Search List option, // as per RFC 8106 section 5.2. - NDPDNSSearchListOptionType NDPOptionIdentifier = 31 + ndpDNSSearchListOptionType ndpOptionIdentifier = 31 ) const ( @@ -202,7 +202,7 @@ func (i *NDPOptionIterator) Next() (NDPOption, bool, error) { // bytes for the whole option. return nil, true, fmt.Errorf("unexpectedly exhausted buffer when reading the option's Type field: %w", io.ErrUnexpectedEOF) } - kind := NDPOptionIdentifier(temp) + kind := ndpOptionIdentifier(temp) // Get the Length field. length, err := i.opts.ReadByte() @@ -229,16 +229,16 @@ func (i *NDPOptionIterator) Next() (NDPOption, bool, error) { } switch kind { - case NDPSourceLinkLayerAddressOptionType: + case ndpSourceLinkLayerAddressOptionType: return NDPSourceLinkLayerAddressOption(body), false, nil - case NDPTargetLinkLayerAddressOptionType: + case ndpTargetLinkLayerAddressOptionType: return NDPTargetLinkLayerAddressOption(body), false, nil - case NDPNonceOptionType: + case ndpNonceOptionType: return NDPNonceOption(body), false, nil - case NDPPrefixInformationType: + case ndpPrefixInformationType: // Make sure the length of a Prefix Information option // body is ndpPrefixInformationLength, as per RFC 4861 // section 4.6.2. @@ -248,7 +248,7 @@ func (i *NDPOptionIterator) Next() (NDPOption, bool, error) { return NDPPrefixInformation(body), false, nil - case NDPRecursiveDNSServerOptionType: + case ndpRecursiveDNSServerOptionType: opt := NDPRecursiveDNSServer(body) if err := opt.checkAddresses(); err != nil { return nil, true, err @@ -256,7 +256,7 @@ func (i *NDPOptionIterator) Next() (NDPOption, bool, error) { return opt, false, nil - case NDPDNSSearchListOptionType: + case ndpDNSSearchListOptionType: opt := NDPDNSSearchList(body) if err := opt.checkDomainNames(); err != nil { return nil, true, err @@ -323,7 +323,7 @@ func (b NDPOptions) Serialize(s NDPOptionsSerializer) int { continue } - b[0] = byte(o.Type()) + b[0] = byte(o.kind()) // We know this safe because paddedLength would have returned // 0 if o had an invalid length (> 255 * lengthByteUnits). @@ -348,11 +348,11 @@ func (b NDPOptions) Serialize(s NDPOptionsSerializer) int { type NDPOption interface { fmt.Stringer - // Type returns the type of the receiver. - Type() NDPOptionIdentifier + // kind returns the type of the receiver. + kind() ndpOptionIdentifier - // Length returns the length of the body of the receiver, in bytes. - Length() int + // length returns the length of the body of the receiver, in bytes. + length() int // serializeInto serializes the receiver into the provided byte // buffer. @@ -372,7 +372,7 @@ type NDPOption interface { // paddedLength returns the length of o, in bytes, with any padding bytes, if // required. func paddedLength(o NDPOption) int { - l := o.Length() + l := o.length() if l == 0 { return 0 @@ -429,13 +429,13 @@ func (b NDPOptionsSerializer) Length() int { // where X is the value in Length multiplied by lengthByteUnits - 2 bytes. type NDPNonceOption []byte -// Type implements NDPOption. -func (o NDPNonceOption) Type() NDPOptionIdentifier { - return NDPNonceOptionType +// kind implements NDPOption. +func (o NDPNonceOption) kind() ndpOptionIdentifier { + return ndpNonceOptionType } -// Length implements NDPOption. -func (o NDPNonceOption) Length() int { +// length implements NDPOption. +func (o NDPNonceOption) length() int { return len(o) } @@ -461,22 +461,22 @@ func (o NDPNonceOption) Nonce() []byte { // where X is the value in Length multiplied by lengthByteUnits - 2 bytes. type NDPSourceLinkLayerAddressOption tcpip.LinkAddress -// Type implements NDPOption.Type. -func (o NDPSourceLinkLayerAddressOption) Type() NDPOptionIdentifier { - return NDPSourceLinkLayerAddressOptionType +// kind implements NDPOption. +func (o NDPSourceLinkLayerAddressOption) kind() ndpOptionIdentifier { + return ndpSourceLinkLayerAddressOptionType } -// Length implements NDPOption.Length. -func (o NDPSourceLinkLayerAddressOption) Length() int { +// length implements NDPOption. +func (o NDPSourceLinkLayerAddressOption) length() int { return len(o) } -// serializeInto implements NDPOption.serializeInto. +// serializeInto implements NDPOption. func (o NDPSourceLinkLayerAddressOption) serializeInto(b []byte) int { return copy(b, o) } -// String implements fmt.Stringer.String. +// String implements fmt.Stringer. func (o NDPSourceLinkLayerAddressOption) String() string { return fmt.Sprintf("%T(%s)", o, tcpip.LinkAddress(o)) } @@ -501,22 +501,22 @@ func (o NDPSourceLinkLayerAddressOption) EthernetAddress() tcpip.LinkAddress { // where X is the value in Length multiplied by lengthByteUnits - 2 bytes. type NDPTargetLinkLayerAddressOption tcpip.LinkAddress -// Type implements NDPOption.Type. -func (o NDPTargetLinkLayerAddressOption) Type() NDPOptionIdentifier { - return NDPTargetLinkLayerAddressOptionType +// kind implements NDPOption. +func (o NDPTargetLinkLayerAddressOption) kind() ndpOptionIdentifier { + return ndpTargetLinkLayerAddressOptionType } -// Length implements NDPOption.Length. -func (o NDPTargetLinkLayerAddressOption) Length() int { +// length implements NDPOption. +func (o NDPTargetLinkLayerAddressOption) length() int { return len(o) } -// serializeInto implements NDPOption.serializeInto. +// serializeInto implements NDPOption. func (o NDPTargetLinkLayerAddressOption) serializeInto(b []byte) int { return copy(b, o) } -// String implements fmt.Stringer.String. +// String implements fmt.Stringer. func (o NDPTargetLinkLayerAddressOption) String() string { return fmt.Sprintf("%T(%s)", o, tcpip.LinkAddress(o)) } @@ -541,17 +541,17 @@ func (o NDPTargetLinkLayerAddressOption) EthernetAddress() tcpip.LinkAddress { // ndpPrefixInformationLength bytes. type NDPPrefixInformation []byte -// Type implements NDPOption.Type. -func (o NDPPrefixInformation) Type() NDPOptionIdentifier { - return NDPPrefixInformationType +// kind implements NDPOption. +func (o NDPPrefixInformation) kind() ndpOptionIdentifier { + return ndpPrefixInformationType } -// Length implements NDPOption.Length. -func (o NDPPrefixInformation) Length() int { +// length implements NDPOption. +func (o NDPPrefixInformation) length() int { return ndpPrefixInformationLength } -// serializeInto implements NDPOption.serializeInto. +// serializeInto implements NDPOption. func (o NDPPrefixInformation) serializeInto(b []byte) int { used := copy(b, o) @@ -567,7 +567,7 @@ func (o NDPPrefixInformation) serializeInto(b []byte) int { return used } -// String implements fmt.Stringer.String. +// String implements fmt.Stringer. func (o NDPPrefixInformation) String() string { return fmt.Sprintf("%T(O=%t, A=%t, PL=%s, VL=%s, Prefix=%s)", o, @@ -665,17 +665,17 @@ type NDPRecursiveDNSServer []byte // Type returns the type of an NDP Recursive DNS Server option. // -// Type implements NDPOption.Type. -func (NDPRecursiveDNSServer) Type() NDPOptionIdentifier { - return NDPRecursiveDNSServerOptionType +// kind implements NDPOption. +func (NDPRecursiveDNSServer) kind() ndpOptionIdentifier { + return ndpRecursiveDNSServerOptionType } -// Length implements NDPOption.Length. -func (o NDPRecursiveDNSServer) Length() int { +// length implements NDPOption. +func (o NDPRecursiveDNSServer) length() int { return len(o) } -// serializeInto implements NDPOption.serializeInto. +// serializeInto implements NDPOption. func (o NDPRecursiveDNSServer) serializeInto(b []byte) int { used := copy(b, o) @@ -687,7 +687,7 @@ func (o NDPRecursiveDNSServer) serializeInto(b []byte) int { return used } -// String implements fmt.Stringer.String. +// String implements fmt.Stringer. func (o NDPRecursiveDNSServer) String() string { lt := o.Lifetime() addrs, err := o.Addresses() @@ -760,17 +760,17 @@ func (o NDPRecursiveDNSServer) iterAddresses(fn func(tcpip.Address)) error { // RFC 8106 section 5.2. type NDPDNSSearchList []byte -// Type implements NDPOption.Type. -func (o NDPDNSSearchList) Type() NDPOptionIdentifier { - return NDPDNSSearchListOptionType +// kind implements NDPOption. +func (o NDPDNSSearchList) kind() ndpOptionIdentifier { + return ndpDNSSearchListOptionType } -// Length implements NDPOption.Length. -func (o NDPDNSSearchList) Length() int { +// length implements NDPOption. +func (o NDPDNSSearchList) length() int { return len(o) } -// serializeInto implements NDPOption.serializeInto. +// serializeInto implements NDPOption. func (o NDPDNSSearchList) serializeInto(b []byte) int { used := copy(b, o) @@ -782,7 +782,7 @@ func (o NDPDNSSearchList) serializeInto(b []byte) int { return used } -// String implements fmt.Stringer.String. +// String implements fmt.Stringer. func (o NDPDNSSearchList) String() string { lt := o.Lifetime() domainNames, err := o.DomainNames() diff --git a/pkg/tcpip/header/ndp_test.go b/pkg/tcpip/header/ndp_test.go index bfc73e245..d0a1a2492 100644 --- a/pkg/tcpip/header/ndp_test.go +++ b/pkg/tcpip/header/ndp_test.go @@ -233,8 +233,8 @@ func TestOpts(t *testing.T) { checkNonce := func(expectedNonce []byte) func(*testing.T, NDPOption) { return func(t *testing.T, opt NDPOption) { - if got := opt.Type(); got != NDPNonceOptionType { - t.Errorf("got Type() = %d, want = %d", got, NDPNonceOptionType) + if got := opt.kind(); got != ndpNonceOptionType { + t.Errorf("got kind() = %d, want = %d", got, ndpNonceOptionType) } nonce, ok := opt.(NDPNonceOption) if !ok { @@ -248,8 +248,8 @@ func TestOpts(t *testing.T) { checkTLL := func(expectedAddr tcpip.LinkAddress) func(*testing.T, NDPOption) { return func(t *testing.T, opt NDPOption) { - if got := opt.Type(); got != NDPTargetLinkLayerAddressOptionType { - t.Errorf("got Type() = %d, want = %d", got, NDPTargetLinkLayerAddressOptionType) + if got := opt.kind(); got != ndpTargetLinkLayerAddressOptionType { + t.Errorf("got kind() = %d, want = %d", got, ndpTargetLinkLayerAddressOptionType) } tll, ok := opt.(NDPTargetLinkLayerAddressOption) if !ok { @@ -263,8 +263,8 @@ func TestOpts(t *testing.T) { checkSLL := func(expectedAddr tcpip.LinkAddress) func(*testing.T, NDPOption) { return func(t *testing.T, opt NDPOption) { - if got := opt.Type(); got != NDPSourceLinkLayerAddressOptionType { - t.Errorf("got Type() = %d, want = %d", got, NDPSourceLinkLayerAddressOptionType) + if got := opt.kind(); got != ndpSourceLinkLayerAddressOptionType { + t.Errorf("got kind() = %d, want = %d", got, ndpSourceLinkLayerAddressOptionType) } sll, ok := opt.(NDPSourceLinkLayerAddressOption) if !ok { @@ -443,15 +443,15 @@ func TestOpts(t *testing.T) { opt: NDPRecursiveDNSServer(rdnssBytes[optionHeaderLen:]), expectedBuf: expectedRDNSSBytes[:], check: func(t *testing.T, opt NDPOption) { - if got := opt.Type(); got != NDPRecursiveDNSServerOptionType { - t.Errorf("got Type() = %d, want = %d", got, NDPRecursiveDNSServerOptionType) + if got := opt.kind(); got != ndpRecursiveDNSServerOptionType { + t.Errorf("got kind() = %d, want = %d", got, ndpRecursiveDNSServerOptionType) } rdnss, ok := opt.(NDPRecursiveDNSServer) if !ok { t.Fatalf("got opt = %T, want = NDPRecursiveDNSServer", opt) } - if got, want := rdnss.Length(), len(expectedRDNSSBytes[optionHeaderLen:]); got != want { - t.Errorf("got Length() = %d, want = %d", got, want) + if got, want := rdnss.length(), len(expectedRDNSSBytes[optionHeaderLen:]); got != want { + t.Errorf("got length() = %d, want = %d", got, want) } if got, want := rdnss.Lifetime(), validLifetimeSeconds*time.Second; got != want { t.Errorf("got Lifetime() = %s, want = %s", got, want) @@ -470,16 +470,16 @@ func TestOpts(t *testing.T) { opt: NDPDNSSearchList(searchListBytes[optionHeaderLen:]), expectedBuf: expectedSearchListBytes[:], check: func(t *testing.T, opt NDPOption) { - if got := opt.Type(); got != NDPDNSSearchListOptionType { - t.Errorf("got Type() = %d, want = %d", got, NDPDNSSearchListOptionType) + if got := opt.kind(); got != ndpDNSSearchListOptionType { + t.Errorf("got kind() = %d, want = %d", got, ndpDNSSearchListOptionType) } dnssl, ok := opt.(NDPDNSSearchList) if !ok { t.Fatalf("got opt = %T, want = NDPDNSSearchList", opt) } - if got, want := dnssl.Length(), len(expectedRDNSSBytes[optionHeaderLen:]); got != want { - t.Errorf("got Length() = %d, want = %d", got, want) + if got, want := dnssl.length(), len(expectedRDNSSBytes[optionHeaderLen:]); got != want { + t.Errorf("got length() = %d, want = %d", got, want) } if got, want := dnssl.Lifetime(), validLifetimeSeconds*time.Second; got != want { t.Errorf("got Lifetime() = %s, want = %s", got, want) @@ -500,8 +500,8 @@ func TestOpts(t *testing.T) { opt: NDPPrefixInformation(prefixInformationBytes[optionHeaderLen:]), expectedBuf: expectedPrefixInformationBytes[:], check: func(t *testing.T, opt NDPOption) { - if got := opt.Type(); got != NDPPrefixInformationType { - t.Errorf("got Type() = %d, want = %d", got, NDPPrefixInformationType) + if got := opt.kind(); got != ndpPrefixInformationType { + t.Errorf("got kind() = %d, want = %d", got, ndpPrefixInformationType) } pi, ok := opt.(NDPPrefixInformation) @@ -509,8 +509,8 @@ func TestOpts(t *testing.T) { t.Fatalf("got opt = %T, want = NDPPrefixInformation", opt) } - if got, want := pi.Length(), len(expectedPrefixInformationBytes[optionHeaderLen:]); got != want { - t.Errorf("got Length() = %d, want = %d", got, want) + if got, want := pi.length(), len(expectedPrefixInformationBytes[optionHeaderLen:]); got != want { + t.Errorf("got length() = %d, want = %d", got, want) } if got := pi.PrefixLength(); got != prefixLength { t.Errorf("got PrefixLength() = %d, want = %d", got, prefixLength) @@ -646,8 +646,8 @@ func TestNDPRecursiveDNSServerOption(t *testing.T) { if done { t.Fatal("got Next = (_, true, _), want = (_, false, _)") } - if got := next.Type(); got != NDPRecursiveDNSServerOptionType { - t.Fatalf("got Type = %d, want = %d", got, NDPRecursiveDNSServerOptionType) + if got := next.kind(); got != ndpRecursiveDNSServerOptionType { + t.Fatalf("got Type = %d, want = %d", got, ndpRecursiveDNSServerOptionType) } opt, ok := next.(NDPRecursiveDNSServer) @@ -1403,8 +1403,8 @@ func TestNDPOptionsIter(t *testing.T) { if got, want := []byte(next.(NDPSourceLinkLayerAddressOption)), buf[2:][:6]; !bytes.Equal(got, want) { t.Errorf("got Next = (%x, _, _), want = (%x, _, _)", got, want) } - if got := next.Type(); got != NDPSourceLinkLayerAddressOptionType { - t.Errorf("got Type = %d, want = %d", got, NDPSourceLinkLayerAddressOptionType) + if got := next.kind(); got != ndpSourceLinkLayerAddressOptionType { + t.Errorf("got Type = %d, want = %d", got, ndpSourceLinkLayerAddressOptionType) } // Test the next (Target Link-Layer) option. @@ -1418,8 +1418,8 @@ func TestNDPOptionsIter(t *testing.T) { if got, want := []byte(next.(NDPTargetLinkLayerAddressOption)), buf[10:][:6]; !bytes.Equal(got, want) { t.Errorf("got Next = (%x, _, _), want = (%x, _, _)", got, want) } - if got := next.Type(); got != NDPTargetLinkLayerAddressOptionType { - t.Errorf("got Type = %d, want = %d", got, NDPTargetLinkLayerAddressOptionType) + if got := next.kind(); got != ndpTargetLinkLayerAddressOptionType { + t.Errorf("got Type = %d, want = %d", got, ndpTargetLinkLayerAddressOptionType) } // Test the next (Prefix Information) option. @@ -1434,8 +1434,8 @@ func TestNDPOptionsIter(t *testing.T) { if got, want := next.(NDPPrefixInformation), buf[34:][:30]; !bytes.Equal(got, want) { t.Errorf("got Next = (%x, _, _), want = (%x, _, _)", got, want) } - if got := next.Type(); got != NDPPrefixInformationType { - t.Errorf("got Type = %d, want = %d", got, NDPPrefixInformationType) + if got := next.kind(); got != ndpPrefixInformationType { + t.Errorf("got Type = %d, want = %d", got, ndpPrefixInformationType) } // Iterator should not return anything else. diff --git a/pkg/tcpip/header/ndpoptionidentifier_string.go b/pkg/tcpip/header/ndpoptionidentifier_string.go index 83f94a730..55ab1d7cf 100644 --- a/pkg/tcpip/header/ndpoptionidentifier_string.go +++ b/pkg/tcpip/header/ndpoptionidentifier_string.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Code generated by "stringer -type NDPOptionIdentifier"; DO NOT EDIT. +// Code generated by "stringer -type ndpOptionIdentifier"; DO NOT EDIT. package header @@ -22,37 +22,37 @@ func _() { // An "invalid array index" compiler error signifies that the constant values have changed. // Re-run the stringer command to generate them again. var x [1]struct{} - _ = x[NDPSourceLinkLayerAddressOptionType-1] - _ = x[NDPTargetLinkLayerAddressOptionType-2] - _ = x[NDPPrefixInformationType-3] - _ = x[NDPNonceOptionType-14] - _ = x[NDPRecursiveDNSServerOptionType-25] - _ = x[NDPDNSSearchListOptionType-31] + _ = x[ndpSourceLinkLayerAddressOptionType-1] + _ = x[ndpTargetLinkLayerAddressOptionType-2] + _ = x[ndpPrefixInformationType-3] + _ = x[ndpNonceOptionType-14] + _ = x[ndpRecursiveDNSServerOptionType-25] + _ = x[ndpDNSSearchListOptionType-31] } const ( - _NDPOptionIdentifier_name_0 = "NDPSourceLinkLayerAddressOptionTypeNDPTargetLinkLayerAddressOptionTypeNDPPrefixInformationType" - _NDPOptionIdentifier_name_1 = "NDPNonceOptionType" - _NDPOptionIdentifier_name_2 = "NDPRecursiveDNSServerOptionType" - _NDPOptionIdentifier_name_3 = "NDPDNSSearchListOptionType" + _ndpOptionIdentifier_name_0 = "ndpSourceLinkLayerAddressOptionTypendpTargetLinkLayerAddressOptionTypendpPrefixInformationType" + _ndpOptionIdentifier_name_1 = "ndpNonceOptionType" + _ndpOptionIdentifier_name_2 = "ndpRecursiveDNSServerOptionType" + _ndpOptionIdentifier_name_3 = "ndpDNSSearchListOptionType" ) var ( - _NDPOptionIdentifier_index_0 = [...]uint8{0, 35, 70, 94} + _ndpOptionIdentifier_index_0 = [...]uint8{0, 35, 70, 94} ) -func (i NDPOptionIdentifier) String() string { +func (i ndpOptionIdentifier) String() string { switch { case 1 <= i && i <= 3: i -= 1 - return _NDPOptionIdentifier_name_0[_NDPOptionIdentifier_index_0[i]:_NDPOptionIdentifier_index_0[i+1]] + return _ndpOptionIdentifier_name_0[_ndpOptionIdentifier_index_0[i]:_ndpOptionIdentifier_index_0[i+1]] case i == 14: - return _NDPOptionIdentifier_name_1 + return _ndpOptionIdentifier_name_1 case i == 25: - return _NDPOptionIdentifier_name_2 + return _ndpOptionIdentifier_name_2 case i == 31: - return _NDPOptionIdentifier_name_3 + return _ndpOptionIdentifier_name_3 default: - return "NDPOptionIdentifier(" + strconv.FormatInt(int64(i), 10) + ")" + return "ndpOptionIdentifier(" + strconv.FormatInt(int64(i), 10) + ")" } } |