summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/duid.go
diff options
context:
space:
mode:
authorMichael Stapelberg <stapelberg@users.noreply.github.com>2018-06-11 14:15:37 +0200
committerinsomniac <insomniacslk@users.noreply.github.com>2018-06-11 13:15:37 +0100
commit5be287562fa0c968908d8d908cb695db880dfec4 (patch)
tree63d2907a107aea720817553a75e70ca3c26fbb7d /dhcpv6/duid.go
parent5717652a33b34ce6ee9a9e89602b4eb323cea4af (diff)
Pass through unknown DUIDs (#71)
I’m building on a program which works with user-supplied DUIDs. Before this change, the code would panic when users provide a DUID which is not (yet) implemented. In addition to this being a better failure mode, the behavior is also mandated by the DHCPv6 RFC: https://tools.ietf.org/html/rfc3315#section-9 states: Clients and servers MUST treat DUIDs as opaque values and MUST only compare DUIDs for equality.
Diffstat (limited to 'dhcpv6/duid.go')
-rw-r--r--dhcpv6/duid.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/dhcpv6/duid.go b/dhcpv6/duid.go
index 22529c2..36da9cd 100644
--- a/dhcpv6/duid.go
+++ b/dhcpv6/duid.go
@@ -33,6 +33,7 @@ type Duid struct {
EnterpriseNumber uint32 // for DUID-EN. Ignored otherwise
EnterpriseIdentifier []byte // for DUID-EN. Ignored otherwise
Uuid []byte // for DUID-UUID. Ignored otherwise
+ Opaque []byte // for unknown DUIDs
}
func (d *Duid) Length() int {
@@ -44,8 +45,9 @@ func (d *Duid) Length() int {
return 6 + len(d.EnterpriseIdentifier)
} else if d.Type == DUID_UUID {
return 18
+ } else {
+ return 2 + len(d.Opaque)
}
- panic(fmt.Sprintf("Unknown DUID type: %v", d.Type))
}
func (d *Duid) ToBytes() []byte {
@@ -69,8 +71,11 @@ func (d *Duid) ToBytes() []byte {
buf := make([]byte, 2)
binary.BigEndian.PutUint16(buf[0:2], uint16(d.Type))
return append(buf, d.Uuid...)
+ } else {
+ buf := make([]byte, 2)
+ binary.BigEndian.PutUint16(buf[0:2], uint16(d.Type))
+ return append(buf, d.Opaque...)
}
- panic(fmt.Sprintf("Unknown DUID type: %v", d.Type))
}
func (d *Duid) String() string {
@@ -124,6 +129,8 @@ func DuidFromBytes(data []byte) (*Duid, error) {
return nil, fmt.Errorf("Invalid DUID-UUID length. Expected 18, got %v", len(data))
}
d.Uuid = data[2:18]
+ } else {
+ d.Opaque = data[2:]
}
return &d, nil
}