Do not use netns as ID or for entropy
ContainerID is now required so use that or generate random bytes. Fixes #5
This commit is contained in:
@ -48,9 +48,9 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
|
||||
switch ipamConf.Type {
|
||||
case "host-local":
|
||||
ipConf, err = allocator.Get(args.Netns)
|
||||
ipConf, err = allocator.Get(args.ContainerID)
|
||||
case "host-local-ptp":
|
||||
ipConf, err = allocator.GetPtP(args.Netns)
|
||||
ipConf, err = allocator.GetPtP(args.ContainerID)
|
||||
default:
|
||||
return errors.New("Unsupported IPAM plugin type")
|
||||
}
|
||||
@ -81,5 +81,5 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return allocator.Release(args.Netns)
|
||||
return allocator.Release(args.ContainerID)
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ func setupVeth(netns string, br *netlink.Bridge, ifName string, mtu int, pr *plu
|
||||
|
||||
err := ns.WithNetNSPath(netns, func(hostNS *os.File) error {
|
||||
// create the veth pair in the container and move host end into host netns
|
||||
hostVeth, _, err := ip.SetupVeth(netns, ifName, mtu, hostNS)
|
||||
hostVeth, _, err := ip.SetupVeth(ifName, mtu, hostNS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -107,7 +107,11 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
}
|
||||
defer netns.Close()
|
||||
|
||||
tmpName := ip.RandomVethName(args.Netns)
|
||||
tmpName, err := ip.RandomVethName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = createIpvlan(n, tmpName, netns); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -111,7 +111,11 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
}
|
||||
defer netns.Close()
|
||||
|
||||
tmpName := ip.RandomVethName(args.Netns)
|
||||
tmpName, err := ip.RandomVethName()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = createMacvlan(n, tmpName, netns); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -47,9 +47,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 {
|
||||
entropy := netns + ifName
|
||||
|
||||
hostVeth, _, err := ip.SetupVeth(entropy, ifName, mtu, hostNS)
|
||||
hostVeth, _, err := ip.SetupVeth(ifName, mtu, hostNS)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -116,7 +114,7 @@ func cmdAdd(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
if conf.IPMasq {
|
||||
h := sha512.Sum512([]byte(args.Netns))
|
||||
h := sha512.Sum512([]byte(args.ContainerID))
|
||||
chain := fmt.Sprintf("CNI-%s-%x", conf.Name, h[:8])
|
||||
if err = ip.SetupIPMasq(&result.IP4.IP, chain); err != nil {
|
||||
return err
|
||||
@ -143,7 +141,7 @@ func cmdDel(args *skel.CmdArgs) error {
|
||||
}
|
||||
|
||||
if conf.IPMasq {
|
||||
h := sha512.Sum512([]byte(args.Netns))
|
||||
h := sha512.Sum512([]byte(args.ContainerID))
|
||||
chain := fmt.Sprintf("CNI-%s-%x", conf.Name, h[:8])
|
||||
if err = ip.TeardownIPMasq(ipn, chain); err != nil {
|
||||
return err
|
||||
|
Reference in New Issue
Block a user