Skip to content

Commit a00472e

Browse files
committed
rename chain variable to reflect its value
1 parent bfb74f4 commit a00472e

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

cns/restserver/internalapi_linux.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/pkg/errors"
1515
)
1616

17-
const SWIFT = "SWIFT-POSTROUTING"
17+
const SWIFTPOSTROUTING = "SWIFT-POSTROUTING"
1818

1919
type IPtablesProvider struct{}
2020

@@ -37,13 +37,13 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
3737
return types.UnexpectedError, fmt.Sprintf("[Azure CNS] Error. Failed to create iptables interface : %v", err)
3838
}
3939

40-
chainExist, err := ipt.ChainExists(iptables.Nat, SWIFT)
40+
chainExist, err := ipt.ChainExists(iptables.Nat, SWIFTPOSTROUTING)
4141
if err != nil {
4242
return types.UnexpectedError, fmt.Sprintf("[Azure CNS] Error. Failed to check for existence of SWIFT-POSTROUTING chain: %v", err)
4343
}
4444
if !chainExist { // create and append chain if it doesn't exist
45-
logger.Printf("[Azure CNS] Creating SWIFT Chain ...")
46-
err = ipt.NewChain(iptables.Nat, SWIFT)
45+
logger.Printf("[Azure CNS] Creating SWIFT-POSTROUTING Chain ...")
46+
err = ipt.NewChain(iptables.Nat, SWIFTPOSTROUTING)
4747
if err != nil {
4848
return types.FailedToRunIPTableCmd, "[Azure CNS] failed to create SWIFT-POSTROUTING chain : " + err.Error()
4949
}
@@ -73,12 +73,12 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
7373
// jump SWIFT rule exists, insert SWIFT-POSTROUTING rule at the same position so it ends up running first
7474
// first, remove any existing SWIFT-POSTROUTING rules to avoid duplicates
7575
// note: inserting at len(rules) and deleting a jump to SWIFT-POSTROUTING is mutually exclusive
76-
swiftPostroutingExists, err := ipt.Exists(iptables.Nat, iptables.Postrouting, "-j", SWIFT)
76+
swiftPostroutingExists, err := ipt.Exists(iptables.Nat, iptables.Postrouting, "-j", SWIFTPOSTROUTING)
7777
if err != nil {
7878
return types.UnexpectedError, fmt.Sprintf("[Azure CNS] Error. Failed to check for existence of SWIFT-POSTROUTING rule: %v", err)
7979
}
8080
if swiftPostroutingExists {
81-
err = ipt.Delete(iptables.Nat, iptables.Postrouting, "-j", SWIFT)
81+
err = ipt.Delete(iptables.Nat, iptables.Postrouting, "-j", SWIFTPOSTROUTING)
8282
if err != nil {
8383
return types.FailedToRunIPTableCmd, "[Azure CNS] failed to delete existing SWIFT-POSTROUTING rule : " + err.Error()
8484
}
@@ -90,7 +90,7 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
9090
// -P POSTROUTING ACCEPT is at swiftRuleIndex 0
9191
// -A POSTROUTING -j SWIFT is at swiftRuleIndex 1, and iptables index 1
9292
logger.Printf("[Azure CNS] Inserting SWIFT-POSTROUTING Chain at iptables position %d", swiftRuleIndex)
93-
err = ipt.Insert(iptables.Nat, iptables.Postrouting, swiftRuleIndex, "-j", SWIFT)
93+
err = ipt.Insert(iptables.Nat, iptables.Postrouting, swiftRuleIndex, "-j", SWIFTPOSTROUTING)
9494
if err != nil {
9595
return types.FailedToRunIPTableCmd, "[Azure CNS] failed to insert SWIFT-POSTROUTING chain : " + err.Error()
9696
}
@@ -111,7 +111,7 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
111111
// check if all rules exist
112112
allRulesExist := true
113113
for _, rule := range rules {
114-
exists, err := ipt.Exists(iptables.Nat, SWIFT, rule...)
114+
exists, err := ipt.Exists(iptables.Nat, SWIFTPOSTROUTING, rule...)
115115
if err != nil {
116116
return types.UnexpectedError, fmt.Sprintf("[Azure CNS] Error. Failed to check for existence of rule: %v", err)
117117
}
@@ -122,7 +122,7 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
122122
}
123123

124124
// get current rule count in SWIFT-POSTROUTING chain
125-
currentRules, err := ipt.List(iptables.Nat, SWIFT)
125+
currentRules, err := ipt.List(iptables.Nat, SWIFTPOSTROUTING)
126126
if err != nil {
127127
return types.UnexpectedError, fmt.Sprintf("[Azure CNS] Error. Failed to list rules in SWIFT-POSTROUTING chain: %v", err)
128128
}
@@ -132,13 +132,13 @@ func (service *HTTPRestService) programSNATRules(req *cns.CreateNetworkContainer
132132
if len(currentRules) != len(rules)+1 || !allRulesExist {
133133
logger.Printf("[Azure CNS] Reconciling SWIFT-POSTROUTING chain rules")
134134

135-
err = ipt.ClearChain(iptables.Nat, SWIFT)
135+
err = ipt.ClearChain(iptables.Nat, SWIFTPOSTROUTING)
136136
if err != nil {
137137
return types.FailedToRunIPTableCmd, "[Azure CNS] failed to flush SWIFT-POSTROUTING chain : " + err.Error()
138138
}
139139

140140
for _, rule := range rules {
141-
err = ipt.Append(iptables.Nat, SWIFT, rule...)
141+
err = ipt.Append(iptables.Nat, SWIFTPOSTROUTING, rule...)
142142
if err != nil {
143143
return types.FailedToRunIPTableCmd, "[Azure CNS] failed to append rule to SWIFT-POSTROUTING chain : " + err.Error()
144144
}

cns/restserver/internalapi_linux_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func TestAddSNATRules(t *testing.T) {
6767
expectedChains: []chainExpectation{
6868
{
6969
table: iptables.Nat,
70-
chain: SWIFT,
70+
chain: SWIFTPOSTROUTING,
7171
expected: []string{
7272
"-N SWIFT-POSTROUTING",
7373
"-A SWIFT-POSTROUTING -m addrtype ! --dst-type local -s 240.1.2.0/24 -d " + networkutils.AzureDNS + " -p udp --dport " + strconv.Itoa(iptables.DNSPort) + " -j SNAT --to 240.1.2.1",
@@ -119,7 +119,7 @@ func TestAddSNATRules(t *testing.T) {
119119
{
120120
// should be cleaned up
121121
table: iptables.Nat,
122-
chain: SWIFT,
122+
chain: SWIFTPOSTROUTING,
123123
rule: []string{"-m", "addrtype", "!", "--dst-type", "local", "-s", "240.1.2.0/24", "-d", networkutils.AzureDNS, "-p", "udp", "--dport", strconv.Itoa(iptables.DNSPort), "-j", "SNAT", "--to", "99.1.2.1"},
124124
},
125125
{
@@ -131,7 +131,7 @@ func TestAddSNATRules(t *testing.T) {
131131
expectedChains: []chainExpectation{
132132
{
133133
table: iptables.Nat,
134-
chain: SWIFT,
134+
chain: SWIFTPOSTROUTING,
135135
expected: []string{
136136
"-N SWIFT-POSTROUTING",
137137
"-A SWIFT-POSTROUTING -m addrtype ! --dst-type local -s 240.1.2.0/24 -d " + networkutils.AzureDNS + " -p udp --dport " + strconv.Itoa(iptables.DNSPort) + " -j SNAT --to 240.1.2.1",
@@ -192,17 +192,17 @@ func TestAddSNATRules(t *testing.T) {
192192
},
193193
{
194194
table: iptables.Nat,
195-
chain: SWIFT,
195+
chain: SWIFTPOSTROUTING,
196196
rule: []string{"-m", "addrtype", "!", "--dst-type", "local", "-s", "240.1.2.0/24", "-d", networkutils.AzureDNS, "-p", "udp", "--dport", strconv.Itoa(iptables.DNSPort), "-j", "SNAT", "--to", "240.1.2.1"},
197197
},
198198
{
199199
table: iptables.Nat,
200-
chain: SWIFT,
200+
chain: SWIFTPOSTROUTING,
201201
rule: []string{"-m", "addrtype", "!", "--dst-type", "local", "-s", "240.1.2.0/24", "-d", networkutils.AzureDNS, "-p", "tcp", "--dport", strconv.Itoa(iptables.DNSPort), "-j", "SNAT", "--to", "240.1.2.1"},
202202
},
203203
{
204204
table: iptables.Nat,
205-
chain: SWIFT,
205+
chain: SWIFTPOSTROUTING,
206206
rule: []string{"-m", "addrtype", "!", "--dst-type", "local", "-s", "240.1.2.0/24", "-d", networkutils.AzureIMDS, "-p", "tcp", "--dport", strconv.Itoa(iptables.HTTPPort), "-j", "SNAT", "--to", "10.0.0.4"},
207207
},
208208
{
@@ -214,7 +214,7 @@ func TestAddSNATRules(t *testing.T) {
214214
expectedChains: []chainExpectation{
215215
{
216216
table: iptables.Nat,
217-
chain: SWIFT,
217+
chain: SWIFTPOSTROUTING,
218218
expected: []string{
219219
"-N SWIFT-POSTROUTING",
220220
"-A SWIFT-POSTROUTING -m addrtype ! --dst-type local -s 240.1.2.0/24 -d " + networkutils.AzureDNS + " -p udp --dport " + strconv.Itoa(iptables.DNSPort) + " -j SNAT --to 240.1.2.1",
@@ -264,7 +264,7 @@ func TestAddSNATRules(t *testing.T) {
264264
expectedChains: []chainExpectation{
265265
{
266266
table: iptables.Nat,
267-
chain: SWIFT,
267+
chain: SWIFTPOSTROUTING,
268268
expected: []string{
269269
"-N SWIFT-POSTROUTING",
270270
"-A SWIFT-POSTROUTING -m addrtype ! --dst-type local -s 240.1.2.0/28 -d " + networkutils.AzureDNS + " -p udp --dport " + strconv.Itoa(iptables.DNSPort) + " -j SNAT --to 10.0.0.4",

0 commit comments

Comments
 (0)