#!/bin/sh

# Entrer l' IP 44.151 (AMPRIP) et l'adresse IP Fixe WAN de votre routeur ADSL (COMMIP)
AMPRIP='44.151.XX.XX'
COMMIP='AAA.BBB.CCC.DDD'

case "$1" in 

start)
    # Charger votre module "ip encap" dans le noyau :
        modprobe ipip

    # Permettre le forward IP depuis amprnet vers votre interface  ethernet
        echo "1" > /proc/sys/net/ipv4/ip_forward

    # Charge le routage RIPv2 utilisant le "daemon" ampr-ripd 
        /usr/sbin/ampr-ripd -t 1 -a $COMMIP -p pLaInTeXtpAsSwD -i tunl0 -v -s -r

    # Configure votre tunnel ip encap nécessaire à amprnet
        ifconfig tunl0 $AMPRIP netmask 255.255.255.255 mtu 1480 up

    # Permet aux traceroutes de fonctionner sur amprnet:
        ip tunnel change ttl 64 mode ipip tunl0 pmtudisc

    # Ne pas supprimer la ligne ci-dessous (route vers le serveur US) :
        ip route add default via 169.228.34.84 dev tunl0  src $AMPRIP onlink table 1

    # Configure la politique de routage des trames du réseau 44
        ip rule add from 44/8 pref 1 table 1
        ip rule add to 44/8 pref 1 table 1

    # Fin du script
        exit 0
        ;;

  stop)
        ip rule del to 44/8 pref 1 table 1
        ip rule del from 44/8 pref 1 table 1
        ifconfig tunl0 down
        killall -TERM ampr-ripd
        modprobe -r ipip
        exit 0
        ;;

  restart)
        dotun stop
      sleep 3
        dotun start
        exit 0
        ;;
  *)
        echo "Usage: dotun {start|stop|restart}"
        exit 0
        ;;

esac
exit 0
