Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing hardwareAddr in uuid v1 generation #10005

Merged
merged 1 commit into from
Jul 9, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions uuid/uuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,35 @@ package uuid // import "github.com/influxdata/influxdb/uuid"
import (
"sync/atomic"
"time"
"net"
"crypto/rand"
)

// UUID - unique identifier type representing a 128 bit number
type UUID [16]byte

var timeBase = time.Date(1582, time.October, 15, 0, 0, 0, 0, time.UTC).Unix()
var hardwareAddr []byte
var hardwareAddr [6]byte = hwAddrFunc()
var clockSeq uint32

func hwAddrFunc() [6]byte {
u := [6]byte{}

ifaces, err := net.Interfaces()
if err != nil {
rand.Reader.Read(u[:])
return u
}
for _, iface := range ifaces {
if len(iface.HardwareAddr) >= 6 {
copy(u[:], iface.HardwareAddr)
return u
}
}
rand.Reader.Read(u[:])
return u
}

// TimeUUID generates a new time based UUID (version 1) using the current
// time as the timestamp.
func TimeUUID() UUID {
Expand All @@ -68,7 +88,7 @@ func FromTime(aTime time.Time) UUID {
u[8] = byte(clock >> 8)
u[9] = byte(clock)

copy(u[10:], hardwareAddr)
copy(u[10:], hardwareAddr[:])

u[6] |= 0x10 // set version to 1 (time based uuid)
u[8] &= 0x3F // clear variant
Expand Down