Mot-clé - vif-route

Fil des billets

04janv. 2012

Xen vif-route and private lan

Xen_logo.png
J'utilisais depuis quelques années un lan privé entre mes DomU et le Dom0 (le Dom0 génère les graphs Munin) qui fonctionnait sans problème en bridge mais suite à l'allocation de ma plage IPv6 routé, j'ai du modifier ma configuration Xen en mode routé (vif-route).

En mode routé je devais exécuter des commandes manuellement sur le Dom0 afin de modifier le routage de l'interface eth1.

ip route del 10.41.233.XXX dev blog.1  scope link  src 78.41.233.XXX
ip route add 10.41.233.XXX dev blog.1  scope link  src 10.41.233.XXX

Ce fonctionnement me permettait des communications DomU <=> Dom0 mais pas DomU <=> DomU (perte de paquet aléatoire).

Suite à la réinstallation de mon hyperviseur Xen en 64Bits (ca m'aura pris du temps pour trouver la motivation), je me suis décidé à tout remettre au propre. (je traine des patchs homemade depuis Xen-3.2.1)

Voici donc ma nouvelle configuration permettant l'utilisation du vif-route et du vif-bridge simultanément, pour éviter d'éventuel bug j'ai préféré créer une interface dummy plutôt que d'ajouter un alias à l'interface loopback.

  • /etc/conf.d/net
config_dummy0=( "10.41.233.1/24" )
  • /etc/xen/scripts/network-custom
#!/bin/sh
dir=$(dirname "$0")
"$dir/network-route" "$@" netdev=eth0
"$dir/network-bridge" "$@" netdev=dummy0 bridge=private
  • /etc/xen/scripts/vif-custom
#!/bin/sh
dir=$(dirname "$0")
IFNUM=$(echo ${vif}|> | cut -d. -f2)
 
if [ "$IFNUM" = "0" ] ; then
	# Interface 0 = public lan
	"$dir/vif-route" "$@"
else
	# Sinon private lan
	"$dir/vif-bridge" "$@"
fi
  • /etc/xen/xend-config.sxp

On commente l'ensemble des autres scripts réseaux (bridge, route, nat)

(network-script network-custom)
(vif-script     vif-custom)

On relance xend

/etc/init.d/xend restart

A ce stade vous devriez avoir une interface nommée private disposant de l'IP privée assignée.

15: private: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN 
    link/ether 16:c7:56:f6:4d:3c brd ff:ff:ff:ff:ff:ff
    inet 10.41.233.1/24 brd 10.41.233.255 scope global private
    inet6 fe80::14c7:56ff:fef6:4d3c/64 scope link 
       valid_lft forever preferred_lft forever

Il vous suffit à présent d'adopter cette configuration sur vos DomU.

vif = [ 'mac=XX:XX:XX:XX:XX:XX, ip=78.41.233.XXX', 'mac=XX:XX:XX:XX:XX:XX, ip=10.41.233.XXX, bridge=private' ]


Liens utiles :
- Xen Networking Examples

26juin 2010

Xen utilisation de l'IPv6 vif-route

Xen_logo.png
Mon bloc IPv6 étant enfin routé correctement, je me suis attelé à la configuration de ce dernier sur le Dom0 et DomU Xen.

Ma configuration Xen étant à l'origine en bridge et disposant d'un bloc routé vers mon serveur, j'ai donc dût basculer ma configuration Xen en mode route. (vif-route)

Bien entendu à l'instar du mode bridge, le mode route n'est pas compatible IPv6 ...
Voici deux patch à appliquer (compatible Xen-4) ainsi qu'un exemple de configuration (Gentoo).

1) Dom0


  • vif-common
--- vif-common.sh~      2010-04-07 18:12:04.000000000 +0200
+++ vif-common.sh       2010-06-26 23:08:38.000000000 +0200
@@ -14,7 +14,7 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #
-
+# IPv6 Patched by Timeuhmeuh
 
 dir=$(dirname "$0")
 . "$dir/xen-hotplug-common.sh"
@@ -135,6 +135,17 @@
   ip addr show "$1" | awk "/^.*inet.*$1\$/{print \$2}" | sed -n '1 s,/.*,,p'
 }
 
+##
+# ip6_of interface
+#
+# Print the IPv6 address currently in use at the given interface, or nothing if
+# the interface is not up.
+#
+ip6_of()
+{
+        ip -6 addr show dev "$1" scope global | awk -F'[ |/]' '/inet6 (([0-9a-f]+:*)+)/ { print $6 } ' | awk '/::/ {print $1}'
+}
+
 
 ##
 # dom0_ip
@@ -156,3 +167,38 @@
   fi
   echo "$result"
 }
+
+##
+# dom0_ip6
+#
+# Print the IPv6 address of the interface in dom0 through which we are routing.
+# This is the IPv6 address on the interface specified as "netdev" as a parameter
+# to these scripts, or eth0 by default.  This function will call fatal if no
+# such interface could be found.
#
+dom0_ip6()
+{
+    local nd=${netdev:-eth0}
+    local result=$(ip6_of "$nd")
+    if [ -z "$result" ]; then
+        echo ""
+    else
+        echo "$result"
+    fi
+}
+
+##
+# is_ip6
+#
+# Verifing IPv6 address
+#
+is_ipv6()
+{
+case "$1" in
+    *:*:*)
+        echo "yes"
+        ;;
+    *)
+        echo ""
+esac
+}
  • vif-route
--- vif-route~	2010-04-07 18:12:04.000000000 +0200
+++ vif-route	2010-06-26 23:12:45.000000000 +0200
@@ -18,17 +18,24 @@
 # Read from the store:
 # ip      list of IP networks for the vif, space-separated (default given in
 #         this script).
+#
+# IPv6 Patched by Timeuhmeuh - http://blog.yacoubi.fr
 #============================================================================
 
 dir=$(dirname "$0")
 . "$dir/vif-common.sh"
 
 main_ip=$(dom0_ip)
+main_ip6=$(dom0_ip6)
 
 case "$command" in
     online)
+	log info "[vif-route] online request, ip ${ip} with main_ip ${main_ip} and main_ip6 ${main_ip6} for $vif."
         ifconfig ${vif} ${main_ip} netmask 255.255.255.255 up
-        echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
+	if [ ! -z "${main_ip6}" ]; then
+		ip -6 addr add ${main_ip6} dev ${vif}
+	fi
+	echo 1 >/proc/sys/net/ipv4/conf/${vif}/proxy_arp
         ipcmd='add'
         cmdprefix=''
         ;;
@@ -43,7 +50,16 @@
     # If we've been given a list of IP addresses, then add routes from dom0 to
     # the guest using those addresses.
     for addr in ${ip} ; do
-      ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}
+	result=$(is_ipv6 "${addr}")
+	if [ -z "${result}" ] ; then
+		result=`${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip} 2>&1`
+		log info "[vif-route] Result: ${result}"
+	else
+		log info "[vif-route] Adding IPv6 address ${addr} with src ${main_ip6} for $vif."
+	      result=`${cmdprefix} ip -6 route ${ipcmd} ${addr} dev ${vif} src ${main_ip6} 2>&1`
+		log info "[vif-route] Result: ${result}"
+	fi
+#      ${cmdprefix} ip route ${ipcmd} ${addr} dev ${vif} src ${main_ip}
     done 
 fi
  • /etc/conf.d/net
config_eth0=( "192.168.0.1/24" "2001:758:f00:340:192:168:0:12/64" "2001:758:5312::/48" )
  • /etc/xen/domU
vif = [ 'ip=2001:758:5312::2 192.168.0.10' ]

2) Dom0


  • /etc/conf.d/net
config_eth0=( "192.168.0.2/24" "2001:758:5312::2/48" )
routes_eth0=( "default gw 192.168.0.1" "default via 2001:758:5312::" )

Patch :


Lien utile : xen-and-routed-ipv6