summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/duid.go
diff options
context:
space:
mode:
authorChris Koch <chrisko@google.com>2023-02-19 11:32:54 -0800
committerChris K <c@chrisko.ch>2023-02-19 13:39:52 -0800
commit223c67f573a916a45313dd6c17013e2ea804ce2a (patch)
tree92ebb00d6ce98ff2d8f97174358ec5915a728950 /dhcpv6/duid.go
parent93dbaf95ae931da311e1671fd0f470f2aa5f6980 (diff)
dhcpv6 DUID: re-add Equal function
Signed-off-by: Chris Koch <chrisko@google.com>
Diffstat (limited to 'dhcpv6/duid.go')
-rw-r--r--dhcpv6/duid.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/dhcpv6/duid.go b/dhcpv6/duid.go
index fcd785d..027c6b0 100644
--- a/dhcpv6/duid.go
+++ b/dhcpv6/duid.go
@@ -1,6 +1,7 @@
package dhcpv6
import (
+ "bytes"
"fmt"
"net"
@@ -15,6 +16,7 @@ type DUID interface {
ToBytes() []byte
FromBytes(p []byte) error
DUIDType() DUIDType
+ Equal(d DUID) bool
}
// DUIDLLT is a DUID based on link-layer address plus time (RFC 8415 Section 11.2).
@@ -53,6 +55,15 @@ func (d *DUIDLLT) FromBytes(p []byte) error {
return buf.FinError()
}
+// Equal returns true if e is a DUID-LLT with the same values as d.
+func (d *DUIDLLT) Equal(e DUID) bool {
+ ellt, ok := e.(*DUIDLLT)
+ if !ok {
+ return false
+ }
+ return d.HWType == ellt.HWType && d.Time == ellt.Time && bytes.Equal(d.LinkLayerAddr, ellt.LinkLayerAddr)
+}
+
// DUIDLL is a DUID based on link-layer (RFC 8415 Section 11.4).
type DUIDLL struct {
HWType iana.HWType
@@ -86,6 +97,15 @@ func (d *DUIDLL) FromBytes(p []byte) error {
return buf.FinError()
}
+// Equal returns true if e is a DUID-LL with the same values as d.
+func (d *DUIDLL) Equal(e DUID) bool {
+ ell, ok := e.(*DUIDLL)
+ if !ok {
+ return false
+ }
+ return d.HWType == ell.HWType && bytes.Equal(d.LinkLayerAddr, ell.LinkLayerAddr)
+}
+
// DUIDEN is a DUID based on enterprise number (RFC 8415 Section 11.3).
type DUIDEN struct {
EnterpriseNumber uint32
@@ -119,6 +139,15 @@ func (d *DUIDEN) FromBytes(p []byte) error {
return buf.FinError()
}
+// Equal returns true if e is a DUID-EN with the same values as d.
+func (d *DUIDEN) Equal(e DUID) bool {
+ en, ok := e.(*DUIDEN)
+ if !ok {
+ return false
+ }
+ return d.EnterpriseNumber == en.EnterpriseNumber && bytes.Equal(d.EnterpriseIdentifier, en.EnterpriseIdentifier)
+}
+
// DUIDUUID is a DUID based on UUID (RFC 8415 Section 11.5).
type DUIDUUID struct {
// Defined by RFC 6355.
@@ -191,6 +220,15 @@ func (d *DUIDOpaque) FromBytes(p []byte) error {
return nil
}
+// Equal returns true if e is an opaque DUID with the same values as d.
+func (d *DUIDOpaque) Equal(e DUID) bool {
+ eopaque, ok := e.(*DUIDOpaque)
+ if !ok {
+ return false
+ }
+ return d.Type == eopaque.Type && bytes.Equal(d.Data, eopaque.Data)
+}
+
// DUIDType is the DUID type as defined in RFC 3315.
type DUIDType uint16