Bruce, Nathan, et al.,
I've run into an interesting issue with our ifup/bridge/ipv4-static
trinity-of-awesome, and it's closely related to Bruce's gut feeling that
CHECK_LINK was...not quite right. Turns out, CHECK_LINK makes perfect
sense--it was the bridge script that wasn't quite right...
I ran into this because I needed to set MTU.
CHECK_LINK is fine the way it's conceived. /sbin/if{up,down} should handle the
PHY link, and issue the 'ip link' commands. So, they should bring the PHY link
up and down. The problem was the wrench that bridging threw at it. Bridging
sort of "inverted" the semantics of /lib/lsb/<service> by setting IFACE to the
bridge interface. It inverted the semantics in ipv4-static. I just altered it
so the semantics are identical.
Basically, in my ifconfig.brX (I'm using 1 in my example), IFACE needs to be
the PHY link (eth1). That way, ifup/ifdown can treat it as a physical link.
The beauty is that as long as "bridge" is specified in $SERVICE, it's perfectly
clear which "interface/link" is the bridge:
It's just ${1} passed from ifup/ifdown.
Then, the bridge script simply uses ${1} as the bridge name, and ${IFACE} as
the port to enslave. Other than a typo, ifdown remains unchanged. The typo
was passing ${IFACE} instead of ${1} to the service; and, this was never an
issue with ipv4-static, since they are synonymous. It wasn't an issue with
bridge, because bridge didn't use the positionals; it just used $IFACE and
$INTERFACES, but "backwards".
Scripts below. Search for #QRUX for my edits. Nathan, bridge is mostly yours;
mind taking a quick look to see if I didn't completely bork it? The scripts
are working for me, but there are two issues I haven't completely thought
through:
1) What happens with something like br0:1?
2) Using CHECK_LINK in /lib/lsb/<service>
I'm not sure (1) is even allowed or well-defined; if so, the complexity is
worrisome. (2) is more a cosmetic consideration, so that if you call ifup when
it's already up, or ifdown when it's already down doesn't create extra error
messages.
But, I'm able to set the MTU to 9000 in ifconfig.br1 (as you can see):
====
host [/lib/services] # ifconfig br1
br1 Link encap:Ethernet HWaddr 00:1B:21:9E:EF:8F
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:9000 Metric:1
RX packets:1 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:46 (46.0 b) TX bytes:132 (132.0 b)
====
Q
########################################################################
# BEGIN ifconfig.br1
ONBOOT=yes
IFACE="eth1" # Enslaved port
#
# Don't need a variable telling us which "interface" should be the
# bridge interface. That's what the name of the script (ifconfig.brN)
# is for. We just need to see 'bridge' in SERVICE, and then let
# /lib/lsb/bridge figure out what our interface is:
# it's just $1 from /sbin/if{up,down}.
#
SERVICE="bridge ipv4-static"
IP=192.168.1.102
PREFIX=24
BROADCAST=192.168.1.255
STP=no # Use Spanning Tree Protocol?
MTU=9000
# END ifconfig.br1
########################################################################
#!/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_warning_msg "\n${file} does not define an interface [IFACE]; hoping this
is a bridge..."
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 ${SERVICE}; 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
if [ -z "$IFACE" ] ; then
log_error_msg "\n${file} defines [CHECK_LINK], but not [IFACE]; no link to
check; exiting."
exit 1
fi
# 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
#QRUX - Link is up, so set MTU (if value is a positive int).
test -n "${MTU}" -a $MTU -eq $MTU -a 0 -lt $MTU 2> /dev/null && \
ip link set dev ${IFACE} mtu $MTU
fi
for S in ${SERVICE}; do
IFCONFIG=${file} /lib/services/${S} ${1} up
done
# End /sbin/ifup
#!/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 "${IFACE}" ]; then
#log_failure_msg "INTERFACES variable missing from ${IFCONFIG}"
#exit 1
#fi
# For clarity, set BRIDGE to $1
BRIDGE=$1
case "${2}" in
up)
log_info_msg2 "\n"
log_info_msg "Creating the ${BRIDGE} interface..."
brctl addbr ${BRIDGE}
ip link set ${BRIDGE} up
evaluate_retval
for IF in ${IFACE}; do
log_info_msg "Adding ${IF} to ${BRIDGE}..."
#QRUX - This should be done in /sbin/ifup
#QRUX ip link set ${IF} up &&
brctl addif ${BRIDGE} ${IF}
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 IF in ${IFACE}; do
log_info_msg "Removing ${IF} from ${BRIDGE}..."
#QRUX - This also prob needs to happen in /sbin/ifdown
#QRUX ip link set ${I} down &&
brctl delif ${BRIDGE} ${IF}
evaluate_retval
done
log_info_msg "Bringing down the ${BRIDGE} interface..."
ip link set ${BRIDGE} down
brctl delbr ${BRIDGE}
evaluate_retval
;;
*)
echo "Usage: ${0} [interface] {up|down}"
exit 1
;;
esac
# End /lib/services/bridge
#!/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
#QRUX - Not totally sure about this; is there a "real" use-case of a bridge
#QRUX - without an enslaved link?
log_warning_msg "${file} does not define an interface [IFACE]; hoping this is
a bridge..."
#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
#QRUX - This used to be a bug, where ${1} was ${IFACE}.
#QRUX - It needs to be symmetric to ifup, which is passing ${1}.
IFCONFIG=${file} /lib/services/${S} ${1} 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
--
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page