From 4101e3fc446f7be27de19e62dcc4424949ddf3f9 Mon Sep 17 00:00:00 2001 From: Paulo Nascimento Date: Sat, 20 Mar 2021 19:35:35 -0300 Subject: [PATCH] ipv4 and ipv6 detection using regex --- pkg/iptables/iptables.go | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) mode change 100644 => 100755 pkg/iptables/iptables.go diff --git a/pkg/iptables/iptables.go b/pkg/iptables/iptables.go old mode 100644 new mode 100755 index 1d83af5..f8827e7 --- a/pkg/iptables/iptables.go +++ b/pkg/iptables/iptables.go @@ -73,7 +73,7 @@ type rule struct { proto Protocol } -var ipv6Regex,_ = regexp.Compile("[-]d\\s(.*:.*\\s[-]m\\scomment)") +var ipv6Regex, _ = regexp.Compile("[-]d\\s(.*:.*\\s[-]m\\scomment)") // NewRule creates a new iptables or ip6tables rule in the given table and chain // depending on the given protocol. @@ -380,21 +380,10 @@ func (c *Controller) Set(rules []Rule) error { } } if i >= len(c.rules) { - proto := rules[i].Proto() - - protocolName := "ipv4" - - if proto == ProtocolIPv6 { - protocolName = "ipv6" - } - - var ruleString = rules[i].String() - level.Debug(c.logger).Log("msg", "Applying Firewall Rule...", "Rule", ruleString, "Protocol", protocolName) - if err := rules[i].Add(c.v4); err != nil { + if err := rules[i].Add(c.client(rules[i].Proto())); err != nil { return fmt.Errorf("failed to add rule: %v", err) } - level.Debug(c.logger).Log("msg", "Firewall Rule applied.", "Rule", ruleString, "Protocol", protocolName) - c.rules = append(c.rules, rules[i]) + c.rules = append(c.rulIes, rules[i]) } }