summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv6')
-rw-r--r--dhcpv6/dhcpv6.go24
-rw-r--r--dhcpv6/dhcpv6message.go12
-rw-r--r--dhcpv6/dhcpv6relay.go11
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
+}