Skip to content

Commit 33b94f9

Browse files
committed
Add individual config options for threaded client/service detection
Add automatic classification options to readme - `threaded_service_detection` - `threaded_client_detection` Include threaded client/service detection options in default config
1 parent 97f5f49 commit 33b94f9

File tree

3 files changed

+35
-23
lines changed

3 files changed

+35
-23
lines changed

README.md

+23-15
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# What is DSCP Classify?
2-
DSCP Classify is an nftables based service for applying DSCP classifications to connections, compatible with OpenWrt's firewall4 for dynamically setting DSCP packet marks (this only works in OpenWrt 22.03 and above).
2+
DSCP Classify is an nftables based service for applying DSCP class to connections (this only works in OpenWrt 22.03 and above).
33

44
This should be used in conjunction with layer-cake SQM queue with ctinfo configured to restore DSCP on the device ingress.
55
The dscpclassify service uses the last 8 bits of the conntrack mark (0x000000ff).
@@ -14,13 +14,13 @@ These follow a similar syntax to the OpenWrt firewall config and can match upon
1414

1515
The rules support the use of nft sets, which could be dynamically updated from external sources such as dnsmasq.
1616

17-
### 2. Client DSCP hinting
17+
### 2. Client class hinting
1818
The service can be configured to apply the DSCP mark supplied by a non WAN originating client.
1919

2020
This function ignores CS6 and CS7 classes to avoid abuse from inappropriately configed LAN clients such as IoT devices.
2121

22-
### 3. Dynamic classification
23-
Connections that do not match a user rule or client hint will be dynamically classified by the service to reduce their priority.
22+
### 3. Automatic classification
23+
Connections that do not match a user rule or client class hint will be automatically classified by the service to set their priority.
2424

2525
#### Multi-connection client port detection for detecting P2P traffic
2626
These connections are classified as **Low Effort (LE**) by default and therefore prioritised **below Best Effort** traffic when using the layer-cake qdisc.
@@ -64,28 +64,37 @@ opkg install kmod-sched-ctinfo
6464
wget "$repo/usr/lib/sqm/layer_cake_ct.qos" -O "/usr/lib/sqm/layer_cake_ct.qos"
6565
wget "$repo/usr/lib/sqm/layer_cake_ct.qos.help" -O "/usr/lib/sqm/layer_cake_ct.qos.help"
6666
```
67-
# Service configuration
68-
The user rules in '/etc/config/dscpclassify' use the same syntax as OpenWrt's firewall config, the 'class' option is used to specified the desired DSCP.
69-
70-
A working default configuration is provided with the service which should work for most users.
67+
# Configuration
68+
The service configuration is located in '/etc/config/dscpclassify'.
7169

72-
### The service supports the following configuration options
70+
### A working default configuration is provided with the service which should work for most users.
7371

74-
|Config option | Description | Type | Default|
72+
#### Global options
73+
|Option | Description | Type | Default|
7574
|--- | --- | --- | ---|
7675
|class_bulk | The class applied to threaded bulk clients | string | le|
7776
|class_high_throughput | The class applied to threaded high-throughput services | string | af13|
7877
|client_hints | Adopt the DSCP class supplied by a non-WAN client (this exludes CS6 and CS7 classes to avoid abuse) | boolean | 1|
79-
|threaded_client_min_bytes | The total bytes before a threaded client port (i.e. P2P) is classified as bulk | uint | 10000|
80-
|threaded_client_min_connections | The number of established connections for a client port to be considered threaded | uint | 10|
81-
|threaded_service_min_bytes | The total bytes before a threaded service's connection is classed as high-throughput | uint | 1000000|
82-
|threaded_service_min_connections | The number of established connections for a service to be considered threaded | uint | 3|
78+
|threaded_client_detection | Automatically and classify threaded client connections (i.e. P2P) as bulk | boolean | 1|
79+
|threaded_service_detection | Automatically and classify threaded service connections (i.e. Windows Update/Steam downloads) as bulk | boolean | 1|
8380
|lan_device | Manually specify devices that the service should treat as LAN | list: string | |
8481
|lan_zone | Manually specify firewall zones that the service should treat as LAN | list: string | lan|
8582
|wan_device | Manually specify devices that the service should treat as WAN | list: string | |
8683
|wan_zone | Manually specify firewall zones that the service should treat as WAN | list: string | wan|
8784
|wmm | When enabled the service will mark LAN bound packets with DSCP values respective of WMM (RFC-8325) | boolean | 0|
8885

86+
#### Advanced global options (not recommended for most users)
87+
|Option | Description | Type | Default|
88+
|--- | --- | --- | ---|
89+
|threaded_client_min_bytes | The total bytes before a threaded client port (i.e. P2P) is classified as bulk | uint | 10000|
90+
|threaded_client_min_connections | The number of established connections for a client port to be considered threaded | uint | 10|
91+
|threaded_service_min_bytes | The total bytes before a threaded service's connection is classed as high-throughput | uint | 1000000|
92+
|threaded_service_min_connections | The number of established connections for a service to be considered threaded | uint | 3|
93+
94+
# User rules
95+
The user rules in '/etc/config/dscpclassify' use the same syntax as OpenWrt's firewall config, the 'class' option is used to specified the desired DSCP.
96+
The OpenWrt firewall syntax is outlined [here](https://openwrt.org/docs/guide-user/firewall/firewall_configuration).
97+
8998
### Example user rule
9099

91100
```
@@ -100,7 +109,6 @@ config rule
100109
option counter '0'
101110
```
102111
The counter option can be enabled to count the number of matched connections for a rule.
103-
The OpenWrt firewall syntax is outlined [here](https://openwrt.org/docs/guide-user/firewall/firewall_configuration).
104112

105113
# SQM configuration
106114

etc/config/dscpclassify

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ config global 'global'
22
option class_bulk 'le'
33
option class_high_throughput 'af13'
44
option client_hints '1'
5-
option threaded_client_min_bytes '10000'
6-
option threaded_service_min_bytes '1000000'
5+
option threaded_client_detection '1'
6+
option threaded_service_detection '1'
77
option wmm '0'
88

99
config ipset

etc/init.d/dscpclassify

+10-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@ CLASS_BULK=le
2020
CLASS_HIGH_THROUGHPUT=af13
2121
CLIENT_HINTS=1
2222
DYNAMIC_CLASSIFY=1
23+
THREADED_CLIENT_DETECTION=1
2324
THREADED_CLIENT_MIN_BYTES=10000
2425
THREADED_CLIENT_MIN_CONNECTIONS=10
26+
THREADED_SERVICE_DETECTION=1
2527
THREADED_SERVICE_MIN_BYTES=1000000
2628
THREADED_SERVICE_MIN_CONNECTIONS=3
2729
WMM=0
@@ -639,13 +641,14 @@ destroy_threaded_client_rules() {
639641
}
640642

641643
create_threaded_client_rules() {
642-
local class_bulk threaded_client_min_bytes threaded_client_min_connections
644+
local class_bulk dynamic_classify threaded_client_detection threaded_client_min_bytes threaded_client_min_connections
643645

644646
config_get_bool dynamic_classify global dynamic_classify $DYNAMIC_CLASSIFY
645-
[ "$dynamic_classify" = 1 ] || {
647+
config_get_bool threaded_client_detection global threaded_client_detection $THREADED_CLIENT_DETECTION
648+
if [ "$dynamic_classify" != 1 ] || [ "$threaded_client_detection" != 1 ]; then
646649
destroy_threaded_client_rules
647650
return 0
648-
}
651+
fi
649652

650653
config_get threaded_client_min_connections global threaded_client_min_connections $THREADED_CLIENT_MIN_CONNECTIONS
651654
if ! check_uint "$threaded_client_min_connections" || [ "$threaded_client_min_connections" -lt 2 ]; then
@@ -702,13 +705,14 @@ destroy_threaded_service_rules() {
702705
}
703706

704707
create_threaded_service_rules() {
705-
local class_high_throughput threaded_service_min_bytes threaded_service_min_connections
708+
local class_high_throughput dynamic_classify threaded_service_detection threaded_service_min_bytes threaded_service_min_connections
706709

707710
config_get_bool dynamic_classify global dynamic_classify $DYNAMIC_CLASSIFY
708-
[ "$dynamic_classify" = 1 ] || {
711+
config_get_bool threaded_service_detection global threaded_service_detection $THREADED_SERVICE_DETECTION
712+
if [ "$dynamic_classify" != 1 ] || [ "$threaded_service_detection" != 1 ]; then
709713
destroy_threaded_service_rules
710714
return 0
711-
}
715+
fi
712716

713717
config_get threaded_service_min_connections global threaded_service_min_connections $THREADED_SERVICE_MIN_CONNECTIONS
714718
if ! check_uint "$threaded_service_min_connections" || [ "$threaded_service_min_connections" -lt 2 ]; then

0 commit comments

Comments
 (0)