summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAndrea Barberio <insomniac@slackware.it>2017-12-10 17:37:20 +0000
committerAndrea Barberio <insomniac@slackware.it>2017-12-10 17:37:20 +0000
commit1f2c4839b76dbb92927040bfa51bda70e9cc5b91 (patch)
treeec0cb0d6d69da03ae3f3d163b39adc5c57645098
parent78200b484e408d3e7efae04a3b6cdaaccbaff29f (diff)
Fixed DUID_LL handling
-rw-r--r--dhcpv6/duid.go24
1 files changed, 18 insertions, 6 deletions
diff --git a/dhcpv6/duid.go b/dhcpv6/duid.go
index 59a48a4..e3da8ff 100644
--- a/dhcpv6/duid.go
+++ b/dhcpv6/duid.go
@@ -31,22 +31,28 @@ type Duid struct {
}
func (d *Duid) Length() int {
- if d.Type == DUID_LLT || d.Type == DUID_LL {
+ if d.Type == DUID_LLT {
return 8 + len(d.LinkLayerAddr)
- }
- if d.Type == DUID_EN {
+ } else if d.Type == DUID_LL {
+ return 4 + len(d.LinkLayerAddr)
+ } else if d.Type == DUID_EN {
return 6 + len(d.EnterpriseIdentifier)
}
panic(fmt.Sprintf("Unknown DUID type: %v", d.Type))
}
func (d *Duid) ToBytes() []byte {
- if d.Type == DUID_LLT || d.Type == DUID_LL {
+ if d.Type == DUID_LLT {
buf := make([]byte, 8)
binary.BigEndian.PutUint16(buf[0:2], uint16(d.Type))
binary.BigEndian.PutUint16(buf[2:4], uint16(d.HwType))
binary.BigEndian.PutUint32(buf[4:8], d.Time)
return append(buf, d.LinkLayerAddr...)
+ } else if d.Type == DUID_LL {
+ buf := make([]byte, 4)
+ binary.BigEndian.PutUint16(buf[0:2], uint16(d.Type))
+ binary.BigEndian.PutUint16(buf[2:4], uint16(d.HwType))
+ return append(buf, d.LinkLayerAddr...)
} else if d.Type == DUID_EN {
buf := make([]byte, 6)
binary.BigEndian.PutUint16(buf[0:2], uint16(d.Type))
@@ -83,13 +89,19 @@ func DuidFromBytes(data []byte) (*Duid, error) {
}
d := Duid{}
d.Type = DuidType(binary.BigEndian.Uint16(data[0:2]))
- if d.Type == DUID_LLT || d.Type == DUID_LL {
+ if d.Type == DUID_LLT {
if len(data) < 8 {
- return nil, fmt.Errorf("Invalid DUID-LL/LLT: shorter than 8 bytes")
+ return nil, fmt.Errorf("Invalid DUID-LLT: shorter than 8 bytes")
}
d.HwType = iana.HwTypeType(binary.BigEndian.Uint16(data[2:4]))
d.Time = binary.BigEndian.Uint32(data[4:8])
d.LinkLayerAddr = data[8:]
+ } else if d.Type == DUID_LL {
+ if len(data) < 4 {
+ return nil, fmt.Errorf("Invalid DUID-LL: shorter than 4 bytes")
+ }
+ d.HwType = iana.HwTypeType(binary.BigEndian.Uint16(data[2:4]))
+ d.LinkLayerAddr = data[4:]
} else if d.Type == DUID_EN {
if len(data) < 6 {
return nil, fmt.Errorf("Invalid DUID-EN: shorter than 6 bytes")