From 663b9649d37a2d0f2bdae4134ba55ed36e97ba3f Mon Sep 17 00:00:00 2001 From: Vladimir Pouzanov Date: Wed, 18 Jun 2014 21:07:31 +0100 Subject: [PATCH] setBridgeMacAddress ARM support --- pkg/netlink/netlink_linux.go | 19 ------------------- pkg/netlink/setbridgemacaddress_amd64.go | 27 +++++++++++++++++++++++++++ pkg/netlink/setbridgemacaddress_arm.go | 27 +++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 19 deletions(-) create mode 100644 pkg/netlink/setbridgemacaddress_amd64.go create mode 100644 pkg/netlink/setbridgemacaddress_arm.go diff --git a/pkg/netlink/netlink_linux.go b/pkg/netlink/netlink_linux.go index 14e30aa..12aee4d 100644 --- a/pkg/netlink/netlink_linux.go +++ b/pkg/netlink/netlink_linux.go @@ -5,7 +5,6 @@ package netlink import ( "encoding/binary" "fmt" - "math/rand" "net" "sync/atomic" "syscall" @@ -944,21 +943,3 @@ func AddToBridge(iface, master *net.Interface) error { return nil } - -func setBridgeMacAddress(s int, name string) error { - ifr := ifreqHwaddr{} - ifr.IfruHwaddr.Family = syscall.ARPHRD_ETHER - copy(ifr.IfrnName[:], name) - - for i := 0; i < 6; i++ { - ifr.IfruHwaddr.Data[i] = int8(rand.Intn(255)) - } - - ifr.IfruHwaddr.Data[0] &^= 0x1 // clear multicast bit - ifr.IfruHwaddr.Data[0] |= 0x2 // set local assignment bit (IEEE802) - - if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), syscall.SIOCSIFHWADDR, uintptr(unsafe.Pointer(&ifr))); err != 0 { - return err - } - return nil -} diff --git a/pkg/netlink/setbridgemacaddress_amd64.go b/pkg/netlink/setbridgemacaddress_amd64.go new file mode 100644 index 0000000..dea7e1a --- /dev/null +++ b/pkg/netlink/setbridgemacaddress_amd64.go @@ -0,0 +1,27 @@ +// +build amd64 + +package netlink + +import ( + "math/rand" + "syscall" + "unsafe" +) + +func setBridgeMacAddress(s int, name string) error { + ifr := ifreqHwaddr{} + ifr.IfruHwaddr.Family = syscall.ARPHRD_ETHER + copy(ifr.IfrnName[:], name) + + for i := 0; i < 6; i++ { + ifr.IfruHwaddr.Data[i] = int8(rand.Intn(255)) + } + + ifr.IfruHwaddr.Data[0] &^= 0x1 // clear multicast bit + ifr.IfruHwaddr.Data[0] |= 0x2 // set local assignment bit (IEEE802) + + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), syscall.SIOCSIFHWADDR, uintptr(unsafe.Pointer(&ifr))); err != 0 { + return err + } + return nil +} diff --git a/pkg/netlink/setbridgemacaddress_arm.go b/pkg/netlink/setbridgemacaddress_arm.go new file mode 100644 index 0000000..f5e116e --- /dev/null +++ b/pkg/netlink/setbridgemacaddress_arm.go @@ -0,0 +1,27 @@ +// +build arm + +package netlink + +import ( + "math/rand" + "syscall" + "unsafe" +) + +func setBridgeMacAddress(s int, name string) error { + ifr := ifreqHwaddr{} + ifr.IfruHwaddr.Family = syscall.ARPHRD_ETHER + copy(ifr.IfrnName[:], name) + + for i := 0; i < 6; i++ { + ifr.IfruHwaddr.Data[i] = uint8(rand.Intn(128)) + } + + ifr.IfruHwaddr.Data[0] &^= 0x1 // clear multicast bit + ifr.IfruHwaddr.Data[0] |= 0x2 // set local assignment bit (IEEE802) + + if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), syscall.SIOCSIFHWADDR, uintptr(unsafe.Pointer(&ifr))); err != 0 { + return err + } + return nil +} -- 1.8.5.2