Provide large warnings when net-tools functionality is used. Add documentation in rc.conf for the new iproute2 based config. --- PKGBUILD | 7 ++-- network | 118 ++++++++++++++++++++++++++++++++++++++++++++---------------- rc.conf | 40 +++++--------------- rc.sysinit | 2 +- 4 files changed, 102 insertions(+), 65 deletions(-) diff --git a/PKGBUILD b/PKGBUILD index c5f2acd..5c9764c 100644 --- a/PKGBUILD +++ b/PKGBUILD @@ -9,9 +9,10 @@ groups=('base') conflicts=('initscripts') provides=('initscripts=9999') backup=(etc/inittab etc/rc.conf etc/rc.local etc/rc.local.shutdown) -depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1' - 'net-tools' 'ncurses' 'kbd' 'findutils' 'sysvinit') -optdepends=('bridge-utils: Network bridging support' +depends=('glibc' 'bash' 'grep' 'coreutils' 'udev>=139-1' 'iproute2' + 'ncurses' 'kbd' 'findutils' 'sysvinit') +optdepends=('net-tools: legacy networking support' + 'bridge-utils: Network bridging support' 'dhcpcd: DHCP network configuration' 'wireless_tools: Wireless networking') source=() diff --git a/network b/network index 9cd6109..7350149 100755 --- a/network +++ b/network @@ -7,6 +7,49 @@ for s in wireless bonding bridges dhcpcd; do [[ -f /etc/conf.d/$s ]] && . "/etc/conf.d/$s" done +# helper function to determine if legacy network support is needed +need_legacy() { + if [[ -z $interface ]]; then + return 0 # need legacy + fi + + return 1 # enough present for iproute2 support +} + +deprecated() { + printf "${C_FAIL}Warning:${C_CLEAR} This functionality is deprecated.\n" + printf " Please refer to /etc/rc.conf on how to define a single wired\n" + printf " connection, or use a utility such as netcfg.\n" +} + +network_up() { + /usr/sbin/ip link set dev $interface up || return 1 + + if [[ $address ]]; then + for var in netmask gateway; do + if [[ -z ${!var} ]]; then + printf "${C_FAIL}Error: static address defined without $var!\n" + return 1 + fi + done + /usr/sbin/ip addr add $address/$netmask dev $interface || return 1 + /usr/sbin/ip route add default via $gateway || return 1 + else + /sbin/dhcpcd $DHCPCD_ARGS $interface || return 1 + fi +} + +network_down() { + if [[ -f /var/run/dhcpcd-$interface.pid ]]; then + /sbin/dhcpcd -k $interface || return 1 + else + /usr/sbin/ip route del default || return 1 + /usr/sbin/ip addr flush dev $interface || return 1 + fi + + /usr/sbin/ip link set dev $interface down || return 1 +} + ifup() { local ifcfg=${!1} @@ -179,29 +222,34 @@ bridge_down() { case "$1" in start) + # deprecation check + need_legacy && deprecated if ! ck_daemon network; then echo "Network is already running. Try 'network restart'" exit fi - stat_busy "Starting Network" error=0 - # bring up bridge interfaces - bridge_up - # bring up ethernet interfaces - for ifline in ${INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then - ifup $ifline || error=1 - fi - done - # bring up bond interfaces - bond_up - # bring up routes - for rtline in "${ROUTES[@]}"; do - if [ "$rtline" = "${rtline#!}" ]; then - rtup $rtline || error=1 - fi - done + if need_legacy; then + # bring up bridge interfaces + bridge_up + # bring up ethernet interfaces + for ifline in ${INTERFACES[@]}; do + if [[ $ifline = ${ifline#!} ]]; then + ifup $ifline || error=1 + fi + done + # bring up bond interfaces + bond_up + # bring up routes + for rtline in "${ROUTES[@]}"; do + if [ "$rtline" = "${rtline#!}" ]; then + rtup $rtline || error=1 + fi + done + else + network_up + fi if ((error == 0)); then add_daemon network stat_done @@ -210,6 +258,8 @@ case "$1" in fi ;; stop) + # deprecation check + need_legacy && deprecated if [[ $NETWORK_PERSIST =~ yes|YES && $RUNLEVEL == [06] ]]; then status "Skipping Network Shutdown" true exit 0 @@ -218,20 +268,24 @@ case "$1" in stat_busy "Stopping Network" rm_daemon network error=0 - for rtline in "${ROUTES[@]}"; do - if [[ $rtline = ${rtline#!} ]]; then - rtdown $rtline || error=1 - fi - done - # bring down bond interfaces - bond_down - for ifline in ${INTERFACES[@]}; do - if [[ $ifline = ${ifline#!} ]]; then - ifdown $ifline || error=1 - fi - done - # bring down bridge interfaces - bridge_down + if need_legacy; then + for rtline in "${ROUTES[@]}"; do + if [[ $rtline = ${rtline#!} ]]; then + rtdown $rtline || error=1 + fi + done + # bring down bond interfaces + bond_down + for ifline in ${INTERFACES[@]}; do + if [[ $ifline = ${ifline#!} ]]; then + ifdown $ifline || error=1 + fi + done + # bring down bridge interfaces + bridge_down + else + network_down + fi if ((error == 0)); then stat_done else @@ -244,6 +298,8 @@ case "$1" in $0 start ;; ifup|ifdown|iflist|rtup|rtdown|rtlist) + # deprecation check + need_legacy && deprecated $1 $2 ;; *) diff --git a/rc.conf b/rc.conf index 89ea27e..5ebcd35 100644 --- a/rc.conf +++ b/rc.conf @@ -59,44 +59,24 @@ USELVM="no" # HOSTNAME="myhost" -# Use 'ifconfig -a' or 'ls /sys/class/net/' to see all available interfaces. +# Use 'ip addr' or 'ls /sys/class/net/' to see all available interfaces. # -# Interfaces to start at boot-up (in this order) -# Declare each interface then list in INTERFACES -# - prefix an entry in INTERFACES with a ! to disable it -# - no hyphens in your interface names - Bash doesn't like it +# Wired network setup +# - interface: name of device (required) +# - address: IP address (leave blank for DHCP) +# - netmask: subnet mask (ignored for DHCP) +# - gateway: default route (ignored for DHCP) # -# DHCP: Set your interface to "dhcp" (eth0="dhcp") -# Wireless: See network profiles below -# - -#Static IP example -#eth0="eth0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255" -eth0="dhcp" -INTERFACES=(eth0) -# Routes to start at boot-up (in this order) -# Declare each route then list in ROUTES -# - prefix an entry in ROUTES with a ! to disable it -# -gateway="default gw 192.168.0.1" -ROUTES=(!gateway) +interface= +address= +netmask= +gateway= # Setting this to "yes" will skip network shutdown. # This is required if your root device is on NFS. NETWORK_PERSIST="no" -# Enable these network profiles at boot-up. These are only useful -# if you happen to need multiple network configurations (ie, laptop users) -# - set to 'menu' to present a menu during boot-up (dialog package required) -# - prefix an entry with a ! to disable it -# -# Network profiles are found in /etc/network.d -# -# This now requires the netcfg package -# -#NETWORKS=(main) - # ----------------------------------------------------------------------- # DAEMONS # ----------------------------------------------------------------------- diff --git a/rc.sysinit b/rc.sysinit index 5a21539..9d30da2 100755 --- a/rc.sysinit +++ b/rc.sysinit @@ -115,7 +115,7 @@ run_hook sysinit_udevsettled # bring up the loopback interface [[ -d /sys/class/net/lo ]] && \ - status "Bringing up loopback interface" /sbin/ifconfig lo 127.0.0.1 up + status "Bringing up loopback interface" /usr/sbin/ip link set up dev lo # FakeRAID devices detection if [[ $USEDMRAID =~ yes|YES && -x /sbin/dmraid ]]; then -- 1.7.5.2