]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/initscripts/networking/any
:xMerge branch 'next' of ssh://git.ipfire.org/pub/git/ipfire-2.x into next-switch...
[people/pmueller/ipfire-2.x.git] / src / initscripts / networking / any
1 #!/bin/sh
2 ########################################################################
3 # Begin
4 #
5 # Description : ANY Device Script
6 #
7 # Authors : Nathan Coulson - nathan@linuxfromscratch.org
8 # Kevin P. Fleming - kpfleming@linuxfromscratch.org
9 # Michael Tremer - mitch@ipfire.org
10 # Maniacikarus - maniacikarus@ipfire.org
11 #
12 # Version : 01.00
13 #
14 # Notes :
15 #
16 ########################################################################
17
18 . /etc/sysconfig/rc
19 . ${rc_functions}
20 eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
21
22 if [ "$(basename $0)" == "green" ]; then
23 DEVICE="${GREEN_DEV}"
24 ADDRESS="${GREEN_ADDRESS}"
25 BROADCAST="${GREEN_BROADCAST}"
26 NETADDRESS="${GREEN_NETADDRESS}"
27 NETMASK="${GREEN_NETMASK}"
28 DEVICE="${GREEN_DEV}"
29 MTU="${GREEN_MTU}"
30 elif [ "$(basename $0)" == "blue" ]; then
31 DEVICE="${BLUE_DEV}"
32 ADDRESS="${BLUE_ADDRESS}"
33 BROADCAST="${BLUE_BROADCAST}"
34 NETADDRESS="${BLUE_NETADDRESS}"
35 NETMASK="${BLUE_NETMASK}"
36 DEVICE="${BLUE_DEV}"
37 MTU="${GREEN_MTU}"
38 elif [ "$(basename $0)" == "orange" ]; then
39 DEVICE="${ORANGE_DEV}"
40 ADDRESS="${ORANGE_ADDRESS}"
41 BROADCAST="${ORANGE_BROADCAST}"
42 NETADDRESS="${ORANGE_NETADDRESS}"
43 NETMASK="${ORANGE_NETMASK}"
44 DEVICE="${ORANGE_DEV}"
45 MTU="${ORANGE_MTU}"
46 fi
47
48 if [ -z "${BROADCAST}" ]; then
49 boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE}
50 echo_failure
51 exit 1
52 fi
53
54 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
55 PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
56 args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
57 else
58 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
59 echo_failure
60 exit 1
61 fi
62
63 case "${1}" in
64
65 start)
66 boot_mesg "Bringing up the ${DEVICE} interface..."
67 boot_mesg_flush
68
69 # Check if an interface is there...
70 if ip link show ${DEVICE} > /dev/null 2>&1; then
71 link_status=`ip link show ${DEVICE} 2> /dev/null`
72 if [ -n "${link_status}" ]; then
73 if ! echo "${link_status}" | grep -q UP; then
74 ip link set ${DEVICE} up
75 fi
76 fi
77 else
78 boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
79 echo_failure
80 exit 1
81 fi
82
83 # Set the MTU
84 if [ -n "${MTU}" ]; then
85 if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then
86 boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..."
87 echo_warning
88 fi
89 fi
90
91 # Create & Enable vnstat data collection
92 /usr/bin/vnstat -u -i ${DEVICE} -r --enable --force > /dev/null 2>&1
93
94 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
95 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
96 ip addr add ${args} dev ${DEVICE}
97 evaluate_retval
98 fi
99 ;;
100
101 stop)
102 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
103 boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..."
104 ip addr flush dev ${DEVICE}
105 evaluate_retval
106 fi
107
108 # Disable vnstat collection
109 /usr/bin/vnstat -u -i ${DEVICE} -r --disable > /dev/null 2>&1
110 exit 0;
111 ;;
112 esac
113 # End