Add code review updates

Docker-DCO-1.1-Signed-off-by: Dhammika Pathirana <dhammika@gmail.com> (github: dhammika)
This commit is contained in:
Dhammika Pathirana 2014-07-10 23:25:53 -07:00
parent 2d69029a83
commit a3a4da3822
1 changed files with 9 additions and 22 deletions

View File

@ -22,18 +22,17 @@ const (
SIOC_BRADDBR = 0x89a0 SIOC_BRADDBR = 0x89a0
SIOC_BRDELBR = 0x89a1 SIOC_BRDELBR = 0x89a1
SIOC_BRADDIF = 0x89a2 SIOC_BRADDIF = 0x89a2
SIOC_BRDELIF = 0x89a3
) )
var nextSeqNr uint32 var nextSeqNr uint32
type ifreqHwaddr struct { type ifreqHwaddr struct {
IfrnName [16]byte IfrnName [IFNAMSIZ]byte
IfruHwaddr syscall.RawSockaddr IfruHwaddr syscall.RawSockaddr
} }
type ifreqIndex struct { type ifreqIndex struct {
IfrnName [16]byte IfrnName [IFNAMSIZ]byte
IfruIndex int32 IfruIndex int32
} }
@ -905,14 +904,10 @@ func NetworkCreateVethPair(name1, name2 string) error {
// Create the actual bridge device. This is more backward-compatible than // Create the actual bridge device. This is more backward-compatible than
// netlink.NetworkLinkAdd and works on RHEL 6. // netlink.NetworkLinkAdd and works on RHEL 6.
func CreateBridge(name string, setMacAddr bool) error { 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 { if err != nil {
return err return err
} }
}
defer syscall.Close(s) defer syscall.Close(s)
nameBytePtr, err := syscall.BytePtrFromString(name) nameBytePtr, err := syscall.BytePtrFromString(name)
@ -930,14 +925,10 @@ func CreateBridge(name string, setMacAddr bool) error {
// Delete the actual bridge device. // Delete the actual bridge device.
func DeleteBridge(name string) error { 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 { if err != nil {
return err return err
} }
}
defer syscall.Close(s) defer syscall.Close(s)
nameBytePtr, err := syscall.BytePtrFromString(name) nameBytePtr, err := syscall.BytePtrFromString(name)
@ -946,7 +937,7 @@ func DeleteBridge(name string) error {
} }
var ifr ifreqFlags 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), if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s),
syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifr))); err != 0 { syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifr))); err != 0 {
return err return err
@ -962,14 +953,10 @@ func DeleteBridge(name string) error {
// Add a slave to abridge device. This is more backward-compatible than // Add a slave to abridge device. This is more backward-compatible than
// netlink.NetworkSetMaster and works on RHEL 6. // netlink.NetworkSetMaster and works on RHEL 6.
func AddToBridge(iface, master *net.Interface) error { 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 { if err != nil {
return err return err
} }
}
defer syscall.Close(s) defer syscall.Close(s)
ifr := ifreqIndex{} ifr := ifreqIndex{}