OK, I've put together the attached scripts.
They seem to work for me. If there are errors, like doing
ifup br0; ifup br0
or
ifup br0; ifup eth0
or other out of order sequences, the error messages do not have a nice
format, but I don't know if that is necessary. Correct sequences like
ifup br0; ifdown br0; ifup eth0; ifdown eth0
are OK. Please give them a try and let me know what you think.
I have not tried using SERVICE="bridge dhcpcd".
Of course the ifup/ifdown/ipv4-static scripts will need to go into LFS,
not BLFS. The only change in ifconfig.eth0 is ONBOOT=no.
-- Bruce
#!/bin/sh
########################################################################
# Begin /lib/services/bridge
#
# Description : Bridge Boot Script
#
# Authors : Nathan Coulson - [email protected]
# Bruce Dubbs - [email protected]
#
# Version : LFS-7.0
#
########################################################################
. /lib/lsb/init-functions
. ${IFCONFIG}
if [ -n "${INTERFACE}" ]; then
log_failure_msg "INTERFACES variable missing from ${IFCONFIG}"
exit 1
fi
case "${2}" in
up)
log_info_msg2 "\n"
log_info_msg "Creating the ${1} interface..."
brctl addbr ${1}
ip link set ${1} up
evaluate_retval
for I in ${INTERFACES}; do
log_info_msg "Adding ${I} to ${1}..."
ip link set ${I} up &&
brctl addif ${1} ${I}
evaluate_retval
done
if [ "${IP_FORWARD}" = "y" -o \
"${IP_FORWARD}" = "yes" -o \
"${IP_FORWARD}" = "t" -o \
"${IP_FORWARD}" = "true" -o \
"${IP_FORWARD}" = "1" ]; then
sysctl -w net.ipv4.ip_forward=1 > /dev/null
log_success_msg "Setting net.ipv4.ip_forward = 1"
fi
;;
down)
for I in ${INTERFACES}; do
log_info_msg "Removing ${I} from ${1}..."
ip link set ${I} down &&
brctl delif ${1} ${I}
evaluate_retval
done
log_info_msg "Bringing down the ${1} interface..."
ip link set ${1} down
brctl delbr ${1}
evaluate_retval
;;
*)
echo "Usage: ${0} [interface] {up|down}"
exit 1
;;
esac
# End /lib/services/bridge
ONBOOT=yes
IFACE=br0
SERVICE="bridge ipv4-static"
IP=192.168.0.22
GATEWAY=192.168.0.1
PREFIX=24
BROADCAST=192.168.0.255
CHECK_LINK=no # Don't check before created
STP=no # Spanning tree protocol, default no
INTERFACES=eth0 # Add to IFACE
IP_FORWARD=true
ONBOOT=no
IFACE=eth0
SERVICE=ipv4-static
IP=192.168.0.22
GATEWAY=192.168.0.1
PREFIX=24
BROADCAST=192.168.0.255
#!/bin/bash
########################################################################
# Begin /sbin/ifdown
#
# Description : Interface Down
#
# Authors : Nathan Coulson - [email protected]
# Kevin P. Fleming - [email protected]
# Update : Bruce Dubbs - [email protected]
#
# 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
# Reverse the order
SERVICES=
for S in ${SERVICE}; do SERVICES="${SERVICES} ${S}"; done
# 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
else
log_warning_msg "Interface ${1} doesn't exist."
fi
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
#!/bin/sh
########################################################################
# Begin /sbin/ifup
#
# Description : Interface Up
#
# Authors : Nathan Coulson - [email protected]
# Kevin P. Fleming - [email protected]
# Update : Bruce Dubbs - [email protected]
#
# Version : LFS 7.0
#
# 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.
#
########################################################################
RELEASE="7.0"
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
log_info_msg "Bringing up the ${1} interface... "
if [ ! -r "${file}" ]; then
log_warning_msg "\n${file} is missing or cannot be accessed."
exit 1
fi
. $file
if [ "$IFACE" = "" ]; then
log_failure_msg "\n${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
log_info_msg2 "skipped\n"
exit 0
fi
for S in ${SERVICES}; do
if [ ! -n "${S}" -o ! -x "/lib/services/${S}" ]; then
MSG="\nUnable 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 [ -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
else
log_warning_msg "\nInterface ${IFACE} doesn't exist."
exit 0
fi
fi
for S in ${SERVICE}; do
IFCONFIG=${file} /lib/services/${S} ${IFACE} up
done
# End /sbin/ifup
#!/bin/sh
########################################################################
# Begin /lib/services/ipv4-static
#
# Description : IPV4 Static Boot Script
#
# Authors : Nathan Coulson - [email protected]
# Kevin P. Fleming - [email protected]
# Update : Bruce Dubbs - [email protected]
#
# Version : LFS 7.0
#
########################################################################
. /lib/lsb/init-functions
. ${IFCONFIG}
if [ -z "${IP}" ]; then
log_failure_msg "\nIP variable missing from ${IFCONFIG}, cannot continue."
exit 1
fi
if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
log_warning_msg "\nPREFIX variable missing from ${IFCONFIG}, assuming 24."
PREFIX=24
args="${args} ${IP}/${PREFIX}"
elif [ -n "${PREFIX}" -a -n "${PEER}" ]; then
log_failure_msg "\nPREFIX and PEER both specified in ${IFCONFIG}, cannot
continue."
exit 1
elif [ -n "${PREFIX}" ]; then
args="${args} ${IP}/${PREFIX}"
elif [ -n "${PEER}" ]; then
args="${args} ${IP} peer ${PEER}"
fi
if [ -n "${BROADCAST}" ]; then
args="${args} broadcast ${BROADCAST}"
fi
case "${2}" in
up)
if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP})" == "" ]; then
# Cosmetic output not needed for multiple services
if ! $(echo ${SERVICE} | grep -q " "); then
log_info_msg2 "\n" # Terminate the previous message
fi
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"
fi
;;
down)
if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP})" != "" ]; then
log_info_msg "Removing IPv4 address ${IP} from the ${1} interface..."
ip addr del ${args} dev ${1}
evaluate_retval
fi
if [ -n "${GATEWAY}" ]; then
# Only remove the gateway if ther are no remaining ipv4 addresses
if [ "$(ip addr show ${1} 2>/dev/null | grep 'inet ')" != "" ]; then
log_info_msg "Removing default gateway..."
ip route del default
evaluate_retval
fi
fi
;;
*)
echo "Usage: ${0} [interface] {up|down}"
exit 1
;;
esac
# End /lib/services/ipv4-static
--
http://linuxfromscratch.org/mailman/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page