Skip to content

Commit ed7b047

Browse files
Added endpoint /api/v1/firewall/traffic_shaper/limiter/queue to add and delete child queues for limiters, added corresponding unit tests, minor adjustments to traffic shaper application
1 parent 3ce4b59 commit ed7b047

10 files changed

Lines changed: 1629 additions & 5 deletions

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: jaredhendrickson13
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
// Copyright 2021 Jared Hendrickson
3+
//
4+
// Licensed under the Apache License, Version 2.0 (the "License");
5+
// you may not use this file except in compliance with the License.
6+
// You may obtain a copy of the License at
7+
//
8+
// http://www.apache.org/licenses/LICENSE-2.0
9+
//
10+
// Unless required by applicable law or agreed to in writing, software
11+
// distributed under the License is distributed on an "AS IS" BASIS,
12+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
// See the License for the specific language governing permissions and
14+
// limitations under the License.
15+
16+
require_once("api/framework/APIEndpoint.inc");
17+
18+
class APIFirewallTrafficShaperLimiterQueue extends APIEndpoint {
19+
public function __construct() {
20+
$this->url = "/api/v1/firewall/traffic_shaper/limiter/queue";
21+
}
22+
23+
protected function post() {
24+
return (new APIFirewallTrafficShaperLimiterQueueCreate())->call();
25+
}
26+
27+
protected function delete() {
28+
return (new APIFirewallTrafficShaperLimiterQueueDelete())->call();
29+
}
30+
}

pfSense-pkg-API/files/etc/inc/api/framework/APIResponse.inc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2282,6 +2282,36 @@ function get($id, $data=[], $all=false) {
22822282
"return" => $id,
22832283
"message" => "Firewall traffic shaper limiter bandwidth ID does not exist"
22842284
],
2285+
4217 => [
2286+
"status" => "bad request",
2287+
"code" => 400,
2288+
"return" => $id,
2289+
"message" => "Firewall traffic shaper limiter queue weight must be between 1 and 100"
2290+
],
2291+
4218 => [
2292+
"status" => "bad request",
2293+
"code" => 400,
2294+
"return" => $id,
2295+
"message" => "Firewall traffic shaper parent limiter required"
2296+
],
2297+
4219 => [
2298+
"status" => "bad request",
2299+
"code" => 400,
2300+
"return" => $id,
2301+
"message" => "Firewall traffic shaper parent limiter does not exist"
2302+
],
2303+
4220 => [
2304+
"status" => "bad request",
2305+
"code" => 400,
2306+
"return" => $id,
2307+
"message" => "Firewall traffic shaper limiter queue name required"
2308+
],
2309+
4221 => [
2310+
"status" => "bad request",
2311+
"code" => 400,
2312+
"return" => $id,
2313+
"message" => "Firewall traffic shaper limiter queue name does not exist"
2314+
],
22852315

22862316
//5000-5999 reserved for /users API calls
22872317
5000 => [

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallTrafficShaperLimiterBandwidthCreate.inc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,17 @@ class APIFirewallTrafficShaperLimiterBandwidthCreate extends APIModel {
2929
$this->__init_config();
3030
$this->config["dnshaper"]["queue"][$this->id]["bandwidth"]["item"][] = $this->validated_data;
3131
$this->write_config();
32-
filter_configure();
32+
mark_subsystem_dirty('shaper');
3333

34+
# Only reload the filter immediately if it was requested by the client
35+
if ($this->initial_data["apply"] === true) {
36+
# Reload the filter, reset RRD logs and mark the subsystem as applied
37+
filter_configure();
38+
system("rm -f /var/db/rrd/*queuedrops.rrd");
39+
system("rm -f /var/db/rrd/*queues.rrd");
40+
enable_rrd_graphing();
41+
clear_subsystem_dirty('shaper');
42+
}
3443
return APIResponse\get(0, $this->validated_data);
3544
}
3645

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallTrafficShaperLimiterBandwidthDelete.inc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,17 @@ class APIFirewallTrafficShaperLimiterBandwidthDelete extends APIModel {
3030
public function action() {
3131
unset($this->config["dnshaper"]["queue"][$this->parent_id]["bandwidth"]["item"][$this->id]);
3232
$this->write_config();
33-
filter_configure();
33+
mark_subsystem_dirty('shaper');
3434

35+
# Only reload the filter immediately if it was requested by the client
36+
if ($this->initial_data["apply"] === true) {
37+
# Reload the filter, reset RRD logs and mark the subsystem as applied
38+
filter_configure();
39+
system("rm -f /var/db/rrd/*queuedrops.rrd");
40+
system("rm -f /var/db/rrd/*queues.rrd");
41+
enable_rrd_graphing();
42+
clear_subsystem_dirty('shaper');
43+
}
3544
return APIResponse\get(0, $this->validated_data);
3645
}
3746

pfSense-pkg-API/files/etc/inc/api/models/APIFirewallTrafficShaperLimiterDelete.inc

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,17 @@ class APIFirewallTrafficShaperLimiterDelete extends APIModel {
2828
public function action() {
2929
unset($this->config["dnshaper"]["queue"][$this->id]);
3030
$this->write_config();
31-
filter_configure();
31+
mark_subsystem_dirty('shaper');
3232

33+
# Only reload the filter immediately if it was requested by the client
34+
if ($this->initial_data["apply"] === true) {
35+
# Reload the filter, reset RRD logs and mark the subsystem as applied
36+
filter_configure();
37+
system("rm -f /var/db/rrd/*queuedrops.rrd");
38+
system("rm -f /var/db/rrd/*queues.rrd");
39+
enable_rrd_graphing();
40+
clear_subsystem_dirty('shaper');
41+
}
3342
return APIResponse\get(0, $this->validated_data);
3443
}
3544

0 commit comments

Comments
 (0)