4 # This is not a shell script; it provides functions to network scripts
9 DEVNAME=$(basename "$CONFIG" | awk ' { gsub(/^ifcfg-/,NIL); print $0; } ')
11 if echo "$CONFIG"|egrep "^/" >/dev/null 2>&1 ; then
12 if [ -f "$CONFIG" ] ; then
15 elif [ -f "/etc/sysconfig/interfaces/$CONFIG" ] ; then
16 . "/etc/sysconfig/interfaces/$CONFIG"
18 if [ -n "${PREFIX}" ] && ! $(echo $IPADDR | grep "/" 2>&1 >/dev/null) ; then
19 IPADDR="$IPADDR/$PREFIX"
25 # Notify programs that have requested notification
26 ( cd /var/run/netreport || exit
29 kill -SIGIO $i >/dev/null 2>&1 || \
30 rm -f $i >/dev/null 2>&1
37 if [ "`hostname`" = "(none)" -o "`hostname`" = "localhost" -o \
38 "`hostname`" = "localhost.localdomain" ]; then
47 typeset hostname domain
48 hostname=$(echo $1 | awk ' { gsub(/\..*$/,NIL); print $0; } ')
49 domain=$(echo $1 | awk ' { sub(/^[^\.]*\./,NIL); print $0; } ')
51 if [ -n "$hostname" ] ; then
52 echo "$hostname" > /etc/HOSTNAME
56 if [ -n "$domain" ] ; then
58 if ! grep -q "search $domain" /etc/resolv.conf ; then
59 echo "search $domain" >> /etc/resolv.conf.new
61 echo "domain $domain" >> /etc/resolv.conf.new
62 grep -v "^domain " /etc/resolv.conf >> /etc/resolv.conf.new
63 mv -f /etc/resolv.conf.new /etc/resolv.conf
67 # PLD Linux Distribution network functions
68 # Copyright (C) 1999, 2000 Arkadiusz Mi¶kiewicz <misiek@pld-linux.org>
70 # Setup Network Address Translation (NAT)
74 if [ -r /etc/sysconfig/static-nat ]; then
75 grep "^[0-9]" /etc/sysconfig/static-nat | while read src via dst; do
76 if [ "$1" = "on" ]; then
77 /sbin/ip route add nat $dst via $src
78 /sbin/ip rule add from $src nat $dst
79 elif [ "$1" = "off" ]; then
80 /sbin/ip rule del from $src nat $dst
81 /sbin/ip route del nat $dst via $src
90 typeset rc arpdev host hwaddr flags neflags
91 if is_yes "$STATIC_ARP" && [ -r /etc/ethers ]; then
92 if [ -x /sbin/arp ]; then
93 run_cmd "Setting static ARP entries" /sbin/arp -f /etc/ethers
95 show "Setting static ARP entries"; busy
97 arpdev=$(ip link show | awk -F':' '(/UP/) && ! (/NOARP/) && ! (/lo:/) && ! (/NONE:/) { print $2; exit }')
98 if [ -z "$arpdev" ]; then
101 # ip supports only ip addresses
102 grep "^[0-9]" /etc/ethers | \
103 while read host hwaddr flags; do
109 neflags="nud permanent"
112 if ! /sbin/ip neigh add $host lladdr $hwaddr $neflags dev $arpdev; then
117 if [ "$rc" -gt 0 ]; then
126 if is_yes "$STATIC_RARP"; then
127 if [ ! -e /proc/net/rarp ]; then
128 _modprobe single -k rarp
130 if [ -r /etc/ethers -a -x /sbin/rarp ]; then
131 run_cmd "Setting static RARP entries" /sbin/rarp -f /etc/ethers
138 if [ -x /sbin/vconfig -a -e /proc/net/vlan/config ] && `echo $DEVICE | grep -q ^eth`; then
139 /sbin/vconfig set_name_type DEV_PLUS_VID_NO_PAD 2>&1 > /dev/null
146 # Set up all IP && IP parameter variables
149 # detect network device type (ie. dummy, eth for dummy0, eth0 ..)
150 if [ -z "$DEVICETYPE" ]; then
151 DEVICETYPE=$(echo $DEVICE | awk ' { gsub(/[0-9]*\.?[0-9]*$/,NUL); print $0 } ')
154 # Setup DEVICETYPE for special cases.
155 if (echo ${DEVICE} | LC_ALL=C egrep -q '^[a-z0-9]+\.[0-9]+$'); then
159 # real name of device (ie. is eth0 for eth0,eth0:1,eth0:alias)
160 DEVICE=$(echo $DEVICE | awk ' { gsub(/:.*$/,NUL); print $0 } ')
162 eval IP4ADDR="\$IPADDR${IP4_PRIM_IF:-}"
163 if echo "${IP4ADDR}" | grep -q ":" ; then
167 eval IP4ADDROPT="\$IP_AOPTS${IP4_PRIM_IF:-}"
168 eval IP4ROUTEOPT="\$IP_ROPTS${IP4_PRIM_IF:-}"
170 if [ -n "${IP6_PRIM_IF}" ] ; then
171 eval IP6ADDR="\$IPADDR${IP6_PRIM_IF:-}"
172 eval IP6ADDROPT="\$IPV6_AOPTS${IP6_PRIM_IF:-}"
174 if [ -n "${IP4_SRC_IF}" ] ; then
175 eval IP4SRCADDR="\$IPADDR${IP4_SRC_IF}"
176 IP4SRCADDR=$(echo ${IP4SRCADDR} | awk ' { gsub(/\/.*/,NIL); print "src " $0; } ')
178 if [ -n "${IP6_SRC_IF}" ] ; then
179 eval IP6SRCADDR="\$IPADDR${IP6_SRC_IF}"
180 IP6SRCADDR=$(echo ${IP6SRCADDR} | awk ' { gsub(/\/.*/,NIL); print "src " $0; } ')
183 # new rc-scripts 0.4.x option
184 if [ -z "$HANDLING" ]; then
188 # set handling for bridge
189 case "$DEVICETYPE" in
190 br|atm|lec|irda|vlan)
195 # Multicast ready devices
196 if is_yes "$MULTICAST"; then
199 case "$DEVICETYPE" in
210 if [ -n "$ARP" ] ; then
211 if is_yes "$ARP"; then
222 if (ip link show dev ${DEVICE} 2> /dev/null | grep -q UP); then
232 if is_yes "$IPV4_NETWORKING"; then
233 if [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${DEVICE}" ]; then
234 # set up default gateway
235 if [ -n "${GATEWAY}" ]; then
236 ip -4 route add default via ${GATEWAY} dev ${DEVICE} ${IP4SRCADDR} onlink
238 elif [ "${GATEWAYDEV}" = "${DEVICE}" ]; then
239 ip -4 route add default dev ${DEVICE} ${IP4SRCADDR}
244 # IPv6 gateway && IPv6 globalroute
245 if is_yes "$IPV6_NETWORKING"; then
246 if [ -z "${GATEWAY6DEV}" -o "${GATEWAY6DEV}" = "${DEVICE}" ]; then
247 # set up default gateway
248 if [ -n "${GATEWAY6}" ]; then
249 ip -6 route add default via ${GATEWAY6} dev ${DEVICE} ${IP6SRCADDR} onlink
251 elif [ "${GATEWAY6DEV}" = "${DEVICE}" ]; then
252 ip -6 route add default dev ${DEVICE} ${IP6SRCADDR}
255 if [ -z "${IPV6_GLOBALROUTEDEV}" -o "${IPV6_GLOBALROUTEDEV}" = "${DEVICE}" ]; then
256 # set up default route
257 if [ -n "${IPV6_GLOBALROUTEGW}" ]; then
258 ip -6 route add 2000::/3 via ${IPV6_GLOBALROUTEGW} dev ${DEVICE} ${IP6SRCADDR} onlink
259 elif [ "${IPV6_GLOBALROUTEDEV}" = "${DEVICE}" ]; then
260 ip -6 route add 2000::/3 dev ${DEVICE} ${IP6SRCADDR}
267 # following function sets up routes not associated to any device
268 # eg. unreachable or blackhole routes
269 # (c) 1999 Jacek Konieczny <jajcus@pld-linux.org>
274 if [ -f /etc/sysconfig/static-routes ]; then
275 if [ "$1" = "on" -o "$1" = "yes" ] ; then
276 egrep "^(none)|(any)[[:blank:]]" /etc/sysconfig/static-routes | while read device args; do
277 /sbin/ip route add $args
280 egrep "^(none)|(any)[[:blank:]]" /etc/sysconfig/static-routes | while read device args; do
281 /sbin/ip route del $args 2>/dev/null
287 # Add ONLY IPv4 address (IPv6 address is added automaticly)
290 if is_yes "$IPV4_NETWORKING"; then
291 ip addr add 127.0.0.1/8 dev lo
293 ip link set dev lo up
298 ip addr flush dev lo 2>&1 | grep -v "Nothing to flush"
299 ip link set dev lo down
304 if is_yes "$IPV6_NETWORKING" && is_module "ipv6"; then
305 _modprobe single -k ipv6
308 if is_yes "$IPX" && is_module "ipx"; then
309 _modprobe single -k ipx
314 # folowing function calculates network prefix from given network mask
315 # (c) 1999 Grzegorz Stanislawski <stangrze@open.net.pl>
319 typeset OISF len olen bad prefix
341 if [ "$len" -gt "$olen" ] ; then bad=1; fi
342 prefix=$(($prefix + $len))
347 if [ "$bad" = "0" ]; then
356 # folowing function calculates network mask from given prefix
357 # (c) 1999 Grzegorz Stanislawski <stangrze@open.net.pl>
361 typeset prefix a MASK
363 if [ "`echo "${1}" | grep "^[0-9]"`" = "" ]; then
378 if [ $prefix -ge 8 ]; then a=255; fi
379 if [ $prefix -le 0 ]; then a=0; fi
383 prefix="$(( $prefix - 8))"
384 if [ -z "$MASK" ]; then
395 # Retrievies PPPD PID and real interface name from /var/run/ppp-*.pid
396 get_ppp_device_and_pid () {
398 if [ -f "/var/run/ppp-$DEVICE.pid" ] ; then
400 read PID ; echo "PID='$PID'"
401 read REALDEVICE ; echo "REALDEVICE=$REALDEVICE"
402 } < "/var/run/ppp-$DEVICE.pid"`
405 if [ -z "$REALDEVICE" ] ; then
410 # following function setups advanced routing rules
411 # Olgierd Pieczul <wojrus@pld-linux.org>
414 if [ -f /etc/sysconfig/static-routes ] ; then
416 egrep "^(from|to|iif|tos|fwmark|dev|pref)[[:blank:]]" /etc/sysconfig/static-routes | while read args; do
417 /sbin/ip rule add $args
419 elif is_no "$1"; then
420 egrep "^(from|to|iif|tos|fwmark|dev|pref)[[:blank:]]" /etc/sysconfig/static-routes | while read args; do
421 /sbin/ip rule del $args
429 is_wireless_device () {
430 if [ -x /sbin/iwconfig ]; then
431 LC_ALL=C iwconfig "${1}" 2>&1 | grep -q "no wireless extensions" || return 0
436 # This must be last line !
437 # vi:syntax=sh:tw=78:ts=8:sw=4