Skip to content

Commit

Permalink
Firewall: Automation: Filter - add Max source connections for #8143
Browse files Browse the repository at this point in the history
  • Loading branch information
AdSchellevis committed Dec 28, 2024
1 parent b8e3015 commit 70b4823
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,13 @@
<help>Limits the maximum number of simultaneous state entries that a single source address can create with this rule.</help>
<advanced>true</advanced>
</field>
<field>
<id>rule.max-src-conn</id>
<label>Max source connections</label>
<type>text</type>
<help>Limit the maximum number of simultaneous TCP connections which have completed the 3-way handshake that a single host can make.</help>
<advanced>true</advanced>
</field>
<field>
<id>rule.nopfsync</id>
<label>NO pfsync</label>
Expand Down
17 changes: 11 additions & 6 deletions src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public function performValidation($validateFullModel = false)
}
if ($rule->statetype == 'none') {
foreach ([
'statetimeout', 'max', 'max-src-states', 'max-src-nodes', 'adaptivestart', 'adaptiveend'
'statetimeout', 'max', 'max-src-states', 'max-src-nodes', 'adaptivestart', 'adaptiveend',
'max-src-conn'
] as $fieldname) {
if (!empty((string)$rule->$fieldname)) {
$messages->appendMessage(new Message(
Expand All @@ -130,11 +131,15 @@ public function performValidation($validateFullModel = false)
}
}
}
if (!in_array($rule->protocol, ['TCP', 'TCP/UDP']) && !empty((string)$rule->statetimeout)) {
$messages->appendMessage(new Message(
gettext("You can only specify the state timeout (advanced option) for TCP protocol."),
$rule->statetimeout->__reference
));
if (!in_array($rule->protocol, ['TCP', 'TCP/UDP'])) {
foreach (['statetimeout', 'max-src-conn'] as $fieldname) {
if (!empty((string)$rule->$fieldname)) {
$messages->appendMessage(new Message(
gettext("Invalid option for other than TCP protocol choices."),
$rule->$fieldname->__reference
));
}
}
}
if (empty((string)$rule->max) && ($rule->adaptivestart == '0' || $rule->adaptiveend == '0')) {
$messages->appendMessage(new Message(
Expand Down
3 changes: 3 additions & 0 deletions src/opnsense/mvc/app/models/OPNsense/Firewall/Filter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@
<max-src-states type="IntegerField">
<MinimumValue>1</MinimumValue>
</max-src-states>
<max-src-conn type="IntegerField">
<MinimumValue>1</MinimumValue>
</max-src-conn>
<max type="IntegerField">
<MinimumValue>1</MinimumValue>
</max>
Expand Down

0 comments on commit 70b4823

Please sign in to comment.