Add netlink hooks to delete a bridge dev
Signed-off-by: Dhammika Pathirana <dhammika@gmail.com> Docker-DCO-1.1-Signed-off-by: Dhammika Pathirana <dhammika@gmail.com> (github: dhammika)
This commit is contained in:
parent
b325827144
commit
2d69029a83
|
@ -20,7 +20,9 @@ const (
|
|||
VETH_INFO_PEER = 1
|
||||
IFLA_NET_NS_FD = 28
|
||||
SIOC_BRADDBR = 0x89a0
|
||||
SIOC_BRDELBR = 0x89a1
|
||||
SIOC_BRADDIF = 0x89a2
|
||||
SIOC_BRDELIF = 0x89a3
|
||||
)
|
||||
|
||||
var nextSeqNr uint32
|
||||
|
@ -35,6 +37,11 @@ type ifreqIndex struct {
|
|||
IfruIndex int32
|
||||
}
|
||||
|
||||
type ifreqFlags struct {
|
||||
IfrnName [IFNAMSIZ]byte
|
||||
Ifruflags uint16
|
||||
}
|
||||
|
||||
func nativeEndian() binary.ByteOrder {
|
||||
var x uint32 = 0x01020304
|
||||
if *(*byte)(unsafe.Pointer(&x)) == 0x01 {
|
||||
|
@ -921,6 +928,37 @@ func CreateBridge(name string, setMacAddr bool) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// Delete the actual bridge device.
|
||||
func DeleteBridge(name string) error {
|
||||
s, err := syscall.Socket(syscall.AF_INET6, syscall.SOCK_STREAM, syscall.IPPROTO_IP)
|
||||
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
|
||||
}
|
||||
}
|
||||
defer syscall.Close(s)
|
||||
|
||||
nameBytePtr, err := syscall.BytePtrFromString(name)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var ifr ifreqFlags
|
||||
copy(ifr.IfrnName[:], []byte(name))
|
||||
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s),
|
||||
syscall.SIOCSIFFLAGS, uintptr(unsafe.Pointer(&ifr))); err != 0 {
|
||||
return err
|
||||
}
|
||||
|
||||
if _, _, err := syscall.Syscall(syscall.SYS_IOCTL, uintptr(s),
|
||||
SIOC_BRDELBR, uintptr(unsafe.Pointer(nameBytePtr))); err != 0 {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// 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 {
|
||||
|
|
|
@ -67,6 +67,10 @@ func CreateBridge(name string, setMacAddr bool) error {
|
|||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func DeleteBridge(name string) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
||||
func AddToBridge(iface, master *net.Interface) error {
|
||||
return ErrNotImplemented
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue