]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blob - src/initscripts/networking/any
core164: exclude boot/uEnv.txt
[people/mfischer/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 NETADDRESS="${GREEN_NETADDRESS}"
26 NETMASK="${GREEN_NETMASK}"
27 DEVICE="${GREEN_DEV}"
28 MTU="${GREEN_MTU}"
29 elif [ "$(basename $0)" == "blue" ]; then
30 DEVICE="${BLUE_DEV}"
31 ADDRESS="${BLUE_ADDRESS}"
32 NETADDRESS="${BLUE_NETADDRESS}"
33 NETMASK="${BLUE_NETMASK}"
34 DEVICE="${BLUE_DEV}"
35 MTU="${BLUE_MTU}"
36 elif [ "$(basename $0)" == "orange" ]; then
37 DEVICE="${ORANGE_DEV}"
38 ADDRESS="${ORANGE_ADDRESS}"
39 NETADDRESS="${ORANGE_NETADDRESS}"
40 NETMASK="${ORANGE_NETMASK}"
41 DEVICE="${ORANGE_DEV}"
42 MTU="${ORANGE_MTU}"
43 fi
44
45 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
46 PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
47 args="${args} ${ADDRESS}/${PREFIX}"
48 else
49 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
50 echo_failure
51 exit 1
52 fi
53
54 case "${1}" in
55
56 start)
57 boot_mesg "Bringing up the ${DEVICE} interface..."
58 boot_mesg_flush
59
60 # Check if an interface is there...
61 if ip link show ${DEVICE} > /dev/null 2>&1; then
62 link_status=`ip link show ${DEVICE} 2> /dev/null`
63 if [ -n "${link_status}" ]; then
64 if ! echo "${link_status}" | grep -q UP; then
65 ip link set ${DEVICE} up
66 fi
67 fi
68 else
69 boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
70 echo_failure
71 exit 1
72 fi
73
74 # Set the MTU
75 if [ -n "${MTU}" ]; then
76 if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then
77 boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..."
78 echo_warning
79 fi
80 fi
81
82 # Create & Enable vnstat data collection
83 /usr/bin/vnstat -u -i ${DEVICE} -r --enable --force > /dev/null 2>&1
84
85 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
86 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
87 ip addr add ${args} dev ${DEVICE}
88 evaluate_retval
89 fi
90 ;;
91
92 stop)
93 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
94 boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..."
95 ip addr flush dev ${DEVICE}
96 evaluate_retval
97 fi
98
99 # Disable vnstat collection
100 /usr/bin/vnstat -u -i ${DEVICE} -r --disable > /dev/null 2>&1
101 exit 0;
102 ;;
103 esac
104 # End