diff options
Diffstat (limited to 'xi/sbin')
-rwxr-xr-x | xi/sbin/ifdown | 100 | ||||
-rwxr-xr-x | xi/sbin/ifup | 150 | ||||
-rw-r--r-- | xi/sbin/ifup.8 | 185 |
3 files changed, 435 insertions, 0 deletions
diff --git a/xi/sbin/ifdown b/xi/sbin/ifdown new file mode 100755 index 0000000..05d7b41 --- /dev/null +++ b/xi/sbin/ifdown @@ -0,0 +1,100 @@ +#!/bin/bash +######################################################################## +# Begin /sbin/ifdown +# +# Description : Interface Down +# +# Authors : Nathan Coulson - nathan@linuxfromscratch.org +# Kevin P. Fleming - kpfleming@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# +# Version : LFS 7.0 +# +# Notes : the IFCONFIG variable is passed to the scripts found +# in the /lib/services directory, to indicate what file the +# service should source to get interface specifications. +# +######################################################################## + +RELEASE="7.0" + +USAGE="Usage: $0 [ -hV ] [--help] [--version] interface" +VERSTR="LFS ifdown, version ${RELEASE}" + +while [ $# -gt 0 ]; do + case "$1" in + --help | -h) help="y"; break ;; + + --version | -V) echo "${VERSTR}"; exit 0 ;; + + -*) echo "ifup: ${1}: invalid option" >&2 + echo "${USAGE}" >& 2 + exit 2 ;; + + *) break ;; + esac +done + +if [ -n "$help" ]; then + echo "${VERSTR}" + echo "${USAGE}" + echo + cat << HERE_EOF +ifdown is used to bring down a network interface. The interface +parameter, e.g. eth0 or eth0:2, must match the trailing part of the +interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2. + +HERE_EOF + exit 0 +fi + +file=/etc/sysconfig/ifconfig.${1} + +# Skip backup files +[ "${file}" = "${file%""~""}" ] || exit 0 + +. /lib/lsb/init-functions + +if [ ! -r "${file}" ]; then + log_warning_msg "${file} is missing or cannot be accessed." + exit 1 +fi + +. ${file} + +if [ "$IFACE" = "" ]; then + log_failure_msg "${file} does not define an interface [IFACE]." + exit 1 +fi + +# We only need to first service to bring down the interface +S=`echo ${SERVICE} | cut -f1 -d" "` + +if ip link show ${IFACE} > /dev/null 2>&1; then + 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 + if [ "$(ip addr show ${IFACE} | grep 'inet ')" == "" ]; then + log_info_msg "Bringing down the ${IFACE} interface..." + ip link set ${IFACE} down + evaluate_retval + fi + fi +fi + +# End /sbin/ifdown diff --git a/xi/sbin/ifup b/xi/sbin/ifup new file mode 100755 index 0000000..4c70810 --- /dev/null +++ b/xi/sbin/ifup @@ -0,0 +1,150 @@ +#!/bin/sh +######################################################################## +# Begin /sbin/ifup +# +# Description : Interface Up +# +# Authors : Nathan Coulson - nathan@linuxfromscratch.org +# Kevin P. Fleming - kpfleming@linuxfromscratch.org +# Update : Bruce Dubbs - bdubbs@linuxfromscratch.org +# DJ Lucas - dj@linuxfromscratch.org +# +# Version : LFS 7.7 +# +# Notes : The IFCONFIG variable is passed to the SERVICE script +# in the /lib/services directory, to indicate what file the +# service should source to get interface specifications. +# +######################################################################## + +up() +{ + log_info_msg "Bringing up the ${1} interface..." + + 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 "Interface ${IFACE} doesn't exist." + exit 1 + fi + + evaluate_retval +} + +RELEASE="7.7" + +USAGE="Usage: $0 [ -hV ] [--help] [--version] interface" +VERSTR="LFS ifup, version ${RELEASE}" + +while [ $# -gt 0 ]; do + case "$1" in + --help | -h) help="y"; break ;; + + --version | -V) echo "${VERSTR}"; exit 0 ;; + + -*) echo "ifup: ${1}: invalid option" >&2 + echo "${USAGE}" >& 2 + exit 2 ;; + + *) break ;; + esac +done + +if [ -n "$help" ]; then + echo "${VERSTR}" + echo "${USAGE}" + echo + cat << HERE_EOF +ifup is used to bring up a network interface. The interface +parameter, e.g. eth0 or eth0:2, must match the trailing part of the +interface specifications file, e.g. /etc/sysconfig/ifconfig.eth0:2. + +HERE_EOF + exit 0 +fi + +file=/etc/sysconfig/ifconfig.${1} + +# Skip backup files +[ "${file}" = "${file%""~""}" ] || exit 0 + +. /lib/lsb/init-functions + +if [ ! -r "${file}" ]; then + log_failure_msg "Unable to bring up ${1} interface! ${file} is missing or cannot be accessed." + exit 1 +fi + +. $file + +if [ "$IFACE" = "" ]; then + log_failure_msg "Unable to bring up ${1} interface! ${file} does not define an interface [IFACE]." + exit 1 +fi + +# Do not process this service if started by boot, and ONBOOT +# is not set to yes +if [ "${IN_BOOT}" = "1" -a "${ONBOOT}" != "yes" ]; then + exit 0 +fi + +# Bring up the interface +if [ "$VIRTINT" != "yes" ]; then + up ${IFACE} +fi + +for S in ${SERVICE}; do + if [ ! -x "/lib/services/${S}" ]; then + MSG="\nUnable to process ${file}. Either " + MSG="${MSG}the SERVICE '${S} was not present " + MSG="${MSG}or cannot be executed." + log_failure_msg "$MSG" + exit 1 + fi +done + +if [ "${SERVICE}" = "wpa" ]; then log_success_msg; fi + +# Create/configure the interface +for S in ${SERVICE}; do + IFCONFIG=${file} /lib/services/${S} ${IFACE} up +done + +# Set link up virtual interfaces +if [ "${VIRTINT}" == "yes" ]; then + up ${IFACE} +fi + +# Bring up any additional interface components +for I in $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 + for I in $IFACE $INTERFACE_COMPONENTS; do + ip link set dev $I mtu $MTU; + done + else + log_info_msg2 "Invalid MTU $MTU" + fi +fi + +# Set the route default gateway if requested +if [ -n "${GATEWAY}" ]; then + if ip route | grep -q default; then + log_warning_msg "Gateway already setup; skipping." + else + log_info_msg "Adding default gateway ${GATEWAY} to the ${IFACE} interface..." + ip route add default via ${GATEWAY} dev ${IFACE} + evaluate_retval + fi +fi + +# End /sbin/ifup diff --git a/xi/sbin/ifup.8 b/xi/sbin/ifup.8 new file mode 100644 index 0000000..2fb7873 --- /dev/null +++ b/xi/sbin/ifup.8 @@ -0,0 +1,185 @@ +ifup(8) ifup(8) + +NAME + ifup - bring a network interface up + ifdown - take a network interface down + +SYNOPSIS + ifup IFACE + ifup -h|--help + ifup -V|--version + + ifdown IFACE + ifdown -h|--help + ifdown -V|--version + +DESCRIPTION + The ifup and ifdown commands may be used to configure + (or, respectively, deconfigure) a network interface based + on interface definitions in the file + /etc/sysconfig/ifconfig.IFACE. + +OPTIONS + A summary of options is included below. + + -h, --help + Show summary of options. + + -V, --version + Show version information. + +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 + LABEL=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 + the network configuration file. + + The configuration files must have the following environ- + ment variables set: + + IFACE - The interface to configure, e.g. eth0. It must + be available in /sys/class/net. + + 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 + 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. If the service + is ipv4-static-route, this parameter must NOT + be set. + + STATIC_GATEWAY - The default IP address to use for routing + when setting a static routing address. + + 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 + + IP - The IP address of the interface, + e.g. 192.168.1.2. + + PREFIX - The number of bits that specify the network + number of the interface. The default, if not + specified, is 24. + + LABEL - The label to be assigned to the interface. + This is normally specified for assigning + additional IP addresses to a network + device. Example: eth0:2 (optional) + + BROADCAST - The brodcast address for this interface, + 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 the + TYPE is not 'default'. + + PREFIX - The prefix for the associated IP address. + + STATIC_GATEWAY - The IP address for a network route. + + SOURCE - The source IP address to prefer when sending + 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 + <nathan@linuxfromscratch.org> and Kevin P. Fleming + <kpfleming@linuxfromscratch.org> + and updated by Bruce Dubbs <bdubbs@linuxfromscratch>. + +SEE ALSO + ip(8). + +IFUP/IFDOWN 8 February 2015 ifup(8) |