2015-05-14 02:23:45 -04:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
2015-06-05 16:31:12 -04:00
|
|
|
"encoding/json"
|
2015-10-05 07:21:15 -04:00
|
|
|
"fmt"
|
2015-05-14 02:23:45 -04:00
|
|
|
"net"
|
|
|
|
|
|
|
|
"github.com/docker/libnetwork/driverapi"
|
2015-05-20 16:28:46 -04:00
|
|
|
"github.com/docker/libnetwork/types"
|
2015-05-14 02:23:45 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// EndpointInfo provides an interface to retrieve network resources bound to the endpoint.
|
|
|
|
type EndpointInfo interface {
|
2015-09-09 19:06:35 -04:00
|
|
|
// Iface returns InterfaceInfo, go interface that can be used
|
|
|
|
// to get more information on the interface which was assigned to
|
|
|
|
// the endpoint by the driver. This can be used after the
|
|
|
|
// endpoint has been created.
|
|
|
|
Iface() InterfaceInfo
|
2015-05-14 02:23:45 -04:00
|
|
|
|
|
|
|
// Gateway returns the IPv4 gateway assigned by the driver.
|
|
|
|
// This will only return a valid value if a container has joined the endpoint.
|
|
|
|
Gateway() net.IP
|
|
|
|
|
|
|
|
// GatewayIPv6 returns the IPv6 gateway assigned by the driver.
|
|
|
|
// This will only return a valid value if a container has joined the endpoint.
|
|
|
|
GatewayIPv6() net.IP
|
|
|
|
|
2015-12-02 18:21:50 -05:00
|
|
|
// StaticRoutes returns the list of static routes configured by the network
|
|
|
|
// driver when the container joins a network
|
|
|
|
StaticRoutes() []*types.StaticRoute
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
// Sandbox returns the attached sandbox if there, nil otherwise.
|
|
|
|
Sandbox() Sandbox
|
2017-08-29 02:35:31 -04:00
|
|
|
|
|
|
|
// LoadBalancer returns whether the endpoint is the load balancer endpoint for the network.
|
|
|
|
LoadBalancer() bool
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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.
|
2015-10-03 19:11:50 -04:00
|
|
|
Address() *net.IPNet
|
2015-05-14 02:23:45 -04:00
|
|
|
|
|
|
|
// AddressIPv6 returns the IPv6 address assigned to the endpoint.
|
2015-10-03 19:11:50 -04:00
|
|
|
AddressIPv6() *net.IPNet
|
2016-05-24 23:04:49 -04:00
|
|
|
|
|
|
|
// LinkLocalAddresses returns the list of link-local (IPv4/IPv6) addresses assigned to the endpoint.
|
|
|
|
LinkLocalAddresses() []*net.IPNet
|
2018-04-09 18:15:01 -04:00
|
|
|
|
|
|
|
// SrcName returns the name of the interface w/in the container
|
|
|
|
SrcName() string
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
type endpointInterface struct {
|
2015-05-21 14:04:49 -04:00
|
|
|
mac net.HardwareAddr
|
2015-10-03 19:11:50 -04:00
|
|
|
addr *net.IPNet
|
|
|
|
addrv6 *net.IPNet
|
2016-05-24 23:04:49 -04:00
|
|
|
llAddrs []*net.IPNet
|
2015-05-21 14:04:49 -04:00
|
|
|
srcName string
|
|
|
|
dstPrefix string
|
2015-05-19 20:08:56 -04:00
|
|
|
routes []*net.IPNet
|
2015-10-04 00:25:57 -04:00
|
|
|
v4PoolID string
|
|
|
|
v6PoolID string
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-06-05 16:31:12 -04:00
|
|
|
func (epi *endpointInterface) MarshalJSON() ([]byte, error) {
|
|
|
|
epMap := make(map[string]interface{})
|
2015-10-03 19:11:50 -04:00
|
|
|
if epi.mac != nil {
|
|
|
|
epMap["mac"] = epi.mac.String()
|
|
|
|
}
|
|
|
|
if epi.addr != nil {
|
|
|
|
epMap["addr"] = epi.addr.String()
|
|
|
|
}
|
|
|
|
if epi.addrv6 != nil {
|
|
|
|
epMap["addrv6"] = epi.addrv6.String()
|
|
|
|
}
|
2016-05-24 23:04:49 -04:00
|
|
|
if len(epi.llAddrs) != 0 {
|
|
|
|
list := make([]string, 0, len(epi.llAddrs))
|
|
|
|
for _, ll := range epi.llAddrs {
|
|
|
|
list = append(list, ll.String())
|
|
|
|
}
|
|
|
|
epMap["llAddrs"] = list
|
|
|
|
}
|
2015-06-05 16:31:12 -04:00
|
|
|
epMap["srcName"] = epi.srcName
|
|
|
|
epMap["dstPrefix"] = epi.dstPrefix
|
|
|
|
var routes []string
|
|
|
|
for _, route := range epi.routes {
|
|
|
|
routes = append(routes, route.String())
|
|
|
|
}
|
|
|
|
epMap["routes"] = routes
|
2015-10-04 00:25:57 -04:00
|
|
|
epMap["v4PoolID"] = epi.v4PoolID
|
|
|
|
epMap["v6PoolID"] = epi.v6PoolID
|
2015-06-05 16:31:12 -04:00
|
|
|
return json.Marshal(epMap)
|
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
func (epi *endpointInterface) UnmarshalJSON(b []byte) error {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
epMap map[string]interface{}
|
|
|
|
)
|
|
|
|
if err = json.Unmarshal(b, &epMap); err != nil {
|
2015-06-05 16:31:12 -04:00
|
|
|
return err
|
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
if v, ok := epMap["mac"]; ok {
|
|
|
|
if epi.mac, err = net.ParseMAC(v.(string)); err != nil {
|
|
|
|
return types.InternalErrorf("failed to decode endpoint interface mac address after json unmarshal: %s", v.(string))
|
|
|
|
}
|
2015-06-05 16:31:12 -04:00
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
if v, ok := epMap["addr"]; ok {
|
|
|
|
if epi.addr, err = types.ParseCIDR(v.(string)); err != nil {
|
|
|
|
return types.InternalErrorf("failed to decode endpoint interface ipv4 address after json unmarshal: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if v, ok := epMap["addrv6"]; ok {
|
|
|
|
if epi.addrv6, err = types.ParseCIDR(v.(string)); err != nil {
|
|
|
|
return types.InternalErrorf("failed to decode endpoint interface ipv6 address after json unmarshal: %v", err)
|
|
|
|
}
|
2015-06-05 16:31:12 -04:00
|
|
|
}
|
2016-05-24 23:04:49 -04:00
|
|
|
if v, ok := epMap["llAddrs"]; ok {
|
2016-11-21 00:25:01 -05:00
|
|
|
list := v.([]interface{})
|
2016-05-24 23:04:49 -04:00
|
|
|
epi.llAddrs = make([]*net.IPNet, 0, len(list))
|
|
|
|
for _, llS := range list {
|
2016-11-21 00:25:01 -05:00
|
|
|
ll, err := types.ParseCIDR(llS.(string))
|
2016-05-24 23:04:49 -04:00
|
|
|
if err != nil {
|
2016-11-21 00:25:01 -05:00
|
|
|
return types.InternalErrorf("failed to decode endpoint interface link-local address (%v) after json unmarshal: %v", llS, err)
|
2016-05-24 23:04:49 -04:00
|
|
|
}
|
|
|
|
epi.llAddrs = append(epi.llAddrs, ll)
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 16:31:12 -04:00
|
|
|
epi.srcName = epMap["srcName"].(string)
|
|
|
|
epi.dstPrefix = epMap["dstPrefix"].(string)
|
|
|
|
|
|
|
|
rb, _ := json.Marshal(epMap["routes"])
|
|
|
|
var routes []string
|
|
|
|
json.Unmarshal(rb, &routes)
|
|
|
|
epi.routes = make([]*net.IPNet, 0)
|
|
|
|
for _, route := range routes {
|
2015-06-18 21:49:34 -04:00
|
|
|
ip, ipr, err := net.ParseCIDR(route)
|
2015-06-05 16:31:12 -04:00
|
|
|
if err == nil {
|
2015-06-18 21:49:34 -04:00
|
|
|
ipr.IP = ip
|
2015-06-05 16:31:12 -04:00
|
|
|
epi.routes = append(epi.routes, ipr)
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 00:25:57 -04:00
|
|
|
epi.v4PoolID = epMap["v4PoolID"].(string)
|
|
|
|
epi.v6PoolID = epMap["v6PoolID"].(string)
|
2015-06-05 16:31:12 -04:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-05 07:21:15 -04:00
|
|
|
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)
|
|
|
|
dstEpi.srcName = epi.srcName
|
|
|
|
dstEpi.dstPrefix = epi.dstPrefix
|
2015-10-04 00:25:57 -04:00
|
|
|
dstEpi.v4PoolID = epi.v4PoolID
|
|
|
|
dstEpi.v6PoolID = epi.v6PoolID
|
2016-05-24 23:04:49 -04:00
|
|
|
if len(epi.llAddrs) != 0 {
|
|
|
|
dstEpi.llAddrs = make([]*net.IPNet, 0, len(epi.llAddrs))
|
2017-07-06 12:42:38 -04:00
|
|
|
dstEpi.llAddrs = append(dstEpi.llAddrs, epi.llAddrs...)
|
2016-05-24 23:04:49 -04:00
|
|
|
}
|
2015-10-05 07:21:15 -04:00
|
|
|
|
|
|
|
for _, route := range epi.routes {
|
|
|
|
dstEpi.routes = append(dstEpi.routes, types.GetIPNetCopy(route))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-14 02:23:45 -04:00
|
|
|
type endpointJoinInfo struct {
|
2015-12-02 21:07:44 -05:00
|
|
|
gw net.IP
|
|
|
|
gw6 net.IP
|
|
|
|
StaticRoutes []*types.StaticRoute
|
2016-03-30 17:42:58 -04:00
|
|
|
driverTableEntries []*tableEntry
|
2015-12-02 21:07:44 -05:00
|
|
|
disableGatewayService bool
|
2015-06-10 21:50:19 -04:00
|
|
|
}
|
|
|
|
|
2016-03-30 17:42:58 -04:00
|
|
|
type tableEntry struct {
|
|
|
|
tableName string
|
|
|
|
key string
|
|
|
|
value []byte
|
|
|
|
}
|
|
|
|
|
2015-05-14 02:23:45 -04:00
|
|
|
func (ep *endpoint) Info() EndpointInfo {
|
2017-02-02 17:46:59 -05:00
|
|
|
if ep.sandboxID != "" {
|
|
|
|
return ep
|
|
|
|
}
|
2015-10-05 07:21:15 -04:00
|
|
|
n, err := ep.getNetworkFromStore()
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
ep, err = n.getEndpointFromStore(ep.ID())
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
sb, ok := ep.getSandbox()
|
|
|
|
if !ok {
|
|
|
|
// endpoint hasn't joined any sandbox.
|
|
|
|
// Just return the endpoint
|
|
|
|
return ep
|
|
|
|
}
|
|
|
|
|
2017-09-20 11:57:02 -04:00
|
|
|
return sb.getEndpoint(ep.ID())
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
func (ep *endpoint) Iface() InterfaceInfo {
|
2015-05-14 02:23:45 -04:00
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
if ep.iface != nil {
|
|
|
|
return ep.iface
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
return nil
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
func (ep *endpoint) Interface() driverapi.InterfaceInfo {
|
2015-05-14 02:23:45 -04:00
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
if ep.iface != nil {
|
|
|
|
return ep.iface
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
return nil
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
if mac == nil {
|
|
|
|
return types.BadRequestErrorf("tried to set nil MAC address to endpoint interface")
|
|
|
|
}
|
|
|
|
epi.mac = types.GetMacCopy(mac)
|
|
|
|
return nil
|
|
|
|
}
|
2015-05-14 02:23:45 -04:00
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
func (epi *endpointInterface) SetIPAddress(address *net.IPNet) error {
|
|
|
|
if address.IP == nil {
|
|
|
|
return types.BadRequestErrorf("tried to set nil IP address to endpoint interface")
|
|
|
|
}
|
|
|
|
if address.IP.To4() == nil {
|
|
|
|
return setAddress(&epi.addrv6, address)
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
2015-10-03 19:11:50 -04:00
|
|
|
return setAddress(&epi.addr, address)
|
|
|
|
}
|
2015-05-14 02:23:45 -04:00
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
func setAddress(ifaceAddr **net.IPNet, address *net.IPNet) error {
|
|
|
|
if *ifaceAddr != nil {
|
|
|
|
return types.ForbiddenErrorf("endpoint interface IP present (%s). Cannot be modified with (%s).", *ifaceAddr, address)
|
|
|
|
}
|
|
|
|
*ifaceAddr = types.GetIPNetCopy(address)
|
2015-05-14 02:23:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-05 16:31:12 -04:00
|
|
|
func (epi *endpointInterface) MacAddress() net.HardwareAddr {
|
|
|
|
return types.GetMacCopy(epi.mac)
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
func (epi *endpointInterface) Address() *net.IPNet {
|
|
|
|
return types.GetIPNetCopy(epi.addr)
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-10-03 19:11:50 -04:00
|
|
|
func (epi *endpointInterface) AddressIPv6() *net.IPNet {
|
|
|
|
return types.GetIPNetCopy(epi.addrv6)
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2016-05-24 23:04:49 -04:00
|
|
|
func (epi *endpointInterface) LinkLocalAddresses() []*net.IPNet {
|
|
|
|
return epi.llAddrs
|
|
|
|
}
|
|
|
|
|
2018-04-09 18:15:01 -04:00
|
|
|
func (epi *endpointInterface) SrcName() string {
|
|
|
|
return epi.srcName
|
|
|
|
}
|
|
|
|
|
2015-06-05 16:31:12 -04:00
|
|
|
func (epi *endpointInterface) SetNames(srcName string, dstPrefix string) error {
|
|
|
|
epi.srcName = srcName
|
|
|
|
epi.dstPrefix = dstPrefix
|
2015-05-14 02:23:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
func (ep *endpoint) InterfaceName() driverapi.InterfaceNameInfo {
|
2015-05-14 02:23:45 -04:00
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
if ep.iface != nil {
|
|
|
|
return ep.iface
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
return nil
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
func (ep *endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
|
2015-05-19 20:08:56 -04:00
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
2015-09-09 19:06:35 -04:00
|
|
|
r := types.StaticRoute{Destination: destination, RouteType: routeType, NextHop: nextHop}
|
2015-05-19 20:08:56 -04:00
|
|
|
|
|
|
|
if routeType == types.NEXTHOP {
|
|
|
|
// If the route specifies a next-hop, then it's loosely routed (i.e. not bound to a particular interface).
|
|
|
|
ep.joinInfo.StaticRoutes = append(ep.joinInfo.StaticRoutes, &r)
|
|
|
|
} else {
|
|
|
|
// If the route doesn't specify a next-hop, it must be a connected route, bound to an interface.
|
2015-09-17 20:55:24 -04:00
|
|
|
ep.iface.routes = append(ep.iface.routes, r.Destination)
|
2015-05-19 20:08:56 -04:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-04-18 22:55:39 -04:00
|
|
|
func (ep *endpoint) AddTableEntry(tableName, key string, value []byte) error {
|
2016-03-30 17:42:58 -04:00
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
|
|
|
ep.joinInfo.driverTableEntries = append(ep.joinInfo.driverTableEntries, &tableEntry{
|
|
|
|
tableName: tableName,
|
|
|
|
key: key,
|
|
|
|
value: value,
|
|
|
|
})
|
|
|
|
|
2016-04-18 22:55:39 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-07-02 01:00:48 -04:00
|
|
|
func (ep *endpoint) Sandbox() Sandbox {
|
|
|
|
cnt, ok := ep.getSandbox()
|
|
|
|
if !ok {
|
|
|
|
return nil
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
2015-07-02 01:00:48 -04:00
|
|
|
return cnt
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
2017-08-29 02:35:31 -04:00
|
|
|
func (ep *endpoint) LoadBalancer() bool {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
return ep.loadBalancer
|
|
|
|
}
|
|
|
|
|
2015-12-02 18:21:50 -05:00
|
|
|
func (ep *endpoint) StaticRoutes() []*types.StaticRoute {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
|
|
|
if ep.joinInfo == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return ep.joinInfo.StaticRoutes
|
|
|
|
}
|
|
|
|
|
2015-05-14 02:23:45 -04:00
|
|
|
func (ep *endpoint) Gateway() net.IP {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
|
|
|
if ep.joinInfo == nil {
|
|
|
|
return net.IP{}
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:28:46 -04:00
|
|
|
return types.GetIPCopy(ep.joinInfo.gw)
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ep *endpoint) GatewayIPv6() net.IP {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
|
|
|
if ep.joinInfo == nil {
|
|
|
|
return net.IP{}
|
|
|
|
}
|
|
|
|
|
2015-05-20 16:28:46 -04:00
|
|
|
return types.GetIPCopy(ep.joinInfo.gw6)
|
2015-05-14 02:23:45 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func (ep *endpoint) SetGateway(gw net.IP) error {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
2015-05-20 16:28:46 -04:00
|
|
|
ep.joinInfo.gw = types.GetIPCopy(gw)
|
2015-05-14 02:23:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ep *endpoint) SetGatewayIPv6(gw6 net.IP) error {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
2015-05-20 16:28:46 -04:00
|
|
|
ep.joinInfo.gw6 = types.GetIPCopy(gw6)
|
2015-05-14 02:23:45 -04:00
|
|
|
return nil
|
|
|
|
}
|
2015-10-28 19:22:18 -04:00
|
|
|
|
|
|
|
func (ep *endpoint) retrieveFromStore() (*endpoint, error) {
|
|
|
|
n, err := ep.getNetworkFromStore()
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("could not find network in store to get latest endpoint %s: %v", ep.Name(), err)
|
|
|
|
}
|
|
|
|
return n.getEndpointFromStore(ep.ID())
|
|
|
|
}
|
2015-12-02 21:07:44 -05:00
|
|
|
|
|
|
|
func (ep *endpoint) DisableGatewayService() {
|
|
|
|
ep.Lock()
|
|
|
|
defer ep.Unlock()
|
|
|
|
|
|
|
|
ep.joinInfo.disableGatewayService = true
|
|
|
|
}
|
2016-06-10 20:32:19 -04:00
|
|
|
|
|
|
|
func (epj *endpointJoinInfo) MarshalJSON() ([]byte, error) {
|
|
|
|
epMap := make(map[string]interface{})
|
|
|
|
if epj.gw != nil {
|
|
|
|
epMap["gw"] = epj.gw.String()
|
|
|
|
}
|
|
|
|
if epj.gw6 != nil {
|
|
|
|
epMap["gw6"] = epj.gw6.String()
|
|
|
|
}
|
|
|
|
epMap["disableGatewayService"] = epj.disableGatewayService
|
|
|
|
epMap["StaticRoutes"] = epj.StaticRoutes
|
|
|
|
return json.Marshal(epMap)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (epj *endpointJoinInfo) UnmarshalJSON(b []byte) error {
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
epMap map[string]interface{}
|
|
|
|
)
|
|
|
|
if err = json.Unmarshal(b, &epMap); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if v, ok := epMap["gw"]; ok {
|
2017-08-03 06:33:23 -04:00
|
|
|
epj.gw = net.ParseIP(v.(string))
|
2016-06-10 20:32:19 -04:00
|
|
|
}
|
|
|
|
if v, ok := epMap["gw6"]; ok {
|
|
|
|
epj.gw6 = net.ParseIP(v.(string))
|
|
|
|
}
|
|
|
|
epj.disableGatewayService = epMap["disableGatewayService"].(bool)
|
|
|
|
|
|
|
|
var tStaticRoute []types.StaticRoute
|
|
|
|
if v, ok := epMap["StaticRoutes"]; ok {
|
|
|
|
tb, _ := json.Marshal(v)
|
|
|
|
var tStaticRoute []types.StaticRoute
|
|
|
|
json.Unmarshal(tb, &tStaticRoute)
|
|
|
|
}
|
|
|
|
var StaticRoutes []*types.StaticRoute
|
|
|
|
for _, r := range tStaticRoute {
|
|
|
|
StaticRoutes = append(StaticRoutes, &r)
|
|
|
|
}
|
|
|
|
epj.StaticRoutes = StaticRoutes
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (epj *endpointJoinInfo) CopyTo(dstEpj *endpointJoinInfo) error {
|
|
|
|
dstEpj.disableGatewayService = epj.disableGatewayService
|
|
|
|
dstEpj.StaticRoutes = make([]*types.StaticRoute, len(epj.StaticRoutes))
|
|
|
|
copy(dstEpj.StaticRoutes, epj.StaticRoutes)
|
2016-08-02 17:06:41 -04:00
|
|
|
dstEpj.driverTableEntries = make([]*tableEntry, len(epj.driverTableEntries))
|
|
|
|
copy(dstEpj.driverTableEntries, epj.driverTableEntries)
|
2016-06-10 20:32:19 -04:00
|
|
|
dstEpj.gw = types.GetIPCopy(epj.gw)
|
2017-08-03 06:33:23 -04:00
|
|
|
dstEpj.gw6 = types.GetIPCopy(epj.gw6)
|
2016-06-10 20:32:19 -04:00
|
|
|
return nil
|
|
|
|
}
|