Skip to content

Commit 19ac791

Browse files
vipulhatamilmani1989
authored andcommitted
Option to not enable hairpin on the host interface. (Azure#472)
1 parent 546b0b0 commit 19ac791

File tree

4 files changed

+39
-34
lines changed

4 files changed

+39
-34
lines changed

cni/netconfig.go

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,22 +42,23 @@ type RuntimeDNSConfig struct {
4242

4343
// NetworkConfig represents Azure CNI plugin network configuration.
4444
type NetworkConfig struct {
45-
CNIVersion string `json:"cniVersion"`
46-
Name string `json:"name"`
47-
Type string `json:"type"`
48-
Mode string `json:"mode"`
49-
Master string `json:"master"`
50-
Bridge string `json:"bridge,omitempty"`
51-
LogLevel string `json:"logLevel,omitempty"`
52-
LogTarget string `json:"logTarget,omitempty"`
53-
InfraVnetAddressSpace string `json:"infraVnetAddressSpace,omitempty"`
54-
PodNamespaceForDualNetwork []string `json:"podNamespaceForDualNetwork,omitempty"`
55-
MultiTenancy bool `json:"multiTenancy,omitempty"`
56-
EnableSnatOnHost bool `json:"enableSnatOnHost,omitempty"`
57-
EnableExactMatchForPodName bool `json:"enableExactMatchForPodName,omitempty"`
58-
DisableIPTableLock bool `json:"disableIPTableLock,omitempty"`
59-
CNSUrl string `json:"cnsurl,omitempty"`
60-
Ipam struct {
45+
CNIVersion string `json:"cniVersion"`
46+
Name string `json:"name"`
47+
Type string `json:"type"`
48+
Mode string `json:"mode"`
49+
Master string `json:"master"`
50+
Bridge string `json:"bridge,omitempty"`
51+
LogLevel string `json:"logLevel,omitempty"`
52+
LogTarget string `json:"logTarget,omitempty"`
53+
InfraVnetAddressSpace string `json:"infraVnetAddressSpace,omitempty"`
54+
PodNamespaceForDualNetwork []string `json:"podNamespaceForDualNetwork,omitempty"`
55+
MultiTenancy bool `json:"multiTenancy,omitempty"`
56+
EnableSnatOnHost bool `json:"enableSnatOnHost,omitempty"`
57+
EnableExactMatchForPodName bool `json:"enableExactMatchForPodName,omitempty"`
58+
DisableHairpinOnHostInterface bool `json:"disableHairpinOnHostInterface,omitempty"`
59+
DisableIPTableLock bool `json:"disableIPTableLock,omitempty"`
60+
CNSUrl string `json:"cnsurl,omitempty"`
61+
Ipam struct {
6162
Type string `json:"type"`
6263
Environment string `json:"environment,omitempty"`
6364
AddrSpace string `json:"addressSpace,omitempty"`

cni/network/network.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -466,11 +466,12 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) error {
466466
Gateway: gateway,
467467
},
468468
},
469-
BridgeName: nwCfg.Bridge,
470-
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
471-
DNS: nwDNSInfo,
472-
Policies: policies,
473-
NetNs: args.Netns,
469+
BridgeName: nwCfg.Bridge,
470+
EnableSnatOnHost: nwCfg.EnableSnatOnHost,
471+
DNS: nwDNSInfo,
472+
Policies: policies,
473+
NetNs: args.Netns,
474+
DisableHairpinOnHostInterface: nwCfg.DisableHairpinOnHostInterface,
474475
}
475476

476477
nwInfo.Options = make(map[string]interface{})

network/network.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,17 @@ type network struct {
5151

5252
// NetworkInfo contains read-only information about a container network.
5353
type NetworkInfo struct {
54-
MasterIfName string
55-
Id string
56-
Mode string
57-
Subnets []SubnetInfo
58-
DNS DNSInfo
59-
Policies []policy.Policy
60-
BridgeName string
61-
EnableSnatOnHost bool
62-
NetNs string
63-
Options map[string]interface{}
54+
MasterIfName string
55+
Id string
56+
Mode string
57+
Subnets []SubnetInfo
58+
DNS DNSInfo
59+
Policies []policy.Policy
60+
BridgeName string
61+
EnableSnatOnHost bool
62+
NetNs string
63+
Options map[string]interface{}
64+
DisableHairpinOnHostInterface bool
6465
}
6566

6667
// SubnetInfo contains subnet information for a container network.

network/network_linux.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,11 @@ func (nm *networkManager) connectExternalInterface(extIf *externalInterface, nwI
391391
}
392392

393393
// External interface hairpin on.
394-
log.Printf("[net] Setting link %v hairpin on.", hostIf.Name)
395-
if err := networkClient.SetHairpinOnHostInterface(true); err != nil {
396-
return err
394+
if !nwInfo.DisableHairpinOnHostInterface {
395+
log.Printf("[net] Setting link %v hairpin on.", hostIf.Name)
396+
if err := networkClient.SetHairpinOnHostInterface(true); err != nil {
397+
return err
398+
}
397399
}
398400

399401
// Apply IP configuration to the bridge for host traffic.

0 commit comments

Comments
 (0)