diff --git a/plugins/module_utils/nat_port_forward.py b/plugins/module_utils/nat_port_forward.py index d0899289..9511d7e6 100644 --- a/plugins/module_utils/nat_port_forward.py +++ b/plugins/module_utils/nat_port_forward.py @@ -19,7 +19,9 @@ ipprotocol=dict(default='inet', choices=['inet', 'inet6']), protocol=dict(default='tcp', required=False, choices=["tcp", "udp", "tcp/udp", "icmp", "esp", "ah", "gre", "ipv6", "igmp", "pim", "ospf"]), source=dict(required=False, type='str'), + source_port=dict(required=False, type='str'), destination=dict(required=False, type='str'), + destination_port=dict(required=False, type='str'), target=dict(required=False, type='str'), natreflection=dict(default='system-default', choices=["system-default", "enable", "purenat", "disable"]), associated_rule=dict(default='associated', required=False, choices=["associated", "unassociated", "pass", "none"]), @@ -47,8 +49,6 @@ def get_argument_spec(): def __init__(self, module, pfsense=None): super(PFSenseNatPortForwardModule, self).__init__(module, pfsense) self.name = "pfsense_nat_port_forward" - # Override for use with aggregate - self.argument_spec = NAT_PORT_FORWARD_ARGUMENT_SPEC self.obj = dict() self.after = None @@ -102,7 +102,15 @@ def _params_to_obj(self): self.before = self.params['before'] obj['source'] = self.pfsense.parse_address(self.params['source'], allow_self=False) + if self.params.get('source_port'): + if not self.pfsense.is_port_or_alias(self.params['source_port']): + self.module.fail_json(msg='Cannot parse port %s, not port number or alias' % (self.params['source_port'])) + obj['source']['port'] = self.params['source_port'] obj['destination'] = self.pfsense.parse_address(self.params['destination']) + if self.params.get('destination_port'): + if not self.pfsense.is_port_or_alias(self.params['destination_port']): + self.module.fail_json(msg='Cannot parse port %s, not port number or alias' % (self.params['destination_port'])) + obj['destination']['port'] = self.params['destination_port'] self._parse_target_address(obj) return obj diff --git a/plugins/modules/pfsense_nat_port_forward.py b/plugins/modules/pfsense_nat_port_forward.py index 87b93fb8..82702a4a 100644 --- a/plugins/modules/pfsense_nat_port_forward.py +++ b/plugins/modules/pfsense_nat_port_forward.py @@ -53,10 +53,24 @@ description: The source address, in [!]{IP,HOST,ALIAS,any,IP:INTERFACE,NET:INTERFACE}[:port] format. default: null type: str + source_port: + description: + - Source port or port range specification. + - This can either be a alias or a port number. + - An inclusive range can also be specified, using the format C(first-last). + default: null + type: str destination: description: The destination address, in [!]{IP,HOST,ALIAS,any,IP:INTERFACE,NET:INTERFACE}[:port] format. default: null type: str + destination_port: + description: + - Destination port or port range specification. + - This can either be a alias or a port number. + - An inclusive range can also be specified, using the format C(first-last). + default: null + type: str target: description: The translated to address, in {ALIAS,IP}[:port] format. required: false