Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelogs/fragemnts/219_parse_address_ipv6.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
bugfixes:
- pfsense_rule - Allow IPv6 addresses in source and destination (https://github.com/pfsensible/core/issues/219).
9 changes: 6 additions & 3 deletions plugins/module_utils/__impl/addresses.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ def parse_ip_network(address, strict=True, returns_ip=True):

def parse_address(self, param, allow_self=True):
""" validate param address field and returns it as a dict """
addr = param.split(':')
if len(addr) > 3:
self.module.fail_json(msg='Cannot parse address %s' % (param))
if self.is_ipv6_address(param) or self.is_ipv6_network(param):
addr = [param]
else:
addr = param.split(':', maxsplit=3)
if len(addr) > 3:
self.module.fail_json(msg='Cannot parse address %s' % (param))

address = addr[0]

Expand Down
6 changes: 5 additions & 1 deletion tests/unit/plugins/modules/test_pfsense_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from ansible_collections.pfsensible.core.plugins.modules import pfsense_rule
from ansible_collections.pfsensible.core.plugins.module_utils.rule import PFSenseRuleModule
from ansible_collections.pfsensible.core.plugins.module_utils.__impl.addresses import is_ipv6_address, is_ipv6_network
from .pfsense_module import TestPFSenseModule


Expand All @@ -31,7 +32,10 @@ def runTest():

def parse_address(self, addr):
""" return address parsed in dict """
parts = addr.split(':')
if is_ipv6_address(addr) or is_ipv6_network(addr):
parts = [addr]
else:
parts = addr.split(':')
res = {}
if parts[0][0] == '!':
res['not'] = None
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/plugins/modules/test_pfsense_rule_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,12 +329,24 @@ def test_rule_create_ip_to_ip(self):
command = "create rule 'one_rule' on 'lan', source='10.10.1.1', destination='10.10.10.1'"
self.do_module_test(obj, command=command)

def test_rule_create_ip6_to_ip6(self):
""" test creation of a new rule with valid ips """
obj = dict(name='one_rule', source='2001:db8:1::1', destination='2001:db8:2::2', ipprotocol='inet6', interface='lan')
command = "create rule 'one_rule' on 'lan', source='2001:db8:1::1', destination='2001:db8:2::2', ipprotocol='inet6'"
self.do_module_test(obj, command=command)

def test_rule_create_net_to_net(self):
""" test creation of a new rule valid networks """
obj = dict(name='one_rule', source='10.10.1.0/24', destination='10.10.10.0/24', interface='lan')
command = "create rule 'one_rule' on 'lan', source='10.10.1.0/24', destination='10.10.10.0/24'"
self.do_module_test(obj, command=command)

def test_rule_create_net6_to_net6(self):
""" test creation of a new rule valid networks """
obj = dict(name='one_rule', source='2001:db8:1::/64', destination='2001:db8:2::/64', ipprotocol='inet6', interface='lan')
command = "create rule 'one_rule' on 'lan', source='2001:db8:1::/64', destination='2001:db8:2::/64', ipprotocol='inet6'"
self.do_module_test(obj, command=command)

def test_rule_create_net_interface(self):
""" test creation of a new rule with valid interface """
obj = dict(name='one_rule', source='NET:lan', destination='any', interface='lan')
Expand Down