Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Thursday, March 28, 2024

Diff for scripts/shell/firewall/fw-universal.sh between version 2.57 and 2.73

version 2.57, 2008/02/02 22:57:54 version 2.73, 2010/06/21 21:52:16
Line 1 
Line 1 
 #!/bin/sh  #!/bin/bash
   
 #  #
 # This will be universal firewalling script for Linux kernel (iptables) in near future  # This will be universal firewalling script for Linux kernel (iptables) in near future
 # Can be started by init or by hand.  # Can be started by init or by hand.
 #  #
 # Developed by Lubomir Host 'rajo' <rajo AT platon.sk>  # Developed by Lubomir Host 'rajo' <rajo AT platon.sk>
 # Copyright (c) 2003-2006 Platon SDG, http://platon.sk/  # Copyright (c) 2003-2009 Platon Group, http://platon.sk/
 # Licensed under terms of GNU General Public License.  # Licensed under terms of GNU General Public License.
 # All rights reserved.  # All rights reserved.
 #  #
 # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.56 2008-01-27 13:36:02 rajo Exp $  # $Platon: scripts/shell/firewall/fw-universal.sh,v 2.72 2010-06-09 11:29:14 nepto Exp $
 #  #
 # Changelog:  # Changelog:
 # 2003-10-24 - created  # 2003-10-24 - created
Line 70  IFCONFIG="${IFCONFIG:=/sbin/ifconfig}"
Line 70  IFCONFIG="${IFCONFIG:=/sbin/ifconfig}"
 DEPMOD="${DEPMOD:=/sbin/depmod}"  DEPMOD="${DEPMOD:=/sbin/depmod}"
 MODPROBE="${MODPROBE:=/sbin/modprobe}"  MODPROBE="${MODPROBE:=/sbin/modprobe}"
 RMMOD="${RMMOD:=/sbin/rmmod}"  RMMOD="${RMMOD:=/sbin/rmmod}"
 AWK="${AWK:=/usr/bin/awk}"  AWK="${AWK:=/usr/bin/gawk}"
 PERL="${PERL:=/usr/bin/perl}"  PERL="${PERL:=/usr/bin/perl}"
   
   # shaping
   TC="${TC:=/sbin/tc}"
   
 # loopback interface  # loopback interface
 LO_IFACE="${LO_IFACE:=lo}"  LO_IFACE="${LO_IFACE:=lo}"
 # Hide NAT clients behind firewall  # Hide NAT clients behind firewall
Line 102  TRACEROUTE_DEST_PORTS="33434:33523"    # Tr
Line 105  TRACEROUTE_DEST_PORTS="33434:33523"    # Tr
 # allow some ICMP packets - needed for ping etc.  # allow some ICMP packets - needed for ping etc.
 ACCEPT_ICMP_PACKETS="${ACCEPT_ICMP_PACKETS:=echo-reply destination-unreachable echo-request time-exceeded}"  ACCEPT_ICMP_PACKETS="${ACCEPT_ICMP_PACKETS:=echo-reply destination-unreachable echo-request time-exceeded}"
   
   # check if all required tools are installed
   check_tools()
   { # {{{
           [ -x $AWK ]                                     || (echo "AWK not found: please install gawk"                                   && exit 1);
           [ -x $PERL ]                            || (echo "PERL not found: please install perl"                                  && exit 1);
           [ -x $IPTABLES ]                        || (echo "IPTABLES not found: please install iptables"                  && exit 1);
           [ -x $IPTABLES_SAVE ]           || (echo "IPTABLES_SAVE not found: please install iptables"             && exit 1);
           [ -x $IPTABLES_RESTORE ]        || (echo "IPTABLES_RESTORE not found: please install iptables"  && exit 1);
   } # }}}
   
 print_first()  print_first()
 { # {{{  { # {{{
Line 116  get_first_ip_addr()
Line 128  get_first_ip_addr()
   
 read_config_ips()  read_config_ips()
 { # {{{  { # {{{
         PARSE_CONFIG=$1 perl -ne 'if (m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/(\d+)$/g) { print; } elsif ($_ !~ m/^\s*#/ && $_ !~ m/^\s*$/ ) { print STDERR "ERROR: $ENV{PARSE_CONFIG}:$.: ignored string $_\n"; }' $1          PARSE_CONFIG=$1 $PERL -ne 'if (m/^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\/(\d+)$/g) { print; } elsif ($_ !~ m/^\s*#/ && $_ !~ m/^\s*$/ ) { print STDERR "ERROR: $ENV{PARSE_CONFIG}:$.: ignored string $_\n"; }' $1
 } # }}}  } # }}}
   
 # load necessary modules from $MODULES variable  # load necessary modules from $MODULES variable
Line 146  load_cache()
Line 158  load_cache()
   
         if [ -f "$CACHE_FILE" ]; then          if [ -f "$CACHE_FILE" ]; then
                 print_info "Loading rules from cache file $CACHE_FILE"                  print_info "Loading rules from cache file $CACHE_FILE"
   
                   # this has nothing to do with IPtables rules, we need to run them explicitly
                   forward_on
                   shaping_on
   
                   # restore IPtables rules
                 $IPTABLES_RESTORE -c < $CACHE_FILE;                  $IPTABLES_RESTORE -c < $CACHE_FILE;
                 forward_on # this has nothing to do with IPtables rules, we need to run them explicitly                  #echo "exit code $IPTABLES_RESTORE: $?"
                 exit 0;                  [ $? -eq 0 ] && exit 0; # exit if load succesfull
         fi          fi
 } # }}}  } # }}}
   
Line 170  unload_modules()
Line 188  unload_modules()
 print_iface_status()  print_iface_status()
 { # {{{  { # {{{
         # Print interfaces:          # Print interfaces:
         print_info "# iface     | IP addr       | Gateway       | broadcast     | netmask       | HW addr"          print_info "$(pad7 "# iface") | $(pad15 "IP address") | $(pad15 "Gateway") | $(pad15 "Broadcast") | $(pad15 "Netmask") | HW address";
         for iface in $interfaces; do          for iface in $interfaces; do
                 IPS="IP_$iface";                  IPS="IP_$iface";
                 for IP in ${!IPS}; do                  for IP in ${!IPS}; do
                         Gateway="Gateway_$iface"; Bcast="Bcast_$iface"; Mask="Mask_$iface"; HWaddr="HWaddr_$iface";                          Gateway="Gateway_$iface";
                         print_info "$iface      | ${IP} | ${!Gateway}   | ${!Bcast}     | ${!Mask}      | ${!HWaddr}"                          Bcast="Bcast_$iface";
                           Mask="Mask_$iface";
                           HWaddr="HWaddr_$iface";
                           print_info "$(pad7 $iface) | $(pad15 ${IP}) | $(pad15 ${!Gateway}) | $(pad15 ${!Bcast}) | $(pad15 ${!Mask}) | ${!HWaddr}";
                 done                  done
         done          done
 } # }}}  } # }}}
Line 282  syn_flood()
Line 303  syn_flood()
         $IPTABLES -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN          $IPTABLES -A syn-flood -m limit --limit 1/s --limit-burst 4 -j RETURN
         $IPTABLES -A syn-flood -j DROP          $IPTABLES -A syn-flood -j DROP
   
         for iface in $INTERFACES; do          for riface in $REAL_INTERFACES; do
                 $IPTABLES -A INPUT -i $iface -p TCP --syn -j syn-flood                  $IPTABLES -A INPUT -i $riface -p TCP --syn -j syn-flood
   
                 # packet is marked az NEW, but doesn't have SYN flag - drop it                  # packet is marked az NEW, but doesn't have SYN flag - drop it
                 $IPTABLES -A INPUT -i $iface -p TCP ! --syn -m state --state NEW -j DROP                  $IPTABLES -A INPUT -i $riface -p TCP ! --syn -m state --state NEW -j DROP
         done          done
   
   
Line 314  anti_spoof_filter()
Line 335  anti_spoof_filter()
                 $IPTABLES               -A spoof -s 172.16.0.0/12 -j DROP               # RFC1918                  $IPTABLES               -A spoof -s 172.16.0.0/12 -j DROP               # RFC1918
                 $IPTABLES_LOG   -A spoof -s 10.0.0.0/8  $LOG_LIMIT "RESERVED:10.0.0.0/8 src"                  $IPTABLES_LOG   -A spoof -s 10.0.0.0/8  $LOG_LIMIT "RESERVED:10.0.0.0/8 src"
                 $IPTABLES               -A spoof -s 10.0.0.0/8 -j DROP  # RFC1918 len pre sietovy interface do Internetu, kedze 10.0.0.0 je adresa LAN                  $IPTABLES               -A spoof -s 10.0.0.0/8 -j DROP  # RFC1918 len pre sietovy interface do Internetu, kedze 10.0.0.0 je adresa LAN
                 $IPTABLES_LOG   -A spoof -s 96.0.0.0/4 $LOG_LIMIT "RESERVED:96.0.0.0/4 src"  
                 $IPTABLES               -A spoof -s 96.0.0.0/4 -j DROP                          # IANA                  # 2009-02-11 - Not reserver anymore: http://www.iana.org/assignments/ipv4-address-space/
                   #              - it is a Comcast network now
                   #$IPTABLES_LOG  -A spoof -s 96.0.0.0/4 $LOG_LIMIT "RESERVED:96.0.0.0/4 src"
                   #$IPTABLES              -A spoof -s 96.0.0.0/4 -j DROP                          # IANA
   
                 for iface in $ANTISPOOF_IFACE; do                  for iface in $ANTISPOOF_IFACE; do
                         print_info -en " $iface"                          print_info -en " $iface"
Line 354  mangle_output()
Line 378  mangle_output()
         print_info -en "Optimizing OUTPUT TOS:"          print_info -en "Optimizing OUTPUT TOS:"
         # TOS flagy slouzi k optimalizaci datovych cest. Pro ssh, ftp a telnet          # TOS flagy slouzi k optimalizaci datovych cest. Pro ssh, ftp a telnet
         # pozadujeme minimalni zpozdeni. Pro ftp-data zase maximalni propostnost          # pozadujeme minimalni zpozdeni. Pro ftp-data zase maximalni propostnost
         for iface in $INTERFACES; do          for riface in $REAL_INTERFACES; do
                 print_info -en " $iface";                  print_info -en " $riface";
                 $IPTABLES -t mangle -A OUTPUT -o $iface -p TCP --sport ssh -j TOS --set-tos Minimize-Delay                  $IPTABLES -t mangle -A OUTPUT -o $riface -p TCP --sport ssh -j TOS --set-tos Minimize-Delay
                 $IPTABLES -t mangle -A OUTPUT -o $iface -p TCP --dport ssh -j TOS --set-tos Minimize-Delay                  $IPTABLES -t mangle -A OUTPUT -o $riface -p TCP --dport ssh -j TOS --set-tos Minimize-Delay
                 $IPTABLES -t mangle -A OUTPUT -o $iface -p TCP --sport ftp -j TOS --set-tos Minimize-Delay                  $IPTABLES -t mangle -A OUTPUT -o $riface -p TCP --sport ftp -j TOS --set-tos Minimize-Delay
                 $IPTABLES -t mangle -A OUTPUT -o $iface -p TCP --dport ftp -j TOS --set-tos Minimize-Delay                  $IPTABLES -t mangle -A OUTPUT -o $riface -p TCP --dport ftp -j TOS --set-tos Minimize-Delay
                 $IPTABLES -t mangle -A OUTPUT -o $iface -p TCP --dport telnet -j TOS --set-tos Minimize-Delay                  $IPTABLES -t mangle -A OUTPUT -o $riface -p TCP --dport telnet -j TOS --set-tos Minimize-Delay
                 $IPTABLES -t mangle -A OUTPUT -o $iface -p TCP --sport ftp-data -j TOS --set-tos Maximize-Throughput                  $IPTABLES -t mangle -A OUTPUT -o $riface -p TCP --sport ftp-data -j TOS --set-tos Maximize-Throughput
         done          done
         print_info " done."          print_info " done."
   
Line 395  masquerade()
Line 419  masquerade()
                                 $AWK -v FS=: '  (NF == 2) { remote_ip = "$lan_ip"; remote_port = $1; local_port = $2; } \                                  $AWK -v FS=: '  (NF == 2) { remote_ip = "$lan_ip"; remote_port = $1; local_port = $2; } \
                                                                 (NF == 3) { remote_ip = $2;        remote_port = $1; local_port = $3; } \                                                                  (NF == 3) { remote_ip = $2;        remote_port = $1; local_port = $3; } \
                                                                 END { printf "remote_ip=%s; remote_port=%s; local_port=%s;", remote_ip, remote_port, local_port; }'`                                                                  END { printf "remote_ip=%s; remote_port=%s; local_port=%s;", remote_ip, remote_port, local_port; }'`
                         print_info -en " $remote_port>>$remote_ip:$local_port(udp)"                          print_info -en " $remote_port>>$remote_ip:$local_port(tcp)"
                         $IPTABLES -t nat -A PREROUTING -p TCP \                          $IPTABLES -t nat -A PREROUTING -p TCP \
                                 -i ! $NAT_LAN_IFACE -d ! $lan_ip \                                  -i ! $NAT_LAN_IFACE -d ! $lan_ip \
                                 --dport $remote_port -j REDIRECT --to-port $local_port                                  --dport $remote_port -j REDIRECT --to-port $local_port
Line 465  masquerade()
Line 489  masquerade()
                 if [ ! -z "$NAT_TCP_PORT_FORWARD" ]; then                  if [ ! -z "$NAT_TCP_PORT_FORWARD" ]; then
                         print_info -en "\tForwarding TCP ports to local machines:"                          print_info -en "\tForwarding TCP ports to local machines:"
                         for redirect in $NAT_TCP_PORT_FORWARD; do                          for redirect in $NAT_TCP_PORT_FORWARD; do
                                 eval `echo $redirect | $AWK -v FS=: '{ printf "src_port=%s; local_machine=%s; dest_port=%s;", $1, $2, $3; }'`                                  #eval `echo $redirect | $AWK -v FS=: '{ printf "src_port=%s; local_machine=%s; dest_port=%s;", $1, $2, $3; }'`
                                 print_info -en " $src_port -> $local_machine:$dest_port"                                  eval `echo $redirect | \
                                 $IPTABLES -t nat -A PREROUTING -p TCP -i $NAT_LAN_IFACE -d $lan_ip \                                          $AWK -v FS=: '  (NF == 3) { src_ip = "$lan_ip" ; src_port = $1; local_machine = $2; dest_port = $3; } \
                                                                           (NF == 4) { src_ip = $1 ; src_port = $2; local_machine = $3; dest_port = $4; } \
                                                                           END { printf "src_ip=%s; src_port=%s; local_machine=%s; dest_port=%s;", src_ip, src_port, local_machine, dest_port; }'`
                                   print_info -en " $src_ip:$src_port -> $local_machine:$dest_port"
                                   $IPTABLES -t nat -A PREROUTING -p TCP -i $NAT_LAN_IFACE -d $src_ip \
                                 --dport $src_port -j DNAT --to $local_machine:$dest_port                                  --dport $src_port -j DNAT --to $local_machine:$dest_port
                                 $IPTABLES -A FORWARD -p TCP -i $NAT_LAN_IFACE -d $local_machine --dport $dest_port -j ACCEPT                                  $IPTABLES -A FORWARD -p TCP -i $NAT_LAN_IFACE -d $local_machine --dport $dest_port -j ACCEPT
                         done                          done
Line 476  masquerade()
Line 504  masquerade()
                 if [ ! -z "$NAT_UDP_PORT_FORWARD" ]; then                  if [ ! -z "$NAT_UDP_PORT_FORWARD" ]; then
                         print_info -en "\tForwarding UDP ports to local machines:"                          print_info -en "\tForwarding UDP ports to local machines:"
                         for redirect in $NAT_UDP_PORT_FORWARD; do                          for redirect in $NAT_UDP_PORT_FORWARD; do
                                 eval `echo $redirect | $AWK -v FS=: '{ printf "src_port=%s; local_machine=%s; dest_port=%s;", $1, $2, $3; }'`                                  #eval `echo $redirect | $AWK -v FS=: '{ printf "src_port=%s; local_machine=%s; dest_port=%s;", $1, $2, $3; }'`
                                   eval `echo $redirect | \
                                           $AWK -v FS=: '  (NF == 3) { src_ip = "$lan_ip" ; src_port = $1; local_machine = $2; dest_port = $3; } \
                                                                           (NF == 4) { src_ip = $1 ; src_port = $2; local_machine = $3; dest_port = $4; } \
                                                                           END { printf "src_ip=%s; src_port=%s; local_machine=%s; dest_port=%s;", src_ip, src_port, local_machine, dest_port; }'`
                                 print_info -en " $src_port -> $local_machine:$dest_port"                                  print_info -en " $src_port -> $local_machine:$dest_port"
                                 $IPTABLES -t nat -A PREROUTING -p UDP -i $NAT_LAN_IFACE -d $lan_ip \                                  $IPTABLES -t nat -A PREROUTING -p UDP -i $NAT_LAN_IFACE -d $lan_ip \
                                 --dport $src_port -j DNAT --to $local_machine:$dest_port                                  --dport $src_port -j DNAT --to $local_machine:$dest_port
Line 522  log_new_connections()
Line 554  log_new_connections()
 drop_output()  drop_output()
 { # {{{  { # {{{
   
         for iface in $INTERFACES; do          for riface in $REAL_INTERFACES; do
                 drop_output_tcp="${iface}_DROP_OUTPUT_TCP"                  drop_output_tcp="${riface}_DROP_OUTPUT_TCP"
                 DROP_OUTPUT_TCP="${!drop_output_tcp}"                  DROP_OUTPUT_TCP="${!drop_output_tcp}"
                 drop_output_udp="${iface}_DROP_OUTPUT_UDP"                  drop_output_udp="${riface}_DROP_OUTPUT_UDP"
                 DROP_OUTPUT_UDP="${!drop_output_udp}"                  DROP_OUTPUT_UDP="${!drop_output_udp}"
   
                 if [ ! -z "$DROP_OUTPUT_TCP" ]; then                  if [ ! -z "$DROP_OUTPUT_TCP" ]; then
                         print_info -en "$iface: Dropping outgoing packets from ports:"                          print_info -en "$riface: Dropping outgoing packets from ports:"
                         for port in $DROP_OUTPUT_TCP; do                          for port in $DROP_OUTPUT_TCP; do
                                 print_info -en " $port"                                  print_info -en " $port"
                                 $IPTABLES -A FORWARD -p TCP --sport $port -o $iface -j DROP                                  $IPTABLES -A FORWARD -p TCP --sport $port -o $riface -j DROP
                                 $IPTABLES -A OUTPUT  -p TCP --sport $port -o $iface -j DROP                                  $IPTABLES -A OUTPUT  -p TCP --sport $port -o $riface -j DROP
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
   
                 if [ ! -z "$DROP_OUTPUT_UDP" ]; then                  if [ ! -z "$DROP_OUTPUT_UDP" ]; then
                         print_info -en "$iface: Dropping outgoing packets from ports:"                          print_info -en "$riface: Dropping outgoing packets from ports:"
                         for port in $DROP_OUTPUT_UDP; do                          for port in $DROP_OUTPUT_UDP; do
                                 print_info -en " $port"                                  print_info -en " $port"
                                 $IPTABLES -A FORWARD -p UDP --sport $port -o $iface -j DROP                                  $IPTABLES -A FORWARD -p UDP --sport $port -o $riface -j DROP
                                 $IPTABLES -A OUTPUT  -p UDP --sport $port -o $iface -j DROP                                  $IPTABLES -A OUTPUT  -p UDP --sport $port -o $riface -j DROP
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
Line 603  drop_input()
Line 635  drop_input()
         if [ ! -z "$ALL_DROP_INPUT_TCP" ]; then          if [ ! -z "$ALL_DROP_INPUT_TCP" ]; then
                 print_info -en "Drop ALL INPUT TCP connections on ports:"                  print_info -en "Drop ALL INPUT TCP connections on ports:"
                 for port in $ALL_DROP_INPUT_TCP; do                  for port in $ALL_DROP_INPUT_TCP; do
                         for iface in $INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($iface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $iface -p TCP --dport $port -j DROP                                  $IPTABLES -A INPUT -i $riface -p TCP --dport $port -j DROP
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 613  drop_input()
Line 645  drop_input()
         if [ ! -z "$ALL_DROP_INPUT_UDP" ]; then          if [ ! -z "$ALL_DROP_INPUT_UDP" ]; then
                 print_info -en "Drop ALL INPUT UDP connections on ports:"                  print_info -en "Drop ALL INPUT UDP connections on ports:"
                 for port in $ALL_DROP_INPUT_UDP; do                  for port in $ALL_DROP_INPUT_UDP; do
                         for iface in $INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($iface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $iface -p UDP --dport $port -j DROP                                  $IPTABLES -A INPUT -i $riface -p UDP --dport $port -j DROP
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
         fi          fi
           if [ ! -z "$REAL_DROP_INPUT_TCP" ]; then
                   print_info -en "Drop REAL all INPUT TCP connections for ALL interfaces on ports:"
                   for port in $REAL_DROP_INPUT_TCP; do
                           print_info -en " $port(ALL)"
                           $IPTABLES -A INPUT -p TCP --dport $port -j DROP
                   done
                   print_info " done."
           fi
           if [ ! -z "$REAL_DROP_INPUT_UDP" ]; then
                   print_info -en "Drop REAL all INPUT UDP connections for ALL interfaces on ports:"
                   for port in $REAL_DROP_INPUT_UDP; do
                           print_info -en " $port(ALL)"
                           $IPTABLES -A INPUT -p UDP --dport $port -j DROP
                   done
                   print_info " done."
           fi
 } # }}}  } # }}}
   
 reject_input()  reject_input()
Line 627  reject_input()
Line 675  reject_input()
         if [ ! -z "$ALL_REJECT_INPUT_TCP" ]; then          if [ ! -z "$ALL_REJECT_INPUT_TCP" ]; then
                 print_info -en "Reject ALL INPUT TCP connections on ports:"                  print_info -en "Reject ALL INPUT TCP connections on ports:"
                 for port in $ALL_REJECT_INPUT_TCP; do                  for port in $ALL_REJECT_INPUT_TCP; do
                         for iface in $INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($iface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $iface -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH                                  $IPTABLES -A INPUT -i $riface -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 637  reject_input()
Line 685  reject_input()
         if [ ! -z "$ALL_REJECT_INPUT_UDP" ]; then          if [ ! -z "$ALL_REJECT_INPUT_UDP" ]; then
                 print_info -en "Reject ALL INPUT UDP connections on ports:"                  print_info -en "Reject ALL INPUT UDP connections on ports:"
                 for port in $ALL_REJECT_INPUT_UDP; do                  for port in $ALL_REJECT_INPUT_UDP; do
                         for iface in $INTERFACES; do                          for riface in $REAL_INTERFACES; do
                                 print_info -en " $port($iface)"                                  print_info -en " $port($riface)"
                                 $IPTABLES -A INPUT -i $iface -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH                                  $IPTABLES -A INPUT -i $riface -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH
                           done
                   done
                   print_info " done."
           fi
           if [ ! -z "$REAL_REJECT_INPUT_TCP" ]; then
                   print_info -en "Reject REAL all INPUT TCP connections for ALL interfaces on ports:"
                   for port in $REAL_REJECT_INPUT_TCP; do
                           print_info -en " $port(ALL)"
                           $IPTABLES -A INPUT -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH
                   done
                   print_info " done."
           fi
           if [ ! -z "$REAL_REJECT_INPUT_UDP" ]; then
                   print_info -en "Reject REAL all INPUT UDP connections for ALL interfaces on ports:"
                   for port in $REAL_REJECT_INPUT_UDP; do
                           for riface in $REAL_INTERFACES; do
                                   print_info -en " $port(ALL)"
                                   $IPTABLES -A INPUT -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH
                         done                          done
                 done                  done
                 print_info " done."                  print_info " done."
Line 648  reject_input()
Line 714  reject_input()
   
 allow_input()  allow_input()
 { # {{{  { # {{{
   
         if [ ! -z "$ALL_ACCEPT_INPUT_TCP" ]; then          if [ ! -z "$ALL_ACCEPT_INPUT_TCP" ]; then
                 print_info -en "Accepting ALL INPUT TCP connections on ports:"                  print_info -en "Accepting ALL INPUT TCP connections on ports:"
                 for port in $ALL_ACCEPT_INPUT_TCP; do                  for port in $ALL_ACCEPT_INPUT_TCP; do
                         src_ip=""                          src_ip=""
                         eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                          eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                   riface="IFname_$iface";
                                 print_info -en " $port($iface)"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port($iface)"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                                 IPS="IP_$iface";                                  IPS="IP_$iface";
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z "$src_ip" ]; then                                          if [ -z "$src_ip" ]; then
                                                 $IPTABLES -A INPUT -i $iface -d $ip -p TCP --dport $port -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP --dport $port -j ACCEPT
                                         else                                          else
                                                 $IPTABLES -A INPUT -i $iface -s $src_ip -d $ip -p TCP --dport $port -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p TCP --dport $port -j ACCEPT
                                         fi                                          fi
                                 done                                  done
                         done                          done
Line 674  allow_input()
Line 740  allow_input()
                         src_ip=""                          src_ip=""
                         eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                          eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                         for iface in $INTERFACES; do                          for iface in $INTERFACES; do
                                   riface="IFname_$iface";
                                 print_info -en " $port($iface)"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port($iface)"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                                 IPS="IP_$iface";                                  IPS="IP_$iface";
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z "$src_ip" ]; then                                          if [ -z "$src_ip" ]; then
                                                 $IPTABLES -A INPUT -i $iface -d $ip -p UDP --dport $port -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP --dport $port -j ACCEPT
                                         else                                          else
                                                 $IPTABLES -A INPUT -i $iface -s $src_ip -d $ip -p UDP --dport $port -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p UDP --dport $port -j ACCEPT
                                         fi                                          fi
                                 done                                  done
                         done                          done
Line 688  allow_input()
Line 755  allow_input()
                 print_info " done."                  print_info " done."
         fi          fi
   
           if [ ! -z "$REAL_ACCEPT_INPUT_TCP" ]; then
                   print_info -en "Accepting REAL all INPUT TCP connections for ALL interfaces on ports:"
                   for port in $REAL_ACCEPT_INPUT_TCP; do
                           src_ip=""
                           eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                           print_info -en " $port(ALL)"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                           if [ -z "$src_ip" ]; then
                                   $IPTABLES -A INPUT -p TCP --dport $port -j ACCEPT
                           else
                                   $IPTABLES -A INPUT -s $src_ip -p TCP --dport $port -j ACCEPT
                           fi
                   done
                   print_info " done."
           fi
           if [ ! -z "$REAL_ACCEPT_INPUT_UDP" ]; then
                   print_info -en "Accepting REAL all INPUT UDP connections for ALL interfaces on ports:"
                   for port in $REAL_ACCEPT_INPUT_UDP; do
                           src_ip=""
                           eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                           print_info -en " $port(ALL)"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                           if [ -z "$src_ip" ]; then
                                   $IPTABLES -A INPUT -p UDP --dport $port -j ACCEPT
                           else
                                   $IPTABLES -A INPUT -s $src_ip -p UDP --dport $port -j ACCEPT
                           fi
                   done
                   print_info " done."
           fi
   
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                   riface="IFname_$iface";
                 IPS="IP_$iface";                  IPS="IP_$iface";
   
                 redirect_tcp="${iface}_REDIRECT_TCP"                  redirect_tcp="${iface}_REDIRECT_TCP"
Line 715  allow_input()
Line 812  allow_input()
                                                                         (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \                                                                          (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \
                                                                         END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`                                                                          END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`
                                 print_info -en " $remote_ip:$from_port->$to_port"                                  print_info -en " $remote_ip:$from_port->$to_port"
                                 $IPTABLES -t nat -A PREROUTING -p TCP -i $iface -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port                                  $IPTABLES -t nat -A PREROUTING -p TCP -i ${!riface} -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
Line 729  allow_input()
Line 826  allow_input()
                                                                         (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \                                                                          (NF == 3) { remote_ip = $1;          from_port = $2; to_port = $3; } \
                                                                         END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`                                                                          END { printf "remote_ip=%s; from_port=%s; to_port=%s;", remote_ip, from_port, to_port; }'`
                                 print_info -en " $remote_ip:$from_port->$to_port"                                  print_info -en " $remote_ip:$from_port->$to_port"
                                 $IPTABLES -t nat -A PREROUTING -p UDP -i $iface -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port                                  $IPTABLES -t nat -A PREROUTING -p UDP -i ${!riface} -s $remote_ip -d $ip --dport $from_port -j REDIRECT --to-port $to_port
                         done                          done
                         print_info " done."                          print_info " done."
                 fi                  fi
Line 743  allow_input()
Line 840  allow_input()
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z $src_ip ]; then
                                                 $IPTABLES -A INPUT -i $iface -d $ip -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH
                                         else                                          else
                                                 $IPTABLES -A INPUT -i $iface -s $src_ip -d $ip -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p TCP --dport $port -j REJECT --reject-with $REJECT_WITH
                                         fi                                          fi
                                 done                                  done
                         done                          done
Line 760  allow_input()
Line 857  allow_input()
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z $src_ip ]; then
                                                 $IPTABLES -A INPUT -i $iface -d $ip -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH
                                         else                                          else
                                                 $IPTABLES -A INPUT -i $iface -s $src_ip -d $ip -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH                                                  $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p UDP --dport $port -j REJECT --reject-with $REJECT_WITH
                                         fi                                          fi
                                 done                                  done
                         done                          done
Line 776  allow_input()
Line 873  allow_input()
                         for port in $ACCEPT_INPUT_TCP; do                          for port in $ACCEPT_INPUT_TCP; do
                                 src_ip=""                                  src_ip=""
                                 eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                                  eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                                   if [ -n "$src_ip" -a "$port" = "0" ]; then
                                           port="ALL";
                                   fi
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z $src_ip ]; then
                                                 $IPTABLES -A INPUT -i $iface -d $ip -p TCP --dport $port -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p TCP --dport $port -j ACCEPT
                                         else                                          else
                                                 $IPTABLES -A INPUT -i $iface -s $src_ip -d $ip -p TCP --dport $port -j ACCEPT                                                  if [ "$port" = "ALL" ]; then
                                                           $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p TCP -j ACCEPT
                                                   else
                                                           $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p TCP --dport $port -j ACCEPT
                                                   fi
                                         fi                                          fi
                                 done                                  done
                         done                          done
Line 793  allow_input()
Line 897  allow_input()
                         for port in $ACCEPT_INPUT_UDP; do                          for port in $ACCEPT_INPUT_UDP; do
                                 src_ip=""                                  src_ip=""
                                 eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`                                  eval `echo $port | awk -v FS=: '/:/ { printf "src_ip=\"%s\"; port=\"%s\";", $1, $2; }'`
                                   if [ -n "$src_ip" -a "$port" = "0" ]; then
                                           port="ALL";
                                   fi
                                 print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`                                  print_info -en " $port"`[ ! -z $src_ip ] && echo "[$src_ip]"`
                                 #$IPTABLES -A INPUT -i $iface -d ${!INET_IP} -p UDP --dport $port -j ACCEPT                                  #$IPTABLES -A INPUT -i $iface -d ${!INET_IP} -p UDP --dport $port -j ACCEPT
                                 #$IPTABLES -A INPUT -i $iface --source 192.168.1.0/16 -p UDP --dport $port -j ACCEPT                                  #$IPTABLES -A INPUT -i $iface --source 192.168.1.0/16 -p UDP --dport $port -j ACCEPT
                                 for ip in ${!IPS}; do                                  for ip in ${!IPS}; do
                                         if [ -z $src_ip ]; then                                          if [ -z $src_ip ]; then
                                                 $IPTABLES -A INPUT -i $iface -d $ip -p UDP --dport $port -j ACCEPT                                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p UDP --dport $port -j ACCEPT
                                         else                                          else
                                                 $IPTABLES -A INPUT -i $iface -s $src_ip -d $ip -p UDP --dport $port -j ACCEPT                                                  if [ "$port" = "ALL" ]; then
                                                           $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p UDP -j ACCEPT
                                                   else
                                                           $IPTABLES -A INPUT -i ${!riface} -s $src_ip -d $ip -p UDP --dport $port -j ACCEPT
                                                   fi
                                         fi                                          fi
                                 done                                  done
                         done                          done
Line 834  allow_output()
Line 945  allow_output()
         # Povolíme odchozí pakety, které mají naše IP adresy          # Povolíme odchozí pakety, které mají naše IP adresy
         print_info -en "Accepting OUTPUT packets from"          print_info -en "Accepting OUTPUT packets from"
         for iface in $INTERFACES; do          for iface in $INTERFACES; do
                   riface="IFname_$iface";
                 IPS="IP_$iface";                  IPS="IP_$iface";
                 for ip in ${!IPS}; do                  for ip in ${!IPS}; do
                         print_info -en " $ip($iface)"                          print_info -en " $ip($iface)"
                         $IPTABLES -A OUTPUT -o $iface -s $ip -j ACCEPT                          $IPTABLES -A OUTPUT -o ${!riface} -s $ip -j ACCEPT
                 done                  done
         done;          done;
         print_info " done.";          print_info " done.";
Line 853  allow_icmp()
Line 965  allow_icmp()
         for type in $ACCEPT_ICMP_PACKETS; do          for type in $ACCEPT_ICMP_PACKETS; do
                 print_info -en " $type"                  print_info -en " $type"
                 for iface in $INTERFACES; do                  for iface in $INTERFACES; do
                           riface="IFname_$iface";
                         IPS="IP_$iface";                          IPS="IP_$iface";
                         for ip in ${!IPS}; do                          for ip in ${!IPS}; do
                                 $IPTABLES -A INPUT -i $iface -d $ip -p ICMP --icmp-type $type -j ACCEPT                                  $IPTABLES -A INPUT -i ${!riface} -d $ip -p ICMP --icmp-type $type -j ACCEPT
                         done                          done
                 done                  done
         done          done
Line 962  do_ip_accounting()
Line 1075  do_ip_accounting()
 accept_related()  accept_related()
 { # {{{  { # {{{
   
         print_info -en "Accepting ESTABLISHED, RELATED packets for IP:"          print_info -en "Accepting ESTABLISHED, RELATED packets ..."
         for iface in $INTERFACES; do          $IPTABLES -A INPUT      -m state --state ESTABLISHED,RELATED -j ACCEPT
                 IPS="IP_$iface";          $IPTABLES -A OUTPUT     -m state --state ESTABLISHED,RELATED -j ACCEPT
                 for ip in ${!IPS}; do  
                         print_info -en " $ip($iface)"  
                 done  
                 $IPTABLES -A INPUT      -m state --state ESTABLISHED,RELATED -j ACCEPT  
                 $IPTABLES -A OUTPUT     -m state --state ESTABLISHED,RELATED -j ACCEPT  
         done  
         print_info " done."          print_info " done."
   
 } # }}}  } # }}}
Line 986  accept_loopback()
Line 1093  accept_loopback()
   
 } # }}}  } # }}}
   
   #
   # Shaping support {{{
   #
   # http://koti.welho.com/ntoivol2/shaping/
   #
   
   shaping_on()
   { # {{{
   
           mark_idx=1
           if [ ! -z $SHAPING_IFACE ]; then
                   for iface in $SHAPING_IFACE; do
                           echo "Shaping for interface $iface"
                           shaping_classes="${iface}_SHAPING_CLASSES"
   
                           # root qdisc: 2-band prio with everything defaulting to band 0
                           $TC qdisc add dev $iface root handle 1: prio bands 2 priomap 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
   
                           for class in ${!shaping_classes}; do
                                   rate="${iface}_SHAPING_RATE_${class}"
                                   latency="${iface}_SHAPING_LATENCY_${class}"
                                   burst="${iface}_SHAPING_BURST_${class}"
                                   netmask="${iface}_SHAPING_NETMASK_${class}"
                                   echo -e "\tshaping \"$class\" traffic: rate=${!rate} burst=${!burst} netmask=${!netmask}"
                                   if [ -z ${!netmask} ]; then
                                           $IPTABLES -t mangle -A OUTPUT -j MARK --set-mark 0x$mark_idx
                                   else
                                           $IPTABLES -t mangle -A OUTPUT -d ${!netmask} -j MARK --set-mark 0x$mark_idx
                                   fi
   
                                   if [ -z ${!rate} ]; then
                                           # SFQ for local traffic
                                           $TC qdisc add dev $iface parent 1:$mark_idx handle $((10 + $mark_idx)): sfq perturb 10
                                   else
                                           # TBF shaping and SFQ for internet traffic
                                           $TC qdisc add dev $iface parent 1:$mark_idx handle $((10 + $mark_idx)): tbf rate ${!rate} burst ${!burst} latency ${!latency}
                                           $TC qdisc add dev $iface parent $((10 + $mark_idx)): handle $((10 * $mark_idx)): sfq perturb 10
                                   fi
   
                                   mark_idx=$(($mark_idx + 1))
                           done
                   done
           fi
   
   } # }}}
   
   shaping_off()
   { # {{{
           if [ ! -z $SHAPING_IFACE ]; then
                   echo -en "Shaping turned off for interface"
                   for iface in $SHAPING_IFACE; do
                           echo -en " $iface"
                           $TC qdisc del dev $iface root 2>/dev/null
                   done
                   echo ". done"
           fi
   } # }}}
   
   shaping_status()
   { # {{{
           if [ ! -z $SHAPING_IFACE ]; then
                   echo "# Shaping status: "
                   $TC qdisc list
           else
                   echo "# Shaping turned off"
           fi
   } # }}}
   
   # }}}
   
 add_banned_ip()  add_banned_ip()
 { # {{{  { # {{{
         echo "# `date '+%Y-%m-%d %X' ` - ${SSH_CLIENT:=local}" >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf          echo "# `date '+%Y-%m-%d %X' ` - ${SSH_CLIENT:=local}" >> $DEFAULT_FIREWALL_CONFIG_DIR/BANNED_IP.conf
Line 1040  parse_ifconfig()
Line 1217  parse_ifconfig()
                 $PERL -e '                  $PERL -e '
 my $iface_count = 0;  my $iface_count = 0;
 my $iface;  my $iface;
 my (%ip6, %scope6, %bcast, %mask, %hwaddr, %ipcount);  my (%ip, %ifname, %ip6, %scope6, %bcast, %mask, %hwaddr, %ipcount);
   
 while (my $line = <STDIN>) {  while (my $line = <STDIN>) {
         chomp $line;          chomp $line;
         if ($line =~ m/^([a-z0-9:]+)\s+.*?([a-z0-9:]+)\s*$/i) { # Linux interface          if ($line =~ m/^([a-z0-9:]+)\s+.*?([a-z0-9:]+)\s*$/i) { # Linux interface
                 $iface  = $1;                  $iface  = $1;
                 my $iface_hwaddr = $2;                  my $iface_hwaddr = $2;
                 $iface  = [ $iface =~ m/^([a-z0-9]+)/i ]->[0]; # convert "eth0:0" --> "eth0"                  my $x_iface     = $iface;
                   $iface  =~ s/:/_/; # convert "eth0:0" --> "eth0_0"
                   $x_iface                = [ $x_iface =~ m/^([a-z0-9]+)/i ]->[0]; # convert "eth0:0" --> "eth0"
                   $ifname{$iface} = $x_iface;
                 $ipcount{$iface}++;                  $ipcount{$iface}++;
                 $hwaddr{$iface} = $iface_hwaddr;                  $hwaddr{$iface} = $iface_hwaddr;
                 $iface_count++;                  $iface_count++;
Line 1075  map { printf "Bcast_%s=\"%s\";        export B
Line 1255  map { printf "Bcast_%s=\"%s\";        export B
 map { printf "Mask_%s=\"%s\";           export Mask_%s;\n",             $_, $mask{$_},  $_; } keys %mask;  map { printf "Mask_%s=\"%s\";           export Mask_%s;\n",             $_, $mask{$_},  $_; } keys %mask;
 map { printf "HWaddr_%s=\"%s\";         export HWaddr_%s;\n",   $_, $hwaddr{$_},        $_; } keys %hwaddr;  map { printf "HWaddr_%s=\"%s\";         export HWaddr_%s;\n",   $_, $hwaddr{$_},        $_; } keys %hwaddr;
 map { printf "IPcount_%s=\"%s\";        export IPcount_%s;\n",  $_, $ipcount{$_},       $_; } keys %ipcount;  map { printf "IPcount_%s=\"%s\";        export IPcount_%s;\n",  $_, $ipcount{$_},       $_; } keys %ipcount;
 printf "interfaces=\"%s\";      export interfaces;\n", join(" ", keys %ip);  map { printf "IFname_%s=\"%s\";         export IFname_%s;\n",   $_, $ifname{$_},        $_; } keys %ifname;
   printf "interfaces=\"%s\";      export interfaces;\n", join(" ", sort keys %ip);
         '`          '`
         eval "$parsed_interfaces";          eval "$parsed_interfaces";
           #echo "$parsed_interfaces";
   
         parsed_routes=`$PERL -e '          parsed_routes=`$PERL -e '
         $\ = "\n";          $\ = "\n";
Line 1135  printf "interfaces=\"%s\";     export inter
Line 1317  printf "interfaces=\"%s\";     export inter
   
 } # }}}  } # }}}
   
   # helper function for string padding
   str_pad_right()
   { # {{{
           num="$1";
           string="$2";
           count=$(echo -n "$string" | wc -c);
           count=$((count + 0))
           while [ $count -lt $num ]; do
                   string="$string ";
                   count=$((count + 1));
           done
           echo -n "$string"
           return;
   } # }}}
   
   pad7()  { str_pad_right  7 "$1"; }
   pad15() { str_pad_right 15 "$1"; }
   
   
   check_tools
 parse_ifconfig  parse_ifconfig
 print_iface_status  print_iface_status
   
Line 1145  print_iface_status
Line 1346  print_iface_status
 # $INTERFACES_ACCEPT_ALL - interfaces withouth restrictions  # $INTERFACES_ACCEPT_ALL - interfaces withouth restrictions
 #  #
 # $INTERFACES - all interfaces withouth loopback  # $INTERFACES - all interfaces withouth loopback
 #               and devices without restrictions (e.g. tun0 tun1 tap0 ...)  #               and devices without restrictions (e.g. tun0 tun1 tap0 eth0_0 eth0_1 ...)
   #
   # $REAL_INTERFACES - aliases like eth0:0, eth1:0 are transformed to eth0, eth1, ...
 #  #
 # list of all interfaces is in $interfaces variable  # list of all interfaces is in $interfaces variable
 #  #
 INTERFACES=""  INTERFACES=""
 INTERFACES_ACCEPT_ALL=""  INTERFACES_ACCEPT_ALL=""
   x_REAL_INTERFACES=""
 regexp='^\('`echo $IFACE_ACCEPT_ALL | sed 's/ /\\\|/g; s/+/.*/g;'`'\)$'  regexp='^\('`echo $IFACE_ACCEPT_ALL | sed 's/ /\\\|/g; s/+/.*/g;'`'\)$'
 for iface in $interfaces; do  for iface in $interfaces; do
           riface="IFname_$iface";
           x_REAL_INTERFACES="$x_REAL_INTERFACES ${!riface}"
         #if [ "o$iface" = "olo" ]; then continue; fi          #if [ "o$iface" = "olo" ]; then continue; fi
         echo $iface | grep -q -e "$regexp"          echo $iface | grep -q -e "$regexp"
         if [ $? = 0 ] || [ "o$iface" = "olo" ]; then # lo interface is always here          if [ $? = 0 ] || [ "o$iface" = "olo" ]; then # lo interface is always here
Line 1161  for iface in $interfaces; do
Line 1367  for iface in $interfaces; do
                 INTERFACES="$INTERFACES $iface";                  INTERFACES="$INTERFACES $iface";
         fi          fi
 done  done
   REAL_INTERFACES="`echo $x_REAL_INTERFACES | awk -v RS=' ' '{ print; }' | sort -u`"
 INTERFACES_ACCEPT_ALL="$IFACE_ACCEPT_ALL"  INTERFACES_ACCEPT_ALL="$IFACE_ACCEPT_ALL"
   
   
Line 1199  case "$1" in
Line 1406  case "$1" in
                 log_forward_drop                  log_forward_drop
                 forward_on                  forward_on
                 do_ip_accounting                  do_ip_accounting
                   shaping_off
                   shaping_on
                 configure_special_rules                  configure_special_rules
                 $IPTABLES_SAVE -c > $CACHE_FILE                  $IPTABLES_SAVE -c > $CACHE_FILE
                 ;;                  ;;
   
         stop)          stop)
                 print_info -n "Stopping $DESC: "                  print_info -n "Stopping $DESC: "
                   shaping_off
                 set_default_policy                  set_default_policy
                 remove_chains                  remove_chains
                 unload_modules                  unload_modules
Line 1223  case "$1" in
Line 1433  case "$1" in
         status)          status)
                 print_iface_status; echo                  print_iface_status; echo
                 $IPTABLES -L -nv                  $IPTABLES -L -nv
                   shaping_status
                 ;;                  ;;
   
         purge)          purge)

Legend:
Removed from v.2.57  
changed lines
  Added in v.2.73

Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top