Skip to content

Commit 633a313

Browse files
authored
Firewall: NAT: Source NAT: add pool options and source hash key (#10815)
1 parent 7729c98 commit 633a313

4 files changed

Lines changed: 45 additions & 0 deletions

File tree

src/opnsense/mvc/app/controllers/OPNsense/Firewall/forms/dialogSNatRule.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,26 @@
211211
<min-width>60</min-width>
212212
</grid_view>
213213
</field>
214+
<field>
215+
<id>rule.poolopts</id>
216+
<label>Pool Options</label>
217+
<type>dropdown</type>
218+
<help>Choose how traffic is distributed when multiple translation addresses are used. When nothing is selected, the current default is round-robin.</help>
219+
<advanced>true</advanced>
220+
<grid_view>
221+
<visible>false</visible>
222+
</grid_view>
223+
</field>
224+
<field>
225+
<id>rule.poolopts_sourcehashkey</id>
226+
<label>Source Hash Key</label>
227+
<type>text</type>
228+
<help>Optionally specify a key to keep Source Hash mappings stable across ruleset reloads. Enter 0x followed by 32 hexadecimal digits.</help>
229+
<advanced>true</advanced>
230+
<grid_view>
231+
<visible>false</visible>
232+
</grid_view>
233+
</field>
214234
<field>
215235
<id>rule.staticnatport</id>
216236
<label>Static-port</label>

src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ public function performValidation($validateFullModel = false)
186186
$rule->{'endpoint-independent'}->__reference
187187
));
188188
}
189+
if (
190+
!$rule->poolopts_sourcehashkey->isEmpty() &&
191+
!$rule->poolopts->isEqual('source-hash')
192+
) {
193+
$messages->appendMessage(new Message(
194+
gettext("Source Hash Key is only valid for Source Hash type."),
195+
$rule->poolopts_sourcehashkey->__reference
196+
));
197+
}
189198
} else {
190199
// Additional filter validations
191200
if (!$rule->{'received-on'}->isEmpty() && $rule->direction != 'out') {

src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,20 @@
531531
<EnableAlias>Y</EnableAlias>
532532
<ValidationMessage>Please specify a valid port number, well-known name, alias or range.</ValidationMessage>
533533
</target_port>
534+
<poolopts type="OptionField">
535+
<OptionValues>
536+
<p1 value="round-robin">Round Robin</p1>
537+
<p2 value="round-robin sticky-address">Round Robin with Sticky Address</p2>
538+
<p3 value="random">Random</p3>
539+
<p4 value="random sticky-address">Random with Sticky Address</p4>
540+
<p5 value="source-hash">Source Hash</p5>
541+
<p6 value="bitmask">Bitmask</p6>
542+
</OptionValues>
543+
</poolopts>
544+
<poolopts_sourcehashkey type="StrictTextField">
545+
<Mask>/^0x[0-9a-fA-F]{32}$/</Mask>
546+
<ValidationMessage>Source Hash Key must be 0x followed by 32 hexadecimal digits.</ValidationMessage>
547+
</poolopts_sourcehashkey>
534548
<staticnatport type="BooleanField"/>
535549
<log type="BooleanField">
536550
<Default>0</Default>

src/opnsense/scripts/filter/list_legacy_outbound_nat.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@ function legacy_target_to_network($rule)
115115
'destination_port' => normalize_port($rule['dstport'] ?? ''),
116116
'target' => legacy_target_to_network($rule),
117117
'target_port' => normalize_port($rule['natport'] ?? ''),
118+
'poolopts' => $rule['poolopts'] ?? '',
119+
'poolopts_sourcehashkey' => $rule['poolopts_sourcehashkey'] ?? '',
118120
'staticnatport' => !empty($rule['staticnatport']) ? '1' : '0',
119121
'log' => !empty($rule['log']) ? '1' : '0',
120122
'categories' => $rule['category'] ?? '',

0 commit comments

Comments
 (0)