Skip to content

Commit 5e0ea2a

Browse files
committed
[pfsense_nat_port_forward] Always add a local-port element
1 parent 0ffd133 commit 5e0ea2a

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

plugins/module_utils/nat_port_forward.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,12 @@ def _parse_target_address(self, obj):
123123
else:
124124
self.module.fail_json(msg='"%s" is not a valid redirect target IP address or host alias.' % (param))
125125

126-
if ports is None and self.params['protocol'] in ["tcp", "udp", "tcp/udp"]:
127-
self.module.fail_json(msg='Must specify a target port with protocol "{0}".'.format(self.params['protocol']))
126+
if ports is None:
127+
if self.params['protocol'] in ["tcp", "udp", "tcp/udp"]:
128+
self.module.fail_json(msg='Must specify a target port with protocol "{0}".'.format(self.params['protocol']))
129+
else:
130+
# pfSense seems to always add an empty local-port element
131+
obj['local-port'] = ''
128132

129133
if ports is not None:
130134
if self.params['protocol'] not in ["tcp", "udp", "tcp/udp"]:

tests/unit/plugins/modules/test_pfsense_nat_port_forward.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def check_target_elt(self, obj, target_elt, target_idx=-1):
5454
self.check_value_equal(target_elt, 'interface', self.unalias_interface(obj['interface']))
5555
self.check_param_equal(obj, target_elt, 'ipprotocol', 'inet')
5656
self.check_param_equal(obj, target_elt, 'protocol', 'tcp')
57+
self.check_param_equal_or_present(obj, target_elt, 'local-port')
5758

5859
self.check_rule_idx(obj, target_idx)
5960
if 'associated_rule' not in obj:

0 commit comments

Comments
 (0)