flannel源码分析--RegisterNetwork

main函数中RegisterNetwork会根据不同的后端类型调用不同的RegisterNetwork,这里以vxlan为例:

  • 定义cfg变量匿名结构体,并使用Unmarshal解析配置文件初始化cfg,结构体如下:

    struct {
    	VNI           int
    	Port          int
    	GBP           bool
    	Learning      bool
    	DirectRouting bool
    }
    
  • 初始化vxlanDeviceAttrs结构体变量devAttrs

    vxlanDeviceAttrs{
    	vni:       uint32(cfg.VNI),
    	name:      fmt.Sprintf("flannel.%v", cfg.VNI),
    	vtepIndex: be.extIface.Iface.Index,
    	vtepAddr:  be.extIface.IfaceAddr,
    	vtepPort:  cfg.Port,
    	gbp:       cfg.GBP,
    	learning:  cfg.Learning,
    }
    
  • 使用newVXLANDevice新建vxlan设备,devAttrs作为参数,完成设备的初始化,vxlan设备结构体如下:

    type vxlanDevice struct {
    	link          *netlink.Vxlan
    	directRouting bool
    }
    
    type Vxlan struct {
    	LinkAttrs
    	VxlanId      int
    	VtepDevIndex int
    	SrcAddr      net.IP
    	Group        net.IP
    	TTL          int
    	TOS          int
    	Learning     bool
    	Proxy        bool
    	RSC          bool
    	L2miss       bool
    	L3miss       bool
    	UDPCSum      bool
    	NoAge        bool
    	GBP          bool
    	Age          int
    	Limit        int
    	Port         int
    	PortLow      int
    	PortHigh     int
    }
    
    type LinkAttrs struct {
    	Index        int
    	MTU          int
    	TxQLen       int // Transmit Queue Length
    	Name         string
    	HardwareAddr net.HardwareAddr
    	Flags        net.Flags
    	RawFlags     uint32
    	ParentIndex  int         // index of the parent link device
    	MasterIndex  int         // must be the index of a bridge
    	Namespace    interface{} // nil | NsPid | NsFd
    	Alias        string
    	Statistics   *LinkStatistics
    	Promisc      int
    	Xdp          *LinkXdp
    	EncapType    string
    	Protinfo     *Protinfo
    	OperState    LinkOperState
    }
    
  • newSubnetAttrs新建并初始化subnet.LeaseAttrs属性

  • AcquireLease分配子网租约

  • newNetwork创建网络

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值