home *** CD-ROM | disk | FTP | other *** search
/ chilidog.highland.cc.ks.us / chilidog.highland.cc.ks.us.zip / chilidog.highland.cc.ks.us / backup / bradford.20110725.etc.tar.gz / bradford.20110725.etc.tar / etc / sysconfig / scripts / SuSEfirewall2-qdisc < prev    next >
Text File  |  2006-04-22  |  5KB  |  122 lines

  1. #!/bin/bash
  2. # SuSEfirewall2-qdisc - upstream tuning
  3. # Copyright (C) 2004 SUSE LINUX Products GmbH
  4. #
  5. # Author:     Uwe Gansert
  6. # This program is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU General Public License
  8. # version 2 as published by the Free Software Foundation.
  9. # This program is distributed in the hope that it will be useful,
  10. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12. # GNU General Public License for more details.
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  16.  
  17. # tune the upload stream a little bit
  18. # with DSL for example, you have the problem, that your
  19. # downstream collapses if your upstream is full.
  20. # After this tuning this should not happen anymore.
  21. # interactive SSH and VPN are faster too, because they
  22. # get some extra bandwidth besides the bulk traffic
  23. #
  24. # variabel from sysconfig:
  25. #   FW_HTB_TUNE_DEV="DEV1,BANDWIDTH1 DEV2,BANDWIDTH2 ..."
  26. #
  27. # any questions about this to uwe.gansert@suse.de
  28. #
  29. do_qdisc_settings()
  30. {
  31.     if [ -n "$FW_HTB_TUNE_DEV" ]; then
  32.     modprobe sch_htb 2> /dev/null
  33.     fi
  34.     clear_qdisc_settings
  35.     for DEVICE_DATA in $FW_HTB_TUNE_DEV; do
  36.         IFS="," read DEV BANDWIDTH < <(echo "$DEVICE_DATA")
  37.  
  38.     DEV=`getdevinfo "$DEV"` || continue
  39.  
  40.         # sanity check
  41.         if [ -n "$DEV" -a -n "$BANDWIDTH" ]; then
  42.             # reserve about 15% for small packets (TCP ACK),
  43.             # interactive SSH from and to us and DNS querys.
  44.             # We don't need too much bandwidth but we need it fast.
  45.             SMALL_PACKET_BW=$(( $BANDWIDTH / 7 ))
  46.             if [ "$SMALL_PACKET_BW" -eq 0 ]; then
  47.                 warning "illegal bandwidth settings for $DEV in FW_HTB_TUNE_DEV"
  48.             fi
  49.  
  50.             # reserve 25% for VPN traffic. Never mind if we don't have
  51.             # a VPN. No bandwidth will be wasted
  52.             VPN_BW=$(( $BANDWIDTH / 4 ))
  53.             if [ "$VPN_BW" -eq 0 ];then
  54.                 warning "illegal bandwidth settings for $DEV in FW_HTB_TUNE_DEV"
  55.             fi
  56.  
  57.             # bulk traffic
  58.             REST_BW=$(( ${BANDWIDTH}-${SMALL_PACKET_BW}-${VPN_BW} ))
  59.  
  60.             $TC qdisc add dev $DEV root handle 1:0 htb default 20       # adding the queing discipline
  61.  
  62.         # adding the root class 1:1
  63.             $TC class add dev $DEV parent 1:0 classid 1:1 htb \
  64.                 rate ${BANDWIDTH}kbit ceil ${BANDWIDTH}kbit
  65.  
  66.             # class for small tcp packets 1:10
  67.             $TC class add dev $DEV parent 1:1 classid 1:10 htb \
  68.                 rate ${SMALL_PACKET_BW}kbit ceil ${BANDWIDTH}kbit prio 0 quantum 3000 # and interactive SSH
  69.         # class for VPN traffic       1:11
  70.             $TC class add dev $DEV parent 1:1 classid 1:11 htb \
  71.                 rate ${VPN_BW}kbit ceil ${BANDWIDTH}kbit prio 1 quantum 3000
  72.         # class for all the rest      1:20
  73.             $TC class add dev $DEV parent 1:1 classid 1:20 htb \
  74.                 rate ${REST_BW}kbit ceil ${BANDWIDTH}kbit prio 2 quantum 3000
  75.         # packets, marked with "10" to queue 1:10
  76.             $TC filter add dev $DEV parent 1:0 prio 0 protocol ip \
  77.                 handle 10 fw flowid 1:10
  78.         # packets, marked with "11" to queue 1:11
  79.             $TC filter add dev $DEV parent 1:0 prio 1 protocol ip \
  80.                 handle 11 fw flowid 1:11
  81.  
  82.         # iptables marks small TCP packets (potentially ACK)
  83.         # with 10, so "tc" will send them to queue 1:10
  84.             $IPTABLES -A POSTROUTING -t mangle -o $DEV -p tcp \
  85.                       -m length --length :64 -j MARK --set-mark 10
  86.  
  87.         # iptables marks SSH interactive ssh traffic
  88.         # with 10 too. So it gets to queue 1:10 like
  89.             $IPTABLES -A POSTROUTING -t mangle -o $DEV -p tcp \
  90.                       -m tos --tos Minimize-Delay \
  91.                       -m tcp --dport 22 -j MARK --set-mark 10
  92.  
  93.         # like the rule above, but this time we are
  94.         # the sshd and want to respond fast, even when
  95.             $IPTABLES -A POSTROUTING -t mangle -o $DEV -p tcp \
  96.                       -m tos --tos Minimize-Delay \
  97.                       -m tcp --sport 22 -j MARK --set-mark 10 
  98.  
  99.             # same like above for DNS
  100.             $IPTABLES -A POSTROUTING -t mangle -o $DEV -p udp \
  101.                       -m udp --dport 53 -j MARK --set-mark 10
  102.             $IPTABLES -A POSTROUTING -t mangle -o $DEV -p tcp \
  103.                       -m tcp --dport 53 -j MARK --set-mark 10
  104.  
  105.         # iptables marks VPN traffic with 11
  106.         # if we don't have VPN, never mind, no bandwidth
  107.         # will be wastet and if we need more, then it'll be
  108.         # be "borrowed" from the other queues
  109.             $IPTABLES -A POSTROUTING -t mangle -o $DEV -p 50 \
  110.                       -j MARK --set-mark 11
  111.  
  112.         else
  113.             warning "illegal settings in FW_HTB_TUNE_DEV=\"$FW_HTB_TUNE_DEV\", skipped device \"$DEV\""
  114.         fi
  115.     done
  116. }
  117.  
  118. # vim: sw=4
  119.