|
@@ -11,11 +11,10 @@ import (
|
|
|
|
|
|
// EndpointInfo provides an interface to retrieve network resources bound to the endpoint.
|
|
|
type EndpointInfo interface {
|
|
|
- // Iface returns InterfaceInfo, go interface that can be used
|
|
|
- // to get more information on the interface which was assigned to
|
|
|
+ // Iface returns information about the interface which was assigned to
|
|
|
// the endpoint by the driver. This can be used after the
|
|
|
// endpoint has been created.
|
|
|
- Iface() InterfaceInfo
|
|
|
+ Iface() *EndpointInterface
|
|
|
|
|
|
// Gateway returns the IPv4 gateway assigned by the driver.
|
|
|
// This will only return a valid value if a container has joined the endpoint.
|
|
@@ -36,25 +35,8 @@ type EndpointInfo interface {
|
|
|
LoadBalancer() bool
|
|
|
}
|
|
|
|
|
|
-// InterfaceInfo provides an interface to retrieve interface addresses bound to the endpoint.
|
|
|
-type InterfaceInfo interface {
|
|
|
- // MacAddress returns the MAC address assigned to the endpoint.
|
|
|
- MacAddress() net.HardwareAddr
|
|
|
-
|
|
|
- // Address returns the IPv4 address assigned to the endpoint.
|
|
|
- Address() *net.IPNet
|
|
|
-
|
|
|
- // AddressIPv6 returns the IPv6 address assigned to the endpoint.
|
|
|
- AddressIPv6() *net.IPNet
|
|
|
-
|
|
|
- // LinkLocalAddresses returns the list of link-local (IPv4/IPv6) addresses assigned to the endpoint.
|
|
|
- LinkLocalAddresses() []*net.IPNet
|
|
|
-
|
|
|
- // SrcName returns the name of the interface w/in the container
|
|
|
- SrcName() string
|
|
|
-}
|
|
|
-
|
|
|
-type endpointInterface struct {
|
|
|
+// EndpointInterface holds interface addresses bound to the endpoint.
|
|
|
+type EndpointInterface struct {
|
|
|
mac net.HardwareAddr
|
|
|
addr *net.IPNet
|
|
|
addrv6 *net.IPNet
|
|
@@ -66,7 +48,7 @@ type endpointInterface struct {
|
|
|
v6PoolID string
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) MarshalJSON() ([]byte, error) {
|
|
|
+func (epi *EndpointInterface) MarshalJSON() ([]byte, error) {
|
|
|
epMap := make(map[string]interface{})
|
|
|
if epi.mac != nil {
|
|
|
epMap["mac"] = epi.mac.String()
|
|
@@ -96,7 +78,7 @@ func (epi *endpointInterface) MarshalJSON() ([]byte, error) {
|
|
|
return json.Marshal(epMap)
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) UnmarshalJSON(b []byte) error {
|
|
|
+func (epi *EndpointInterface) UnmarshalJSON(b []byte) error {
|
|
|
var (
|
|
|
err error
|
|
|
epMap map[string]interface{}
|
|
@@ -153,7 +135,7 @@ func (epi *endpointInterface) UnmarshalJSON(b []byte) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) CopyTo(dstEpi *endpointInterface) error {
|
|
|
+func (epi *EndpointInterface) CopyTo(dstEpi *EndpointInterface) error {
|
|
|
dstEpi.mac = types.GetMacCopy(epi.mac)
|
|
|
dstEpi.addr = types.GetIPNetCopy(epi.addr)
|
|
|
dstEpi.addrv6 = types.GetIPNetCopy(epi.addrv6)
|
|
@@ -212,7 +194,7 @@ func (ep *Endpoint) Info() EndpointInfo {
|
|
|
return sb.getEndpoint(ep.ID())
|
|
|
}
|
|
|
|
|
|
-func (ep *Endpoint) Iface() InterfaceInfo {
|
|
|
+func (ep *Endpoint) Iface() *EndpointInterface {
|
|
|
ep.mu.Lock()
|
|
|
defer ep.mu.Unlock()
|
|
|
|
|
@@ -234,7 +216,9 @@ func (ep *Endpoint) Interface() driverapi.InterfaceInfo {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) SetMacAddress(mac net.HardwareAddr) error {
|
|
|
+// SetMacAddress allows the driver to set the mac address to the endpoint interface
|
|
|
+// during the call to CreateEndpoint, if the mac address is not already set.
|
|
|
+func (epi *EndpointInterface) SetMacAddress(mac net.HardwareAddr) error {
|
|
|
if epi.mac != nil {
|
|
|
return types.ForbiddenErrorf("endpoint interface MAC address present (%s). Cannot be modified with %s.", epi.mac, mac)
|
|
|
}
|
|
@@ -245,7 +229,7 @@ func (epi *endpointInterface) SetMacAddress(mac net.HardwareAddr) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) SetIPAddress(address *net.IPNet) error {
|
|
|
+func (epi *EndpointInterface) SetIPAddress(address *net.IPNet) error {
|
|
|
if address.IP == nil {
|
|
|
return types.InvalidParameterErrorf("tried to set nil IP address to endpoint interface")
|
|
|
}
|
|
@@ -263,27 +247,33 @@ func setAddress(ifaceAddr **net.IPNet, address *net.IPNet) error {
|
|
|
return nil
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) MacAddress() net.HardwareAddr {
|
|
|
+// MacAddress returns the MAC address assigned to the endpoint.
|
|
|
+func (epi *EndpointInterface) MacAddress() net.HardwareAddr {
|
|
|
return types.GetMacCopy(epi.mac)
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) Address() *net.IPNet {
|
|
|
+// Address returns the IPv4 address assigned to the endpoint.
|
|
|
+func (epi *EndpointInterface) Address() *net.IPNet {
|
|
|
return types.GetIPNetCopy(epi.addr)
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) AddressIPv6() *net.IPNet {
|
|
|
+// AddressIPv6 returns the IPv6 address assigned to the endpoint.
|
|
|
+func (epi *EndpointInterface) AddressIPv6() *net.IPNet {
|
|
|
return types.GetIPNetCopy(epi.addrv6)
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) LinkLocalAddresses() []*net.IPNet {
|
|
|
+// LinkLocalAddresses returns the list of link-local (IPv4/IPv6) addresses assigned to the endpoint.
|
|
|
+func (epi *EndpointInterface) LinkLocalAddresses() []*net.IPNet {
|
|
|
return epi.llAddrs
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) SrcName() string {
|
|
|
+// SrcName returns the name of the interface w/in the container
|
|
|
+func (epi *EndpointInterface) SrcName() string {
|
|
|
return epi.srcName
|
|
|
}
|
|
|
|
|
|
-func (epi *endpointInterface) SetNames(srcName string, dstPrefix string) error {
|
|
|
+// SetNames method assigns the srcName and dstPrefix for the interface.
|
|
|
+func (epi *EndpointInterface) SetNames(srcName string, dstPrefix string) error {
|
|
|
epi.srcName = srcName
|
|
|
epi.dstPrefix = dstPrefix
|
|
|
return nil
|