Changeset 28622


Ignore:
Timestamp:
2011-10-27T14:39:16+02:00 (6 years ago)
Author:
jow
Message:

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@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/package/qos-scripts/files/usr/lib/qos/generate.sh

    r26622 r28622  
    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 
     
    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 
     
    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} 
     
    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 
     442} 
     443 
     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' 
    445463} 
    446464 
Note: See TracChangeset for help on using the changeset viewer.