2016-02-16 22:15:18 -05:00
|
|
|
package macvlan
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2016-03-02 20:13:15 -05:00
|
|
|
"github.com/Sirupsen/logrus"
|
2016-02-16 22:15:18 -05:00
|
|
|
"github.com/docker/libnetwork/driverapi"
|
|
|
|
"github.com/docker/libnetwork/netlabel"
|
|
|
|
"github.com/docker/libnetwork/netutils"
|
2016-05-16 14:51:40 -04:00
|
|
|
"github.com/docker/libnetwork/ns"
|
2016-03-10 16:23:04 -05:00
|
|
|
"github.com/docker/libnetwork/osl"
|
2016-02-16 22:15:18 -05:00
|
|
|
"github.com/docker/libnetwork/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// CreateEndpoint assigns the mac, ip and endpoint id for the new container
|
|
|
|
func (d *driver) CreateEndpoint(nid, eid string, ifInfo driverapi.InterfaceInfo,
|
|
|
|
epOptions map[string]interface{}) error {
|
2016-03-10 16:23:04 -05:00
|
|
|
defer osl.InitOSContext()()
|
2016-02-16 22:15:18 -05:00
|
|
|
|
|
|
|
if err := validateID(nid, eid); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
n, err := d.getNetwork(nid)
|
|
|
|
if err != nil {
|
|
|
|
return fmt.Errorf("network id %q not found", nid)
|
|
|
|
}
|
|
|
|
ep := &endpoint{
|
|
|
|
id: eid,
|
|
|
|
addr: ifInfo.Address(),
|
|
|
|
addrv6: ifInfo.AddressIPv6(),
|
|
|
|
mac: ifInfo.MacAddress(),
|
|
|
|
}
|
|
|
|
if ep.addr == nil {
|
|
|
|
return fmt.Errorf("create endpoint was not passed an IP address")
|
|
|
|
}
|
|
|
|
if ep.mac == nil {
|
|
|
|
ep.mac = netutils.GenerateMACFromIP(ep.addr.IP)
|
|
|
|
if err := ifInfo.SetMacAddress(ep.mac); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// disallow portmapping -p
|
|
|
|
if opt, ok := epOptions[netlabel.PortMap]; ok {
|
|
|
|
if _, ok := opt.([]types.PortBinding); ok {
|
|
|
|
if len(opt.([]types.PortBinding)) > 0 {
|
2016-03-02 20:13:15 -05:00
|
|
|
logrus.Warnf("%s driver does not support port mappings", macvlanType)
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// disallow port exposure --expose
|
|
|
|
if opt, ok := epOptions[netlabel.ExposedPorts]; ok {
|
|
|
|
if _, ok := opt.([]types.TransportPort); ok {
|
|
|
|
if len(opt.([]types.TransportPort)) > 0 {
|
2016-03-02 20:13:15 -05:00
|
|
|
logrus.Warnf("%s driver does not support port exposures", macvlanType)
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
n.addEndpoint(ep)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteEndpoint remove the endpoint and associated netlink interface
|
|
|
|
func (d *driver) DeleteEndpoint(nid, eid string) error {
|
2016-03-10 16:23:04 -05:00
|
|
|
defer osl.InitOSContext()()
|
2016-02-16 22:15:18 -05:00
|
|
|
if err := validateID(nid, eid); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
n := d.network(nid)
|
|
|
|
if n == nil {
|
|
|
|
return fmt.Errorf("network id %q not found", nid)
|
|
|
|
}
|
|
|
|
ep := n.endpoint(eid)
|
|
|
|
if ep == nil {
|
|
|
|
return fmt.Errorf("endpoint id %q not found", eid)
|
|
|
|
}
|
2016-05-16 14:51:40 -04:00
|
|
|
if link, err := ns.NlHandle().LinkByName(ep.srcName); err == nil {
|
|
|
|
ns.NlHandle().LinkDel(link)
|
2016-02-16 22:15:18 -05:00
|
|
|
}
|
2016-03-02 20:13:15 -05:00
|
|
|
|
2016-02-16 22:15:18 -05:00
|
|
|
return nil
|
|
|
|
}
|