Skip to content

Commit f656f44

Browse files
tamilmani1989sharmasushant
authored andcommitted
Block apipa address (#238)
* block apipa address and remove reading dns from dnc. Added config for passing dns * modified iptable rule to allow dns server to top of chain
1 parent 9a9c2cd commit f656f44

File tree

3 files changed

+33
-6
lines changed

3 files changed

+33
-6
lines changed

cni/azure-linux-multitenancy.conflist

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@
77
"mode":"bridge",
88
"bridge":"azure0",
99
"multiTenancy":true,
10+
"infraVnetAddressSpace":"",
11+
"podNamespaceForDualNetwork":[],
12+
"enableExactMatchForPodName": false,
1013
"enableSnatOnHost":true,
1114
"ipam":{
1215
"type":"azure-vnet-ipam"
13-
}
16+
},
17+
"dns":{
18+
"nameservers":[]
19+
}
1420
},
1521
{
1622
"type":"portmap",
@@ -20,4 +26,4 @@
2026
"snat":true
2127
}
2228
]
23-
}
29+
}

cni/network/mutlitenancy.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,6 @@ func convertToCniResult(networkConfig *cns.GetNetworkContainerResponse, ifName s
112112

113113
resultIpconfig.Gateway = net.ParseIP(ipconfig.GatewayIPAddress)
114114
result.IPs = append(result.IPs, resultIpconfig)
115-
result.DNS.Nameservers = ipconfig.DNSServers
116115

117116
if networkConfig.Routes != nil && len(networkConfig.Routes) > 0 {
118117
for _, route := range networkConfig.Routes {

network/epcommon/endpoint_common_linux.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,23 @@ import (
99
"github.com/Azure/azure-container-networking/platform"
1010
)
1111

12+
/*RFC For Private Address Space: https://tools.ietf.org/html/rfc1918
13+
The Internet Assigned Numbers Authority (IANA) has reserved the
14+
following three blocks of the IP address space for private internets:
15+
16+
10.0.0.0 - 10.255.255.255 (10/8 prefix)
17+
172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
18+
192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
19+
20+
RFC for Link Local Addresses: https://tools.ietf.org/html/rfc3927
21+
This document describes how a host may
22+
automatically configure an interface with an IPv4 address within the
23+
169.254/16 prefix that is valid for communication with other devices
24+
connected to the same physical (or logical) link.
25+
*/
26+
1227
func getPrivateIPSpace() []string {
13-
privateIPAddresses := []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16"}
28+
privateIPAddresses := []string{"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "169.254.0.0/16"}
1429
return privateIPAddresses
1530
}
1631

@@ -82,22 +97,29 @@ func AssignIPToInterface(interfaceName string, ipAddresses []net.IPNet) error {
8297
}
8398

8499
func addOrDeleteFilterRule(bridgeName string, action string, ipAddress string, chainName string, target string) error {
100+
var cmd string
85101
option := "i"
86102

87103
if chainName == "OUTPUT" {
88104
option = "o"
89105
}
90106

91107
if action != "D" {
92-
cmd := fmt.Sprintf("iptables -t filter -C %v -%v %v -d %v -j %v", chainName, option, bridgeName, ipAddress, target)
108+
cmd = fmt.Sprintf("iptables -t filter -C %v -%v %v -d %v -j %v", chainName, option, bridgeName, ipAddress, target)
93109
_, err := platform.ExecuteCommand(cmd)
94110
if err == nil {
95111
log.Printf("Iptable filter for private ipaddr %v on %v chain %v target rule already exists", ipAddress, chainName, target)
96112
return nil
97113
}
98114
}
99115

100-
cmd := fmt.Sprintf("iptables -t filter -%v %v -%v %v -d %v -j %v", action, chainName, option, bridgeName, ipAddress, target)
116+
if target != "ACCEPT" {
117+
cmd = fmt.Sprintf("iptables -t filter -%v %v -%v %v -d %v -j %v", action, chainName, option, bridgeName, ipAddress, target)
118+
} else {
119+
action = "I"
120+
cmd = fmt.Sprintf("iptables -t filter -%v %v 1 -%v %v -d %v -j %v", action, chainName, option, bridgeName, ipAddress, target)
121+
}
122+
101123
_, err := platform.ExecuteCommand(cmd)
102124
if err != nil {
103125
log.Printf("Iptable filter %v action for private ipaddr %v on %v chain %v target failed with %v", action, ipAddress, chainName, target, err)

0 commit comments

Comments
 (0)