diff options
author | Christopher Koch <chrisko@google.com> | 2019-01-10 13:16:42 -0800 |
---|---|---|
committer | insomniac <insomniacslk@users.noreply.github.com> | 2019-01-10 23:01:22 +0000 |
commit | 512011c2eb80a7c0316405ef7aaae6e0b5b09b1c (patch) | |
tree | e12cdbfa20d212059004efa9efc1cb4a7432ac20 /dhcpv4/dhcpv4.go | |
parent | e87114a6e449d7a2e458b5529923e5668dfa3a11 (diff) |
dhcpv4: remote OptionGetter interface in favor of Options type.
Diffstat (limited to 'dhcpv4/dhcpv4.go')
-rw-r--r-- | dhcpv4/dhcpv4.go | 47 |
1 files changed, 2 insertions, 45 deletions
diff --git a/dhcpv4/dhcpv4.go b/dhcpv4/dhcpv4.go index 2f832e8..98f0eae 100644 --- a/dhcpv4/dhcpv4.go +++ b/dhcpv4/dhcpv4.go @@ -367,45 +367,14 @@ func (d *DHCPv4) SetUnicast() { // According to RFC 3396, options that are specified more than once are // concatenated, and hence this should always just return one option. func (d *DHCPv4) GetOption(code OptionCode) []Option { - return d.Options.GetOption(code) + return d.Options.Get(code) } // GetOneOption will attempt to get an option that match a Option code. // If there are multiple options with the same OptionCode it will only return // the first one found. If no matching option is found nil will be returned. func (d *DHCPv4) GetOneOption(code OptionCode) Option { - return d.Options.GetOneOption(code) -} - -// Options is a collection of options. -type Options []Option - -// GetOption will attempt to get all options that match a DHCPv4 option -// from its OptionCode. If the option was not found it will return an -// empty list. -// -// According to RFC 3396, options that are specified more than once are -// concatenated, and hence this should always just return one option. -func (o Options) GetOption(code OptionCode) []Option { - opts := []Option{} - for _, opt := range o { - if opt.Code() == code { - opts = append(opts, opt) - } - } - return opts -} - -// GetOneOption will attempt to get an option that match a Option code. -// If there are multiple options with the same OptionCode it will only return -// the first one found. If no matching option is found nil will be returned. -func (o Options) GetOneOption(code OptionCode) Option { - for _, opt := range o { - if opt.Code() == code { - return opt - } - } - return nil + return d.Options.GetOne(code) } // AddOption appends an option to the existing ones. If the last option is an @@ -590,15 +559,3 @@ func (d *DHCPv4) ToBytes() []byte { } return buf.Data() } - -// OptionGetter is a interface that knows how to retrieve an option from a -// structure of options given an OptionCode. -type OptionGetter interface { - GetOption(OptionCode) []Option - GetOneOption(OptionCode) Option -} - -// HasOption checks whether the OptionGetter `o` has the given `opcode` Option. -func HasOption(o OptionGetter, opcode OptionCode) bool { - return o.GetOneOption(opcode) != nil -} |