diff options
author | Andrea Barberio <insomniac@slackware.it> | 2017-12-10 16:31:02 +0000 |
---|---|---|
committer | Andrea Barberio <insomniac@slackware.it> | 2017-12-10 16:31:02 +0000 |
commit | 78200b484e408d3e7efae04a3b6cdaaccbaff29f (patch) | |
tree | ea617bbb8d820e171698f61e22d7cf57b2de113a /dhcpv6 | |
parent | 4e5c63276c39898c4bb3662ed0f24f1d938ef3a1 (diff) |
Added GetOption, GetOneOption and IsRelay methods to DHCPv6 interface
Diffstat (limited to 'dhcpv6')
-rw-r--r-- | dhcpv6/dhcpv6.go | 24 | ||||
-rw-r--r-- | dhcpv6/dhcpv6message.go | 12 | ||||
-rw-r--r-- | dhcpv6/dhcpv6relay.go | 11 |
3 files changed, 47 insertions, 0 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go index 9b6ef5c..146687a 100644 --- a/dhcpv6/dhcpv6.go +++ b/dhcpv6/dhcpv6.go @@ -11,6 +11,9 @@ type DHCPv6 interface { String() string Summary() string Length() int + IsRelay() bool + GetOption(code OptionCode) []Option + GetOneOption(code OptionCode) Option } func FromBytes(data []byte) (DHCPv6, error) { @@ -78,3 +81,24 @@ func NewMessage() (*DHCPv6Message, error) { } return &d, nil } + +func getOptions(options []Option, code OptionCode, onlyFirst bool) []Option { + var ret []Option + for _, opt := range options { + if opt.Code() == code { + ret = append(ret, opt) + if onlyFirst { + break + } + } + } + return ret +} + +func getOption(options []Option, code OptionCode) Option { + opts := getOptions(options, code, true) + if opts == nil { + return nil + } + return opts[0] +} diff --git a/dhcpv6/dhcpv6message.go b/dhcpv6/dhcpv6message.go index 93966f7..7151096 100644 --- a/dhcpv6/dhcpv6message.go +++ b/dhcpv6/dhcpv6message.go @@ -190,3 +190,15 @@ func (d *DHCPv6Message) Length() int { func (d *DHCPv6Message) Options() []Option { return d.options } + +func (d *DHCPv6Message) GetOption(code OptionCode) []Option { + return getOptions(d.options, code, false) +} + +func (d *DHCPv6Message) GetOneOption(code OptionCode) Option { + return getOption(d.options, code) +} + +func (d *DHCPv6Message) IsRelay() bool { + return false +} diff --git a/dhcpv6/dhcpv6relay.go b/dhcpv6/dhcpv6relay.go index 716c24f..0423f36 100644 --- a/dhcpv6/dhcpv6relay.go +++ b/dhcpv6/dhcpv6relay.go @@ -72,3 +72,14 @@ func (r *DHCPv6Relay) Length() int { func (r *DHCPv6Relay) Options() []Option { return r.options } +func (r *DHCPv6Relay) GetOption(code OptionCode) []Option { + return getOptions(r.options, code, false) +} + +func (r *DHCPv6Relay) GetOneOption(code OptionCode) Option { + return getOption(r.options, code) +} + +func (r *DHCPv6Relay) IsRelay() bool { + return true +} |