network

package
v0.0.0-...-3ea5cda Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 10, 2022 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanAddr

func CleanAddr(dev netlink.Link)

清空一个设备的所有地址

func CreateNamespace

func CreateNamespace() int

创建一个新的网络命名空间并返回其 fd,当前进程依然留在原命名空间中 原理在于切换当前进程的命名空间并不会影响已打开的文件描述符 所以当前进程就可以根据这些打开的描述符在不同命名空间中反复横跳 fd 的关闭由调用方接管

func EnterNamespaceByFd

func EnterNamespaceByFd(fd int)

func Init

func Init()

func InitBridge

func InitBridge()

初始化网桥设备,如果不存在则创建,否则更新其地址并将其启动

func SetDefaultRoute

func SetDefaultRoute(via net.IP, dev *Device)

设置默认路由

func SetupLookback

func SetupLookback()

启动 loopback 设备

Types

type Device

type Device struct {
	// contains filtered or unexported fields
}
var Bridge *Device

func GetOrCreateBridge

func GetOrCreateBridge(name string) *Device

获取或创建一个网桥

func (*Device) GetIP

func (d *Device) GetIP() net.IP

返回设备的 ip

func (*Device) SetAddress

func (d *Device) SetAddress(cidr string)

为设备设置地址

func (*Device) SetMaster

func (d *Device) SetMaster(master *Device)

设置主设备,这里用于连接网桥

func (*Device) SetNamespace

func (d *Device) SetNamespace(nsFd int)

根据 fd 设置设备的网络命名空间

func (*Device) SetUp

func (d *Device) SetUp()

启动设备

type VethPair

type VethPair struct {
	HostPeer *Device // 宿主机的一端
	CntrPeer *Device // 容器的一端
}

func CreateVethPairFor

func CreateVethPairFor(containerID string) *VethPair

创建 containerID 对应的容器要使用的 veth pair 设备

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL