add DHCP IPAM plugin
The plugin binary actually functions in two modes. The first mode is a regular CNI plugin. The second mode (when stared with "daemon" arg) runs a DHCP client daemon. When executed as a CNI plugin, it issues an RPC request to the daemon for actual processing. The daemon is required since a DHCP lease needs to be maintained by periodically renewing it. One instance of the daemon can server arbitrary number of containers/leases.
This commit is contained in:
@ -124,7 +124,7 @@ func ensureBridge(brName string, mtu int) (*netlink.Bridge, error) {
|
||||
func setupVeth(netns string, br *netlink.Bridge, ifName string, mtu int) error {
|
||||
var hostVethName string
|
||||
|
||||
err := ns.WithNetNSPath(netns, func(hostNS *os.File) error {
|
||||
err := ns.WithNetNSPath(netns, false, func(hostNS *os.File) error {
|
||||
// create the veth pair in the container and move host end into host netns
|
||||
hostVeth, _, err := ip.SetupVeth(ifName, mtu, hostNS)
|
||||
if err != nil {
|
||||
@ -196,7 +196,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
result.IP4.Gateway = calcGatewayIP(&result.IP4.IP)
|
||||
}
|
||||
|
||||
err = ns.WithNetNSPath(args.Netns, func(hostNS *os.File) error {
|
||||
err = ns.WithNetNSPath(args.Netns, false, func(hostNS *os.File) error {
|
||||
return plugin.ConfigureIface(args.IfName, result)
|
||||
})
|
||||
if err != nil {
|
||||
@ -235,7 +235,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ns.WithNetNSPath(args.Netns, func(hostNS *os.File) error {
|
||||
return ns.WithNetNSPath(args.Netns, false, func(hostNS *os.File) error {
|
||||
return ip.DelLinkByName(args.IfName)
|
||||
})
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ func createIpvlan(conf *NetConf, ifName string, netns *os.File) error {
|
||||
return fmt.Errorf("failed to create ipvlan: %v", err)
|
||||
}
|
||||
|
||||
return ns.WithNetNS(netns, func(_ *os.File) error {
|
||||
return ns.WithNetNS(netns, false, func(_ *os.File) error {
|
||||
err := renameLink(tmpName, ifName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rename ipvlan to %q: %v", ifName, err)
|
||||
@ -131,7 +131,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
return errors.New("IPAM plugin returned missing IPv4 config")
|
||||
}
|
||||
|
||||
err = ns.WithNetNS(netns, func(_ *os.File) error {
|
||||
err = ns.WithNetNS(netns, false, func(_ *os.File) error {
|
||||
return plugin.ConfigureIface(args.IfName, result)
|
||||
})
|
||||
if err != nil {
|
||||
@ -159,7 +159,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ns.WithNetNSPath(args.Netns, func(hostNS *os.File) error {
|
||||
return ns.WithNetNSPath(args.Netns, false, func(hostNS *os.File) error {
|
||||
return ip.DelLinkByName(args.IfName)
|
||||
})
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ func createMacvlan(conf *NetConf, ifName string, netns *os.File) error {
|
||||
return fmt.Errorf("failed to create macvlan: %v", err)
|
||||
}
|
||||
|
||||
return ns.WithNetNS(netns, func(_ *os.File) error {
|
||||
return ns.WithNetNS(netns, false, func(_ *os.File) error {
|
||||
err := renameLink(tmpName, ifName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to rename macvlan to %q: %v", ifName, err)
|
||||
@ -135,7 +135,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
return errors.New("IPAM plugin returned missing IPv4 config")
|
||||
}
|
||||
|
||||
err = ns.WithNetNS(netns, func(_ *os.File) error {
|
||||
err = ns.WithNetNS(netns, false, func(_ *os.File) error {
|
||||
return plugin.ConfigureIface(args.IfName, result)
|
||||
})
|
||||
if err != nil {
|
||||
@ -163,7 +163,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return ns.WithNetNSPath(args.Netns, func(hostNS *os.File) error {
|
||||
return ns.WithNetNSPath(args.Netns, false, func(hostNS *os.File) error {
|
||||
return ip.DelLinkByName(args.IfName)
|
||||
})
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ type NetConf struct {
|
||||
|
||||
func setupContainerVeth(netns, ifName string, mtu int, pr *plugin.Result) (string, error) {
|
||||
var hostVethName string
|
||||
err := ns.WithNetNSPath(netns, func(hostNS *os.File) error {
|
||||
err := ns.WithNetNSPath(netns, false, func(hostNS *os.File) error {
|
||||
hostVeth, _, err := ip.SetupVeth(ifName, mtu, hostNS)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -131,7 +131,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
var ipn *net.IPNet
|
||||
err := ns.WithNetNSPath(args.Netns, func(hostNS *os.File) error {
|
||||
err := ns.WithNetNSPath(args.Netns, false, func(hostNS *os.File) error {
|
||||
var err error
|
||||
ipn, err = ip.DelLinkByNameAddr(args.IfName, netlink.FAMILY_V4)
|
||||
return err
|
||||
|
Reference in New Issue
Block a user