Docker Libnetwork Bridge插件实现代码分析----初始化部分
Bridge driver数据结构如下所示:
type driver struct {
config *configuration
network *bridgeNetwork
natChain *iptables.ChainInfo
filterChain *iptables.ChainInfo
isolationChain *iptables.ChainInfo
networks map[string]*bridgeNetwork
store datastore.DataStore
nlh *netlink.Handle
sync.Mutex
}
// driver/bridge/bridge.go
// Init registers a new instance of bridge driver
1、func Init(dc driverapi.DriverCallback, config map[string]interface{})
- 调用d := newDriver(),初始化driver数据结构
- 调用d.configure(config)对driver进行配置
- 创建c := driverapi.Capability{DataScope: datastore.LocalScope}
- 调用return dc.RegisterDriver(networkType, d, c)
configure数据结构如下所示:
// configuration info for the "bridge" driver
type configuration struct {
EnableIPForwarding bool
EnableIPTables bool
EnableUserlandProxy bool
UserlandProxyPath string
}
// driver/bridge/bridge.go
2、func (d *driver) configure(option map[string]interface{}) error
- 首先从option中解析出config
- 若config.EnableIPTables为真,则先调用removeIPChains(),再调用netChain, filterChain, isolationChain, err = setupIPChain(config)获取各个chain,最后,调用iptables.OnReloaded(func() {logrus.Debugf("Recreating iptables chains on firewall reloaded"); setupIPChain(config)})
- 若config.EnableIPForwarding为真,则调用setupIPForwarding(config.EnableIPTables)
- 接着对d.natChain,d.filterChain,d.isolationChain和d.config分别进行赋值
- 调用err = d.initStore(option)
--------------------------------------------------------- IPTables 配置 --------------------------------------------------------------------
// driver/bridge/setup_ip_tables.go
3、func setupIPChain(config *configuration) (*iptables.ChainInfo, *iptables.ChainInfo, *iptables.ChainInfo, error)
- 设置hairpinMode := !config.EnableUserlanProxy
- 调用netChain, err := iptables.NewChain(DockerChain, iptables.Nat, hairpinMode)
- 调用filterChain, err := iptables.NewChain(DockerChain, iptables.Filter, false),对于isolationChain的调用完全相同
- 调用err := addReturnRule(IsolationChain) ---->为该chain添加返回规则`iptables -I chain -j RETURN`
此函数只是创建了三个chain的实例,并将它们添加到主机中
// iptables/iptables.go
// NewChain adds a new chain to ip tables.
4、func NewChain(name string, table Table, hairpinMode bool) (*ChainInfo, error)
- 用参数填充c := &ChainInfo{},若table为空,则默认置为Filter
- 调用Raw("-t", string(c.Table), "-n", "-L", c.Name)和output, err := Raw("-t", string(c.Table), "-N", c.Name)添加chain,如果不存在的话,Raw函数直接调用iptables系统命令
ChainInfo数据结构如下所示:
// ChainInfo defines the iptables chain
type ChainInfo struct {
Name string
Table Table
HairpinMode bool
}
--------------------------------------------------- IP Forward 配置 ----------------------------------------------------
// driver/bridge/set_ip_forwarding.go
5、func setupIPForwarding(enableIPTables bool) error
- 首先调用ipv4ForwardData, err := ioutil.ReadFile(ipv4ForwardConf)获取当前IPv4 forward的状态,其中ipv4ForwardConf=/proc/sys/net/ipv4/ip_forward
- 若ipv4ForwardData[0]不为'1',则调用configureIPForwarding(true),其实就是将ipv4ForwardConf内容写为'1'
- 如果enableIPTables为假,则返回,否则调用iptables.SetDefaultPolicy(iptables.Filter, "FORWARDING", iptables.Drop),并且接着调用iptables.OnReloaded(..)
Docker Libnetwork Bridge插件实现代码分析----初始化部分的更多相关文章
- Docker Libnetwork Bridge插件实现代码分析----创建网络部分
// drivers/bridge/bridge.go // Create a new network using bridge plugin 1.func (d *driver) CreateNet ...
- CNI bridge 插件实现代码分析
对于每个CNI 插件在执行函数cmdAdd之前的操作是完全一样的,即从环境变量和标准输入内读取配置.这在http://www.cnblogs.com/YaoDD/p/6410725.html这篇博文里 ...
- 使用 Gradle 插件进行代码分析(转)
代码分析在大多数项目中通常是作为最后一个步骤(如果做了的话)完成的.其通常难以配置及与现有代码整合. 本文旨在勾勒出使用 Gradle 整合 PMD 与 FindBugs 的步骤,并将其与一个现有的 ...
- Eclipse插件(导出UML图,打开文件资源管理器插件,静态代码分析工具PMD,在eclipse上安装插件)
目录 能够导出UML图的Eclipse插件 打开文件资源管理器插件 Java静态代码分析工具PMD 如何在eclipse上安装插件 JProfiler性能分析工具 从更新站点安装EclEmma 能够导 ...
- jQuery File Upload 插件 php代码分析
jquery file upload php代码分析首先进入构造方法 __construct() 再进入 initialize()因为我是post方式传的数据 在进入initialize()中的po ...
- 【DWM1000】 code 解密2一 工程初始化代码分析
instance_init 函数追下去,绝大多数的代码都在初始化如下结构体 typedef struct { INST_MODE mode; instance_init -ANCHOR //insta ...
- 完整全面的Java资源库(包括构建、操作、代码分析、编译器、数据库、社区等等)
构建 这里搜集了用来构建应用程序的工具. Apache Maven:Maven使用声明进行构建并进行依赖管理,偏向于使用约定而不是配置进行构建.Maven优于Apache Ant.后者采用了一种过程化 ...
- 常用 Java 静态代码分析工具的分析与比较
常用 Java 静态代码分析工具的分析与比较 简介: 本文首先介绍了静态代码分析的基 本概念及主要技术,随后分别介绍了现有 4 种主流 Java 静态代码分析工具 (Checkstyle,FindBu ...
- lighttpd与fastcgi+cgilua原理、代码分析与安装
原理 http://www.cnblogs.com/skynet/p/4173450.html 快速通用网关接口(Fast Common Gateway Interface/FastCGI)是通用网关 ...
随机推荐
- Xcode5下使用纯代码构建简单的HelloWorld程序
转自:http://blog.csdn.net/developerxyf/article/details/12874935 新发布的Xcode5在使用模板创建工程的时候取消了以往是否要选择storyb ...
- myeclipse修改jsp文件的名称之后,再也打不开的解决方案
方案一.重启myEclipse 方案二. 删除对应workspace目录下 “.metadata\.plugins\org.eclipse.jst.jsp.core\jspsearch” 里的 *.i ...
- 李洪强iOS开发之iOS社区收集
李洪强iOS开发之iOS社区收集 项目 简述 github 全球最大的代码仓库,无论是iOS开发还是Android开发没有人不知道这个网站,它也是一个社区,你可以去follow(关注)某些人或公司. ...
- SpringBoot+Shiro引起事务失效、错误原因、解决方法
一.问题今天发现用户注册的Service的事务并没有起到作用,再抛出一个RuntimeException后,并没有发生回滚,下面是调试步骤: 1.检查数据库的引擎是否是innoDB 2.启动类上是否加 ...
- 有效提升大数据量写入excel的效率
在开发过程中经常会有需要将数据导出到 excel 的需求,当数据量很大,达到几万甚至几十万.几百万级别的时候,如何加快生成 excel 的速度呢?首先普及一下知识背景:Excel2003 及以下版本一 ...
- Missing artifact javax.transaction:jta:jar:1.0.1B解决办法
maven库中缺少了这个jar,需要把这个jar安装到本地库中去. 1.下载包含此jar的zip包,地址: http://download.csdn.net/detail/spring123tt/68 ...
- Vmware虚拟机修改静态IP无法ping外网,以及eth0不见问题解决
1. 修改静态地址后发现无法ping外网 要先把/etc/sysconfig/network-scripts/ifcfg-eth0中的网关设置成192.168.230.2. 需要设置网关 sudo r ...
- yum命令具体解释
yum(全称为 Yellow dog Updater, Modified)是一个在Fedora和RedHat以及SUSE中的Shell前端软件包管理器. 基於RPM包管理.可以从指定的server自己 ...
- 集群下使用redis统一session处理
pom依赖(快照版): <dependency> <groupId>org.springframework.session</groupId> <artifa ...
- .NET中二进制图片的存储与读取
判断HttpContext是否为空: string configPath = "img/defaultPhoto.png"; if (HttpContext.Current != ...