#!/bin/sh

#
# Remember to set up the network interface card with IRQ and base address
# in syslinux.cfg
#

#
# Grabbing the config.
#
. /etc/config

/bin/ifconfig lo 127.0.0.1

#
# Inside:
#
/bin/ifconfig ${INSIDE_DEV} ${INSIDE_IP} netmask ${INSIDE_NETMASK} broadcast ${INSIDE_BROADCAST}
[ ${INSIDE2_DEV} ] && /bin/ifconfig ${INSIDE2_DEV} ${INSIDE2_IP} netmask ${INSIDE2_NETMASK} broadcast ${INSIDE2_BROADCAST}
[ ${INSIDE3_DEV} ] && /bin/ifconfig ${INSIDE3_DEV} ${INSIDE3_IP} netmask ${INSIDE3_NETMASK} broadcast ${INSIDE3_BROADCAST}
[ ${INSIDE4_DEV} ] && /bin/ifconfig ${INSIDE4_DEV} ${INSIDE4_IP} netmask ${INSIDE4_NETMASK} broadcast ${INSIDE4_BROADCAST}
[ ${INSIDE5_DEV} ] && /bin/ifconfig ${INSIDE5_DEV} ${INSIDE5_IP} netmask ${INSIDE5_NETMASK} broadcast ${INSIDE5_BROADCAST}

echo "${INSIDE_IP}	${HOSTNAME}.${DOMAIN}" >> /etc/hosts
[ ${INSIDE2_DEV} ] && echo "${INSIDE2_IP}	${HOSTNAME}.${DOMAIN}" >> /etc/hosts
[ ${INSIDE3_DEV} ] && echo "${INSIDE3_IP}	${HOSTNAME}.${DOMAIN}" >> /etc/hosts
[ ${INSIDE4_DEV} ] && echo "${INSIDE4_IP}	${HOSTNAME}.${DOMAIN}" >> /etc/hosts
[ ${INSIDE5_DEV} ] && echo "${INSIDE5_IP}	${HOSTNAME}.${DOMAIN}" >> /etc/hosts

#
# Outside
#
if [ ${OUTSIDE_IP} = 'DHCP' ];
then 
        echo "Booting dhcpcd"
        mv -f /etc/dhcpc/dhcpcd-eth0.exe /etc/dhcpc/dhcpcd-${OUTSIDE_DEV}.exe 2> /dev/null
        if /bin/dhcpcd -d -h ${HOSTNAME} ${OUTSIDE_DEV}; then
                tmphostname=${HOSTNAME}
                tmpdomain=${DOMAIN}
                . /etc/dhcpc/dhcpcd-${OUTSIDE_DEV}.info
                if [ ! ${tmphostname} = "" ]; then
                        HOSTNAME=${tmphostname}
                        DOMAIN=${tmpdomain}
                fi
                OUTSIDE_IP=${IPADDR}

                echo "dhcp successfully configured:"
                echo "Your address is ${IPADDR}"
                echo "The default gateway is is ${GATEWAY}"
                echo "The lease time is ${LEASETIME} seconds"
                echo "Next lease renewal in ${RENEWALTIME} seconds"
        else
                echo "duh!"     # Or some more useful error handling
        fi
else
        /bin/ifconfig ${OUTSIDE_DEV} ${OUTSIDE_IP} netmask ${OUTSIDE_NETMASK} broadcast ${OUTSIDE_BROADCAST}

        #
        # Default gateway
        #
        /bin/route add default gw ${DEFAULT_GATEWAY} metric 1

        echo "Setting up name server (etc/resolv.conf) "

        echo "domain ${DOMAIN}" >> /etc/resolv.conf
        echo "search ${DOMAIN}" >> /etc/resolv.conf

        echo "nameserver ${NAME_SERVER_IP1}" >> /etc/resolv.conf
        echo "nameserver ${NAME_SERVER_IP2}" >> /etc/resolv.conf
fi

# From the kernel configuration:
#
#  Explicit Congestion Notification (ECN) allows routers to notify
#  clients about network congestion, resulting in fewer dropped packets
#  and increased network performance. This option adds ECN support to the
#  Linux kernel, as well as a sysctl (/proc/sys/net/ipv4/tcp_ecn) which
#  allows ECN support to be disabled at runtime.
#
#  Note that, on the Internet, there are many broken firewalls which
#  refuse connections from ECN-enabled machines, and it may be a while
#  before these firewalls are fixed. Until then, to access a site behind
#  such a firewall (some of which are major sites, at the time of this
#  writing) you will have to disable this option, either by saying N now
#  or by using the sysctl.
echo "0" > /proc/sys/net/ipv4/tcp_ecn

echo "1" > /proc/sys/net/ipv4/tcp_syncookies

if [ -f /proc/sys/net/ipv4/conf/all/rp_filter ] ; then
  echo "Enabling anti spoofing: "

  for f in /proc/sys/net/ipv4/conf/*/rp_filter; do
     echo -n " $f "
       echo 1 > $f
     done
 else
  echo "Anti spoofing is not available, the author of this floppy spoofed, mail him."
fi

