On Feb 25, 2012, at 8:12 PM, Bruce Dubbs wrote:

> Qrux wrote:
> 
>> Probably something like:
>> 
>>      BRIDGE_PORTS="eth0 eth1"
> 
> It's getting complicated.  We then need to consider address1, dhcp2, 
> etc.  What we have now works for kvm, but a general solution is more 
> difficult.

No...I think you're thinking about an IP_FORWARD dual-homed situation, which 
would be two separate ifconfig.{X,Y} files.  A bridge doesn't have that 
configuration.  It's a single IP for the bridge interface, not the two 
separates ports.  Should look like this:

+---------------+
|               |
| LAN SEGMENT 1 | - Let's say it's 192.168.0/24 with 3 hosts .5, .7, .9
|               |
+-------+-------+
        |
        | bridge-host PHY: eth0 (MTU = 1500)
        |
+---------------+
|               |
|  Bridge Host  | - Let's say 192.168.0.1/24.  It just lives on both networks.
|               |
+-------+-------+
        |
        | bridge-host PHY: eth1 (MTU = 9000)
        |
+---------------+
|               |
| LAN SEGMENT 2 | - Let's say it's 192.168.0/24 with 4 hosts .2, .4, .6, .8
|               |
+-------+-------+

But, that's beside the point...A bridge and a bonded interface (AFAIK), are the 
only logical connection types that have multiple PHYS linked together.  But, 
even in those cases, the single logical interface defined per config file 
(which is all we care about) should only have a single IP address.  So, we 
don't have to pass multiple IPV4 configuration parameters for each logical 
connection.  It's just one.

Where we actually do multiple settings is for something like bridge MTUs.  In 
the drawing above, if segment 1 uses an MTU of 1500, but segment 2 uses 9000, 
we have to set it for each.  That should be as simple as this:

        PHYS="eth0 eth1"
        MTU"1500 9000"
        <all other bridge settings stay the same>

Or, if both use the default, then we just avoid setting it.  If both use jumbo 
frames (or any other setting), my solution just uses the singular value.  Like 
this:

        PHYS="eth0 eth1"
        MTU="9000"

where both eth0 and eth1 will get an MTU of 9000.

======================================================================

Here's my "general solution" config file:

        ONBOOT=yes
        PHYS="eth1"
        MTU=9000                       # phy-specific
        SERVICE="bridge ipv4-static"
        BRIDGE_IF="br1"                # bridge-specific
        STP=no                         # bridge-specific
        IPV4_IF="br1"                  # ipv4-specific
        IP=192.168.1.102               # ipv4-specific
        PREFIX=24                      # ipv4-specific

The changes are mostly that instead of having ifup/ifdown setting ${IFCONFIG} 
as an envvar to each service script (seems messy), just pass the 
config-file-path.  I've changed ${IFACE} to ${PHYS} to make things more clear. 
There are two new service-specific variables:

        * BRIDGE_IF
        * IPV4_IF

Which, in the case of a bridge, are necessary.  Plus, we don't have to argue 
about using ${1} or ${PHY} (which no longer make sense in the case where you're 
using a hardware bridge with 2 NICs--like my drawing--as opposed to a kvm/Xen 
bridge).

I also handle the default case pretty nicely (only one PHY which matches 
${IPV4_IF}): it's absolutely the same as the default config:

        ONBOOT=yes
        PHYS="eth0"
        SERVICE="ipv4-static"
        IP=10.0.0.102
        PREFIX=24

because I've changed ipv4-static to use the first ${PHYS} if no ${IPV4_IF} is 
defined.  Anyway, here's the patch (all four files: ifup, ifdown, bridge, 
ipv4-static) which is working for me on my bridged configuration.  Maybe 
someone with a non-bridged setup can tell me if it's working for them, too.

        Q



--- /sbin/ifup-BLFS     2012-02-25 20:34:29.916457718 -0800
+++ /sbin/ifup  2012-02-25 21:00:47.997339357 -0800
@@ -10,7 +10,7 @@
 #
 # Version     : LFS 7.0
 #
-# Notes       : The IFCONFIG variable is passed to the SERVICE script
+# Notes       : The ${file} variable is passed to the SERVICE script
 #               in the /lib/services directory, to indicate what file the
 #               service should source to get interface specifications.
 #
@@ -55,8 +55,6 @@
 
 . /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
@@ -64,11 +62,6 @@
 
 . $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
@@ -76,39 +69,67 @@
   exit 0
 fi
 
+log_info_msg "Bringing up the ${1} interface... "
+
+if [ -z "$PHYS" ]; then
+  log_failure_msg "\n${file} does not define any physical interfaces [PHYS]."
+  exit 1
+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."
+   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
+PHY_IDX=0
+for PHY in $PHYS ; do
+  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 ${PHY} > /dev/null 2>&1; then
+       link_status=`ip link show ${PHY}`
+
+       if [ -n "${link_status}" ]; then
+          if ! echo "${link_status}" | grep -q UP; then
+             ip link set ${PHY} up
+          fi
+       fi
+
+    else
+       log_warning_msg "\nInterface ${PHY} doesn't exist."
+       exit 0
+    fi
+
+    # Link is up, so set MTU
+    if test -n "${MTU}"; then
+      # Use the proper MTU if there are multiple MTUs set in ${MTU}.
+      M=$(echo $MTU | awk -v idx=$PHY_IDX '{printf("%s", $idk);}')
+
+      # If there is only one ${MTU}, but multiple ${PHYS}, use ${MTU}.
+      test -z ${M} && M="${MTU}"
+
+      # Check if MTU has a "good" value.
+      if [ ${M} -gt 0 ] ; then
+        ip link set dev ${PHY} mtu ${M}
+      else
+        echo "Invalid MTU ${M}"
+      fi
+    fi
   fi
-fi
+
+  PHY_IDX=$((1 + ${PHY_IDX}))
+done
 
 for S in ${SERVICE}; do 
- IFCONFIG=${file} /lib/services/${S} ${IFACE} up
+  /lib/services/${S} ${file} up
 done
 
 # End /sbin/ifup
--- /lib/services/bridge-BLFS   2012-02-25 20:34:48.244888569 -0800
+++ /lib/services/bridge        2012-02-25 21:00:47.993339261 -0800
@@ -12,24 +12,30 @@
 ########################################################################
 
 . /lib/lsb/init-functions
+
+if [ -z ${1} ] ; then
+  log_failure_msg "No ifconfig file specified"
+  exit 1
+fi
+IFCONFIG=$1
 . ${IFCONFIG}
 
-if [ -n "${INTERFACE}" ]; then
-  log_failure_msg "INTERFACES variable missing from ${IFCONFIG}"
+# Call the bridge ${BRIDGE_IF} for clarity.
+if [ -z ${BRIDGE_IF} ]; then
+  log_failure_msg "BRIDGE_IF 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
+     log_info_msg "Creating the ${BRIDGE_IF} interface..."
+     brctl addbr ${BRIDGE_IF}
+     ip link set ${BRIDGE_IF} up
      evaluate_retval
-     for I in ${INTERFACES}; do
-        log_info_msg "Adding ${I} to ${1}..."
-        ip link set ${I} up &&
-        brctl addif ${1} ${I}
+     for PHY in ${PHYS}; do
+        log_info_msg "Adding ${PHY} to ${BRIDGE_IF}..."
+        brctl addif ${BRIDGE_IF} ${PHY}
         evaluate_retval
      done
 
@@ -44,21 +50,20 @@
   ;;
 
   down)
-     for I in ${INTERFACES}; do
-        log_info_msg "Removing ${I} from ${1}..."
-        ip link set ${I} down &&
-        brctl delif ${1} ${I}
+     for PHY in ${PHYS}; do
+        log_info_msg "Removing ${PHY} from ${BRIDGE_IF}..."
+        brctl delif ${BRIDGE_IF} ${PHY}
         evaluate_retval
      done
 
-     log_info_msg "Bringing down the ${1} interface..."
-     ip link set ${1} down
-     brctl delbr ${1}
+     log_info_msg "Bringing down the ${BRIDGE_IF} interface..."
+     ip link set ${BRIDGE_IF} down
+     brctl delbr ${BRIDGE_IF}
      evaluate_retval
   ;;
 
   *)
-     echo "Usage: ${0} [interface] {up|down}"
+     echo "Usage: ${0} <ifconfig-file> {up|down}"
      exit 1
   ;;
 esac
--- /lib/services/ipv4-static-BLFS      2012-02-25 20:34:56.885090831 -0800
+++ /lib/services/ipv4-static   2012-02-25 21:00:47.993339261 -0800
@@ -13,6 +13,12 @@
 ########################################################################
 
 . /lib/lsb/init-functions
+
+if [ -z ${1} ] ; then
+  log_failure_msg "No ifconfig file specified"
+  exit 1
+fi
+IFCONFIG=$1
 . ${IFCONFIG}
 
 if [ -z "${IP}" ]; then
@@ -20,6 +26,9 @@
   exit 1
 fi
 
+# If there are multiple ${PHYS}, then use the first.
+test -z $IPV4_IF && IPV4_IF="$(echo ${PHYS} | awk '{print $1}')"
+
 if [ -z "${PREFIX}" -a -z "${PEER}" ]; then
   log_warning_msg "\nPREFIX variable missing from ${IFCONFIG}, assuming 24."
   PREFIX=24
@@ -42,15 +51,15 @@
 
 case "${2}" in
   up)
-     if [ "$(ip addr show ${1} 2>/dev/null | grep ${IP})" == "" ]; then
+     if [ "$(ip addr show ${IPV4_IF} 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}
+        log_info_msg "Adding IPv4 address ${IP} to the ${IPV4_IF} interface..."
+        ip addr add ${args} dev ${IPV4_IF}
         evaluate_retval
 
         if [ -n "${GATEWAY}" ]; then
@@ -58,26 +67,26 @@
               log_warning_msg "\nGateway already setup; skipping."
            else
               log_info_msg "Setting up default gateway..."
-              ip route add default via ${GATEWAY} dev ${1}
+              ip route add default via ${GATEWAY} dev ${IPV4_IF}
               evaluate_retval
             fi
         fi
      else
-        msg="Cannot add IPv4 address ${IP} to ${1}.  Already present."
+        msg="Cannot add IPv4 address ${IP} to ${IPV4_IF}.  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}
+     if [ "$(ip addr show ${IPV4_IF} 2>/dev/null | grep ${IP})" != "" ]; then
+        log_info_msg "Removing IPv4 address ${IP} from the ${IPV4_IF} 
interface..."
+        ip addr del ${args} dev ${IPV4_IF}
         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
+        if [ "$(ip addr show ${IPV4_IF} 2>/dev/null | grep 'inet ')" != "" ]; 
then
            log_info_msg "Removing default gateway..."
            ip route del default
            evaluate_retval
@@ -86,7 +95,7 @@
   ;;
 
   *)
-     echo "Usage: ${0} [interface] {up|down}"
+     echo "Usage: ${0} <interface> {up|down}"
      exit 1
   ;;
 esac
--- /sbin/ifdown-BLFS   2012-02-25 20:34:38.812667571 -0800
+++ /sbin/ifdown        2012-02-25 21:00:47.997339357 -0800
@@ -10,7 +10,7 @@
 #
 # Version     : LFS 7.0
 #
-# Notes       : the IFCONFIG variable is passed to the scripts found
+# Notes       : the ${file} variable is passed to the scripts found
 #               in the /lib/services directory, to indicate what file the
 #               service should source to get interface specifications.
 #
@@ -62,8 +62,8 @@
 
 . ${file}
 
-if [ "$IFACE" = "" ]; then
-  log_failure_msg "${file} does not define an interface [IFACE]."
+if [ -z "$PHYS" ]; then
+  log_failure_msg "${file} does not define any physical interfaces [PHYS]."
   exit 1
 fi
 
@@ -72,33 +72,46 @@
 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
+EXISTING_INTERFACES=
+for PHY in ${PHYS} ; do
+  if ip link show ${PHY} > /dev/null 2>&1 ; then
+    EXISTING_INTERFACES="${EXISTING_INTERFACES} ${PHY}"
+  else
+    log_warning_msg "Interface ${PHY} doesn't exist."
+  fi
+done
+
+if [ -n "${EXISTING_INTERFACES}" ] ; then
   for S in ${SERVICES}; do
 
     if [ -n "${S}" -a -x "/lib/services/${S}" ]; then
-      IFCONFIG=${file} /lib/services/${S} ${IFACE} down
+      IFCONFIG=${file} /lib/services/${S} ${file} 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."
+      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`
+  for PHY in "${EXISTING_INTERFACES}" ; do
+    link_status=`ip link show ${PHY} 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
+    if [ -n "${link_status}" ]; then
+      if [ "$(echo "${link_status}" | grep UP)" != "" ]; then
+         #QRUX - Why does it matter if ${PHY} has an IP address?
+         #QRUX - Seems like it should be taken it down regardless.
+         if [ "$(ip addr show ${PHY} | grep 'inet ')" != ""  ]; then
+            log_info_msg "Bringing down the ${PHY} interface..."
+            ip link set ${PHY} down
+            evaluate_retval
+         fi
+      fi
+    fi
+  done
+else
+  log_warning_msg "No interfaces among (${PHYS}) exist."
 fi
 
 # End /sbin/ifdown

-- 
http://linuxfromscratch.org/mailman/listinfo/lfs-dev
FAQ: http://www.linuxfromscratch.org/faq/
Unsubscribe: See the above information page

Reply via email to