diff options
author | Chris Koch <chrisko@google.com> | 2019-09-24 20:50:35 -0700 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-09-25 21:55:11 +0100 |
commit | f4eaaf1f283fe3dc826012a75e7ba0dc4ddc4c1e (patch) | |
tree | 6f96b7f5b6ba490db04f4505ac1e26c9e815449b | |
parent | 8b87dd7716f621fbbfafc65f68f7ec016bebd73b (diff) |
dhcpv6: simplify boot file URL
Signed-off-by: Chris Koch <chrisko@google.com>
-rw-r--r-- | dhcpv6/dhcpv6message_test.go | 4 | ||||
-rw-r--r-- | dhcpv6/option_bootfileurl.go | 22 | ||||
-rw-r--r-- | dhcpv6/option_bootfileurl_test.go | 18 | ||||
-rw-r--r-- | netboot/netboot.go | 4 |
4 files changed, 22 insertions, 26 deletions
diff --git a/dhcpv6/dhcpv6message_test.go b/dhcpv6/dhcpv6message_test.go index 2dd4a1c..d914e74 100644 --- a/dhcpv6/dhcpv6message_test.go +++ b/dhcpv6/dhcpv6message_test.go @@ -17,8 +17,8 @@ func TestIsNetboot(t *testing.T) { require.True(t, msg2.IsNetboot()) msg3 := Message{} - optbf := OptBootFileURL{} - msg3.AddOption(&optbf) + optbf := OptBootFileURL("") + msg3.AddOption(optbf) require.True(t, msg3.IsNetboot()) } diff --git a/dhcpv6/option_bootfileurl.go b/dhcpv6/option_bootfileurl.go index 48c49bc..d37a186 100644 --- a/dhcpv6/option_bootfileurl.go +++ b/dhcpv6/option_bootfileurl.go @@ -8,28 +8,26 @@ import ( // // This module defines the OptBootFileURL structure. // https://www.ietf.org/rfc/rfc5970.txt -type OptBootFileURL struct { - BootFileURL []byte -} +type OptBootFileURL string + +var _ Option = OptBootFileURL("") // Code returns the option code -func (op *OptBootFileURL) Code() OptionCode { +func (op OptBootFileURL) Code() OptionCode { return OptionBootfileURL } // ToBytes serializes the option and returns it as a sequence of bytes -func (op *OptBootFileURL) ToBytes() []byte { - return op.BootFileURL +func (op OptBootFileURL) ToBytes() []byte { + return []byte(op) } -func (op *OptBootFileURL) String() string { - return fmt.Sprintf("OptBootFileURL{BootFileUrl=%s}", op.BootFileURL) +func (op OptBootFileURL) String() string { + return fmt.Sprintf("OptBootFileURL(%s)", string(op)) } // ParseOptBootFileURL builds an OptBootFileURL structure from a sequence // of bytes. The input data does not include option code and length bytes. -func ParseOptBootFileURL(data []byte) (*OptBootFileURL, error) { - var opt OptBootFileURL - opt.BootFileURL = append([]byte(nil), data...) - return &opt, nil +func ParseOptBootFileURL(data []byte) (OptBootFileURL, error) { + return OptBootFileURL(string(data)), nil } diff --git a/dhcpv6/option_bootfileurl_test.go b/dhcpv6/option_bootfileurl_test.go index 7d43003..80cdbf0 100644 --- a/dhcpv6/option_bootfileurl_test.go +++ b/dhcpv6/option_bootfileurl_test.go @@ -8,24 +8,22 @@ import ( ) func TestOptBootFileURL(t *testing.T) { - expected := []byte("https://insomniac.slackware.it") - opt, err := ParseOptBootFileURL(expected) + expected := "https://insomniac.slackware.it" + opt, err := ParseOptBootFileURL([]byte(expected)) if err != nil { t.Fatal(err) } - if url := opt.BootFileURL; !bytes.Equal(url, expected) { - t.Fatalf("Invalid boot file URL. Expected %v, got %v", expected, url) + if string(opt) != expected { + t.Fatalf("Invalid boot file URL. Expected %v, got %v", expected, opt) } - require.Contains(t, opt.String(), "BootFileUrl=https://insomniac.slackware.it", "String() should contain the correct BootFileUrl output") + require.Contains(t, opt.String(), "https://insomniac.slackware.it", "String() should contain the correct BootFileUrl output") } func TestOptBootFileURLToBytes(t *testing.T) { - urlString := []byte("https://insomniac.slackware.it") - opt := OptBootFileURL{ - BootFileURL: urlString, - } + urlString := "https://insomniac.slackware.it" + opt := OptBootFileURL(urlString) toBytes := opt.ToBytes() - if !bytes.Equal(toBytes, urlString) { + if !bytes.Equal(toBytes, []byte(urlString)) { t.Fatalf("Invalid ToBytes result. Expected %v, got %v", urlString, toBytes) } } diff --git a/netboot/netboot.go b/netboot/netboot.go index bfa7ce5..6f113b6 100644 --- a/netboot/netboot.go +++ b/netboot/netboot.go @@ -123,8 +123,8 @@ func ConversationToNetconf(conversation []dhcpv6.DHCPv6) (*NetConf, string, erro } } if opt != nil { - obf := opt.(*dhcpv6.OptBootFileURL) - bootfile = string(obf.BootFileURL) + obf := opt.(dhcpv6.OptBootFileURL) + bootfile = string(obf) } return netconf, bootfile, nil } |