diff options
author | Bruce Dubbs <bdubbs@linuxfromscratch.org> | 2012-04-09 19:14:33 +0000 |
---|---|---|
committer | Bruce Dubbs <bdubbs@linuxfromscratch.org> | 2012-04-09 19:14:33 +0000 |
commit | 970a126c28d18ccec2d6b08dc51ab367de4a4455 (patch) | |
tree | fdaeb512dbfec5d2a3ecb1b3c91115fff5ab5639 /bootscripts | |
parent | b12948d0460a07bbfc8bf5a0ccba5785f97856be (diff) |
Update networking bootscripts. See bootscripts change log for details.
git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@9807 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689
Diffstat (limited to 'bootscripts')
-rw-r--r-- | bootscripts/lfs/lib/services/init-functions | 12 | ||||
-rwxr-xr-x | bootscripts/lfs/lib/services/ipv4-static | 13 | ||||
-rwxr-xr-x | bootscripts/lfs/sbin/ifdown | 31 | ||||
-rwxr-xr-x | bootscripts/lfs/sbin/ifup | 65 | ||||
-rw-r--r-- | bootscripts/lfs/sbin/ifup.8 | 94 |
5 files changed, 145 insertions, 70 deletions
diff --git a/bootscripts/lfs/lib/services/init-functions b/bootscripts/lfs/lib/services/init-functions index 415c65ba8..5f525fce6 100644 --- a/bootscripts/lfs/lib/services/init-functions +++ b/bootscripts/lfs/lib/services/init-functions @@ -778,4 +778,16 @@ wait_for_user() return 0 } +################################################################################ +# is_true() # +# # +# Purpose: Utility to test if a variable is true | yes | 1 # +# # +################################################################################ +is_true() +{ + [ "$1" = "1" ] || [ "$1" = "yes" ] || [ "$1" = "true" ] || [ "$1" = "y" ] || + [ "$1" = "t" ] +} + # End /lib/lsb/init-functions diff --git a/bootscripts/lfs/lib/services/ipv4-static b/bootscripts/lfs/lib/services/ipv4-static index cb9649d4b..5e248c464 100755 --- a/bootscripts/lfs/lib/services/ipv4-static +++ b/bootscripts/lfs/lib/services/ipv4-static @@ -52,19 +52,8 @@ case "${2}" in log_info_msg "Adding IPv4 address ${IP} to the ${1} interface..." ip addr add ${args} dev ${1} evaluate_retval - - if [ -n "${GATEWAY}" ]; then - if ip route | grep -q default; then - log_warning_msg "\nGateway already setup; skipping." - else - log_info_msg "Setting up default gateway..." - ip route add default via ${GATEWAY} dev ${1} - evaluate_retval - fi - fi else - msg="Cannot add IPv4 address ${IP} to ${1}. Already present." - log_warning_msg "$msg" + log_warning_msg "Cannot add IPv4 address ${IP} to ${1}. Already present." fi ;; diff --git a/bootscripts/lfs/sbin/ifdown b/bootscripts/lfs/sbin/ifdown index 15519c37a..e875be905 100755 --- a/bootscripts/lfs/sbin/ifdown +++ b/bootscripts/lfs/sbin/ifdown @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash ######################################################################## # Begin /sbin/ifdown # @@ -67,33 +67,28 @@ if [ "$IFACE" = "" ]; then exit 1 fi -# Reverse the order -SERVICES= -for S in ${SERVICE}; do SERVICES="${SERVICES} ${S}"; done +# We only need to first service to bring down the interface +S=`echo ${SERVICE} | cut -f1 -d" "` -# This will run the service scripts if ip link show ${IFACE} > /dev/null 2>&1; then - for S in ${SERVICES}; do - - if [ -n "${S}" -a -x "/lib/services/${S}" ]; then - IFCONFIG=${file} /lib/services/${S} ${IFACE} down - else - MSG="Unable to process ${file}. Either " - MSG="${MSG}the SERVICE variable was not set " - MSG="${MSG}or the specified service cannot be executed." - log_failure_msg "$MSG" - exit 1 - fi - done + if [ -n "${S}" -a -x "/lib/services/${S}" ]; then + IFCONFIG=${file} /lib/services/${S} ${IFACE} down + else + MSG="Unable to process ${file}. Either " + MSG="${MSG}the SERVICE variable was not set " + MSG="${MSG}or the specified service cannot be executed." + log_failure_msg "$MSG" + exit 1 + fi else log_warning_msg "Interface ${1} doesn't exist." fi +# Leave the interface up if there are additional interfaces in the device link_status=`ip link show ${IFACE} 2>/dev/null` if [ -n "${link_status}" ]; then if [ "$(echo "${link_status}" | grep UP)" != "" ]; then - # Set the interface down only if all IP addresses have been removed. if [ "$(ip addr show ${IFACE} | grep 'inet ')" == "" ]; then log_info_msg "Bringing down the ${IFACE} interface..." ip link set ${IFACE} down diff --git a/bootscripts/lfs/sbin/ifup b/bootscripts/lfs/sbin/ifup index 2facbe8be..bb25176ad 100755 --- a/bootscripts/lfs/sbin/ifup +++ b/bootscripts/lfs/sbin/ifup @@ -8,7 +8,7 @@ # Kevin P. Fleming - kpfleming@linuxfromscratch.org # Update : Bruce Dubbs - bdubbs@linuxfromscratch.org # -# Version : LFS 7.0 +# Version : LFS 7.2 # # Notes : The IFCONFIG variable is passed to the SERVICE script # in the /lib/services directory, to indicate what file the @@ -16,7 +16,24 @@ # ######################################################################## -RELEASE="7.0" +up() +{ + if ip link show $1 > /dev/null 2>&1; then + link_status=`ip link show $1` + + if [ -n "${link_status}" ]; then + if ! echo "${link_status}" | grep -q UP; then + ip link set $1 up + fi + fi + + else + log_failure_msg "\nInterface ${IFACE} doesn't exist." + exit 1 + fi +} + +RELEASE="7.2" USAGE="Usage: $0 [ -hV ] [--help] [--version] interface" VERSTR="LFS ifup, version ${RELEASE}" @@ -78,7 +95,7 @@ fi for S in ${SERVICE}; do if [ ! -x "/lib/services/${S}" ]; then - MSG="\n Unable to process ${file}. Either " + MSG="\nUnable to process ${file}. Either " MSG="${MSG}the SERVICE '${S} was not present " MSG="${MSG}or cannot be executed." log_failure_msg "$MSG" @@ -86,38 +103,34 @@ for S in ${SERVICE}; do fi done -if [ -z "${CHECK_LINK}" -o \ - "${CHECK_LINK}" = "y" -o \ - "${CHECK_LINK}" = "yes" -o \ - "${CHECK_LINK}" = "1" ]; then - - # Bring up the interface - if ip link show ${IFACE} > /dev/null 2>&1; then - link_status=`ip link show ${IFACE}` - - if [ -n "${link_status}" ]; then - if ! echo "${link_status}" | grep -q UP; then - ip link set ${IFACE} up - fi - fi +# Create/configure the interface +for S in ${SERVICE}; do + IFCONFIG=${file} /lib/services/${S} ${IFACE} up +done - else - log_failure_msg2 "Interface ${IFACE} doesn't exist." - exit 1 - fi -fi +# Bring up the interface and any components +for I in $IFACE $INTERFACE_COMPONENTS; do up $I; done # Set MTU if requested. Check if MTU has a "good" value. if test -n "${MTU}"; then if [[ ${MTU} =~ ^[0-9]+$ ]] && [[ $MTU -ge 68 ]] ; then - ip link set dev ${IFACE} mtu $MTU + for I in $IFACE $INTERFACE_COMPONENTS; do + ip link set dev $I mtu $MTU; + done else log_info_msg2 "Invalid MTU $MTU" fi fi -for S in ${SERVICE}; do - IFCONFIG=${file} /lib/services/${S} ${IFACE} up -done +# Set the route default gateway if requested +if [ -n "${GATEWAY}" ]; then + if ip route | grep -q default; then + log_warning_msg "\nGateway already setup; skipping." + else + log_info_msg "Setting up default gateway..." + ip route add default via ${GATEWAY} dev ${IFACE} + evaluate_retval + fi +fi # End /sbin/ifup diff --git a/bootscripts/lfs/sbin/ifup.8 b/bootscripts/lfs/sbin/ifup.8 index 3520d4240..8ed0d9586 100644 --- a/bootscripts/lfs/sbin/ifup.8 +++ b/bootscripts/lfs/sbin/ifup.8 @@ -28,15 +28,52 @@ OPTIONS -V, --version Show version information. -EXAMPLE +EXAMPLES ifup eth0 Bring up the interface defined in the file /etc/sysconfig/ifconfig.eth0 + ONBOOT=no + IFACE=eth0 + SERVICE=ipv4-static + IP=192.168.1.22 + GATEWAY=192.168.1.1 + PREFIX=24 + BROADCAST=192.168.1.255 + ifdown eth0:2 Bring down the interface defined in the file /etc/sysconfig/ifconfig.eth0:2 + ONBOOT=no + IFACE=eth0:2 + SERVICE=dhcpcd + + DHCP_START="--waitip" + DHCP_STOP="-k" + + # Set PRINTIP="yes" to have the script print the DHCP IP address + PRINTIP="yes" + + # Set PRINTALL="yes" to print the DHCP assigned values for + # IP, SM, DG, and 1st NS. + PRINTALL="no" + + ifup br0 + Bring up the interface defined in the file + /etc/sysconfig/ifconfig.br0 + + ONBOOT=yes + IFACE=br0 + SERVICE="bridge ipv4-static" + IP=192.168.1.22 + GATEWAY=192.168.1.1 + PREFIX=24 + BROADCAST=192.168.1.255 + STP=no # Spanning tree protocol, default no + INTERFACE_COMPONENTS=eth0 # Add to IFACE + IP_FORWARD=true + NOTES The program does not configure network interfaces direct- ly. It runs scripts defined by the SERVICE variable in @@ -51,11 +88,24 @@ NOTES SERVICE - The service script to run to bring up the inter- face. Standard services are ipv4-static and ipv4-static-route. Other services such as dhcp - may be installed. + or bridge may be installed. This value may + be a list of services when the interface is a + compound device such as a bridge. ONBOOT - If set to 'yes', the specified interface is configured by the netowrk boot script. + GATEWAY - The default IP address to use for routing if + the destination IP address is not in a static + route or on a local network, e.g., 192.168.1.1. + For secondary IP addresses on an interface, this + parameter should not be specified. + + INTERFACE_COMPONENTS - A list of component interfaces + only needed for a compound device such as a bridge. + This list is normally a single value, e.g. eth0, + for use with a virtual host such as kvm. + Other paramters that are service specific include: ipv4-static @@ -64,24 +114,20 @@ NOTES e.g. 192.168.1.2. PREFIX - The number of bits that specify the network - number of the interface, e.g., 24. + number of the interface. The default, if not + specified, is 24. - GATEWAY - The default IP address to use for routing - if the destination IP address is not in a - static route or on a local network, e.g., - 192.168.1.1. For secondary IP addresses on - an interface, this parameter should not be - specified. - BROADCAST - The brodcast address for this interface, - e.g 192.168.1.255. + e.g 192.168.1.255. If not specified, + the broadcast address will be calculated + from the IP and PREFIX. ipv4-static-route TYPE - The type of route, typically 'default', 'network', 'or host'. - IP - The IP address for a network or host, if thei + IP - The IP address for a network or host, if the TYPE is not 'default'. PREFIX - The prefix for the associated IP address. @@ -92,12 +138,32 @@ NOTES to the destinations covered by the specified route. (optional) + dhcp/dhclient + + DHCP_START - Optional parameters to pass to the dhcp client + at startup. + + DHCP_STOP - Optional paremeters to pass to the dhcp client + at shutdown. + + PRINTIP - Flag to print the dhcp address to stdout + + PRINTALL - Flag to print all obtained dhcp data to stdout + + bridge + + IP_FORWARD - An optional flag to enable the system to forward + inbound IP packets received by one interface to + another outbound interface. + + STP - Set bridge spanning tree protocol. Default is no. + FILES /etc/sysconfig/ifconfig.* definitions of network interfaces AUTHORS - The ifup/ifdown suite was written by Nathan Coulson + The ifup/ifdown suite was written by Nathan Coulson <nathan@linuxfromscratch.org> and Kevin P. Fleming <kpfleming@linuxfromscratch.org> and updated by Bruce Dubbs <bdubbs@linuxfromscratch>. @@ -105,4 +171,4 @@ AUTHORS SEE ALSO ip(8). -IFUP/IFDOWN 18 Sep 2011 ifup(8) +IFUP/IFDOWN 8 April 2012 ifup(8) |