diff options
Diffstat (limited to 'dhcpv6')
-rw-r--r-- | dhcpv6/dhcpv6message.go | 12 | ||||
-rw-r--r-- | dhcpv6/option_bootfileurl.go | 25 | ||||
-rw-r--r-- | dhcpv6/option_bootfileurl_test.go | 2 | ||||
-rw-r--r-- | dhcpv6/options.go | 2 |
4 files changed, 26 insertions, 15 deletions
diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index 400c46a..d099386 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -104,6 +104,18 @@ func (mo MessageOptions) DNS() []net.IP { return nil } +// BootFileURL returns the Boot File URL option as defined by RFC 5970. +func (mo MessageOptions) BootFileURL() string { + opt := mo.Options.GetOne(OptionBootfileURL) + if opt == nil { + return "" + } + if u, ok := opt.(optBootFileURL); ok { + return string(u) + } + return "" +} + // Message represents a DHCPv6 Message as defined by RFC 3315 Section 6. type Message struct { MessageType MessageType diff --git a/dhcpv6/option_bootfileurl.go b/dhcpv6/option_bootfileurl.go index d37a186..695f164 100644 --- a/dhcpv6/option_bootfileurl.go +++ b/dhcpv6/option_bootfileurl.go @@ -4,30 +4,29 @@ import ( "fmt" ) -// OptBootFileURL implements the OptionBootfileURL option -// -// This module defines the OptBootFileURL structure. -// https://www.ietf.org/rfc/rfc5970.txt -type OptBootFileURL string +// OptBootFileURL returns a OptionBootfileURL as defined by RFC 5970. +func OptBootFileURL(url string) Option { + return optBootFileURL(url) +} -var _ Option = OptBootFileURL("") +type optBootFileURL string // 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 { +func (op optBootFileURL) ToBytes() []byte { return []byte(op) } -func (op OptBootFileURL) String() string { - return fmt.Sprintf("OptBootFileURL(%s)", string(op)) +func (op optBootFileURL) String() string { + return fmt.Sprintf("BootFileURL: %s", string(op)) } -// ParseOptBootFileURL builds an OptBootFileURL structure from a sequence +// 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) { - return OptBootFileURL(string(data)), 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 80cdbf0..ac45ef5 100644 --- a/dhcpv6/option_bootfileurl_test.go +++ b/dhcpv6/option_bootfileurl_test.go @@ -9,7 +9,7 @@ import ( func TestOptBootFileURL(t *testing.T) { expected := "https://insomniac.slackware.it" - opt, err := ParseOptBootFileURL([]byte(expected)) + opt, err := parseOptBootFileURL([]byte(expected)) if err != nil { t.Fatal(err) } diff --git a/dhcpv6/options.go b/dhcpv6/options.go index 0db7ebd..9d0ff9d 100644 --- a/dhcpv6/options.go +++ b/dhcpv6/options.go @@ -78,7 +78,7 @@ func ParseOption(code OptionCode, optData []byte) (Option, error) { case OptionFQDN: opt, err = ParseOptFQDN(optData) case OptionBootfileURL: - opt, err = ParseOptBootFileURL(optData) + opt, err = parseOptBootFileURL(optData) case OptionBootfileParam: opt, err = ParseOptBootFileParam(optData) case OptionClientArchType: |