Utilisateur:Marc

Un article de Toulouse Sans Fil, un réseau wifi libre sur Toulouse.

Accueil | Utilisateurs | Marc


Sommaire

Présentation

Vous vous trouvez sur la page d'une personne ayant consacré énormément de temps à la réalisation d'un réseau sans fil dont l'objectif premier est l'acces Internet au meilleur cout, dans les meilleures conditions. Nous avons répondu à l'appel de la DATAR (à l'époque) concernant l'étude et la réalisation de moyen d'acces a Internet alternatif. Nous sommes actuellement à la tête d'un joli petit réseau opérationnel.

Je profite donc de cette page pour faire profiter de ma petite expérience. Très concretement ce sera les fichiers de configurations ; le reste pouvant etre mis en oeuvre rapidement grace à OpenWrt. Nous avons galéré pendant plusieurs semaines (mois sans doute) avec d'obtenir un réseau particulièrement stable même si ce n'est pas encore la stabilité des connexions ADSL, c'est déja tout à fait exploitable dans de bonnes conditions.

Propositions

  • voici quelques propositions concernant l'organisation de l'espace documentaire.

/etc/olsrd.conf

  • voici le fichier de configuration des démons OLSR sur mon réseau. Les points importants :
    • il s'agit de la version 0.49 (http://www.olsr.org/,
    • l'option LinkQuality (LQ) est activée en mode 2,
    • cette option est incompatible avec le fonctionnement Hystersis (UseHysteresis no) ; il n'est pas possible de relier 2 réseau ayant 2 mode différents!
    • un AP qui fait routage vers Internet doit le signaler à tous le réseau : Hna4 { 0.0.0.0 0.0.0.0 }
    • le réseau est principalement un réseau statique (par opposition à un réseay mobile : téléphone, pda) ; c'est pourquoi il a été configuré de cette sorte : LinkQualityWinSize, HelloInterval, HelloValidityTime, TcInterval, TcValidityTime, MidInterval, MidValidityTime, HnaInterval, HnaValidityTime ont tous des valeurs bien supérieur aux valeurs par défaut,
    • la stabilité du réseau a aussi été améliorée en changeant ces valeurs : TcRedundancy 2, MprCoverage 6 ; dans les premieres configurations, j'avais 0 et 2 et des routes qui changeaient sans cesse.
 #
 # olsr.org OLSR daemon config file - version 0.49
 #
 # Lines starting with a # are discarded
 #
 # This file was shipped with olsrd 0.4.9
 #
 
 # This file is an example of a typical
 # configuration for a mostly static
 # network(regarding mobility) using
 # the LQ extention
 
 # Debug level(0-9)
 # If set to 0 the daemon runs in the background
 
 DebugLevel      0
 
 # IP version to use (4 or 6)
 
 IpVersion       4
 
 # Clear the screen each time the internal state changes
 
 ClearScreen     no
 
 # HNA IPv4 routes
 # syntax: netaddr netmask
 # Example Internet gateway:
 # 0.0.0.0 0.0.0.0
 
 Hna4
 {
 #   Internet gateway:
 #    0.0.0.0      0.0.0.0
 #   more entries can be added:
 #   192.168.1.0  255.255.255.0
    169.254.0.0 255.255.0.0
 #  pour TSF et toutes les villes sans fils.
 #  10.0.0.0 255.0.0.0
 }
 
 # HNA IPv6 routes
 # syntax: netaddr prefix
 # Example Internet gateway:
 Hna6
 {
 #   Internet gateway:
 #   ::              0
 #   more entries can be added:
 #   fec0:2200:106:: 48
 }
 
 
 # Should olsrd keep on running even if there are
 # no interfaces available? This is a good idea
 # for a PCMCIA/USB hotswap environment.
 # "yes" OR "no"
 
 AllowNoInt      yes
 
 # TOS(type of service) value for
 # the IP header of control traffic.
 # If not set it will default to 16
 
 #TosValue       16
 
 # The fixed willingness to use(0-7)
 # If not set willingness will be calculated
 # dynamically based on battery/power status
 # if such information is available
 
 #Willingness            4
 
 # Allow processes like the GUI front-end
 # to connect to the daemon.
 
 IpcConnect
 {
      # Determines how many simultaneously
      # IPC connections that will be allowed
      # Setting this to 0 disables IPC
 
      MaxConnections  5
 
      # By default only 127.0.0.1 is allowed
      # to connect. Here allowed hosts can
      # be added
 
      Host            127.0.0.1
      #Host            10.0.0.5
 
      # You can also specify entire net-ranges
      # that are allowed to connect. Multiple
      # entries are allowed
 
      #Net             192.168.1.0 255.255.255.0
      Net 10.0.0.0 255.0.0.0
 }
 
 # Wether to use hysteresis or not
 # Hysteresis adds more robustness to the
 # link sensing but delays neighbor registration.
 # Used by default. 'yes' or 'no'
 
 UseHysteresis   no
 
 # Hysteresis parameters
 # Do not alter these unless you know
 # what you are doing!
 # Set to auto by default. Allowed
 # values are floating point values
 # in the interval 0,1
 # THR_LOW must always be lower than
 # THR_HIGH.
 
 #HystScaling    0.50
 #HystThrHigh    0.80
 #HystThrLow     0.30
 
 
 # Link quality level
 # 0 = do not use link quality
 # 1 = use link quality for MPR selection
 # 2 = use link quality for MPR selection and routing
 # Defaults to 0
 
 LinkQualityLevel        2
 
 # Link quality window size
 # Defaults to 10
 
 LinkQualityWinSize      100
 
 # Polling rate in seconds(float).
 # Default value 0.05 sec
 
 Pollrate        0.1
 
 
 # TC redundancy
 # Specifies how much neighbor info should
 # be sent in TC messages
 # Possible values are:
 # 0 - only send MPR selectors
 # 1 - send MPR selectors and MPRs
 # 2 - send all neighbors
 #
 # defaults to 0
 
 TcRedundancy    2
 
 
 #
 # MPR coverage
 # Specifies how many MPRs a node should
 # try select to reach every 2 hop neighbor
 #
 # Can be set to any integer >0
 #
 # defaults to 1
 
 MprCoverage     6
 
 # Olsrd plugins to load
 # This must be the absolute path to the file
 # or the loader will use the following scheme:
 # - Try the paths in the LD_LIBRARY_PATH
 #   environment variable.
 # - The list of libraries cached in /etc/ld.so.cache
 # - /lib, followed by /usr/lib
 
 # Example plugin entry with parameters:
 
 #LoadPlugin "olsrd_dyn_gw.so.0.3"
 #{
     # Here parameters are set to be sent to the
     # plugin. Theese are on the form "key" "value".
     # Parameters ofcause, differs from plugin to plugin.
     # Consult the documentation of your plugin for details.
 
     # Example: dyn_gw params
 
     # how often to check for Internet connectivity
     # defaults to 5 secs
     #   PlParam     "Interval"   "40"
 
     # if one or more IPv4 addresses are given, do a ping on these in
     # descending order to validate that there is not only an entry in
     # routing table, but also a real internet connection. If any of
     # these addresses could be pinged successfully, the test was
     # succesful, i.e. if the ping on the 1st address was successful,the
     # 2nd won't be pinged
     #   PlParam     "Ping"       "141.1.1.1"
     #   PlParam     "Ping"       "194.25.2.129"
 #}
 
 LoadPlugin "olsrd_httpinfo.so.0.1"
 {
     PlParam     "port"   "80"
     PlParam     "Net"    "10.0.0.0 255.0.0.0"
     PlParam     "Net"    "192.168.0.0 255.255.0.0"
     PlParam     "Net"    "169.254.0.0 255.255.0.0"
 }
 
 # LoadPlugin "olsrd_dot_draw.so.0.3"
 # {
 #     PlParam     "port"   "8081"
 #     PlParam     "Net"    "10.0.0.0 255.0.0.0"
 #     PlParam     "Net"    "192.168.0.0 255.255.0.0"
 #     PlParam     "Net"    "169.254.0.0 255.255.0.0"
 # }
 
 # c'est une version modifié de ce plugin que j'ai installée ; il accepte les connexions quelque soit
 # l'IP source ; ce n'est pas le cas sur la version originale ; peut-etre que ce bug a été corrigé
 LoadPlugin "olsrd_dot_draw.so.0.3-mq"
 {
     PlParam     "port"   "8081"
     # PlParam     "accept"   "10.0.0.121"
     # PlParam     "accept"   "192.168.10.80"
     # PlParam     "Net"    "10.0.0.0 255.0.0.0"
     # PlParam     "Net"    "192.168.0.0 255.255.0.0"
     # PlParam     "Net"    "169.254.0.0 255.255.0.0"
 }
 
 # LoadPlugin "olsrd_nameservice.so.0.2"
 # {
 #    PlParam "name"         "ap70.mesh"
 #    PlParam "hosts-file"   "/tmp/hosts"
 #    PlParam "resolv-file"  "/tmp/resolv.conf"
 # }
 
 # LoadPlugin "olsrd_dyn_gw.so.0.3"
 # {
     # how often to look for a inet gw, in seconds
     # defaults to 5 secs, if commented out
     #     PlParam     "Interval"   "60"
 
     # if one or more IPv4 addresses are given, do a ping on these in
     # descending order to validate that there is not only an entry in
     # routing table, but also a real internet connection. If any of
     # these addresses could be pinged successfully, the test was
     # succesful, i.e. if the ping on the 1st address was successful,the
     # 2nd won't be pinged
     #     PlParam     "Ping"  "213.228.0.77"
     #     PlParam   "HNA"   "169.254.0.0 255.255.0.0"
 # }
 
 
 
 # Interfaces and their rules
 # Omitted options will be set to the
 # default values. Multiple interfaces
 # can be specified in the same block
 # and multiple blocks can be set.
 
 # !!CHANGE THE INTERFACE LABEL(s) TO MATCH YOUR INTERFACE(s)!!
 # (eg. wlan0 or eth1):
 
 Interface "eth1" "eth2"
 {
 
     # IPv4 broadcast address to use. The
     # one usefull example would be 255.255.255.255
     # If not defined the broadcastaddress
     # every card is configured with is used
 
     # Ip4Broadcast              255.255.255.255
 
     # IPv6 address scope to use.
     # Must be 'site-local' or 'global'
 
     # Ip6AddrType               site-local
 
     # IPv6 multicast address to use when
     # using site-local addresses.
     # If not defined, ff05::15 is used
 
     # Ip6MulticastSite          ff05::11
 
     # IPv6 multicast address to use when
     # using global addresses
     # If not defined, ff0e::1 is used
 
     # Ip6MulticastGlobal        ff0e::1
 
 
     # Emission intervals.
     # If not defined, RFC proposed values will
     # be used in most cases.
 
     # Hello interval in seconds(float)
     HelloInterval    5.0
 
     # HELLO validity time
     HelloValidityTime   90.0
 
     # TC interval in seconds(float)
     TcInterval        5.0
 
     # TC validity time
     TcValidityTime      250.0
 
     # MID interval in seconds(float)
     MidInterval 15.0
 
     # MID validity time
     MidValidityTime     90.0
 
     # HNA interval in seconds(float)
     HnaInterval 5.0
 
     # HNA validity time
     HnaValidityTime     90.0
 
     # When multiple links exist between hosts
     # the weight of interface is used to determine
     # the link to use. Normally the weight is
     # automatically calculated by olsrd based
     # on the characteristics of the interface,
     # but here you can specify a fixed value.
     # Olsrd will choose links with the lowest value.
 
     # Weight 0
 
 }

quelques rêgles iptables

Ce fichier n'est pas complet, mais contient des portions importantes.

  • le NAT (fin du fichier) s'effectue non plus sur l'interface de sortie ( -o $WLAN, -o WAN), mais en fonction de l'interface du traffic entrant sur le routeur ( $IPT -t nat -A POSTROUTING -s 10.0.0.0/8 -j MASQUERADE ) ; sans cette astuce, le NAT est actif même pour du transfert de packets (forwarding) ; ce qui est très génant : difficultés de log, et surtout les routes sont instables et statiques ; dans le cadre d'un réseau dynamique c'est inconcevable.
  • on peut voir les rêgles qui permettent d'activer les logs (traces) d'acces au réseau ; par la suite ces logs sont lus par la commande logread via un canal ssh,
  • drop_ip_olsr() permet de bloquer le protocole OLSR : pour monter des réseaux et forcer le routage dans une seule pièce : cela sert pour les démos et la qualification de certains concepts,
  • on voit comment il est possible de refuser les échanges de type P2P : fonction p2p_filter(),
 root@ap200:/etc/init.d# cat /etc/init.d/S45firewall
 #!/bin/sh
 # . /etc/functions.sh
 
 export PATH=/bin:/sbin:/usr/bin:/usr/sbin
 
 IPT=/usr/sbin/iptables
 
 
 WAN=$(/usr/sbin/nvram get wan_ifname)
 LAN=$(/usr/sbin/nvram get lan_ifname)
 WIFI=$(/usr/sbin/nvram get wifi_ifname)
 
 
 drop_ip_olsr () {
   ip=$1
   $IPT  -A INPUT --source $ip -p udp --dport 698 -j DROP
   $IPT  -A INPUT --destination $ip -p udp --dport 698 -j DROP
 }
 
 accept_port(){
   port=$1
 
   $IPT -A INPUT -p tcp --dport $port -j ACCEPT
   $IPT -A INPUT -p udp --dport $port -j ACCEPT
 }
 
 drop_port(){
   port=$1
 
   $IPT -A FORWARD -p tcp --dport $port -j LOG_P2P_DROP
   $IPT -A FORWARD -p udp --dport $port -j LOG_P2P_DROP
 }
 
 
 # ex : forward_port 8080 192.168.10.80 80 tcp
 forward_port(){
   sport=$1
   daddr=$2
   dport=$3
   proto=$4
   $IPT -t nat -A PREROUTING -p $proto --dport $sport -j DNAT --to $daddr:$dport
   $IPT        -A FORWARD    -p $proto -d $daddr  --dport $dport -j ACCEPT
 }
 
 p2p_filter(){
 
         $IPT -N LOG_P2P_DROP
         $IPT -A LOG_P2P_DROP  -j LOG --log-prefix "[IPTABLES P2P_DROP] : "
         $IPT -A LOG_P2P_DROP -j DROP
 
         # gnutella
         drop_port 6346
         drop_port 6347
         drop_port 6348
 
 
         # filter p2p forwarding.
         if [ -f /lib/modules/2.4.29/ipt_ipp2p.o ] ; then
         (lsmod | grep ipt_ipp2p > /dev/null)|| insmod /lib/modules/2.4.29/ipt_ipp2p.o
         $IPT -A FORWARD -m ipp2p --ipp2p --bit --apple --winmx --soul --ares -j LOG_P2P_DROP
         # $IPT -A FORWARD -p udp -m ipp2p --ipp2p -j LOG_P2P_DROP
         # $IPT -A FORWARD -p tcp -m ipp2p --ipp2p -j LOG_P2P_DROP
         fi
 
 }
 
 for T in filter nat mangle ; do
   $IPT -t $T -F
   $IPT -t $T -X
 done
 
 # creation des chaines de log LOG_DROP, LOG_ACCEPT, LOG_REJECT
 for T in DROP ACCEPT REJECT ; do
   $IPT -N LOG_${T}
   $IPT -A LOG_${T}  -j LOG --log-prefix "[IPTABLES $T] : "
   $IPT -A LOG_${T} -j $T
 done
 
 
 # accept OLSR protocol
 $IPT -A INPUT -p tcp --dport 698 -j ACCEPT
 $IPT -A INPUT -p udp --dport 698 -j ACCEPT
 $IPT -A FORWARD -p tcp --dport 698 -j ACCEPT
 $IPT -A FORWARD -p udp --dport 698 -j ACCEPT
 
 # on log les connexion (--state NEW) - le reste est accepté tout simplement.
 $IPT -A FORWARD -i $LAN -o $WIFI -m state --state NEW -j LOG_ACCEPT   # pour ap client
 $IPT -A FORWARD -j ACCEPT
 
 # $IPT -t nat -A POSTROUTING -o $WAN -j MASQUERADE
 # $IPT -t nat -A POSTROUTING -o $LAN -j MASQUERADE
 # $IPT -t nat -A POSTROUTING -o $WIFI -j MASQUERADE
 $IPT -t nat -A POSTROUTING -s 10.0.0.0/8 -j MASQUERADE


connexion ssh avec clé

placer le home du compte root dans un espace non volatile

 root@ap200:/etc/init.d# cat /etc/passwd
 root:$1$.....RH/:0:0:root:/home/root:/bin/ash

dans le home :

  • créer un répertoire .ssh,
  • restreindre les droits d'acces (ce n'est pas le cas ici)
  • il est possible de générer une clé qui sera la même sur tous les routeurs du réseau ; ce n'est pas recommandé pour la sécurité, mais c'est pratique : cela permet de se connecter de point en points sur tous les AP.
  • la clé publique doit être insérée dans le fichier authorized_keys
 root@ap200:/etc/init.d# cd /home/root
 root@ap200:~# ls -al .ssh/
 drwxr-xr-x    1 root     root            0 Mar  9 08:44 .
 drwxr-xr-x    1 root     root            0 Mar  9 08:44 ..
 -rw-------    1 root     root          456 Mar  9 08:44 authorized_keys
 -rw-------    1 root     root          420 Mar  9 08:44 id_rsa.db
 -rw-------    1 root     root         8151 Mar  9 08:44 known_hosts
  • voici à quoi ressemble le fichier contenant les clés publiques ; plusieurs clés peuvent être insérées de façon séquentielle :
 root@ap200:~/.ssh# cat authorized_keys
 ssh-rsa AAAAB3NzhSTGbO4NOl ... NJk7phd0= marc@mq.domain.local
 ssh-rsa AAAAB3NzaC1yc2EAAA ... AD4dGhxU= user2@host.autre-domaine.local
  • le serveur dropbear qui est le server SSH version réduite pour système embarqué doit être lancé au démarrage (/etc/init.d/S50dropbear sur openwrt):
 root@ap200:~# ps -aef | grep -i drop
 460 root        412 S   /usr/sbin/dropbear
 743 root        660 S   /usr/sbin/dropbear
 783 root        308 S   grep -i drop
  • les clés sont générées avec la commande : ssh-keygen -t rsa ; il ne faut pas de mot de passe lorsqu'on vous le demande, il suffit de valider.
  • putty est un client Windows qui devrait fonctionner convenablement avec cet environnement.