lundi 2 juin 2008

Expérience sur les réseaux wifi mesh

Le principe du réseau maillé (mesh network) est que toute machine connecté à ce type de réseau peut être consommateur ou producteur de ressources. Comme ça on peut partager des fichiers, des connexions internet.

Quoi on peut mutualiser des connexions internet? Oui, le mesh publiera l'IP de tous les noeuds ayant un accès au net pour en faire bénéficier ceux qui n'en ont pas.
Et vive le partage entre voisins pour dépanner celui dont l'adsl ne marche plus, ou qui attend toujours son abonnement...



Pour procéder, nous allons utiliser une fonera avec sa fontenna (Magnifique petit routeur wifi bon marché mis au point par Fon). On va en remplacer le firmware pour y mettre un merveilleux OpenWRT Kamikaze!
Qui lui saura faire tourner OLSR, un protocole de gestion de réseaux mesh...
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
KAMIKAZE (7.09) -----------------------------------


1) Débloquer la Fonera:

a- Downgrader le firmware
ATTENTION: Toute cette manipulation doit être faite avec la Fenora non connectée à Internet !

* Lorsque la Fonera est sous tension, appuyer pendant 30 secondes sur le bouton reset.
* Après les 30 secondes mettre la Fonera hors-tension (tout en gardant le bouton enfoncé).
* Ensuite remettre la Fonera sous-tension et ne lacher le bouton reset que lorsque les lumière 'Internet' et/ou 'WLAN' commencent à s'allumer.


Après cela normalement, le firmware doit être dans les 0.7.1 rA (ou A est compris entre 1 et 5. Généralement il descend jusqu'à la révision 2).

b- Utiliser l'exploit de Kolofonium
source: http://stefans.datenbruch.de/lafonera/#kolofonium

Démarrer la fontera sans la raccorder à internet. Se connecter en wifi à "MyPlace" (la clef est notée sous le boitier). Puis, changer les paramètres comme indiqué:

Dans l'interface de gestion de la Fonera (interface Web) passer en ip statique (Advanced -> Network settings) et changer :

* l'addresse ip et la passerelle de tel sorte que la Fenora puisse avoir accès à Internet [192.168.202.100 / 255.255.255.0 | 192.168.202.1]
* le serveur DNS à 88.198.165.155 (serveur mis en place par Kolofonium: un faux serveur DNS qui reconfigure le Fonera et lance dropbear au lancement de Chilispot)
* Valider et faire un hard-reboot de la Fenora (mise hors-tension puis mise sous-tension) en la branchant à votre réseau.


Lorsque la Fenora a redémarré il est possible de se connecter en SSH (via la liaison WIFI, donc attaché au SSID MyPlace avec le numéro de série comme Clé) sur l'adresse 192.168.202.100 (login: root, pw: admin)

fred@kirikou:~$ ssh root@192.168.202.100
BusyBox v1.1.3 (2006.09.11-19:54+0000) Built-in shell (ash)
Enter 'help' for a list of built-in commands.
Fonera Firmware (Version 0.7.0 rev 4) -------------
* Based on OpenWrt - http://openwrt.org
* Powered by FON - http://www.fon.com
---------------------------------------------------
root@OpenWrt:~# echo "alias ll='ls -al'" >> /etc/profile
root@OpenWrt:~# mv /etc/init.d/dropbear /etc/init.d/S51dropbear


Ensuite ajouter à /etc/firewall.user
iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j ACCEPT
iptables -A input_rule -i $WAN -p tcp --dport 22 -j ACCEPT
iptables -t nat -A prerouting_rule -i $LAN -p tcp --dport 22 -j ACCEPT
iptables -A input_rule -i $LAN -p tcp --dport 22 -j ACCEPT

Et voila! On va pouvoir jouer avec...
SSH est ouvert!

Mais Redboot (http://wiki.openwrt.org/OpenWrtDocs/Hardware/Fon/Fonera) ne l'est pas forcément également et nous allons rentrer par là...

Lancer un dmesg et repérer la ligne "RedBoot config":
<5>Creating 6 MTD partitions on "spiflash":
<5>0x00000000-0x00030000 : "RedBoot"
<5>0x00030000-0x00720000 : "rootfs"
<5>0x00730000-0x007e0000 : "vmlinux.bin.l7"
<5>0x007e0000-0x007ef000 : "FIS directory"
<5>0x007ef000-0x007f0000 : "RedBoot config"
<5>0x007f0000-0x00800000 : "board_config"


En comptant de 0, noter son numéro (ici 4),
puis faites en adaptant:
root@OpenWrt:/# cat /dev/mtd/4ro > /tmp/redboot_config
root@OpenWrt:/# strings /tmp/redboot_config
root@OpenWrt:/# cd /tmp
root@OpenWrt:/# wget http://ipkg.k1k2.de/hack/openwrt-ar531x-2.4-vmlinux-CAMICIA.lzma
root@OpenWrt:/# mtd -e vmlinux.bin.l7 write openwrt-ar531x-2.4-vmlinux-CAMICIA.lzma vmlinux.bin.l7
root@OpenWrt:/# reboot
root@OpenWrt:/# cd /tmp
root@OpenWrt:/# wget http://ipkg.k1k2.de/hack/out.hex
root@OpenWrt:/# mtd -e "RedBoot config" write out.hex "RedBoot config"
root@OpenWrt:/# reboot


Enfin redboot devrait être joignable par le port 9000 au démarrage...

2) Installer OpenWRT:

Eteindre la Fonera. La rebrancher sur son ordinateur
Télécharger http://download.berlin.freifunk.net/fonera/ap51-flash-1.0-42 (Parcourir le site pour une version (windows))
Télécharger la dernière version d'openwrt pour cette plateforme:
http://downloads.openwrt.org/kamikaze/7.09/atheros-2.6/openwrt-atheros-2.6-root.squashfs
http://downloads.openwrt.org/kamikaze/7.09/atheros-2.6/openwrt-atheros-2.6-vmlinux.lzma

Ensuite lancer
$ chmod 755 ap51-flash-1.0-42
$ sudo ./ap51-flash-1.0-42 eth0 ./openwrt-atheros-2.6-root.squashfs ./openwrt-atheros-2.6-vmlinux.lzma

Terminé!!! Voila OpenWRT Kamikaze 7.09 installé sur la Fonera ;)
Son adresse IP sera par défault 192.168.1.1

3) Configurer le noeud (ex: ETOILE3)

a- Changer le mot de passe:

root@OpenWrt:/# telnet 192.168.1.1
root@OpenWrt:/# passwd


b- Changer le hostname:


root@OpenWrt:/# uci show system
root@OpenWrt:/# uci set system.cfg1.hostname=ETOILE3
root@OpenWrt:/# uci commit


c- Modifier network et wireless config:

root@OpenWrt:/# vi /etc/config/network
# Copyright (C) 2006 OpenWrt.org

config interface loopback
option ifname lo
option proto static
option ipaddr 127.0.0.1
option netmask 255.0.0.0

config interface lan
option ifname eth0
option proto dhcp
option ipaddr 192.168.203.1
option netmask 255.255.255.0
option gateway 192.168.10.254

config interface wlan0
option ifname ath0
option proto static
option ipaddr 192.168.103.1
option netmask 255.255.255.0

config interface wlan1
option ifname ath1
option proto static
option ipaddr 10.97.2.3
option netmask 255.255.255.0

root@ETOILE3:~# vi /etc/config/wireless
config wifi-device wifi0
option type atheros
option channel 11
option diversity 0
option txantenna 1
option rxantenna 1
option agmode 11bg
option mode '11bg'
option disabled '0'

config wifi-iface
option device wifi0
option network wlan0
option mode ap
option ssid ETOILE3
option encryption 'psk'
option wpa_crypto 'tkip'
option password 'xxxxxxxxxx'
option hidden '0'
option isolate '0'
option txpower '18'
option bgscan '0'
option wds '0'
option key 'xxxxxxxxxx'

config wifi-iface
option device wifi0
option network wlan1
option mode adhoc
option ssid olsr.zicmama.com
option hidden '1'
option encryption none
option bssid ca:fe:ca:fe:ca:fe
option isolate '0'
option bgscan '0'
option wds '0'

d- Ajouter les packages olsr et x-wrt, les configurer:

echo "src X-Wrt http://downloads.x-wrt.org/xwrt/kamikaze/7.09/atheros-2.6/packages" >> /etc/ipkg.conf
ipkg update
ipkg install olsrd olsrd-mod-bmf olsrd-mod-dot-draw olsrd-mod-dyn-gw olsrd-mod-httpinfo olsrd-mod-nameservice webif
hostapd-mini
# autostart olsrd
ln -s /etc/init.d/olsrd /etc/rc.d/S70olsrd

root@ETOILE2:~# vi /etc/firewall.user
#!/bin/sh

# Copyright (C) 2006 OpenWrt.org

iptables -F input_rule
iptables -F output_rule
iptables -F forwarding_rule
iptables -t nat -F prerouting_rule
iptables -t nat -F postrouting_rule

# The following chains are for traffic directed at the IP of the
# WAN interface

iptables -F input_wan
iptables -F forwarding_wan
iptables -t nat -F prerouting_wan

# Does anyone have a command to get the name of the WIFI interface on Kamikaze so
# that it doesn't have to be hard-coded here? This is a bit sloppy it seems.
WIFI=ath1

## -- This allows port 22 to be answered by (dropbear on) the router
iptables -A input_wan -p tcp --dport 22 -j ACCEPT

# Allow connections to olsr info port.
iptables -A input_wan -p tcp --dport 1979 -j ACCEPT

# OLSR needs port 698 to transmit state messages.
iptables -A input_rule -p udp --dport 698 -j ACCEPT

###################################################################
### START Rules that allow forwarding from one network to another.
### Rules based on openwrt wiki page:
### http://wiki.openwrt.org/OlsrMeshHowto
###################################################################
# Debugging... do we have WIFI, LAN and WAN appropriately defined?
# These values are passed to us from /etc/init.d/firewall, which
# calls this script.
WAN=ath0
echo WIFI == $WIFI
echo LAN == $LAN
echo WAN == $WAN

iptables -A forwarding_rule -i $WAN -o $WIFI -j ACCEPT
iptables -A forwarding_rule -i $WIFI -o $WAN -j ACCEPT

# For forwarding LAN & WIFI in nodes
iptables -A forwarding_rule -i $LAN -o $WIFI -j ACCEPT

# For WIFI clients to connect to nodes.
iptables -A forwarding_rule -i $WIFI -o $WIFI -j ACCEPT

# For connecting a wired lan client of node 1 to wired lan client of node 2
iptables -A forwarding_rule -i $LAN -o $LAN -j ACCEPT

# WIFI needs to go to LAN ports, too!
iptables -A forwarding_rule -i $WIFI -o $LAN -j ACCEPT

# Masquerade all traffic to olsr net
iptables -t nat -A POSTROUTING -o $WIFI -j MASQUERADE
iptables -t nat -A POSTROUTING -o $LAN -j MASQUERADE

root@ETOILE2:~# vi /etc/dnsmasq.conf
AJouter:
dhcp-option=6,192.168.102.1
Et ajuster les DNS dans resolv.conf

root@ETOILE2:~# vi /etc/olsrd.conf
DebugLevel 0
IpVersion 4
AllowNoInt yes
Pollrate 0.1
TcRedundancy 2
MprCoverage 7
LinkQualityFishEye 1
LinkQualityWinSize 100
LinkQualityDijkstraLimit 0 6.0
LinkQualityLevel 2
UseHysteresis no

Hna4
{
192.168.103.0 255.255.255.0
192.168.203.0 255.255.255.0
}

Interface "ath1"
{
HelloInterval 4.0
HelloValidityTime 72.0
TcInterval 3.0
TcValidityTime 216.0
MidInterval 12.0
MidValidityTime 216.0
HnaInterval 12.0
HnaValidityTime 72.0
}

LoadPlugin "olsrd_httpinfo.so.0.1"
{
PlParam "port" "8080"
PlParam "Net" "192.168.0.0 255.255.0.0"
PlParam "Net" "10.97.2.0 255.255.255.0"
}

LoadPlugin "olsrd_dyn_gw.so.0.4"
{
PlParam "Interval" "40"
PlParam "Ping" "193.43.210.154"
}

LoadPlugin "olsrd_nameservice.so.0.3"
{
PlParam "name" "etoile3"
PlParam "suffix" ".lan"
PlParam "hosts-file" "/etc/hosts"
}

Une fois ces fichiers à jour rebooter. Si un boitier ayant reçu la même configuration est proche, il fera parti du même groupe WIFI mesh

Se le noeud est instable (ce arrive à cause de la gestion wifi simultanée du mesh et de l'AP)
Ajouter un reboot régulier à /etc/init.d/custom-user-startup

# reboot every 2 hours
(sleep 7200; reboot)&


Références:
http://www.e-bulles.be/bubble/Kamikaze
http://wiki.openwrt.org/OlsrMeshHowto
http://wiki.x-wrt.org/index.php/Kamikaze_Installation
http://www.toulouse-sans-fil.net/wiki/Kamikaze

http://www.fon.com/fr/

1 commentaire:

Fred Auré Lila Emma a dit…

Parfois le réseau plante?? A mon avis un pb de stabilité du courant EDF...

Pour palier à cela, on ajoute un script lancé par cron qui va pinger les voisins proches du noeud et le redémarrer si il ne voit plus personne

root@ETOILE3:~# crontab -l
# m h dom mon dow command
*/5 * * * * /sbin/ping_reboot.sh


root@ETOILE3:~# cat /sbin/ping_reboot.sh
#!/bin/sh
# add ip / hostname separated by white space.
HOSTS="10.97.2.1 10.97.2.2"

# number of ping requests per host.
COUNT=3
RAWOUTPUT=""

for HOST in $HOSTS
do
ping -c $COUNT $HOST > RAWOUTPUT
if [ $? -ne 0 ]
then
if [ -f /tmp/pingerror ]
then
reboot
fi
echo "ping: $HOST unreachable" > /tmp/pingerror
else
rm -f /tmp/pingerror
exit 0 #no sense in going on if all is good
fi
done
exit 0