Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,13 @@ class FirewallRule extends Model {
verbose_name: 'Log',
help_text: 'Enable or disable logging of traffic that matches this rule.',
);
$this->dscp = new StringField(
default: '',
choices: ['af11', 'af12', 'af13', 'af21', 'af22', 'af23', 'af31', 'af32', 'af33', 'af41', 'af42', 'af43', 'VA', 'EF', 'cs1', 'cs2', 'cs3', 'cs4', 'cs5', 'cs6', 'cs7', '0x01', '0x02', '0x04'],
allow_empty: true,
verbose_name: 'DSCP',
help_text: 'The DSCP value this firewall rule should match.',
);
$this->tag = new StringField(
default: '',
allow_empty: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,33 @@ class APIModelsFirewallRuleTestCase extends TestCase {
$rule->delete(apply: true);
}

/**
* Checks that the `dscp` field is properly set in the pfctl rule
*/
public function test_dscp() {
# Create a firewall rule to test with
$rule = new FirewallRule(
data: [
'type' => 'pass',
'interface' => ['lan'],
'ipprotocol' => 'inet',
'protocol' => 'tcp',
'source' => 'any',
'destination' => 'any',
'dscp' => 'af11',
],
async: false,
);
$rule->create(apply: true);

# Ensure the pfctl rule with this rule object's tracker matches the requested DSCP value
$pfctl_rules = file_get_contents('/tmp/rules.debug');
$this->assert_str_contains($pfctl_rules, "tos af11 ridentifier {$rule->tracker->value}");

# Delete the firewall rule
$rule->delete(apply: true);
}

/**
* Checks that firewall rules with `log` enabled have the log flag set in pfctl
*/
Expand Down