summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--dhcpv6/dhcpv6.go10
-rw-r--r--dhcpv6/option_nontemporaryaddress.go5
-rw-r--r--dhcpv6/option_nontemporaryaddress_test.go19
3 files changed, 34 insertions, 0 deletions
diff --git a/dhcpv6/dhcpv6.go b/dhcpv6/dhcpv6.go
index 7a53b90..d8427ea 100644
--- a/dhcpv6/dhcpv6.go
+++ b/dhcpv6/dhcpv6.go
@@ -117,6 +117,16 @@ func getOption(options []Option, code OptionCode) Option {
return opts[0]
}
+func delOption(options []Option, code OptionCode) []Option {
+ newOpts := make([]Option, 0, len(options))
+ for _, opt := range options {
+ if opt.Code() != code {
+ newOpts = append(newOpts, opt)
+ }
+ }
+ return newOpts
+}
+
// DecapsulateRelay extracts the content of a relay message. It does not recurse
// if there are nested relay messages. Returns the original packet if is not not
// a relay message
diff --git a/dhcpv6/option_nontemporaryaddress.go b/dhcpv6/option_nontemporaryaddress.go
index cefca64..9f91b18 100644
--- a/dhcpv6/option_nontemporaryaddress.go
+++ b/dhcpv6/option_nontemporaryaddress.go
@@ -45,6 +45,11 @@ func (op *OptIANA) String() string {
op.IaId, op.T1, op.T2, op.Options)
}
+// DelOption will remove all the options that match a Option code.
+func (op *OptIANA) DelOption(code OptionCode) {
+ op.Options = delOption(op.Options, code)
+}
+
// build an OptIANA structure from a sequence of bytes.
// The input data does not include option code and length bytes.
func ParseOptIANA(data []byte) (*OptIANA, error) {
diff --git a/dhcpv6/option_nontemporaryaddress_test.go b/dhcpv6/option_nontemporaryaddress_test.go
index 4d87122..a9e7087 100644
--- a/dhcpv6/option_nontemporaryaddress_test.go
+++ b/dhcpv6/option_nontemporaryaddress_test.go
@@ -39,6 +39,25 @@ func TestOptIANAParseOptIANAInvalidOptions(t *testing.T) {
require.Error(t, err)
}
+func TestOptIANADelOption(t *testing.T) {
+ optiana1 := OptIANA{}
+ optiana2 := OptIANA{}
+ optiaaddr := OptIAAddress{}
+ optsc := OptStatusCode{}
+
+ optiana1.Options = append(optiana1.Options, &optsc)
+ optiana1.Options = append(optiana1.Options, &optiaaddr)
+ optiana1.Options = append(optiana1.Options, &optiaaddr)
+ optiana1.DelOption(OPTION_IAADDR)
+ require.Equal(t, optiana1.Options, []Option{&optsc})
+
+ optiana2.Options = append(optiana2.Options, &optiaaddr)
+ optiana2.Options = append(optiana2.Options, &optsc)
+ optiana2.Options = append(optiana2.Options, &optiaaddr)
+ optiana2.DelOption(OPTION_IAADDR)
+ require.Equal(t, optiana2.Options, []Option{&optsc})
+}
+
func TestOptIANAToBytes(t *testing.T) {
opt := OptIANA{
IaId: [4]byte{1, 2, 3, 4},