X-Original-To: alpine-devel@lists.alpinelinux.org Delivered-To: alpine-devel@mail.alpinelinux.org Received: from mail-ww0-f42.google.com (mail-ww0-f42.google.com [74.125.82.42]) (using TLSv1 with cipher RC4-SHA (128/128 bits)) (No client certificate requested) by mail.alpinelinux.org (Postfix) with ESMTPS id 158A1DC144F for ; Fri, 30 Dec 2011 09:59:03 +0000 (UTC) Received: by wgbds13 with SMTP id ds13so19471038wgb.1 for ; Fri, 30 Dec 2011 01:59:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=Lz6AWqbVpS1GeHqaUGlBbsa7gcpwlMtsyr2DMV7Qm5o=; b=AZkKVzWACEimul8LhClo9+wQntfmaJ0LBHhwr/AmkbeIR1BImg6mRVvG1RZJ2mLEqQ 09DRKVB6fBoTPanEGBx3UOzMUX2xXv6scuPIq9NbSa7Rcyu8QSSfpAjSaq9/HoMNzC70 oisESMgdQIlbJe3A5aWt4RYCj8H/q12rLp6Mk= Received: by 10.216.139.91 with SMTP id b69mr19461424wej.51.1325238711347; Fri, 30 Dec 2011 01:51:51 -0800 (PST) Received: from localhost.localdomain (81.184.59.225.dyn.user.ono.com. [81.184.59.225]) by mx.google.com with ESMTPS id em4sm38898733wbb.20.2011.12.30.01.51.49 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 30 Dec 2011 01:51:50 -0800 (PST) Sender: =?UTF-8?Q?Roger_Pau_Monn=C3=A9?= From: Roger Pau Monne To: alpine-devel@lists.alpinelinux.org Cc: Roger Pau Monne Subject: [alpine-devel] [PATCH v2] alpine-conf: modify setup-interfaces to create simple bridges Date: Fri, 30 Dec 2011 10:51:38 +0100 Message-Id: <1325238698-1713-1-git-send-email-roger.pau@entel.upc.edu> X-Mailer: git-send-email 1.7.7.1 X-Mailinglist: alpine-devel Precedence: list List-Id: Alpine Development List-Unsubscribe: List-Post: List-Help: List-Subscribe: Modified setup-interfaces to create simple bridges (works only with one interface per bridge). Useful when setting up a Xen system, since interfaces need to be bridged in order for guests to have networking. Some distributions automatically create one bridge for each interface when Xen is installed, but I think this is too aggressive. Changes since v1: * Only ask to bridge interfaces if Xen Dom0 is detected --- libalpine.sh.in | 9 +++++++++ setup-interfaces.in | 49 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 54 insertions(+), 4 deletions(-) diff --git a/libalpine.sh.in b/libalpine.sh.in index 36d2a93..8661643 100755 --- a/libalpine.sh.in +++ b/libalpine.sh.in @@ -106,4 +106,13 @@ askpassword() { IFS=$_oifs } +# Detect if we are running Xen +is_xen() { + test -d /proc/xen +} +# Detect if we are running Xen Dom0 +is_xen_dom0() { + is_xen && \ + grep -q "control_d" /proc/xen/capabilities +} diff --git a/setup-interfaces.in b/setup-interfaces.in index b461529..aee2e83 100755 --- a/setup-interfaces.in +++ b/setup-interfaces.in @@ -5,6 +5,7 @@ PREFIX= . $PREFIX/lib/libalpine.sh +bridges="" detect_interfaces() { ip addr | grep -v ' lo:' | awk -F : '/^[0-9]*:/ { print $2}' @@ -42,7 +43,30 @@ config_iface() { local address local netmask local gateway + local bridge local conf=$prefix$iface.conf + local answer + + if is_xen_dom0; then + while [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; do + echon "Do you want to bridge the interface $iface? [no] " + default_read answer no + done + else + answer="no" + fi + + if [ "$answer" = "yes" ]; then + bridge="br"`echo $iface | sed 's/[^0-9]//g'` + while [ 1 ]; do + echon "Name of the bridge you would like to create: [$bridge] " + default_read bridge $bridge + `echo "$bridges" | grep -q "$bridge"` || break + echo "Name already in use, please choose another one" + done + echo "bridge=${bridge}" > $conf + bridges="$bridges $bridge" + fi # use ipcalc to validate the address. we do accept /mask # we are no interested in the result, only error code, so @@ -55,7 +79,7 @@ config_iface() { [ "$address" = "abort" ] && return if [ "$address" = "dhcp" ] ; then HAS_DHCP=yes - echo "type=dhcp" > $conf + echo "type=dhcp" >> $conf rm $iface.noconf return fi @@ -87,7 +111,7 @@ config_iface() { [ -z "$gateway" ] && break done - echo "type=static" > $conf + echo "type=static" >> $conf echo "address=${address%%/*}" >> $conf #strip off /mask if there echo "netmask=$netmask" >> $conf echo "gateway=$gateway" >> $conf @@ -146,8 +170,20 @@ prompt_for_interfaces() { iface=`basename $i .conf` iface=${iface#[0-9]*~} . ./$i - echo "auto $iface" >> interfaces - echo "iface $iface inet $type" >> interfaces + if [ -n "$bridge" ]; then + echo "auto $iface $bridge" >> interfaces + echo "" >> interfaces + echo "iface $iface inet manual" >> interfaces + echo -e "\tup ip link set \$IFACE up" >> interfaces + echo -e "\tdown ip link set \$IFACE down" >> interfaces + echo "" >> interfaces + echo "iface $bridge inet $type" >> interfaces + echo -e "\tpre-up brctl addbr $bridge" >> interfaces + echo -e "\tpre-up brctl addif $bridge $iface" >> interfaces + else + echo "auto $iface" >> interfaces + echo "iface $iface inet $type" >> interfaces + fi case $type in dhcp) [ -n "$hostname" ] \ @@ -160,7 +196,12 @@ prompt_for_interfaces() { && echo -e "\tgateway $gateway" >> interfaces ;; esac + if [ -n "$bridge" ]; then + echo -e "\tpost-down brctl delif $bridge $iface" >> interfaces + echo -e "\tpost-down brctl delbr $bridge" >> interfaces + fi echo "" >> interfaces + bridge="" done while [ "$answer" != "yes" ] && [ "$answer" != "no" ] ; do -- 1.7.7.1 --- Unsubscribe: alpine-devel+unsubscribe@lists.alpinelinux.org Help: alpine-devel+help@lists.alpinelinux.org ---