4 PATH=/sbin:/usr/sbin:/bin:/usr/bin
6 . /etc/sysconfig/network
7 . /etc/rc.d/init.d/functions
8 . /lib/rc-scripts/functions.network
10 # Will be removed in the future
11 if is_yes "$NETWORKING"; then
12 if [ -z "$IPV4_NETWORKING" ]; then
13 echo "NETWORKING is set to YES, but IPV4_NETWORKING is empty!"
14 echo "Please upgrade your config"
15 echo "Assuming you want IPv4 networking"
17 export IPV4_NETWORKING
23 # device name must be ifcfg-somename
27 nls "Usage: %s <device name>" "ifup" >&2
31 if [ $(id -u) != 0 ]; then
32 if [ -x /sbin/usernetctl ]; then
33 exec /sbin/usernetctl $DEV up
35 nls "Users cannot control this device." >&2
39 if [ -f "/etc/sysconfig/interfaces/ifcfg-$DEV" ]; then
40 CONFIG="/etc/sysconfig/interfaces/ifcfg-$DEV"
41 elif [ -f "/etc/sysconfig/interfaces/$DEV" ]; then
42 CONFIG="/etc/sysconfig/interfaces/$DEV"
49 if [ "foo$2" = "fooboot" ] && is_no "${ONBOOT}"; then
53 if [ "foo$2" = "foohotplug" ] && ! is_yes "${HOTPLUG}"; then
57 if [ "foo$2" = "foopcmcia-hotplug" ] && ! is_yes "${PCMCIA_HOTPLUG}"; then
63 # set all major variables
66 SYSCTLDEVICE=$(echo ${DEVICE} | sed 's/\./\//g')
68 OTHERSCRIPT="/lib/rc-scripts/ifup-${DEVICETYPE}"
70 if [ -x "$OTHERSCRIPT" ]; then
71 if is_yes "$DEFAULTHANDLING"; then
74 if [ "$HANDLING" = "0" ]; then
75 exec $OTHERSCRIPT $CONFIG $2
76 elif [ "$HANDLING" = "1" ]; then
77 $OTHERSCRIPT $CONFIG $2
81 if [ -n "$MACVLAN_DEV" -a -n "$MACVLAN_MACADDR" ]; then
82 ip link del link ${MACVLAN_DEV} ${DEVICE} type macvlan > /dev/null 2>&1
83 ip link add link ${MACVLAN_DEV} address ${MACVLAN_MACADDR} name ${DEVICE} type macvlan
86 # is this device available? (this catches PCMCIA devices for us)
87 if ! /sbin/ip link set multicast ${MULTICAST} dev ${DEVICE} > /dev/null 2>&1; then
88 nls "Delaying %s initialization" ${DEVICE}
92 if [ -n "$MACADDR" ]; then
93 ip link set ${DEVICE} address ${MACADDR}
96 ip link set ${DEVICE} multicast ${MULTICAST} ${ARP} down
98 if [ -n "$MTU" ]; then
99 ip link set ${DEVICE} mtu ${MTU}
102 if is_yes "${IPV6_NETWORKING}" && is_yes "${IPV6_DISABLE_AUTOCONF}"; then
103 run_cmd "Disabling IPv6 autoconfiguration" sysctl -w net.ipv6.conf.${SYSCTLDEVICE}.autoconf=0
106 if is_wireless_device "${DEVICE}"; then
107 is_yes "${WLAN_UPEARLY}" && ip link set ${DEVICE} up
108 wireless_param ${DEVICE}
111 if is_yes "${WLAN_WPA}"; then
112 /usr/sbin/wpa_supplicant -D ${WLAN_WPA_DRIVER:-wext} -c ${WLAN_WPA_CONFIG:-/etc/wpa_supplicant.conf} -i ${DEVICE} ${WLAN_WPA_OPTIONS} -P "/var/run/wpa_supplicant-${DEVICE}.pid" -B
113 [ -z "$WLAN_WPA_WAIT_TIMEOUT" ] && WLAN_WPA_WAIT_TIMEOUT=15
114 # check_link_down sleeps for 0.5s
115 check_link_down ${DEVICE} $(( $WLAN_WPA_WAIT_TIMEOUT * 2 ))
118 if [ -n "$ETHTOOL_OPTS" ] ; then
119 /sbin/ethtool -s $DEVICE $ETHTOOL_OPTS
122 if is_yes "$SLAVE" && [ -n "$MASTER" ] ; then
123 if ! grep -wq "${DEVICE}" /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null; then
124 nls "Enslaving %s to %s" "$DEVICE" "$MASTER"
125 ip link set dev ${DEVICE} down
126 echo "+${DEVICE}" > /sys/class/net/${MASTER}/bonding/slaves 2>/dev/null
131 if [ "$HANDLING" = "2" ]; then
135 if [ -n "$BOOTPROTO" -a "$BOOTPROTO" != "none" -a "$BOOTPROTO" != "static" ]; then
136 if is_yes "$IPV4_NETWORKING"; then
140 if [ -n "$DHCP_CLIENT" ]; then
141 if [ -z "$DHCP_HOSTNAME" ]; then
142 # set DHCP_HOSTNAME only basename
143 DHCP_HOSTNAME=${HOSTNAME%%.*}
145 case ${DHCP_CLIENT##*/} in
147 [ -n "$DHCP_HOSTNAME" ] && DHCP_ARGS="-h $DHCP_HOSTNAME"
148 DHCP_ARGS="$DHCP_ARGS -i $DEVICE"
151 [ -n "$DHCP_HOSTNAME" ] && DHCP_ARGS="-h $DHCP_HOSTNAME"
152 DHCP_ARGS="$DHCP_ARGS $DEVICE"
153 if is_no "$ZEROCONF"; then
154 DHCP_ARGS="$DHCP_ARGS --noipv4ll"
158 [ -n "$DHCP_HOSTNAME" ] && DHCP_ARGS="-H $DHCP_HOSTNAME"
159 DHCP_ARGS="$DHCP_ARGS $DEVICE"
162 # Can't specify a host with dhclient ?
163 DHCP_ARGS="$DEVICE -pf /var/run/dhclient.$DEVICE.pid -lf /var/lib/dhclient/dhclient.$DEVICE.leases"
164 if [ -f /etc/dhclient.$DEVICE.conf ] ; then
165 DHCP_ARGS="$DHCP_ARGS -cf /etc/dhclient.$DEVICE.conf"
169 DHCP_ARGS="-D $DEVICE"
173 DHCP_ARGS="$DHCP_OPTIONS $DHCP_ARGS"
175 if check_link_down ${DEVICE}; then
176 run_cmd "$(nls 'Determining IP information for %s (%s)' "$DEVICE" "${DHCP_CLIENT##*/}")" /bin/false
177 nls '%s: Check cable/radio on-off switch?' "$DEVICE"
181 if ! run_cmd "$(nls 'Determining IP information for %s (%s)' "$DEVICE" "${DHCP_CLIENT##*/}")" $DHCP_CLIENT $DHCP_ARGS; then
185 # give time for determining IP information
186 check_device_down && sleep 1 && check_device_down && sleep 3
187 check_device_down && ip link set ${DEVICE} up
191 if is_yes "$IPV4_NETWORKING" && [ -n "${IP4ADDR}" ]; then
192 # If broadcast is missing then autocalculate it
193 if ! (echo $IP4ADDROPT | grep -qE "brd|broadcast"); then
194 IP4ADDROPT="brd + ${IP4ADDROPT}"
197 if [ -n "${SUBDEVICE}" ]; then
198 ALIAS="label ${SUBDEVICE}"
201 if [ -n "$REMIP" ]; then
202 ip addr add ${IP4ADDR} peer ${REMIP} ${ALIAS} dev ${DEVICE} ${IP4ADDROPT}
204 ip addr add ${IP4ADDR} ${ALIAS} dev ${DEVICE} ${IP4ADDROPT}
209 ip link set ${DEVICE} up
212 if is_yes "$IPV6_NETWORKING" && [ -n "${IP6ADDR}" ]; then
213 ip addr add ${IP6ADDR} dev ${DEVICE} ${IP6ADDROPT}
214 if [ -n "${IP6ADDRLABEL}" ]; then
215 ip addrlabel add prefix ${IP6ADDR} dev ${DEVICE} label ${IP6ADDRLABEL}
219 if is_yes "$IPV4_NETWORKING" && [ -n "${IP4ADDR}" -a -x /sbin/arping ]; then
220 # update ARP cache of neighbouring computers
221 /sbin/arping -q -A -c 1 -I ${DEVICE} ${IP4ADDR%/*}
222 { ( sleep 2; /sbin/arping -q -U -c 1 -I ${DEVICE} ${IP4ADDR%/*} ) & } > /dev/null 2>&1
225 # IPv4/6 gateways and default routes
229 # device have to have ip address set before
230 if is_yes "$PROXYARP"; then
231 run_cmd "$(nls 'Enabling proxy ARP on %s' "${DEVICE}")" sysctl -w net.ipv4.conf.${SYSCTLDEVICE}.proxy_arp=1
234 if [ "$HANDLING" = "3" ]; then
238 if is_yes "$IPX"; then
239 /lib/rc-scripts/ifup-ipx $DEVICE
242 if is_yes "$ENABLE_6TO4"; then
243 # find an usable IPv4 address for this device; might have been obtained by dhcp or ppp
244 for ipv4 in `/sbin/ip addr show dev $DEVICE | awk -F'[ /]+' '/ inet /{print $3}'`; do
245 if [ `ipcalc -n $ipv4/8` != "NETWORK=10.0.0.0" \
246 -a `ipcalc -n $ipv4/12` != "NETWORK=172.16.0.0" \
247 -a `ipcalc -n $ipv4/24` != "NETWORK=192.168.0.0" \
248 -a `ipcalc -n $ipv4/24` != "NETWORK=169.254.0.0" ]; then
250 local_ipv6=`printf "2002:%02x%02x:%02x%02x::1" $(echo $ipv4 | tr . ' ')`
254 if [ -n "$local_ipv4" ]; then # we have an usable IPv4 address; set up the tunnel
255 tun6to4=tun6to4_$DEVICE
256 /sbin/ip tunnel add $tun6to4 mode sit ttl 128 remote any local $local_ipv4
257 /sbin/ip link set dev $tun6to4 up
258 /sbin/ip -6 addr add $local_ipv6/16 dev $tun6to4
259 /sbin/ip -6 route add 2000::/3 via ::192.88.99.1 dev $tun6to4 metric 1
263 if [ "$HANDLING" = "4" ]; then
267 exec /lib/rc-scripts/ifup-post $CONFIG