runC 的网络实现开始于 libcontainer/process_linux.go 中func (p *initProcess) start() 调用createNetworkInterfaces()函数
该函数实现如下:
func (p *initProcess) createNetworkInterfaces() error {
for _, config := range p.config.Config.Networks {//遍历所有网络配置
strategy, err := getStrategy(config.Type)//获取网络类别,桥接或者loopback
if err != nil {
return err
}
n := &network{
Network: *config,
}
if err := strategy.create(n, p.pid()); err != nil {//创建网络。参数为网络配置和进程号
return err
}
p.config.Networks = append(p.config.Networks, n)
}
return nil
}
网络的具体实现在 libcontainer/network_linux.go中