Skip to content

Commit c5ba423

Browse files
committed
refactor: simplify parsePortsFromRules
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent ef25b90 commit c5ba423

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

pkg/guestagent/iptables/iptables.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -68,29 +68,29 @@ func GetPorts() ([]Entry, error) {
6868
func parsePortsFromRules(rules []string) ([]Entry, error) {
6969
var entries []Entry
7070
for _, rule := range rules {
71-
if found := findPortRegex.FindStringSubmatch(rule); found != nil {
72-
if len(found) == 4 {
73-
port64, err := strconv.ParseInt(found[3], 10, 32)
74-
if err != nil {
75-
return nil, err
76-
}
77-
port := int(port64)
78-
79-
istcp := found[2] == "tcp"
80-
81-
// When no IP is present the rule applies to all interfaces.
82-
ip := found[1]
83-
if ip == "" {
84-
ip = "0.0.0.0"
85-
}
86-
ent := Entry{
87-
IP: net.ParseIP(ip),
88-
Port: port,
89-
TCP: istcp,
90-
}
91-
entries = append(entries, ent)
92-
}
71+
found := findPortRegex.FindStringSubmatch(rule)
72+
if len(found) != 4 {
73+
continue
74+
}
75+
port64, err := strconv.ParseInt(found[3], 10, 32)
76+
if err != nil {
77+
return nil, err
78+
}
79+
port := int(port64)
80+
81+
isTCP := found[2] == "tcp"
82+
83+
// When no IP is present the rule applies to all interfaces.
84+
ip := found[1]
85+
if ip == "" {
86+
ip = "0.0.0.0"
87+
}
88+
ent := Entry{
89+
IP: net.ParseIP(ip),
90+
Port: port,
91+
TCP: isTCP,
9392
}
93+
entries = append(entries, ent)
9494
}
9595

9696
return entries, nil

0 commit comments

Comments
 (0)