mirror of
https://github.com/moby/moby.git
synced 2026-08-03 22:51:03 +00:00
libnetwork/drivers/macvlan, ipvlan: driver.Join: don't fetch endpoint twice
The function was fetching a reference to the endpoint twice; while this did give the option for an early return, in practice it didn't mean much, because it could still fail if the endpoint was removed in between. This code still has a race condition, because while a reference to the endpoint is retrieved while acquiring a lock, the result is mutated without. This probably needs to either have some accessor, or the function should keep a lock for the whole operation (possibly switching to an RWMutex). Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -41,10 +41,6 @@ func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinf
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
endpoint := n.endpoint(eid)
|
||||
if endpoint == nil {
|
||||
return fmt.Errorf("could not find endpoint with id %s", eid)
|
||||
}
|
||||
// generate a name for the iface that will be renamed to eth0 in the sbox
|
||||
containerIfName, err := netutils.GenerateIfaceName(ns.NlHandle(), vethPrefix, vethLen)
|
||||
if err != nil {
|
||||
@@ -55,12 +51,15 @@ func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinf
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// bind the generated iface name to the endpoint
|
||||
endpoint.srcName = vethName
|
||||
ep := n.endpoint(eid)
|
||||
if ep == nil {
|
||||
return fmt.Errorf("could not find endpoint with id %s", eid)
|
||||
}
|
||||
// bind the generated iface name to the endpoint
|
||||
//
|
||||
// TODO(thaJeztah): this should really be done under a lock.
|
||||
ep.srcName = vethName
|
||||
|
||||
if !n.config.Internal {
|
||||
switch n.config.IpvlanMode {
|
||||
case modeL3, modeL3S:
|
||||
|
||||
@@ -29,10 +29,6 @@ func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinf
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
endpoint := n.endpoint(eid)
|
||||
if endpoint == nil {
|
||||
return fmt.Errorf("could not find endpoint with id %s", eid)
|
||||
}
|
||||
// generate a name for the iface that will be renamed to eth0 in the sbox
|
||||
containerIfName, err := netutils.GenerateIfaceName(ns.NlHandle(), vethPrefix, vethLen)
|
||||
if err != nil {
|
||||
@@ -43,12 +39,15 @@ func (d *driver) Join(ctx context.Context, nid, eid string, sboxKey string, jinf
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
// bind the generated iface name to the endpoint
|
||||
endpoint.srcName = vethName
|
||||
ep := n.endpoint(eid)
|
||||
if ep == nil {
|
||||
return fmt.Errorf("could not find endpoint with id %s", eid)
|
||||
}
|
||||
// bind the generated iface name to the endpoint
|
||||
//
|
||||
// TODO(thaJeztah): this should really be done under a lock.
|
||||
ep.srcName = vethName
|
||||
|
||||
// parse and match the endpoint address with the available v4 subnets
|
||||
if !n.config.Internal {
|
||||
if len(n.config.Ipv4Subnets) > 0 {
|
||||
|
||||
Reference in New Issue
Block a user