mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
686be57d0a
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
104 lines
1.7 KiB
Go
104 lines
1.7 KiB
Go
//go:build linux
|
|
// +build linux
|
|
|
|
package ipvlan
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/docker/docker/libnetwork/types"
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
func (d *driver) network(nid string) *network {
|
|
d.Lock()
|
|
n, ok := d.networks[nid]
|
|
d.Unlock()
|
|
if !ok {
|
|
logrus.Errorf("network id %s not found", nid)
|
|
}
|
|
|
|
return n
|
|
}
|
|
|
|
func (d *driver) addNetwork(n *network) {
|
|
d.Lock()
|
|
d.networks[n.id] = n
|
|
d.Unlock()
|
|
}
|
|
|
|
func (d *driver) deleteNetwork(nid string) {
|
|
d.Lock()
|
|
delete(d.networks, nid)
|
|
d.Unlock()
|
|
}
|
|
|
|
// getNetworks Safely returns a slice of existing networks
|
|
func (d *driver) getNetworks() []*network {
|
|
d.Lock()
|
|
defer d.Unlock()
|
|
|
|
ls := make([]*network, 0, len(d.networks))
|
|
for _, nw := range d.networks {
|
|
ls = append(ls, nw)
|
|
}
|
|
|
|
return ls
|
|
}
|
|
|
|
func (n *network) endpoint(eid string) *endpoint {
|
|
n.Lock()
|
|
defer n.Unlock()
|
|
|
|
return n.endpoints[eid]
|
|
}
|
|
|
|
func (n *network) addEndpoint(ep *endpoint) {
|
|
n.Lock()
|
|
n.endpoints[ep.id] = ep
|
|
n.Unlock()
|
|
}
|
|
|
|
func (n *network) deleteEndpoint(eid string) {
|
|
n.Lock()
|
|
delete(n.endpoints, eid)
|
|
n.Unlock()
|
|
}
|
|
|
|
func (n *network) getEndpoint(eid string) (*endpoint, error) {
|
|
n.Lock()
|
|
defer n.Unlock()
|
|
if eid == "" {
|
|
return nil, fmt.Errorf("endpoint id %s not found", eid)
|
|
}
|
|
if ep, ok := n.endpoints[eid]; ok {
|
|
return ep, nil
|
|
}
|
|
|
|
return nil, nil
|
|
}
|
|
|
|
func validateID(nid, eid string) error {
|
|
if nid == "" {
|
|
return fmt.Errorf("invalid network id")
|
|
}
|
|
if eid == "" {
|
|
return fmt.Errorf("invalid endpoint id")
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (d *driver) getNetwork(id string) (*network, error) {
|
|
d.Lock()
|
|
defer d.Unlock()
|
|
if id == "" {
|
|
return nil, types.BadRequestErrorf("invalid network id: %s", id)
|
|
}
|
|
|
|
if nw, ok := d.networks[id]; ok {
|
|
return nw, nil
|
|
}
|
|
|
|
return nil, types.NotFoundErrorf("network not found: %s", id)
|
|
}
|