Skip to content

Commit

Permalink
fix mac conflict (#4095)
Browse files Browse the repository at this point in the history
Signed-off-by: oilbeater <liumengxinfly@gmail.com>
  • Loading branch information
oilbeater authored and bobz965 committed May 28, 2024
1 parent 8cfbf71 commit 6505e61
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/util/net.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,17 @@ const (
)

// GenerateMac generates mac address.
// Refer from https://github.com/cilium/cilium/blob/8c7e442ccd48b9011a10f34a128ec98751d9a80e/pkg/mac/mac.go#L106
func GenerateMac() string {
prefix := "00:00:00"
b := make([]byte, 3)
_, err := rand.Read(b)
if err != nil {
klog.Errorf("generate mac error: %v", err)
buf := make([]byte, 6)
if _, err := rand.Read(buf); err != nil {
klog.Errorf("Unable to retrieve 6 rnd bytes: %v", err)
}

mac := fmt.Sprintf("%s:%02X:%02X:%02X", prefix, b[0], b[1], b[2])
return mac
// Set locally administered addresses bit and reset multicast bit
buf[0] = (buf[0] | 0x02) & 0xfe

return net.HardwareAddr(buf).String()
}

func IP2BigInt(ipStr string) *big.Int {
Expand Down

0 comments on commit 6505e61

Please sign in to comment.