2015-05-14 06:23:45 +00:00
|
|
|
package libnetwork
|
|
|
|
|
|
|
|
import (
|
2015-06-05 20:31:12 +00:00
|
|
|
"encoding/json"
|
2015-10-05 11:21:15 +00:00
|
|
|
"fmt"
|
2015-05-14 06:23:45 +00:00
|
|
|
"net"
|
|
|
|
|
2021-04-06 00:24:47 +00:00
|
|
|
"github.com/docker/docker/libnetwork/driverapi"
|
|
|
|
"github.com/docker/docker/libnetwork/types"
|
2015-05-14 06:23:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// EndpointInfo provides an interface to retrieve network resources bound to the endpoint.
|
|
|
|
type EndpointInfo interface {
|
2015-09-09 23:06:35 +00: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 06:23:45 +00: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 23:21:50 +00: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 05:00:48 +00:00
|
|
|
// Sandbox returns the attached sandbox if there, nil otherwise.
|
2023-01-12 01:10:09 +00:00
|
|
|
Sandbox() *Sandbox
|
2017-08-29 06:35:31 +00:00
|
|
|
|
|
|
|
// LoadBalancer returns whether the endpoint is the load balancer endpoint for the network.
|
|
|
|
LoadBalancer() bool
|
2015-05-14 06:23:45 +00: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 23:11:50 +00:00
|
|
|
Address() *net.IPNet
|
2015-05-14 06:23:45 +00:00
|
|
|
|
|
|
|
// AddressIPv6 returns the IPv6 address assigned to the endpoint.
|
2015-10-03 23:11:50 +00:00
|
|
|
AddressIPv6() *net.IPNet
|
2016-05-25 03:04:49 +00:00
|
|
|
|
|
|
|
// LinkLocalAddresses returns the list of link-local (IPv4/IPv6) addresses assigned to the endpoint.
|
|
|
|
LinkLocalAddresses() []*net.IPNet
|
2018-04-09 22:15:01 +00:00
|
|
|
|
|
|
|
// SrcName returns the name of the interface w/in the container
|
|
|
|
SrcName() string
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type endpointInterface struct {
|
2015-05-21 18:04:49 +00:00
|
|
|
mac net.HardwareAddr
|
2015-10-03 23:11:50 +00:00
|
|
|
addr *net.IPNet
|
|
|
|
addrv6 *net.IPNet
|
2016-05-25 03:04:49 +00:00
|
|
|
llAddrs []*net.IPNet
|
2015-05-21 18:04:49 +00:00
|
|
|
srcName string
|
|
|
|
dstPrefix string
|
2015-05-20 00:08:56 +00:00
|
|
|
routes []*net.IPNet
|
2015-10-04 04:25:57 +00:00
|
|
|
v4PoolID string
|
|
|
|
v6PoolID string
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-06-05 20:31:12 +00:00
|
|
|
func (epi *endpointInterface) MarshalJSON() ([]byte, error) {
|
|
|
|
epMap := make(map[string]interface{})
|
2015-10-03 23:11:50 +00: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-25 03:04:49 +00: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 20:31:12 +00: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 04:25:57 +00:00
|
|
|
epMap["v4PoolID"] = epi.v4PoolID
|
|
|
|
epMap["v6PoolID"] = epi.v6PoolID
|
2015-06-05 20:31:12 +00:00
|
|
|
return json.Marshal(epMap)
|
|
|
|
}
|
|
|
|
|
2015-10-03 23:11:50 +00: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 20:31:12 +00:00
|
|
|
return err
|
|
|
|
}
|
2015-10-03 23:11:50 +00: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 20:31:12 +00:00
|
|
|
}
|
2015-10-03 23:11:50 +00: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 20:31:12 +00:00
|
|
|
}
|
2016-05-25 03:04:49 +00:00
|
|
|
if v, ok := epMap["llAddrs"]; ok {
|
2016-11-21 05:25:01 +00:00
|
|
|
list := v.([]interface{})
|
2016-05-25 03:04:49 +00:00
|
|
|
epi.llAddrs = make([]*net.IPNet, 0, len(list))
|
|
|
|
for _, llS := range list {
|
2016-11-21 05:25:01 +00:00
|
|
|
ll, err := types.ParseCIDR(llS.(string))
|
2016-05-25 03:04:49 +00:00
|
|
|
if err != nil {
|
2016-11-21 05:25:01 +00:00
|
|
|
return types.InternalErrorf("failed to decode endpoint interface link-local address (%v) after json unmarshal: %v", llS, err)
|
2016-05-25 03:04:49 +00:00
|
|
|
}
|
|
|
|
epi.llAddrs = append(epi.llAddrs, ll)
|
|
|
|
}
|
|
|
|
}
|
2015-06-05 20:31:12 +00:00
|
|
|
epi.srcName = epMap["srcName"].(string)
|
|
|
|
epi.dstPrefix = epMap["dstPrefix"].(string)
|
|
|
|
|
|
|
|
rb, _ := json.Marshal(epMap["routes"])
|
|
|
|
var routes []string
|
2021-05-28 00:15:56 +00:00
|
|
|
|
|
|
|
// TODO(cpuguy83): linter noticed we don't check the error here... no idea why but it seems like it could introduce problems if we start checking
|
2022-07-13 20:30:47 +00:00
|
|
|
json.Unmarshal(rb, &routes) //nolint:errcheck
|
2021-05-28 00:15:56 +00:00
|
|
|
|
2015-06-05 20:31:12 +00:00
|
|
|
epi.routes = make([]*net.IPNet, 0)
|
|
|
|
for _, route := range routes {
|
2015-06-19 01:49:34 +00:00
|
|
|
ip, ipr, err := net.ParseCIDR(route)
|
2015-06-05 20:31:12 +00:00
|
|
|
if err == nil {
|
2015-06-19 01:49:34 +00:00
|
|
|
ipr.IP = ip
|
2015-06-05 20:31:12 +00:00
|
|
|
epi.routes = append(epi.routes, ipr)
|
|
|
|
}
|
|
|
|
}
|
2015-10-04 04:25:57 +00:00
|
|
|
epi.v4PoolID = epMap["v4PoolID"].(string)
|
|
|
|
epi.v6PoolID = epMap["v6PoolID"].(string)
|
2015-06-05 20:31:12 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-10-05 11:21:15 +00: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 04:25:57 +00:00
|
|
|
dstEpi.v4PoolID = epi.v4PoolID
|
|
|
|
dstEpi.v6PoolID = epi.v6PoolID
|
2016-05-25 03:04:49 +00:00
|
|
|
if len(epi.llAddrs) != 0 {
|
|
|
|
dstEpi.llAddrs = make([]*net.IPNet, 0, len(epi.llAddrs))
|
2017-07-06 16:42:38 +00:00
|
|
|
dstEpi.llAddrs = append(dstEpi.llAddrs, epi.llAddrs...)
|
2016-05-25 03:04:49 +00:00
|
|
|
}
|
2015-10-05 11:21:15 +00:00
|
|
|
|
|
|
|
for _, route := range epi.routes {
|
|
|
|
dstEpi.routes = append(dstEpi.routes, types.GetIPNetCopy(route))
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-05-14 06:23:45 +00:00
|
|
|
type endpointJoinInfo struct {
|
2015-12-03 02:07:44 +00:00
|
|
|
gw net.IP
|
|
|
|
gw6 net.IP
|
|
|
|
StaticRoutes []*types.StaticRoute
|
2016-03-30 21:42:58 +00:00
|
|
|
driverTableEntries []*tableEntry
|
2015-12-03 02:07:44 +00:00
|
|
|
disableGatewayService bool
|
2015-06-11 01:50:19 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 21:42:58 +00:00
|
|
|
type tableEntry struct {
|
|
|
|
tableName string
|
|
|
|
key string
|
|
|
|
value []byte
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
// Info returns certain operational data belonging to this endpoint.
|
|
|
|
func (ep *Endpoint) Info() EndpointInfo {
|
2017-02-02 22:46:59 +00:00
|
|
|
if ep.sandboxID != "" {
|
|
|
|
return ep
|
|
|
|
}
|
2015-10-05 11:21:15 +00: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 15:57:02 +00:00
|
|
|
return sb.getEndpoint(ep.ID())
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) Iface() InterfaceInfo {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
if ep.iface != nil {
|
|
|
|
return ep.iface
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
return nil
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) Interface() driverapi.InterfaceInfo {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
if ep.iface != nil {
|
|
|
|
return ep.iface
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
return nil
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 23:11:50 +00: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 06:23:45 +00:00
|
|
|
|
2015-10-03 23:11:50 +00: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 06:23:45 +00:00
|
|
|
}
|
2015-10-03 23:11:50 +00:00
|
|
|
return setAddress(&epi.addr, address)
|
|
|
|
}
|
2015-05-14 06:23:45 +00:00
|
|
|
|
2015-10-03 23:11:50 +00: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 06:23:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:31:12 +00:00
|
|
|
func (epi *endpointInterface) MacAddress() net.HardwareAddr {
|
|
|
|
return types.GetMacCopy(epi.mac)
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 23:11:50 +00:00
|
|
|
func (epi *endpointInterface) Address() *net.IPNet {
|
|
|
|
return types.GetIPNetCopy(epi.addr)
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-10-03 23:11:50 +00:00
|
|
|
func (epi *endpointInterface) AddressIPv6() *net.IPNet {
|
|
|
|
return types.GetIPNetCopy(epi.addrv6)
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2016-05-25 03:04:49 +00:00
|
|
|
func (epi *endpointInterface) LinkLocalAddresses() []*net.IPNet {
|
|
|
|
return epi.llAddrs
|
|
|
|
}
|
|
|
|
|
2018-04-09 22:15:01 +00:00
|
|
|
func (epi *endpointInterface) SrcName() string {
|
|
|
|
return epi.srcName
|
|
|
|
}
|
|
|
|
|
2015-06-05 20:31:12 +00:00
|
|
|
func (epi *endpointInterface) SetNames(srcName string, dstPrefix string) error {
|
|
|
|
epi.srcName = srcName
|
|
|
|
epi.dstPrefix = dstPrefix
|
2015-05-14 06:23:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) InterfaceName() driverapi.InterfaceNameInfo {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
if ep.iface != nil {
|
|
|
|
return ep.iface
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
return nil
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) AddStaticRoute(destination *net.IPNet, routeType int, nextHop net.IP) error {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-20 00:08:56 +00:00
|
|
|
|
2015-09-09 23:06:35 +00:00
|
|
|
r := types.StaticRoute{Destination: destination, RouteType: routeType, NextHop: nextHop}
|
2015-05-20 00:08:56 +00: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-18 00:55:24 +00:00
|
|
|
ep.iface.routes = append(ep.iface.routes, r.Destination)
|
2015-05-20 00:08:56 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) AddTableEntry(tableName, key string, value []byte) error {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2016-03-30 21:42:58 +00:00
|
|
|
|
|
|
|
ep.joinInfo.driverTableEntries = append(ep.joinInfo.driverTableEntries, &tableEntry{
|
|
|
|
tableName: tableName,
|
|
|
|
key: key,
|
|
|
|
value: value,
|
|
|
|
})
|
|
|
|
|
2016-04-19 02:55:39 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) Sandbox() *Sandbox {
|
2015-07-02 05:00:48 +00:00
|
|
|
cnt, ok := ep.getSandbox()
|
|
|
|
if !ok {
|
|
|
|
return nil
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
2015-07-02 05:00:48 +00:00
|
|
|
return cnt
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) LoadBalancer() bool {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2017-08-29 06:35:31 +00:00
|
|
|
return ep.loadBalancer
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) StaticRoutes() []*types.StaticRoute {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-12-02 23:21:50 +00:00
|
|
|
|
|
|
|
if ep.joinInfo == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return ep.joinInfo.StaticRoutes
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) Gateway() net.IP {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
|
|
|
if ep.joinInfo == nil {
|
|
|
|
return net.IP{}
|
|
|
|
}
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
return types.GetIPCopy(ep.joinInfo.gw)
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) GatewayIPv6() net.IP {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
|
|
|
if ep.joinInfo == nil {
|
|
|
|
return net.IP{}
|
|
|
|
}
|
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
return types.GetIPCopy(ep.joinInfo.gw6)
|
2015-05-14 06:23:45 +00:00
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) SetGateway(gw net.IP) error {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
ep.joinInfo.gw = types.GetIPCopy(gw)
|
2015-05-14 06:23:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) SetGatewayIPv6(gw6 net.IP) error {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-05-14 06:23:45 +00:00
|
|
|
|
2015-05-20 20:28:46 +00:00
|
|
|
ep.joinInfo.gw6 = types.GetIPCopy(gw6)
|
2015-05-14 06:23:45 +00:00
|
|
|
return nil
|
|
|
|
}
|
2015-10-28 23:22:18 +00:00
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) retrieveFromStore() (*Endpoint, error) {
|
2015-10-28 23:22:18 +00:00
|
|
|
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-03 02:07:44 +00:00
|
|
|
|
2023-01-12 01:42:24 +00:00
|
|
|
func (ep *Endpoint) DisableGatewayService() {
|
2023-01-11 22:51:59 +00:00
|
|
|
ep.mu.Lock()
|
|
|
|
defer ep.mu.Unlock()
|
2015-12-03 02:07:44 +00:00
|
|
|
|
|
|
|
ep.joinInfo.disableGatewayService = true
|
|
|
|
}
|
2016-06-11 00:32:19 +00: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 10:33:23 +00:00
|
|
|
epj.gw = net.ParseIP(v.(string))
|
2016-06-11 00:32:19 +00: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
|
2021-05-28 00:15:56 +00:00
|
|
|
// TODO(cpuguy83): Linter caught that we aren't checking errors here
|
|
|
|
// I don't know why we aren't other than potentially the data is not always expected to be right?
|
|
|
|
// This is why I'm not adding the error check.
|
|
|
|
//
|
|
|
|
// In any case for posterity please if you figure this out document it or check the error
|
2022-07-13 20:30:47 +00:00
|
|
|
json.Unmarshal(tb, &tStaticRoute) //nolint:errcheck
|
2016-06-11 00:32:19 +00:00
|
|
|
}
|
|
|
|
var StaticRoutes []*types.StaticRoute
|
|
|
|
for _, r := range tStaticRoute {
|
2021-06-18 22:20:06 +00:00
|
|
|
r := r
|
|
|
|
StaticRoutes = append(StaticRoutes, &r)
|
2016-06-11 00:32:19 +00:00
|
|
|
}
|
|
|
|
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 21:06:41 +00:00
|
|
|
dstEpj.driverTableEntries = make([]*tableEntry, len(epj.driverTableEntries))
|
|
|
|
copy(dstEpj.driverTableEntries, epj.driverTableEntries)
|
2016-06-11 00:32:19 +00:00
|
|
|
dstEpj.gw = types.GetIPCopy(epj.gw)
|
2017-08-03 10:33:23 +00:00
|
|
|
dstEpj.gw6 = types.GetIPCopy(epj.gw6)
|
2016-06-11 00:32:19 +00:00
|
|
|
return nil
|
|
|
|
}
|