20/04/2010

OpenWRT, Xen et ipv6

[ openwrt xen route ipv6 ]

Dans un précédent billet, je décrivais ma configuration xen. Il ne me manquait qu'une seule chose: l'ipv6. Je dois bien avouer que ça ne s'est pas fait en un jour.

J'ai commencé par configurer mon routeur:

root@fonera# route -A inet6 add 2001:470:ca75:100::/64 gw 2001:470:ca75:20:224:1ff:fe0f:f84c

2001:470:ca75:100::/64 est le réseau dédié aux hosts xen et 2001:470:ca75:20:224:1ff:fe0f:f84c l'ipv6 du dongle wifi du portable. Qui dit routage dit forwarding:

root@d531# grep forwarding= /etc/sysctl.conf
net.ipv6.conf.all.forwarding=1

Et pour éviter un message désagréable au boot:

root@d531# echo 'ipv6' >> /etc/modules

J'ai cru avoir une bonne idée en utilisant eth0 (qui me sert très peu) mais c'est vraiment une très mauvaise idée:

root@d531# tail -n 8 /etc/network/interfaces
auto eth0
iface eth0 inet static
    address 192.168.1.116
    netmask 255.255.255.0
iface eth0 inet6 static
    address 2001:470:ca75:100::1
    netmask 64

root@d531# ifconfig eth0 | grep inet6
      adr inet6: 2001:470:ca75:100::1/64 Scope:Global

root@d531# ping6 -c 1 -W 1 2001:470:ca75:100::1
PING 2001:470:ca75:100::1(2001:470:ca75:100::1) 56 data bytes

--- 2001:470:ca75:100::1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

L'absence d'adresse lien-local ne doit pas être innocente dans cette affaire. Une (lllooonnnggggguuuuueeee) série de ping, reboot, man, google, ifup/ifdown plus tard, une idée me traverse la tête: pourquoi ne pas utiliser une interface virtuelle ?

root@d531# tail -n 8 /etc/network/interfaces
auto dummy0
iface dummy0 inet static
  address 10.0.0.1
  netmask 255.255.255.0
iface dummy0 inet6 static
  address 2001:470:ca75:100::1
  netmask 64

root@d531# ifconfig dummy0 | grep inet6
      adr inet6: 2001:470:ca75:100::1/64 Scope:Global
      adr inet6: fe80::9082:a4ff:fe06:92bc/64 Scope:Lien

root@d531# ping6 -c 1 -W 1 2001:470:ca75:100::1
PING 2001:470:ca75:100::1(2001:470:ca75:100::1) 56 data bytes
64 bytes from 2001:470:ca75:100::1: icmp_seq=1 ttl=64 time=0.030 ms

--- 2001:470:ca75:100::1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 0.030/0.030/0.030/0.000 ms

root@linuto# ping6 -n -c 1 2001:470:ca75:100::1
PING6(56=40+8+8 bytes) 2001:470:ca75:10:214:bff:fe80:337b --> 2001:470:ca75:100::1
16 bytes from 2001:470:ca75:100::1, icmp_seq=0 hlim=63 time=7.855 ms

--- 2001:470:ca75:100::1 ping6 statistics ---
1 packets transmitted, 1 packets received, 0.0% packet loss
round-trip min/avg/max/std-dev = 7.855/7.855/7.855/nan ms

It works! Passons à la configuration de xen. Le script vif-route ne prend pas en compte l'ipv6. Heureusement, je ne suis pas seul: http://notes.benv.junerules.com/all/software/xen-and-routed-ipv6/.

J'en profite pour proposer une version perless ici. On précise à xen qu'on utilise une autre interface qu'eth0:

root@d531# grep '\-route' /etc/xen/xend-config.sxp
(network-script 'network-route netdev=dummy0')
(vif-script     'vif-route netdev=dummy0')

Un dernier reboot pour vérifier que le tout survit à un redémarrage et c'est parti:

root@d531# grep vif /etc/xen/openwrt.bsdsx.fr.cfg 
vif         = [ 'ip=10.0.0.33 2001:470:ca75:100::33,mac=00:16:3E:6D:BB:94' ]

root@d531# xm create -c openwrt.bsdsx.fr.cfg
[ snip boot ]
root@OpenWrt:/# ifconfig br-lan|grep inet6
      inet6 addr: 2001:470:ca75:100::33/64 Scope:Global
      inet6 addr: fe80::ac65:afff:fed8:dcc4/64 Scope:Link

Et ça marche ?

root@linutop# traceroute6 -n  2001:470:ca75:100::33
traceroute6 to 2001:470:ca75:100::33 (2001:470:ca75:100::33) from 2001:470:ca75:10:214:bff:fe80:337b, 64 hops max, 12 byte packets
 1  2001:470:ca75:10::1  1.761 ms  1.73 ms  1.324 ms
 2  2001:470:ca75:20:224:1ff:fe0f:f84c  4.317 ms  9.467 ms  10.127 ms
 3  *^C

Hum, pas trop. Un coup de tcpdump plus tard et je me rends compte qu'il manque une route par défaut sur l'invité:

root@OpenWrt:/# ip -6 ro add default via 2001:470:ca75:100::1
root@OpenWrt:/# ping6 -c 1 www.kame.net
PING www.kame.net (2001:200:0:8002:203:47ff:fea5:3085): 56 data bytes
64 bytes from 2001:200:0:8002:203:47ff:fea5:3085: seq=0 ttl=52 time=314.763 ms

--- www.kame.net ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 314.763/314.763/314.763 ms

Un dernier tour sur http://wiki.openwrt.org/doc/uci/network pour enregistrer la route:

root@OpenWrt:/# tail -n 4 /etc/config/network 
config 'route6'
    option 'interface' 'lan'
    option 'target' 'default'
    option 'gateway' '2001:470:ca75:100::1'

Et voilà, c'est bon, servez chaud. Bon appétit.

0 commentaire(s)

03/04/2010

OpenWRT et Xen

[ openwrt xen ]

Depuis quelques temps, ce billet me trottait dans la tête. Petit récapitulatif:

Une recherche avec xen bridge wifi et me voila à configurer mes domU en mode routeur:

d531:~> grep script /etc/xen/xend-config.sxp | grep -v "^#"
(network-script network-route)
(vif-script     vif-route)

Mon interface eth0 ne me sert (presque) à rien:

d531:~> /sbin/ifconfig eth0 | grep 'inet adr'
      inet adr:10.0.0.1  Bcast:10.255.255.255  Masque:255.0.0.0

Afin que mes domU puissent accéder au nain ternet, j'ajoute une route sur mon routeur:

root@fonusb# route add -net 10.0.0.0 netmask 255.255.255.0 gw 172.16.10.116
root@fonusb# tail -n 5 /etc/config/network
config 'route' 'xen'
    option 'interface' 'wpa'
    option 'target' '10.0.0.0'
    option 'netmask' '255.255.255.0'
    option 'gateway' '172.16.10.116'

10.0.0.0 est le réseau de mes domU, 172.16.10.116 l'ip de mon dom0 et wpa le nom logique de mon interface. Voir ici pour la configuration d'une route sous openwrt.

Concernant openwrt, mes tentatives de compilation sur ma machine 64 bits se sont soldées par un cuisant échec. J'ai opté pour une solution simple: un chroot 32 bits. La documentation ne manque pas, je ne vais pas détailler l'opération.

Une fois dans mon chroot et l'installation des paquets nécessaires, on peut commencer à jouer:

bsdsx@chroot> svn co svn://svn.openwrt.org/openwrt/trunk/
bsdsx@chroot> cd trunk
bsdsx@chroot> ./script/feeds update
bsdsx@chroot> make prereq

Et c'est parti pour une partie de coche-mi coche-moi:

Target System
  [x] x86
Subtarget
  [x] Xen Paravirt Guest
Global build settings
  [ ] Compile the kernel with Debug Filesystem enabled
Kernel modules
  Xen paravirtualized guest support
      [x] kmod-xen-evtchn
      [ ] kmod-xen-fbdev
      [x] kmod-xen-fs
      [x] kmod-xen-kbddev
      [x] kmod-xen-netdev

Une fois le make terminé, on installe le tout:

dsx@d531> sudo cp /usr/local/src/x86_32/home/bsdsx/src/svn/openwrt/trunk/bin/x86/openwrt-x86-ext2.fs /usr/local/xen/
dsx@d531> sudo cp /usr/local/src/x86_32/home/bsdsx/src/svn/openwrt/trunk/bin/x86/openwrt-x86-vmlinuz /usr/local/xen/

La configuration du domU:

dsx@d531:/etc/xen> cat /etc/xen/openwrt.bsdsx.fr.cfg 
kernel      = '/usr/local/xen/openwrt-x86-vmlinuz'
memory      = '32'
root        = '/dev/xvda1 rw'
disk        = [ 'file:/usr/local/xen/openwrt-x86-ext2.fs,xvda1,w', ]
name        = 'openwrt.bsdsx.fr'
vif         = [ 'ip=10.0.0.33,mac=00:16:3E:6D:BB:94' ]
gateway     = '10.0.0.1'
on_poweroff = 'destroy'
on_reboot   = 'restart'
on_crash    = 'restart'
extra       = 'console=hvc0 xencons=tty'

Et c'est parti (attention c'est rapide !):

dsx@d531> sudo xm create -c openwrt.bsdsx.fr.cfg
[ snip boot ]
root@OpenWrt:/# cat /proc/version 
Linux version 2.6.32.10 (dsx@d531.bsdsx.fr) (gcc version 4.1.2) #5 SMP Sat Apr 3 08:56:39 UTC 2010
root@OpenWrt:/# tail -n 7 /etc/config/network 
config interface lan
    option ifname   eth0
    option proto    static
    option ipaddr   10.0.0.33
    option netmask  255.255.255.0
    option gateway  10.0.0.1
    option dns      172.16.10.254

On retrouve dans la configuration:

Et ça marche ?

root@OpenWrt:/# ping -c 1 www.google.fr
PING www.google.fr (209.85.229.147): 56 data bytes
64 bytes from 209.85.229.147: seq=0 ttl=53 time=34.268 ms

--- www.google.fr ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 34.268/34.268/34.268 ms
0 commentaire(s)

08/10/2009

Netbsd 5.0.1 et Xen

[ netbsd xen install ]

Le contexte:

A la différence de nombreux tutos où on ne voit que les commandes qui marchent, je vais essayer de partager mes erreurs et mes réflexions.

Installation

Je ne vais pas recopier http://www.netbsd.org/docs/guide/en/chap-exinst.html mais une lecture attentive ne fera pas de mal.

Mes adaptations:

J'ai choisi 'b: Use the entire disk'

Concernant les partition, un / et un swap suffiront pour l'instant.

Par contre, / sera formaté en ffsv2 et mounté avec l'option log (Figure 3.15. Disklabel partition editing)

Full, on sait jamais. Pour être honnête, vu le nombre de réinstallation que j'ai fait, j'ai parfois (souvent :) sélectionné Custom avec les sets pré-sélectionnés.

NetBSD est toujours aussi simple/rapide à installer.

Configuration

Un reboot plus tard et voila le dmesg.

/etc/rc.conf:
hostname=netbsd.domain.tld
ifconfig_bge0="inet 10.50.0.40 netmask 255.255.255.0"
defaultroute="10.50.0.100"
sshd=YES

/etc/ssh/sshd_config:
PermitRootLogin yes

netbsd# /etc/rc.d/network restart
netbsd# /etc/rc.d/sshd restart

Packages

Tant que je suis en mode découverte, pourquoi ne pas essayer pkgin ?

netbsd# export ftp_proxy=http://proxy.domain.tld:3128/
netbsd# export http_proxy=http://proxy.domain.tld:3128/
netbsd# pkg_info
netbsd# pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/i386/5.0.1_2009Q2/All/pkgin-0.2.5.tgz
pkg_add: Can't process ftp://ftp.fr.netbsd.org:21/pub/pkgsrc/packages/NetBSD/i386/5.0.1_2009Q2/All/sqlite3*: Protocol error
pkg_add: no pkg found for 'sqlite3>=3.2.7nb1', sorry.
pkg_add: Can't install dependency sqlite3>=3.2.7nb1
pkg_add: 1 package addition failed

On va lui donner un coup de main:

netbsd# pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/i386/5.0.1_2009Q2/All/sqlite3-3.6.14.2.tgz
bin/sqlite3
include/sqlite3.h
include/sqlite3ext.h
lib/libsqlite3.la
lib/libsqlite3.a
lib/libsqlite3.so
lib/libsqlite3.so.0
lib/libsqlite3.so.0.8.6
lib/pkgconfig/sqlite3.pc
man/man1/sqlite3.1
Package sqlite3-3.6.14.2 registered in /var/db/pkg/sqlite3-3.6.14.2
netbsd# pkg_add -v ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/i386/5.0.1_2009Q2/All/pkgin-0.2.5.tgz
Running install with PRE-INSTALL for pkgin-0.2.5.
bin/pkgin
man/man1/pkgin.1
share/examples/pkgin/repositories.conf.example
Executing '/bin/mkdir -p '/usr/pkg'/etc/pkgin'
Running install with PRE-INSTALL for pkgin-0.2.5.
pkgin-0.2.5: copying /usr/pkg/share/examples/pkgin/repositories.conf.example to /usr/pkg/etc/pkgin/repositories.conf
Package pkgin-0.2.5 registered in /var/db/pkg/pkgin-0.2.5
#========================================================================
$NetBSD: MESSAGE,v 1.1.1.1 2009/06/08 13:58:26 imil Exp $

First steps before using pkgin.

. Modify /usr/pkg/etc/pkgin/repositories.conf to suit your platform
. Initialize the database :

        # pkgin update

#========================================================================
netbsd# vi /usr/pkg/etc/pkgin/repositories.conf
netbsd# pkgin update
processing local summary...
updating database: 100%
downloading pkg_summary.bz2: 100%
processing remote summary (ftp://ftp.fr.netbsd.org/pub/pkgsrc/packages/NetBSD/i386/5.0.1_2009Q2/All/)...
updating database: 100%

Installation de Xen

On garde sous les yeux:

Et on y va:

netbsd# pkgin install xentools33
calculating dependencies for xentools33...
nothing to upgrade.
8 packages to be installed: ncurses-5.7nb1 readline-6.0 libffi-3.0.8nb2 python25-2.5.4nb1 py25-xml-0.8.4nb2 py25-readline-0nb4 py25-curses-0nb4 xentools33-3.3.1nb6 (14M to download, 59M to install)
proceed ? [y/N] y
...
netbsd# cp /usr/pkg/share/examples/rc.d/* /etc/rc.d/
netbsd# chmod 755 /etc/rc.d/xen*
netbsd# cd /dev && sh MAKEDEV xen

netbsd# pkgin install xenkernel33
calculating dependencies for xenkernel33...
nothing to upgrade.
1 packages to be installed: xenkernel33-3.3.1nb1 (828K to download, 828K to install)
proceed ? [y/N] y
...

netbsd# cp /usr/pkg/xen3-kernel/xen.gz /

On récupère depuis ftp://ftp.fr.netbsd.org/pub/NetBSD/NetBSD-5.0.1/i386/binary/kernel/

Tout le monde est là:

netbsd# ls /
.cshrc       cdrom       libexec                     proc        usr
.profile     dev         mnt                         rescue      var
altroot      etc         netbsd                      root        xen.gz
bin          kern        netbsd-INSTALL_XEN3_DOMU.gz sbin
boot         lib         netbsd-XEN3_DOM0.gz         stand
boot.cfg     libdata     netbsd-XEN3_DOMU.gz         tmp

netbsd# cat /boot.cfg
menu=Boot normally:boot netbsd
menu=Boot single user:boot netbsd -s
menu=Disable ACPI:boot netbsd -2
menu=Disable ACPI and SMP:boot netbsd -12
menu=Boot Xen dom0:load /netbsd-XEN3_DOM0.gz console=pc;multiboot /xen.gz dom0_mem=256M -s
menu=Drop to boot prompt:prompt
default=1
timeout=5

netbsd# reboot

On choisit manuellement la cinquième entrée et chocapik:

Mismatch between XEN and DOM0 kernel

On va lire http://archive.netbsd.se/?ml=port-xen&a=2008-08&t=8360302, puis http://www.netbsd.org/ports/xen/ et on se dit qu'on va attendre: "A new kernel XEN3PAE_DOM0 should show up in the next HEAD autobuild."

et c'est (re)parti:

netbsd# pkgin remove xenkernel33
netbsd# pkgin remove xentools33
netbsd# pkgin install xenkernel3
netbsd# pkgin install xentools3
netbsd# cp /usr/pkg/xen3-kernel/xen.gz /
netbsd# reboot

On choisit la cinquième entrée du menu de boot et hop un dmesg

netbsd# cp /usr/pkg/share/examples/rc.d/* /etc/rc.d/
netbsd# chmod 755 /etc/rc.d/xen*
netbsd# echo "xend=YES" >> /etc/rc.conf
netbsd# echo "xenbackendd=YES" >> /etc/rc.conf
netbsd# echo "xendomains=YES" >> /etc/rc.conf
netbsd# xend start
netbsd# xenbackendd

netbsd# cat /etc/ifconfig.bridge0
create
!brconfig $int add bge0 up

On modifie le script /usr/pkg/etc/xen/scripts/vif-bridge

netbsd# grep xbridge= /usr/pkg/etc/xen/scripts/vif-bridge
        #xbridge=$(xenstore-read "$xpath/bridge")
        xbridge=bridge0

Configuration des domU

netbsd# mkdir -p /home/xen
netbsd# dd if=/dev/zero of=/home/xen/netbsd-001.img bs=1m count=2k
netbsd# grep -v "^#" /usr/pkg/etc/xen/netbsd-001
kernel = "/netbsd-INSTALL_XEN3_DOMU.gz"
memory = 128
name = "netbsd-001"
vif = [ 'bridge=bridge0' ]
disk = [ 'file:/home/xen/netbsd-001.img,xbd0a,w', 'file:/home/xen/i386cd-5.0.1.iso,xbd1d,r' ]
root = "/dev/xbd0a"

Roulement de tambour:

netbsd# xm create -c /usr/pkg/etc/xen/netbsd-001
Error: Device 0 (vif) could not be connected. Hotplug scripts not working

On active le bridge0 sinon les domU ne se lance pas:

netbsd# /etc/rc.d/network restart 

On installe tranquillou, minimal, depuis le cd qui est en xbd1d et pas cd0a, et on finit par un

netbsd-001# halt -p

ctrl+] pour quitter la console du domU. On bascule sur le kernel normal:

netbsd# grep ^kernel /usr/pkg/etc/xen/netbsd-001
kernel = "netbsd-XEN3_DOMU.gz"

On boote le domU et voilà-t-y pas qu'il demande sur quoi booter :( On modifie /usr/pkg/etc/xen/netbsd-001

netbsd# grep ^root /usr/pkg/etc/xen/netbsd-001
root = "xbd0a"

Si au prochain reboot du dom0 pas de xen, on n'oublie pas de modifier l'entrée par défaut de /boot.cfg:

netbsd# grep ^default /boot.cfg
default=5

Poufinage domU

On a donc une image d'un domU non configurée. Pourquoi ne pas en profiter ?

netbsd# dd if=/home/xen/netbsd-001.img of=/home/xen/_netbsd.img

On pourra rapidement (re)faire un domU:

netbsd# dd if=/home/xen/_netbsd.img of=/home/xen/netbsd-002.img
netbsd# sed -e 's/001/002/' /usr/pkg/etc/xen/netbsd-001 > /usr/pkg/etc/xen/netbsd-002

Reste à commenter les lignes screen de /etc/wscons.conf et garder uniquement la console on dans /etc/ttys. Un peu de configuration:

netbsd-001# tail /etc/rc.conf
ifconfig_bge0="inet 10.50.0.41 netmask 255.255.255.0"
defaultroute="10.50.0.100"
hostname="netbsd-001.domain.tld"
sshd=YES
powerd=YES

netbsd-001# cat /etc/resolv.conf
domain domain.tld
search domain.tld
nameserver 192.168.0.2
nameserver 192.168.0.1
nameserver 192.168.0.3

Pour démarrer automatiquement notre domU:

netbsd# echo 'xendomains="netbsd-001"' >> /etc/rc.conf

A venir

Un seul disque n'est pas suffisant pour une mise en production. Je vais donc rajouter un disque et refaire une installation sur du raid 1 (mirroir).

Les fichiers utilisés comme device pour les domU je n'aime pas car on superpose les couches:

disque -> partition -> file system -> partition -> file system
           dom0         dom0           domU         domU

On ne dispose pas encore de LVM ni de ZFS (mais c'est en cours). Vu la quantité de RAM et le nombre d'IP disponibles, je vais pouvoir affecter une (des) partitions à mes 4 domU:

disque -> partition -> file system
           dom0         dom0

       -> partition -> file system
           domU         domU
       -> partition -> file system
           domU         domU
       -> partition -> file system
           domU         domU
       -> partition -> file system
           domU         domU

Le dom0 doit être un peu mieux configuré: sshd, pf, ntp, cache dns, centralisation des logs, un petit smartmontool, du symon (ou munin) et deux trois trucs qui facilitent la vie. En attendant un controleur SATA et deux disques de plus grosse capacité, amusez-vous bien avec NetBSD et Xen !

0 commentaire(s)

Pages : 1