aboutsummaryrefslogtreecommitdiffstats
path: root/sysconfig/network-scripts/ifup-aliases
blob: ad4d195cffd244c937bbd9b798a1054e9ca730a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#!/bin/sh

# adds aliases of device $1

if [ "$1" = "" ]; then
	echo "usage: $0 <net-device>"
	exit 1
fi

# don't run linuxconf if /usr isn't there... 
if [ -x /bin/linuxconf -a -f /usr/lib/libncurses.so.4.2 ] ; then
    # ask linuxconf for lines like:
    # add	<device>	<ip>
    # del	<device>
    # reload	<number_of_aliases>
    KERN20=
    if uname -r | grep -q "^2\.0"; then
        KERN20=true
    fi
    linuxconf --hint ipalias $1 | while read verb arg1 arg2 arg3 arg4; do
	case $verb in
	  add)
		if [ -z "$arg3" ] ; then
		    # old linuxconf
		    /sbin/ifconfig $arg1 $arg2
		else
		    # new linuxconf
		    /sbin/ifconfig $arg1 $arg2 netmask $arg3 broadcast $arg4
		fi
		[ -n "$KERN20" ] && /sbin/route add $arg2 $arg1
		;;
	  del)
		# the <device>- 0.0.0.0 tells the kernel to remove the device
		# it is necessary to remove it in order for reload to work.
		if [ -n "$KERN20" ]; then 
                     /sbin/ifconfig ${arg1}- 0.0.0.0
		else
                     /sbin/ifconfig ${arg1} 0.0.0.0
		fi
		;;
	  reload)
		echo $arg1 > /proc/sys/net/core/net_alias_max
		;;
	esac
    done

else
    # we don't have linuxconf to fall back on, so presumably we do
    # not have to parse linuxconf ipalias ranges, either.
    
    # bash 2 is so much fun. 
    if [ "$BASH_VERSINFO" ]; then 
       shopt -s nullglob
    else
       allow_null_glob_expansion=foo
    fi
    for alias in /etc/sysconfig/network-scripts/ifcfg-$1:* ; do
	[ -f $alias ] && /etc/sysconfig/network-scripts/ifup $alias
    done
    if [ "$BASH_VERSINFO" ]; then 
       shopt -u nullglob
    else
       unset allow_null_glob_expansion
    fi
fi