Skip to content

Commit

Permalink
[interface] Support slaac ipv6_type
Browse files Browse the repository at this point in the history
  • Loading branch information
opoplawski committed Mar 24, 2024
1 parent 613d01c commit 062621a
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 4 deletions.
19 changes: 16 additions & 3 deletions plugins/module_utils/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
ipv6_gateway=dict(required=False, type='str'),
blockpriv=dict(required=False, type='bool'),
blockbogons=dict(required=False, type='bool'),
slaacusev4iface=dict(required=False, type='bool'),
)

INTERFACE_REQUIRED_IF = [
Expand Down Expand Up @@ -132,6 +133,10 @@ def _params_to_obj(self):
self._get_ansible_param(obj, 'ipv6_prefixlen', fname='subnetv6')
self._get_ansible_param(obj, 'ipv6_gateway', fname='gatewayv6')

if params['ipv6_type'] == 'slaac':
obj['ipaddrv6'] = 'slaac'
self._get_ansible_param_bool(obj, 'slaacusev4iface', value='')

# get target interface
self.target_elt = self._find_matching_interface()
self._check_overlaps('ipaddrv6', 'subnetv6')
Expand Down Expand Up @@ -527,7 +532,8 @@ def _log_fields(self, before=None):
values += self.format_cli_field(self.obj, 'subnet', fname='ipv4_prefixlen')
values += self.format_cli_field(self.obj, 'gateway', fname='ipv4_gateway')
values += self.format_cli_field(self.params, 'ipv6_type', default='none')
values += self.format_cli_field(self.obj, 'ipaddrv6', fname='ipv6_address')
if self.obj.get('ipaddrv6') != 'slaac':
values += self.format_cli_field(self.obj, 'ipaddrv6', fname='ipv6_address')
values += self.format_cli_field(self.obj, 'subnetv6', fname='ipv6_prefixlen')
values += self.format_cli_field(self.obj, 'gatewayv6', fname='ipv6_gateway')
values += self.format_cli_field(self.params, 'mac')
Expand All @@ -545,8 +551,15 @@ def _log_fields(self, before=None):
values += self.format_updated_cli_field(self.obj, before, 'ipaddr', add_comma=(values), fname='ipv4_address')
values += self.format_updated_cli_field(self.obj, before, 'subnet', add_comma=(values), fname='ipv4_prefixlen')
values += self.format_updated_cli_field(self.obj, before, 'gateway', add_comma=(values), fname='ipv4_gateway')
values += self.format_updated_cli_field(self.obj, before, 'ipv6_type', add_comma=(values), log_none='True')
values += self.format_updated_cli_field(self.obj, before, 'ipaddrv6', add_comma=(values), fname='ipv6_address')
if self.obj.get('ipaddrv6') == 'slaac' and before.get('ipaddrv6') != 'slaac':
res = "ipv6_type=slaac"
if values:
values += ", " + res
else:
values += res
else:
values += self.format_updated_cli_field(self.obj, before, 'ipv6_type', add_comma=(values), log_none='True')
values += self.format_updated_cli_field(self.obj, before, 'ipaddrv6', add_comma=(values), fname='ipv6_address')
values += self.format_updated_cli_field(self.obj, before, 'subnetv6', add_comma=(values), fname='ipv6_prefixlen')
values += self.format_updated_cli_field(self.obj, before, 'gatewayv6', add_comma=(values), fname='ipv6_gateway')
values += self.format_updated_cli_field(self.obj, before, 'spoofmac', add_comma=(values), fname='mac')
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/pfsense_aggregate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@
description: Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA.
required: false
type: bool
slaacusev4iface:
description: IPv6 will use the IPv4 connectivity link (PPPoE). Only used when ipv6_type is slaac.
required: false
type: bool
version_added: 0.6.2
aggregated_nat_outbounds:
description: Dict of nat_outbound rules to apply on the target
required: False
Expand Down
5 changes: 5 additions & 0 deletions plugins/modules/pfsense_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@
description: Blocks traffic from reserved IP addresses (but not RFC 1918) or not yet assigned by IANA.
required: false
type: bool
slaacusev4iface:
description: IPv6 will use the IPv4 connectivity link (PPPoE). Only used when ipv6_type is slaac.
required: false
type: bool
version_added: 0.6.2
"""

EXAMPLES = """
Expand Down
6 changes: 5 additions & 1 deletion tests/unit/plugins/modules/test_pfsense_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,14 @@ def check_target_elt(self, obj, target_elt):
self.assert_xml_elt_equal(target_elt, 'gateway', obj['ipv4_gateway'])

# ipv6 type related
if obj.get('ipv6_type') is None or obj.get('ipv6_type') in ['none', 'slaac']:
if obj.get('ipv6_type') is None or obj.get('ipv6_type') in ['none']:
self.assert_not_find_xml_elt(target_elt, 'ipaddrv6')
self.assert_not_find_xml_elt(target_elt, 'subnetv6')
self.assert_not_find_xml_elt(target_elt, 'gatewayv6')
elif obj.get('ipv6_type') == 'slaac':
self.assert_xml_elt_equal(target_elt, 'ipaddrv6', 'slaac')
self.assert_not_find_xml_elt(target_elt, 'subnetv6')
self.assert_not_find_xml_elt(target_elt, 'gatewayv6')
elif obj.get('ipv6_type') == 'static':
if obj.get('ipv6_address'):
self.assert_xml_elt_equal(target_elt, 'ipaddrv6', obj['ipv6_address'])
Expand Down

0 comments on commit 062621a

Please sign in to comment.