Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
91 commits
Select commit Hold shift + click to select a range
8f64c08
Native Endpoint Client Add Endpoints
QxBytes Jul 6, 2022
2b3cb7a
AddEndpointRules, ConfigureContainerInterfacesAndRoutes
QxBytes Jul 6, 2022
a85c365
Changed interface names, log statements
QxBytes Jul 6, 2022
f08f0b7
Renaming, using lib to set ns
QxBytes Jul 7, 2022
8531563
Namespace "path" is /var/run/netns/<NS>
QxBytes Jul 8, 2022
3752a41
Loopback set up, Remove auto kernel subnet route
QxBytes Jul 8, 2022
3f6507d
Cannot set link to up if it's in another NS
QxBytes Jul 8, 2022
d38d06b
Multiple containers on same VNET NS
QxBytes Jul 11, 2022
1f8d37f
Delete Endpoint routes on Delete
QxBytes Jul 11, 2022
7f8b802
Minimizing netns usage
QxBytes Jul 11, 2022
b622049
Moving NS Exec Code
QxBytes Jul 12, 2022
c1e60a1
Further minimized netns.Set usage
QxBytes Jul 12, 2022
ddd5213
Moved helper methods down, drafted tests
QxBytes Jul 12, 2022
f4b5fd7
Removed DevName from Route Info, more tests
QxBytes Jul 12, 2022
4c280c2
Test existing vnet ns, delete endpoint
QxBytes Jul 13, 2022
7ac1a95
NetNS interface for testing
QxBytes Jul 13, 2022
32b4d98
Separated tests by namespace
QxBytes Jul 13, 2022
9a488f9
Endpoints delete if they cannot be moved into NS
QxBytes Jul 14, 2022
7c8838b
Namespace netns tests
QxBytes Jul 14, 2022
4e4def5
Added Native Client to deleteEndpointImpl
QxBytes Jul 14, 2022
7e593d9
Deletion of Endpoints Impl and Tests
QxBytes Jul 15, 2022
be0191a
Cleaned code (Tests ok)
QxBytes Jul 15, 2022
1f40dd8
Moved mock/netns to package (Tests ok)
QxBytes Jul 18, 2022
0552493
Fixing Netns (wip)
QxBytes Jul 18, 2022
2c2aac5
Using errors.Wrap for error context (wip)
QxBytes Jul 18, 2022
248a90c
Removed sentence case (wip)
QxBytes Jul 19, 2022
3e8e719
Removing variable predeclaration
QxBytes Jul 19, 2022
a3b6277
Removed NewNativeEndpointClient
QxBytes Jul 19, 2022
536a022
Removed generics from ExecuteInNS
QxBytes Jul 19, 2022
9193600
Removed uintptr from mocknetns, tests compile
QxBytes Jul 19, 2022
095fdc9
Fix tests, lint
QxBytes Jul 19, 2022
4a63471
Fixes from linter
QxBytes Jul 19, 2022
c291f1c
Replacing references to ethX with vlan veth
QxBytes Jul 19, 2022
97022b8
Removed unnecessary log
QxBytes Jul 19, 2022
c40d4e8
Removed unnecessary mac, fix tests
QxBytes Jul 19, 2022
c58059b
Mockns method name enum
QxBytes Jul 19, 2022
a724dc5
Unable to use GetNetworkInterfaceByName due to NS
QxBytes Jul 19, 2022
062aa9f
Fixes from linter
QxBytes Jul 19, 2022
a0676b2
Assume if NS exists, vlan veth exists
QxBytes Jul 20, 2022
efdfb96
Fixes for Linter
QxBytes Jul 20, 2022
7349b8d
Snat refactor
QxBytes Jul 20, 2022
adb23b2
Fix delete tests
QxBytes Jul 20, 2022
a775d93
Fix delete tests bug
QxBytes Jul 20, 2022
4f750ef
More snat refactor
QxBytes Jul 20, 2022
580bffd
Breaking, prepping for Native Snat
QxBytes Jul 20, 2022
88a2a50
Go mod tidy for linting
QxBytes Jul 20, 2022
d7c159e
Add fields to native endpoint client for snat
QxBytes Jul 20, 2022
97f99ac
Merge branch 't-allew/develop' into t-allew/snat
QxBytes Jul 20, 2022
b4c1b41
Using New() func to create Native Client
QxBytes Jul 20, 2022
257ab8c
Snat defaults
QxBytes Jul 20, 2022
f6a013c
Insert SNAT entry points
QxBytes Jul 20, 2022
059363c
Native Snat error handling
QxBytes Jul 21, 2022
6c390d3
Breaking, decouple ovsctl from snat
QxBytes Jul 21, 2022
9cb6a51
Delete unecessary ovssnat files
QxBytes Jul 21, 2022
9c150bd
No lint on vishvananda netns
QxBytes Jul 21, 2022
ef4b49f
Build linux only for netns package
QxBytes Jul 21, 2022
df83ada
Remove nolint to see if linter fails
QxBytes Jul 21, 2022
aa5baed
Breaking, removed bridgeName
QxBytes Jul 21, 2022
6a1a06c
If native uses snat bridge, should also get IP
QxBytes Jul 21, 2022
f3bc95b
Breaking, Decouple or Wrap snat route
QxBytes Jul 21, 2022
2d854b8
Check to see if snat triggered
QxBytes Jul 21, 2022
8f2db2f
Snat behaviors specific to ovs/native
QxBytes Jul 22, 2022
faef1ab
Pass the pointer
QxBytes Jul 22, 2022
9fa80a9
Renaming to make consts public
QxBytes Jul 22, 2022
0bc785a
Breaking, moving ovs specific parts of snat to ovs
QxBytes Jul 22, 2022
71dc1e4
Remove enable infra vnet (Tests ok)
QxBytes Jul 22, 2022
49eb30c
Move add port to after exists() check
QxBytes Jul 25, 2022
ba901c5
Moved netns interface to caller, generalized tests
QxBytes Jul 26, 2022
33f4941
Typos
QxBytes Jul 27, 2022
228ba63
Reordered if statement, unwrapped arp
QxBytes Jul 27, 2022
ee1eddc
Merge branch 't-allew/develop' into t-allew/snat
QxBytes Jul 27, 2022
5c2a77d
Linted, wrapping errors
QxBytes Jul 27, 2022
c3e781f
Go fumpt entire network package
QxBytes Jul 27, 2022
0fa38bf
Code markers removed, clean (Tests ok)
QxBytes Aug 1, 2022
18f9652
Renamed veth, fixed logs
QxBytes Aug 1, 2022
7e44c85
Made deleteEndpoints logic clearer, renamed error
QxBytes Aug 1, 2022
1807094
Renamed eth0 to primaryHostIfName, vlanEth to vlanIf
QxBytes Aug 1, 2022
9347d07
Merge branch 't-allew/develop' into t-allew/snat
QxBytes Aug 1, 2022
a99cb45
Deleted debug log
QxBytes Aug 1, 2022
4c30a22
Merge branch 'master' into t-allew/snat
QxBytes Aug 2, 2022
124c409
Corrected merge (hardware addr) (Tests ok)
QxBytes Aug 2, 2022
eef4fd6
Merge branch 'master' into t-allew/snat
QxBytes Aug 3, 2022
fed7864
Renamed vlan veth to hostExtIf_vlanID, Disabled RA
QxBytes Aug 4, 2022
51879e2
Renamed Native to TransparentVlan
QxBytes Aug 8, 2022
5b187bc
Make file updated
QxBytes Aug 8, 2022
c259490
Create azure-windows-multitenancy-transparent-vlan.conflist
QxBytes Aug 8, 2022
21c26a4
Unified snat err format
QxBytes Aug 9, 2022
1f18c1f
Rename to transparent-vlan
QxBytes Aug 9, 2022
dd57afe
Route table support added to local netlink
QxBytes Aug 9, 2022
b2674dc
Moved SNAT to end of function
QxBytes Aug 9, 2022
6f1c50a
Defer deleting vlan interface on failure
QxBytes Aug 9, 2022
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
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ CNM_BUILD_DIR = $(BUILD_DIR)/cnm
CNI_BUILD_DIR = $(BUILD_DIR)/cni
ACNCLI_BUILD_DIR = $(BUILD_DIR)/acncli
CNI_MULTITENANCY_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy
CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR = $(BUILD_DIR)/cni-multitenancy-transparent-vlan
CNI_SWIFT_BUILD_DIR = $(BUILD_DIR)/cni-swift
CNI_OVERLAY_BUILD_DIR = $(BUILD_DIR)/cni-overlay
CNI_BAREMETAL_BUILD_DIR = $(BUILD_DIR)/cni-baremetal
Expand Down Expand Up @@ -77,6 +78,7 @@ CNM_ARCHIVE_NAME = azure-vnet-cnm-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNI_ARCHIVE_NAME = azure-vnet-cni-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
ACNCLI_ARCHIVE_NAME = acncli-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNI_MULTITENANCY_ARCHIVE_NAME = azure-vnet-cni-multitenancy-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNI_MULTITENANCY_TRANSPARENT_VLAN_ARCHIVE_NAME = azure-vnet-cni-multitenancy-transparent-vlan-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNI_SWIFT_ARCHIVE_NAME = azure-vnet-cni-swift-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNI_OVERLAY_ARCHIVE_NAME = azure-vnet-cni-overlay-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
CNI_BAREMETAL_ARCHIVE_NAME = azure-vnet-cni-baremetal-$(GOOS)-$(GOARCH)-$(VERSION).$(ARCHIVE_EXT)
Expand Down Expand Up @@ -439,6 +441,15 @@ ifeq ($(GOOS),linux)
endif
cd $(CNI_MULTITENANCY_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_MULTITENANCY_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config

$(MKDIR) $(CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR)
cp cni/azure-$(GOOS)-multitenancy-transparent-vlan.conflist $(CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR)/10-azure.conflist
cp $(CNI_BUILD_DIR)/azure-vnet$(EXE_EXT) $(CNI_BUILD_DIR)/azure-vnet-ipam$(EXE_EXT) $(CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR)
ifeq ($(GOOS),linux)
cp telemetry/azure-vnet-telemetry.config $(CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR)/azure-vnet-telemetry.config
cp $(CNI_BUILD_DIR)/azure-vnet-telemetry$(EXE_EXT) $(CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR)
endif
cd $(CNI_MULTITENANCY_TRANSPARENT_VLAN_BUILD_DIR) && $(ARCHIVE_CMD) $(CNI_MULTITENANCY_TRANSPARENT_VLAN_ARCHIVE_NAME) azure-vnet$(EXE_EXT) azure-vnet-ipam$(EXE_EXT) azure-vnet-telemetry$(EXE_EXT) 10-azure.conflist azure-vnet-telemetry.config

$(MKDIR) $(CNI_SWIFT_BUILD_DIR)
cp cni/azure-$(GOOS)-swift.conflist $(CNI_SWIFT_BUILD_DIR)/10-azure.conflist
cp telemetry/azure-vnet-telemetry.config $(CNI_SWIFT_BUILD_DIR)/azure-vnet-telemetry.config
Expand Down
29 changes: 29 additions & 0 deletions cni/azure-linux-multitenancy-transparent-vlan.conflist
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"cniVersion":"0.3.0",
"name":"azure",
"plugins":[
{
"type":"azure-vnet",
"mode":"transparent-vlan",
"bridge":"azure0",
"multiTenancy":true,
"infraVnetAddressSpace":"",
"podNamespaceForDualNetwork":[],
"enableExactMatchForPodName": false,
"enableSnatOnHost":true,
"ipam":{
"type":"azure-cns"
},
"dns":{
"nameservers":[]
}
},
{
"type":"portmap",
"capabilities":{
"portMappings":true
},
"snat":true
}
]
}
52 changes: 52 additions & 0 deletions cni/azure-windows-multitenancy-transparent-vlan.conflist
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"cniVersion": "0.3.0",
"name": "azure",
"plugins": [
{
"type": "azure-vnet",
"mode": "transparent-vlan",
"bridge": "azure0",
"multiTenancy":true,
"enableSnatOnHost":true,
"enableExactMatchForPodName": true,
"capabilities": {
"portMappings": true
},
"ipam": {
"type": "azure-cns"
},
"dns": {
"Nameservers": [
"10.0.0.10",
"168.63.129.16"
],
"Search": [
"svc.cluster.local"
]
},
"AdditionalArgs": [
{
"Name": "EndpointPolicy",
"Value": {
"Type": "OutBoundNAT",
"ExceptionList": [
"10.240.0.0/16",
"10.0.0.0/8"
]
}
},
{
"Name": "EndpointPolicy",
"Value": {
"Type": "ROUTE",
"DestinationPrefix": "10.0.0.0/8",
"NeedEncap": true
}
}
],
"windowsSettings": {
"hnsTimeoutDurationInSeconds" : 120
}
}
]
}
1 change: 1 addition & 0 deletions network/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type RouteInfo struct {
DevName string
Scope int
Priority int
Table int
}

type apipaClient interface {
Expand Down
48 changes: 10 additions & 38 deletions network/endpoint_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/netio"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/netns"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Azure/azure-container-networking/ovsctl"
"github.com/Azure/azure-container-networking/platform"
Expand Down Expand Up @@ -90,25 +89,12 @@ func (nw *network) newEndpointImpl(_ apipaClient, nl netlink.NetlinkInterface, p
}

if vlanid != 0 {
if nw.Mode == opModeNative {
log.Printf("Native client")
vlanVethName := fmt.Sprintf("%s.%d", nw.extIf.Name, vlanid)
vnetNSName := fmt.Sprintf("az_ns_%d", vlanid)

epClient = &NativeEndpointClient{
primaryHostIfName: nw.extIf.Name,
vlanIfName: vlanVethName,
vnetVethName: hostIfName,
containerVethName: contIfName,
vnetNSName: vnetNSName,
nw: nw,
vlanID: vlanid,
netnsClient: netns.New(),
netlink: nl,
netioshim: &netio.NetIO{},
plClient: plc,
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
if nw.Mode == opModeTransparentVlan {
log.Printf("Transparent vlan client")
if _, ok := epInfo.Data[SnatBridgeIPKey]; ok {
nw.SnatBridgeIP = epInfo.Data[SnatBridgeIPKey].(string)
}
epClient = NewTransparentVlanEndpointClient(nw, epInfo, hostIfName, contIfName, vlanid, localIP, nl, plc)
} else {
log.Printf("OVS client")
if _, ok := epInfo.Data[SnatBridgeIPKey]; ok {
Expand Down Expand Up @@ -261,25 +247,10 @@ func (nw *network) deleteEndpointImpl(nl netlink.NetlinkInterface, plc platform.
// entering the container netns and hence works both for CNI and CNM.
if ep.VlanID != 0 {
epInfo := ep.getInfo()
if nw.Mode == opModeNative {
log.Printf("Native client")
vlanVethName := fmt.Sprintf("%s.%d", nw.extIf.Name, ep.VlanID)
vnetNSName := fmt.Sprintf("az_ns_%d", ep.VlanID)

epClient = &NativeEndpointClient{
primaryHostIfName: nw.extIf.Name,
vlanIfName: vlanVethName,
vnetVethName: ep.HostIfName,
containerVethName: "",
vnetNSName: vnetNSName,
nw: nw,
vlanID: ep.VlanID,
netnsClient: netns.New(),
netlink: nl,
netioshim: &netio.NetIO{},
plClient: plc,
netUtilsClient: networkutils.NewNetworkUtils(nl, plc),
}
if nw.Mode == opModeTransparentVlan {
log.Printf("Transparent vlan client")
epClient = NewTransparentVlanEndpointClient(nw, epInfo, ep.HostIfName, "", ep.VlanID, ep.LocalIP, nl, plc)

} else {
epClient = NewOVSEndpointClient(nw, epInfo, ep.HostIfName, "", ep.VlanID, ep.LocalIP, nl, ovsctl.NewOvsctl(), plc)
}
Expand Down Expand Up @@ -330,6 +301,7 @@ func addRoutes(nl netlink.NetlinkInterface, netioshim netio.NetIOInterface, inte
Priority: route.Priority,
Protocol: route.Protocol,
Scope: route.Scope,
Table: route.Table,
}

if err := nl.AddIPRoute(nlRoute); err != nil {
Expand Down
100 changes: 100 additions & 0 deletions network/endpoint_snatroute_linux.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package network

import (
"fmt"

"github.com/Azure/azure-container-networking/log"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/networkutils"
"github.com/Azure/azure-container-networking/network/snat"
"github.com/Azure/azure-container-networking/platform"
"github.com/pkg/errors"
)

func GetSnatHostIfName(epInfo *EndpointInfo) string {
return fmt.Sprintf("%s%s", snatVethInterfacePrefix, epInfo.Id[:7])
}

func GetSnatContIfName(epInfo *EndpointInfo) string {
return fmt.Sprintf("%s%s-2", snatVethInterfacePrefix, epInfo.Id[:7])
}

func AddSnatEndpoint(snatClient *snat.Client) error {
if err := snatClient.CreateSnatEndpoint(); err != nil {
return errors.Wrap(err, "failed to add snat endpoint")
}
return nil
}

func AddSnatEndpointRules(snatClient *snat.Client, hostToNC, ncToHost bool, nl netlink.NetlinkInterface, plc platform.ExecClient) error {
// Allow specific Private IPs via Snat Bridge
if err := snatClient.AllowIPAddressesOnSnatBridge(); err != nil {
return errors.Wrap(err, "failed to allow ip addresses on snat bridge")
}

// Block Private IPs via Snat Bridge
if err := snatClient.BlockIPAddressesOnSnatBridge(); err != nil {
return errors.Wrap(err, "failed to block ip addresses on snat bridge")
}
nuc := networkutils.NewNetworkUtils(nl, plc)
if err := nuc.EnableIPForwarding(snat.SnatBridgeName); err != nil {
return errors.Wrap(err, "failed to enable ip forwarding")
}

if hostToNC {
if err := snatClient.AllowInboundFromHostToNC(); err != nil {
return errors.Wrap(err, "failed to allow inbound from host to nc")
}
}

if ncToHost {
if err := snatClient.AllowInboundFromNCToHost(); err != nil {
return errors.Wrap(err, "failed to allow inbound from nc to host")
}
}
return nil
}

func MoveSnatEndpointToContainerNS(snatClient *snat.Client, netnsPath string, nsID uintptr) error {
if err := snatClient.MoveSnatEndpointToContainerNS(netnsPath, nsID); err != nil {
return errors.Wrap(err, "failed to move snat endpoint to container ns")
}
return nil
}

func SetupSnatContainerInterface(snatClient *snat.Client) error {
if err := snatClient.SetupSnatContainerInterface(); err != nil {
return errors.Wrap(err, "failed to setup snat container interface")
}
return nil
}

func ConfigureSnatContainerInterface(snatClient *snat.Client) error {
if err := snatClient.ConfigureSnatContainerInterface(); err != nil {
return errors.Wrap(err, "failed to configure snat container interface")
}
return nil
}

func DeleteSnatEndpoint(snatClient *snat.Client) error {
if err := snatClient.DeleteSnatEndpoint(); err != nil {
return errors.Wrap(err, "failed to delete snat endpoint")
}
return nil
}

func DeleteSnatEndpointRules(snatClient *snat.Client, hostToNC, ncToHost bool) {
if hostToNC {
err := snatClient.DeleteInboundFromHostToNC()
if err != nil {
log.Errorf("failed to delete inbound from host to nc rules")
}
}

if ncToHost {
err := snatClient.DeleteInboundFromNCToHost()
if err != nil {
log.Errorf("failed to delete inbound from nc to host rules")
}
}
}
10 changes: 5 additions & 5 deletions network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import (

const (
// Operational modes.
opModeBridge = "bridge"
opModeTunnel = "tunnel"
opModeTransparent = "transparent"
opModeNative = "native"
opModeDefault = opModeTunnel
opModeBridge = "bridge"
opModeTunnel = "tunnel"
opModeTransparent = "transparent"
opModeTransparentVlan = "transparent-vlan"
opModeDefault = opModeTunnel
)

const (
Expand Down
4 changes: 2 additions & 2 deletions network/network_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ func (nm *networkManager) newNetworkImpl(nwInfo *NetworkInfo, extIf *externalInt
return nil, fmt.Errorf("Ipv6 forwarding failed: %w", err)
}
}
case opModeNative:
log.Printf("Native mode")
case opModeTransparentVlan:
log.Printf("Transparent vlan mode")
ifName = extIf.Name
default:
return nil, errNetworkModeInvalid
Expand Down
Loading