Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 29181 Details for
Bug 47659
baselayout-1.8.8: patch to enable iproute2 style network config
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
baselayout-1.8.8: patch to enable iproute2 style network config - fixed
rc-scripts-1.4.6-iproute2.diff (text/plain), 12.94 KB, created by
Dean Bailey
on 2004-04-12 21:29:22 UTC
(
hide
)
Description:
baselayout-1.8.8: patch to enable iproute2 style network config - fixed
Filename:
MIME Type:
Creator:
Dean Bailey
Created:
2004-04-12 21:29:22 UTC
Size:
12.94 KB
patch
obsolete
>diff -urH rc-scripts-1.4.6/etc/conf.d/net rc-scripts-1.4.6.new/etc/conf.d/net >--- rc-scripts-1.4.6/etc/conf.d/net 2002-11-18 11:39:22.000000000 -0800 >+++ rc-scripts-1.4.6.new/etc/conf.d/net 2004-04-12 19:14:48.806713280 -0700 >@@ -3,10 +3,22 @@ > > # Global config file for net.* rc-scripts > >-# This is basically the ifconfig argument without the ifconfig $iface >+#################################################################################################### >+# Old Style iface config examples ( depreciated ) # >+# NOTE: This uses /sbin/ifconfig and /sbin/route to set the network up # >+#################################################################################################### >+# iface_eth0="192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0" >+ >+# For adding aliases to a interface >+# alias_eth0="192.168.0.3 192.168.0.4" >+ >+# To add a custom netmask/broadcast address to created aliases. >+# broadcast_eth0="192.168.0.255 192.168.0.255" >+# netmask_eth0="255.255.255.0 255.255.255.0" >+ >+# For setting the default gateway > # >-iface_eth0="192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0" >-#iface_eth1="207.170.82.202 broadcast 207.0.255.255 netmask 255.255.0.0" >+# gateway="eth0/192.168.0.1" > > # For DHCP set iface_eth? to "dhcp" > # For passing options to dhcpcd use dhcpcd_eth? >@@ -14,21 +26,50 @@ > #iface_eth0="dhcp" > #dhcpcd_eth0="..." > >-# For adding aliases to a interface >-# >-#alias_eth0="192.168.0.3 192.168.0.4" >+################################################################################################### >+# New style ifconfig config examples. # >+# NOTE: This uses /sbin/ifconfig and /sbin/route to set the network up # >+################################################################################################### >+# This creates two aliases on the eth0 interface along with the primary eth0 address >+# ifconfig_eth0=( >+# "192.168.0.2 broadcast 192.168.0.255 netmask 255.255.255.0" >+# "192.168.0.3 broadcast 192.168.0.255 netmask 255.255.255.0" >+# "192.168.0.4 broadcast 192.168.0.255 netmask 255.255.255.0" >+# ) >+ >+# This is just like setting the gateway config option above, but allows one to add custom routes. >+# routes_eth0=( >+# "default gw 192.168.0.1" >+# ) > >-# NB: The next is only used for aliases. >-# >-# To add a custom netmask/broadcast address to created aliases, >-# uncomment and change accordingly. Leave commented to assign >-# defaults for that interface. >-# >-#broadcast_eth0="192.168.0.255 192.168.0.255" >-#netmask_eth0="255.255.255.0 255.255.255.0" >+# For DHCP set ifconfig_eth? to "dhcp" >+# For passing options to dhcpcd use dhcpcd_eth? >+# ifconfig_eth0=("dhcp") >+# dhcpcd_eth0="..." > >+################################################################################################### >+# This is the iproute2 style configuration # >+# NOTE: This makes use of the /sbin/ip command to set routes and ip addresses # >+# This style is very useful if you are building an advanced linux router or using VRRP # >+# For more information on how to use the iproute2 command have a look at the man page # >+# `man 8 ip` >+################################################################################################### >+# The follow example sets up two aliaes and the primary ip address on the device >+# You may also pass advanced ip addr commands via this option. >+# ipaddr_eth0=( >+# "192.168.0.2/24 brd 192.168.0.255" >+# "192.168.0.3/24 brd 192.168.0.255" >+# "192.168.0.4/24 brd 192.168.0.255" >+# ) >+ >+# The following will set up the default gateway. You can also pass advanced route configs via >+# this option. >+# iproute_eth0=( >+# "default via 192.168.0.1" >+# ) > >-# For setting the default gateway >-# >-#gateway="eth0/192.168.0.1" >+# For DHCP set ipaddr_eth? to "dhcp" >+# For passing options to dhcpcd use dhcpcd_eth? >+# ipaddr_eth0=("dhcp") >+# dhcpcd_eth0="..." > >diff -urH rc-scripts-1.4.6/init.d/net.eth0 rc-scripts-1.4.6.new/init.d/net.eth0 >--- rc-scripts-1.4.6/init.d/net.eth0 2004-03-15 20:08:50.000000000 -0800 >+++ rc-scripts-1.4.6.new/init.d/net.eth0 2004-04-12 18:41:22.157770288 -0700 >@@ -19,9 +19,10 @@ > } > > checkconfig() { >- if [[ -z "${ifconfig_IFACE}" ]]; then >+ if [[ -z "${ifconfig_IFACE}" ]] && [[ -z "${ipaddr_IFACE}" ]]; then > eerror "Please make sure that /etc/conf.d/net has \$ifconfig_$IFACE set" > eerror "(or \$iface_$IFACE for old-style configuration)" >+ eerror "(or \$ipaddr_$IFACE for the iproute2 way)" > return 1 > fi > if [[ -n "${vlans_IFACE}" && ! -x /sbin/vconfig ]]; then >@@ -34,11 +35,14 @@ > # The following variables are set, which should be declared local by > # the calling routine. > # status_IFACE (up or '') >-# vlans_IFACE (space-separated list) >+# vlans_IFACE (space-separated list) > # ifconfig_IFACE (array of ifconfig lines, replaces iface_IFACE) > # dhcpcd_IFACE (command-line args for dhcpcd) > # routes_IFACE (array of route lines) >-# inet6_IFACE (array of inet6 lines) >+# inet6_IFACE (array of inet6 lines) >+# ipaddr_IFACE (array of ip addr lines) >+# iproute_IFACE (array of ip route commands) >+ > setup_vars() { > local i iface="${1//\./_}" > >@@ -48,7 +52,10 @@ > eval dhcpcd_IFACE=\"\$\{dhcpcd_$iface\}\" > eval routes_IFACE=( \"\$\{routes_$iface\[@\]\}\" ) > eval inet6_IFACE=( \"\$\{inet6_$iface\[@\]\}\" ) >- >+ # iproute2 style config vars >+ eval ipaddr_IFACE=( \"\$\{ipaddr_$iface\[@\]\}\" ) >+ eval iproute_IFACE=( \"\$\{iproute_$iface\[@\]\}\" ) >+ > # BACKWARD COMPATIBILITY: populate the ifconfig_IFACE array > # if iface_IFACE is set (fex. iface_eth0 instead of ifconfig_eth0) > eval local iface_IFACE=\"\$\{iface_$iface\}\" >@@ -77,8 +84,45 @@ > iface_start() { > local IFACE=${1} i x > checkconfig || return 1 >+ >+ # Do dhcp if it is enabled in config >+ if [[ ${ifconfig_IFACE} = dhcp ]] || [[ ${ipaddr_IFACE} = dhcp ]]; then >+ # Check that eth0 was not brought up by the kernel ... >+ if [[ ${status_IFACE} == up ]]; then >+ einfo "Keeping kernel configuration for ${IFACE}" >+ else >+ ebegin "Bringing ${IFACE} up via DHCP" >+ /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >+ eend $? || return $? >+ fi >+ # Show address retrieved >+ i=$(ifconfig ${IFACE} | grep -m1 -o 'inet addr:[^ ]*' | cut -d: -f2) >+ [[ -n ${i} ]] && einfo " ${IFACE} received address ${i}" >+ # If not a dhcp interface, do ip address stype if config is in this format. >+ elif [[ -n ${ipaddr_IFACE} ]]; then >+ ebegin "Bringing ${IFACE} up" >+ # Force link to up as inet6 will not work without this >+ /sbin/ip link set dev ${IFACE} up &>${devnull} >+ # Why bother having the aliases in a diffrent section if they can be handled here >+ # This covers inet6 addresses as well >+ if [[ ${#ipaddr_IFACE[@]} -gt 0 ]]; then >+ for ((i = 0; i < ${#ipaddr_IFACE[@]}; i = i + 1)); do >+ if [[ ${i} > 0 ]]; then >+ einfo " ${IFACE}:${i} ${ipaddr_IFACE[i]%% *}" >+ /sbin/ip addr add dev ${IFACE} ${ipaddr_IFACE[i]} label ${IFACE}:${i} >${devnull} && \ >+ /sbin/ip addr show dev ${IFACE} | grep "${ipaddr_IFACE[i]%% *}" &>${devnull} >+ eend $? || return $? >+ else >+ einfo " ${IFACE} ${ipaddr_IFACE[i]%% *}" >+ /sbin/ip addr add dev ${IFACE} ${ipaddr_IFACE[i]} >${devnull} && \ >+ /sbin/ip addr show dev ${IFACE} | grep "${ipaddr_IFACE[i]%% *}" &>${devnull} >+ eend $? || return $? >+ fi > >- if [[ ${ifconfig_IFACE} != dhcp ]]; then >+ done >+ fi >+ # Last do ifconfig/iface style addresses >+ elif [[ -n ${ifconfig_IFACE} ]]; then > # Show the address, but catch if this interface will be inet6 only > i=${ifconfig_IFACE%% *} > if [[ ${i} == *.*.*.* ]]; then >@@ -90,21 +134,10 @@ > /sbin/ifconfig ${IFACE} ${ifconfig_IFACE} >${devnull} && \ > /sbin/ifconfig ${IFACE} &>${devnull} > eend $? || return $? >- else >- # Check that eth0 was not brought up by the kernel ... >- if [[ ${status_IFACE} == up ]]; then >- einfo "Keeping kernel configuration for ${IFACE}" >- else >- ebegin "Bringing ${IFACE} up via DHCP" >- /sbin/dhcpcd ${dhcpcd_IFACE} ${IFACE} >- eend $? || return $? >- fi >- # Show address retrieved >- i=$(ifconfig ${IFACE} | grep -m1 -o 'inet addr:[^ ]*' | cut -d: -f2) >- [[ -n ${i} ]] && einfo " ${IFACE} received address ${i}" > fi >- >- if [[ ${#ifconfig_IFACE[@]} -gt 1 ]]; then >+ # Only add aliases if in ifconfig/iface format as when in ipaddr format >+ # aliases get added along with the primary ip address. >+ if [[ ${#ifconfig_IFACE[@]} -gt 1 ]] && [[ -z ${ipaddr_IFACE} ]]; then > einfo " Adding aliases" > for ((i = 1; i < ${#ifconfig_IFACE[@]}; i = i + 1)); do > ebegin " ${IFACE}:${i} (${ifconfig_IFACE[i]%% *})" >@@ -112,8 +145,8 @@ > eend $? > done > fi >- >- if [[ -n ${inet6_IFACE} ]]; then >+ # Only add inet6 addresses if not using ipaddr format. >+ if [[ -n ${inet6_IFACE} ]] && [[ -z ${ipaddr_IFACE} ]]; then > einfo " Adding inet6 addresses" > for ((i = 0; i < ${#inet6_IFACE[@]}; i = i + 1)); do > ebegin " ${IFACE} inet6 add ${inet6_IFACE[i]}" >@@ -121,9 +154,16 @@ > eend $? > done > fi >- >- # Set static routes >- if [[ -n ${routes_IFACE} ]]; then >+ # Set routes with ip route and print them - this can also include default route >+ if [[ -n ${iproute_IFACE} ]]; then >+ einfo " Adding routes" >+ for ((i = 0; i < ${#iproute_IFACE[@]}; i = i + 1)); do >+ ebegin " ${iproute_IFACE[i]}" >+ /sbin/ip route add dev ${IFACE} ${iproute_IFACE[i]} >+ eend $? >+ done >+ # Set static routes with the route command only if iproute was not called >+ elif [[ -n ${routes_IFACE} ]] ; then > einfo " Adding routes" > for ((i = 0; i < ${#routes_IFACE[@]}; i = i + 1)); do > ebegin " ${routes_IFACE[i]}" >@@ -131,7 +171,6 @@ > eend $? > done > fi >- > # Set default route if applicable to this interface > if [[ ${gateway} == ${IFACE}/* ]]; then > local ogw=$(/bin/netstat -rn | awk '$1 == "0.0.0.0" {print $2}') >@@ -177,60 +216,47 @@ > # iface_start ran. Instead query for current configuration and bring > # down the interface. > iface_stop() { >- local IFACE=${1} i x aliases inet6 count >- >- # Try to do a simple down (no aliases, no inet6, no dhcp) >- aliases="$(/sbin/ifconfig | grep -o "^$IFACE:[0-9]*" | tac)" >- inet6="$(ifconfig ${IFACE} | awk '$1 == "inet6" {print $2}')" >- if [[ -z ${aliases} && -z ${inet6} && ! -e /var/run/dhcpcd-${IFACE}.pid ]]; then >+ local IFACE=${1} i x count addresses >+ # Check and see if interface is dhcp, if so release ip the address. >+ # This should stop the interface if the only address on it is DHCP. >+ if [[ -e /var/run/dhcpcd-${IFACE}.pid ]]; then >+ ebegin "Releasing DHCP lease for ${IFACE}" >+ for ((count = 0; count < 9; count = count + 1)); do >+ /sbin/dhcpcd -z ${i} &>${devnull} || break >+ sleep 1 >+ done >+ [[ ${count} -lt 9 ]] >+ eend $? "Timed out" >+ fi >+ >+ # Gather a list of all the addresses on the specified interface. >+ # inet6 addresses will be in the list along with inet addresses. >+ addresses="$(/sbin/ip address show ${IFACE} | grep 'inet.*' | awk '{print $2}' | tac)" >+ # Bring down each ip address on interface, this can be inet or inet6. >+ # This is done in reverse order to stop any possible errors that >+ # might crop up. Removing a primary address will cause all secondary >+ # address on the interface that are on the same subnet to dissapear. >+ if [[ -n ${addresses} ]]; then > ebegin "Bringing ${IFACE} down" >- /sbin/ifconfig ${IFACE} down &>/dev/null >- eend 0 >- return 0 >- fi >- >- einfo "Bringing ${IFACE} down" >- >- # Stop aliases before primary interface. >- # Note this must be done in reverse order, since ifconfig eth0:1 >- # will remove eth0:2, etc. It might be sufficient to simply remove >- # the base interface but we're being safe here. >- for i in ${aliases} ${IFACE}; do >- >- # Delete all the inet6 addresses for this interface >- inet6="$(ifconfig ${i} | awk '$1 == "inet6" {print $2}')" >- if [[ -n ${inet6} ]]; then >- einfo " Removing inet6 addresses" >- for x in ${inet6}; do >- ebegin " ${IFACE} inet6 del ${x}" >- /sbin/ifconfig ${i} inet6 del ${x} >- eend $? >- done >- fi >- >- # Stop DHCP (should be N/A for aliases) >- # Don't trust current configuration... investigate ourselves >- if /sbin/dhcpcd -z ${i} &>${devnull}; then >- ebegin " Releasing DHCP lease for ${IFACE}" >- for ((count = 0; count < 9; count = count + 1)); do >- /sbin/dhcpcd -z ${i} &>${devnull} || break >- sleep 1 >- done >- [[ ${count} -lt 9 ]] >- eend $? "Timed out" >- fi >- ebegin " Stopping ${i}" >- /sbin/ifconfig ${i} down &>${devnull} >- eend 0 >- done >- >+ for x in ${addresses}; do >+ ebegin " ${IFACE} del ${x}" >+ /sbin/ip addr del dev ${IFACE} ${x} >+ eend $? >+ done >+ fi >+ # Stop the interface if it shows link state to be up. >+ if /sbin/ip address show ${IFACE} | grep -o "UP" &>${devnull}; then >+ ebegin " Stopping ${IFACE}" >+ /sbin/ip link set dev ${IFACE} down &>${devnull} >+ eend $? >+ fi > return 0 > } > > start() { > # These variables are set by setup_vars > local status_IFACE vlans_IFACE dhcpcd_IFACE >- local -a ifconfig_IFACE routes_IFACE inet6_IFACE >+ local -a ifconfig_IFACE routes_IFACE inet6_IFACE iproute_IFACE ipaddr_IFACE > > # Call user-defined preup function if it exists > if [[ $(type -t preup) == function ]]; then
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 47659
:
29178
| 29181 |
31244
|
31247