From 9ededf1d75102bf829562246b527cf617aef7a8a Mon Sep 17 00:00:00 2001 From: Ionut Biru Date: Mon, 19 Dec 2011 17:06:23 +0200 Subject: [PATCH] revamp for iproute2 syntax Use ip from iproute2 rather than ifconfig Add iproute2 to dependencies Document the latest networking changes Signed-off-by: Ionut Biru --- README | 1 + doc/official_installation_guide_en | 34 +++++++++++---------- src/core/libs/lib-ui-interactive.sh | 54 ++++++++++++++++++++-------------- 3 files changed, 51 insertions(+), 38 deletions(-) diff --git a/README b/README index b81d7ab..37ff125 100644 --- a/README +++ b/README @@ -18,6 +18,7 @@ Homepage: http://github.com/Dieterbe/aif - awk - sed - libui-sh + - iproute2 Optionally: - markdown: to generate the html installation guide - cryptsetup: for encryption support diff --git a/doc/official_installation_guide_en b/doc/official_installation_guide_en index 93809dc..89a591f 100644 --- a/doc/official_installation_guide_en +++ b/doc/official_installation_guide_en @@ -116,10 +116,10 @@ These procedures are shipped by default: * partial-disks: Process disk subsystem or do a rollback * partial-keymap: change your keymap/console font settings. (aliased as `km`) -The benefit of procedures such as partial-keymap and -partial-configure-network over direct usage of tools such as loadkeys or -ifconfig is that when running the interactive procedure, you will get asked -if you want to apply your settings to the config files of the target system. +The benefit of procedures such as partial-keymap and partial-configure-network +over direct usage of tools such as loadkeys or ip is that when running the +interactive procedure, you will be asked if you want to apply your settings +to the config files of the target system. If you want to go further, you can also: @@ -567,18 +567,20 @@ LVM groups part. This is totally your choice, as long as you stick to letters, digits and a few common special characters like the dash. -**INTERFACES:** Here you define the settings for your networking interfaces. -The default lines and the included comments explain the setup well enough. If -you use DHCP, 'eth0="dhcp"' should work for you. If you do not use DHCP just -keep in mind that the value of the variable (whose name must be equal to the -name of the device which is supposed to be configured) equals the line which -would be appended to the ifconfig command if you were to configure the device -manually in the shell. - -**ROUTES:** You can define your own static network routes with arbitrary names -here. Look at the example for a default gateway to get the idea. Basically the -quoted part is identical to what you'd pass to a manual route add command, -therefore reading man route is recommended or simply leave this alone. +**interface:** the name of the interface to setup, e.g. eth0 + +**address:** If you use DHCP, leave this blank. If you do not use DHCP, complete +this with your ip. + +**netmask:** The subnet mask. Defaults to 255.255.255.0 if is blank. + +**broadcast:** Set the broadcast address for your network. If left blank, +the host bits of the address will be set to 1 to form the broadcast address. +This setting is sufficient for most user networks.. + +**gateway:** The default route. + +Netmask, broadcast and gateway are optional and ignored when DHCP is used. **[ NET_PROFILES][49]:** Enables certain network profiles at bootup. Network profiles provide a convenient way of managing multiple network configurations, diff --git a/src/core/libs/lib-ui-interactive.sh b/src/core/libs/lib-ui-interactive.sh index 7e60c95..1c2b6bb 100644 --- a/src/core/libs/lib-ui-interactive.sh +++ b/src/core/libs/lib-ui-interactive.sh @@ -796,14 +796,17 @@ If any previous configuration you've done until now (like fancy filesystems) req # returns: 1 on failure interactive_runtime_network() { notify "If you wish to load your ethernet modules manually, please do so now in an another terminal." - local ifaces - ifaces=$(ifconfig -a |grep "Link encap:Ethernet"|sed 's/ \+Link encap:Ethernet \+HWaddr \+/ /g') + local ifaces=() + + for i in /sys/class/net/!(lo); do + ifaces+=(${i##*/} $(<"$i/address")) + done [ -z "$ifaces" ] && show_warning "No network interfaces?" "Cannot find any ethernet interfaces. This usually means udev was\nunable to load the module and you must do it yourself. Switch to\nanother VT, load the appropriate module, and run this step again." && return 1 INTERACE_PREV=$INTERFACE unset INTERFACE DHCP IPADDR SUBNET BROADCAST GW DNS PROXY_HTTP PROXY_FTP - ask_option no "Interface selection" "Select a network interface" required $ifaces || return 1 + ask_option no "Interface selection" "Select a network interface" required "${ifaces[@]}" || return 1 INTERFACE=$ANSWER_OPTION [ "$INTERFACE" = "$INTERFACE_PREV" ] && INTERFACE_PREV= @@ -816,8 +819,8 @@ interactive_runtime_network() { show_warning "Dhcpcd problem" "Failed to run dhcpcd. See $LOG for details." return 1 fi - if ! ifconfig $INTERFACE | grep -q 'inet addr:' - then + if ! ip -o addr show dev $INTERFACE | grep -q inet + then show_warning "Dhcpcd problem" "DHCP request failed. dhcpcd returned 0 but no ip configured for $INTERFACE" return 1 fi @@ -847,24 +850,31 @@ interactive_runtime_network() { USERHAPPY=1 fi done - echo "running: ifconfig $INTERFACE $IPADDR netmask $SUBNET broadcast $BROADCAST up" >$LOG - if ! ifconfig $INTERFACE $IPADDR netmask $SUBNET broadcast $BROADCAST up >$LOG 2>&1 + + echo "running: ip link set dev $INTERFACE up" >$LOG + if ! ip link set dev $INTERFACE up then - show_warning "Ifconfig problem" "Failed to setup interface $INTERFACE" - return 1 - fi - if [ -n "$GW" ]; then - route add default gw $GW >$LOG 2>&1 || notify "Failed to setup your gateway." || return 1 - fi - if [ -z "$PROXY_HTTP" ]; then - unset http_proxy - else - export http_proxy=$PROXY_HTTP - fi - if [ -z "$PROXY_FTP" ]; then - unset ftp_proxy - else - export ftp_proxy=$PROXY_FTP + show_warning "ip link problem" "Failed to bring the interface $INTERFACE up" + return 1 + fi + echo "running: ip addr add $IPADDR/${SUBNET:-24} broadcast ${BROADCAST:-+} dev $INTERFACE" >$LOG + if ! ip addr add $IPADDR/${SUBNET:-24} broadcast ${BROADCAST:-+} dev $INTERFACE >$LOG 2>&1 + then + show_warning "ip addr problem" "Failed to setup interface $INTERFACE" + return 1 + fi + if [ -n "$GW" ]; then + ip route add default via $GW >$LOG 2>&1 || notify "Failed to setup your gateway." || return 1 + fi + if [ -z "$PROXY_HTTP" ]; then + unset http_proxy + else + export http_proxy=$PROXY_HTTP + fi + if [ -z "$PROXY_FTP" ]; then + unset ftp_proxy + else + export ftp_proxy=$PROXY_FTP fi echo "nameserver $DNS" >/etc/resolv.conf fi -- 1.7.8