Skip to content

Commit 3831038

Browse files
authored
Fix two iid issues (#4)
- MakeEUI64Addr() requires a net.HardwareAddr as input and it was modifying that variable in-place before using the result. This modified it for the caller as well - not strictly a bug but GenerateRFC7217Addr() in the iid package used 'iid' as a variable, which seemed dangerous or at least inadvisable. This has been changed
1 parent 353c0b3 commit 3831038

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

iid/iid.go

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -158,20 +158,20 @@ func GenerateRFC7217Addr(ip net.IP, hw net.HardwareAddr, counter int64, netid, s
158158

159159
f := htype.New()
160160

161-
iid := make([]byte, 16)
162-
copy(iid, ip)
161+
ipiid := make([]byte, 16)
162+
copy(ipiid, ip)
163163

164164
f.Write(bs)
165165
rid := f.Sum(nil)
166166
rid = setScopeBit(rid, scope)
167167

168-
copy(iid[8:], rid[0:8])
168+
copy(ipiid[8:], rid[0:8])
169169

170-
if r := GetReservationsForIP(iid); r != nil {
170+
if r := GetReservationsForIP(ipiid); r != nil {
171171
return nil, ErrIIDAddressCollision
172172
}
173173

174-
return iid, nil
174+
return ipiid, nil
175175
}
176176

177177
// GetReservationsForIP returns a list of any IANA reserved networks that
@@ -219,11 +219,14 @@ func MakeEUI64Addr(ip net.IP, hw net.HardwareAddr, scope Scope) net.IP {
219219
eui64 := make([]byte, 16)
220220
copy(eui64, ip)
221221

222-
if len(hw) == 6 {
223-
hw = append(hw[:3], append(tag, hw[3:]...)...)
222+
hwi := make([]byte, len(hw))
223+
copy(hwi, hw)
224+
225+
if len(hwi) == 6 {
226+
hwi = append(hwi[:3], append(tag, hwi[3:]...)...)
224227
}
225228

226-
copy(eui64[8:], hw)
229+
copy(eui64[8:], hwi)
227230
return setScopeBit(eui64, scope)
228231
}
229232

0 commit comments

Comments
 (0)