Hello @Jvendrell,
Linux kernel’s XFRM (IPsec) subsystem does not automatically copy or inherit DSCP/ToS values from the outer IPsec/ESP header down to the inner packet (or vice versa) by default, requiring explicit configuration or firewall mangling.
You can find more about matter using Google search “Linux inheriting dscp from ipsec to gre?”
That will explain three ways around to accomplish that 2-4 in below list when first in which would the desired obviously aren’t there.
- use WebUI or
uci CLI tool, to do it.
- add config directive to that connection that will enable this feature.
- use iptables (nftables when RutOS does support it to enable this feature.
- use “ip tunnel change gre0 tos inherit” to do that on existing connection.
Lookin WebUI I did not find a way to do it. Searching OpenWRT documents for a while either. Thus assuming that if there was uci method, then that probably search would find something with dscp there but none unfortunately. So first option seems not at this point devices I’ve got available yet latest stable version OS images.
From strongSwan documents that feature can be found and it’s configured under the connection where it’s needed.
That list two last work but both bit hard keep maintaining so that feature stays there all the time even when connection drops, device is booted or even upgraded. Therefore second being best workaround until Teltonika gets to implement it WebUI etc.
I spent few minutes Google Search AI to find a quick way in fairly short conversation how to do this.
After few prompts describing the issue and how I would be worth approaching it, letting it write (saved my effort a bit) the script and explanation then I edited removing flowery style and bold styling etc. Following what came to be.
– cut –
Persistent DSCP Inheritance Patch for strongSwan on Teltonika RUTOS
Summary
This provides a way to persistently enable DSCP inheritance (copy_dscp = yes) within strongSwan (swanctl.conf) on Teltonika RUTOS devices.
Because the RUTOS/OpenWrt Unified Configuration Interface (UCI) overwrites configuration files during boot, interface changes, or WebUI modifications, a standard manual file edit will not survive normal operational cycles. The script intercepts IPsec configuration updates in real-time, injects the necessary parameter, and guarantees persistence across firmware upgrades.
Step 1: Deploy the Hotplug Script
Create a new file as a root user at /etc/hotplug.d/service/99-patch-swanctl to handle automated config injection.
#!/bin/sh
# OpenWrt passes the service name as $1 and the action as $2
if [ "$1" = "ipsec" ] && [ "$2" = "start" ]; then
# Change if your connecion config is not in this file.
CONF_FILE="/var/swanctl/swanctl.conf"
# Wait for the RUTOS generation process to complete,
# approximate time, adjust a bit if needs it.
sleep 2
# Inject configuration if it is missing
if [ -f "$CONF_FILE" ] && ! grep -q "copy_dscp" "$CONF_FILE"; then
sed -i '/esp_proposals/i \ copy_dscp = yes' "$CONF_FILE"
swanctl --load-all >/dev/null 2>&1
fi
fi
Notice, that strongSwan default config file contents, shown below you see where actual configs are:
less /etc/swanctl/swanctl.conf
include conf.d/*.conf
include /var/run/ipsec/swanctl/swanctl.conf
Step 2: Set file execute permissions
Run following command via SSH to grant execution privileges to the script:
chmod +x /etc/hotplug.d/service/99-patch-swanctl
Step 3: Add script to remain in use also with Firmware Upgrade
Add the script path to /etc/sysupgrade.conf to ensure it is preserved during future RUTOS firmware updates:
cp -av /etc/sysupgrade.conf /etc/sysupgrade.conf.save
echo "/etc/hotplug.d/service/99-patch-swanctl" >> /etc/sysupgrade.conf
Operational Verification
Step 1: Force Configuration Regeneration
Manually trigger the IPsec service init script to simulate a system event and run the hotplug logic:
/etc/init.d/ipsec restart
Step 2: Inspect Runtime Configuration
Verify that the copy_dscp = yes parameter is correctly injected inside the active child configuration block:
grep copy_dscp /var/swanctl/swanctl.conf
and of course also if you like to see whole config
less /var/swanctl/swanctl.conf
– cut –
I do not have a IPSec config at moment (retired old chap with no need for that you know), so I did not test script myself. But if that doesn’t work if you can post a redacted version of your config with approximately similar looking file with that connections { … } section I can fix it so that it will add that option right place.
Anyway above is just a workaround I would in your position do to get things going. Then ask kindly Teltonika to add at this feature to be added as it apparently is very useful with some DMVPN configs which I’ve encountered earlier too. And once they add. move this script from that directory to somewhere else like /etc/config directory, so that you can restart ipsec and verify it’s not needed any more. Then just remove it from /etc/config and also remove entry from /etc/sysupgrade.conf too, which you can do copying saved file top of the modified.
Cheers,
riku