Ticket #4544: 0001-Add-qos_-iptables-chain-namespace-for-QoS.patch

File 0001-Add-qos_-iptables-chain-namespace-for-QoS.patch, 4.0 KB (added by kevin@…, 7 years ago)

Patch to add qos_* iptables chain namespace for QoS

  • package/qos-scripts/files/usr/lib/qos/generate.sh

    From 98e2b06d6a54a8a11d078c68be6bd25bcfa3f68d Mon Sep 17 00:00:00 2001
    From: Kevin Locke <klocke@digitalenginesoftware.com>
    Date: Tue, 26 Apr 2011 13:45:49 -0600
    Subject: [PATCH 1/2] Add qos_* iptables chain namespace for QoS
    
    Prefix the names of the iptables chains used for QoS with "qos_" to
    allow for identification of QoS chains for removal across configuration
    changes.  When clearing QoS iptables chains, only remove chains with the
    namespace prefix in order to preserve user and/or other package chains
    in the mangle table.
    
    Signed-off-by: Kevin Locke <klocke@digitalenginesoftware.com>
    ---
     package/qos-scripts/files/usr/lib/qos/generate.sh |   46 ++++++++++++++------
     1 files changed, 32 insertions(+), 14 deletions(-)
    
    diff --git a/package/qos-scripts/files/usr/lib/qos/generate.sh b/package/qos-scripts/files/usr/lib/qos/generate.sh
    index a697e9f..093967f 100755
    a b start_cg() { 
    397397        local pktrules 
    398398        local sizerules 
    399399        enum_classes "$cg" 
    400         add_rules iptrules "$ctrules" "iptables -t mangle -A ${cg}_ct" 
     400        add_rules iptrules "$ctrules" "iptables -t mangle -A qos_${cg}_ct" 
    401401        config_get classes "$cg" classes 
    402402        for class in $classes; do 
    403403                config_get mark "$class" classnr 
    404404                config_get maxsize "$class" maxsize 
    405405                [ -z "$maxsize" -o -z "$mark" ] || { 
    406406                        add_insmod ipt_length 
    407                         append pktrules "iptables -t mangle -A ${cg} -m mark --mark $mark -m length --length $maxsize: -j MARK --set-mark 0" "$N" 
     407                        append pktrules "iptables -t mangle -A qos_${cg} -m mark --mark $mark -m length --length $maxsize: -j MARK --set-mark 0" "$N" 
    408408                } 
    409409        done 
    410         add_rules pktrules "$rules" "iptables -t mangle -A ${cg}" 
     410        add_rules pktrules "$rules" "iptables -t mangle -A qos_${cg}" 
    411411        for iface in $INTERFACES; do 
    412412                config_get classgroup "$iface" classgroup 
    413413                config_get device "$iface" device 
    start_cg() { 
    416416                config_get download "$iface" download 
    417417                config_get halfduplex "$iface" halfduplex 
    418418                download="${download:-${halfduplex:+$upload}}" 
    419                 append up "iptables -t mangle -A OUTPUT -o $device -j ${cg}" "$N" 
    420                 append up "iptables -t mangle -A FORWARD -o $device -j ${cg}" "$N" 
     419                append up "iptables -t mangle -A OUTPUT -o $device -j qos_${cg}" "$N" 
     420                append up "iptables -t mangle -A FORWARD -o $device -j qos_${cg}" "$N" 
    421421        done 
    422422        cat <<EOF 
    423423$INSMOD 
    424 iptables -t mangle -N ${cg} >&- 2>&- 
    425 iptables -t mangle -N ${cg}_ct >&- 2>&- 
    426 ${iptrules:+${iptrules}${N}iptables -t mangle -A ${cg}_ct -j CONNMARK --save-mark} 
    427 iptables -t mangle -A ${cg} -j CONNMARK --restore-mark 
    428 iptables -t mangle -A ${cg} -m mark --mark 0 -j ${cg}_ct 
     424iptables -t mangle -N qos_${cg} >&- 2>&- 
     425iptables -t mangle -N qos_${cg}_ct >&- 2>&- 
     426${iptrules:+${iptrules}${N}iptables -t mangle -A qos_${cg}_ct -j CONNMARK --save-mark} 
     427iptables -t mangle -A qos_${cg} -j CONNMARK --restore-mark 
     428iptables -t mangle -A qos_${cg} -m mark --mark 0 -j qos_${cg}_ct 
    429429$pktrules 
    430430$up$N${down:+${down}$N} 
    431431EOF 
    EOF 
    435435start_firewall() { 
    436436        add_insmod ipt_multiport 
    437437        add_insmod ipt_CONNMARK 
    438         cat <<EOF 
    439 iptables -t mangle -F 
    440 iptables -t mangle -X 
    441 EOF 
     438        stop_firewall 
    442439        for group in $CG; do 
    443440                start_cg $group 
    444441        done 
    445442} 
    446443 
     444stop_firewall() { 
     445        # Builds up a list of iptables commands to flush the qos_* chains, 
     446        # remove rules referring to them, then delete them 
     447 
     448        # Print rules in the mangle table, like iptables-save 
     449        iptables -t mangle -S | 
     450                # Find rules for the qos_* chains 
     451                grep '^-N qos_\|-j qos_' | 
     452                # Exclude rules in qos_* chains (inter-qos_* refs) 
     453                grep -v '^-A qos_' | 
     454                # Replace -N with -X and hold, with -F and print 
     455                # Replace -A with -D 
     456                # Print held lines at the end (note leading newline) 
     457                sed -e '/^-N/{s/^-N/-X/;H;s/^-X/-F/}' \ 
     458                        -e 's/^-A/-D/' \ 
     459                        -e '${p;g}' | 
     460                # Make into proper iptables calls 
     461                # Note:  awkward in previous call due to hold space usage 
     462                sed -n -e 's/^./iptables -t mangle &/p' 
     463} 
     464 
    447465C="0" 
    448466INTERFACES="" 
    449467[ -e ./qos.conf ] && {