From a3a4da3822e88ea38b18c6f0e1fb0daabcacc749 Mon Sep 17 00:00:00 2001 From: Dhammika Pathirana Date: Thu, 10 Jul 2014 23:25:53 -0700 Subject: [PATCH] Add code review updates Docker-DCO-1.1-Signed-off-by: Dhammika Pathirana (github: dhammika) --- netlink/netlink_linux.go | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/netlink/netlink_linux.go b/netlink/netlink_linux.go index f5018404..e01496ed 100644 --- a/netlink/netlink_linux.go +++ b/netlink/netlink_linux.go @@ -22,18 +22,17 @@ const ( SIOC_BRADDBR = 0x89a0 SIOC_BRDELBR = 0x89a1 SIOC_BRADDIF = 0x89a2 - SIOC_BRDELIF = 0x89a3 ) var nextSeqNr uint32 type ifreqHwaddr struct { - IfrnName [16]byte + IfrnName [IFNAMSIZ]byte IfruHwaddr syscall.RawSockaddr } type ifreqIndex struct { - IfrnName [16]byte + IfrnName [IFNAMSIZ]byte IfruIndex int32 } @@ -905,13 +904,9 @@ func NetworkCreateVethPair(name1, name2 string) error { // Create the actual bridge device. This is more backward-compatible than // netlink.NetworkLinkAdd and works on RHEL 6. func CreateBridge(name string, setMacAddr bool) error { - s, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_IP) + s, err := getIfSocket() if err != nil { - // ipv6 issue, creating with ipv4 - s, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_IP) - if err != nil { - return err - } + return err } defer syscall.Close(s) @@ -930,13 +925,9 @@ func CreateBridge(name string, setMacAddr bool) error { // Delete the actual bridge device. func DeleteBridge(name string) error { - s, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_IP) + s, err := getIfSocket() if err != nil { - // ipv6 issue, creating with ipv4 - s, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_IP) - if err != nil { - return err - } + return err } defer syscall.Close(s) @@ -946,7 +937,7 @@ func DeleteBridge(name string) error { } var ifr ifreqFlags - copy(ifr.IfrnName[:], []byte(name)) + copy(ifr.IfrnName[:len(ifr.IfrnName)-1], []byte(name)) if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s), syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifr))); err != 0 { return err @@ -962,13 +953,9 @@ func DeleteBridge(name string) error { // Add a slave to abridge device. This is more backward-compatible than // netlink.NetworkSetMaster and works on RHEL 6. func AddToBridge(iface, master *net.Interface) error { - s, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_IP) + s, err := getIfSocket() if err != nil { - // ipv6 issue, creating with ipv4 - s, err = syscall.Socket(syscall.AF_INET, syscall.SOCK_STREAM, syscall.IPPROTO_IP) - if err != nil { - return err - } + return err } defer syscall.Close(s)