Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions network/endpoint_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ func addRoutes(interfaceName string, routes []RouteInfo) error {
Gw: route.Gw,
LinkIndex: ifIndex,
Priority: route.Priority,
Protocol: route.Protocol,
Scope: route.Scope,
}

if err := netlink.AddIpRoute(nlRoute); err != nil {
Expand Down Expand Up @@ -312,6 +314,8 @@ func deleteRoutes(interfaceName string, routes []RouteInfo) error {
Dst: &route.Dst,
Gw: route.Gw,
LinkIndex: ifIndex,
Protocol: route.Protocol,
Scope: route.Scope,
}

if err := netlink.DeleteIpRoute(nlRoute); err != nil {
Expand Down
44 changes: 41 additions & 3 deletions network/transparent_endpointclient_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ import (
)

const (
FAKE_GW_IP = "169.254.1.1/32"
DEFAULT_GW = "0.0.0.0/0"
virtualGwIPString = "169.254.1.1/32"
defaultGwCidr = "0.0.0.0/0"
defaultGw = "0.0.0.0"
)

type TransparentEndpointClient struct {
Expand Down Expand Up @@ -147,7 +148,44 @@ func (client *TransparentEndpointClient) ConfigureContainerInterfacesAndRoutes(e
return err
}

return addRoutes(client.containerVethName, epInfo.Routes)
//ip route del 10.240.0.0/12 dev eth0 (removing kernel subnet route added by above call)
for _, ipAddr := range epInfo.IPAddresses {
_, ipnet, _ := net.ParseCIDR(ipAddr.String())
routeInfo := RouteInfo{
Dst: *ipnet,
Scope: netlink.RT_SCOPE_LINK,
Protocol: netlink.RTPROT_KERNEL,
}
if err := deleteRoutes(client.containerVethName, []RouteInfo{routeInfo}); err != nil {
return err
}
}

//add route for virtualgwip
//ip route add 169.254.1.1/32 dev eth0
virtualGwIP, virtualGwNet, _ := net.ParseCIDR(virtualGwIPString)
routeInfo := RouteInfo{
Dst: *virtualGwNet,
Scope: netlink.RT_SCOPE_LINK,
}
if err := addRoutes(client.containerVethName, []RouteInfo{routeInfo}); err != nil {
return err
}

//ip route add default via 169.254.1.1 dev eth0
_, defaultIPNet, _ := net.ParseCIDR(defaultGwCidr)
dstIP := net.IPNet{IP: net.ParseIP(defaultGw), Mask: defaultIPNet.Mask}
routeInfo = RouteInfo{
Dst: dstIP,
Gw: virtualGwIP,
}
if err := addRoutes(client.containerVethName, []RouteInfo{routeInfo}); err != nil {
return err
}

//arp -s 169.254.1.1 e3:45:f4:ac:34:12 - add static arp entry for virtualgwip to hostveth interface mac
log.Printf("[net] Adding static arp for IP address %v and MAC %v in Container namespace", virtualGwNet.String(), client.hostVethMac)
return netlink.AddOrRemoveStaticArp(netlink.ADD, client.containerVethName, virtualGwNet.IP, client.hostVethMac, false)
}

func (client *TransparentEndpointClient) DeleteEndpoints(ep *endpoint) error {
Expand Down