]> git.ipfire.org Git - ipfire-2.x.git/blob - src/initscripts/init.d/networking/any
use vnstat for traffic statistic now
[ipfire-2.x.git] / src / initscripts / init.d / 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 elif [ "$(basename $0)" == "blue" ]; then
30 DEVICE="${BLUE_DEV}"
31 ADDRESS="${BLUE_ADDRESS}"
32 BROADCAST="${BLUE_BROADCAST}"
33 NETADDRESS="${BLUE_NETADDRESS}"
34 NETMASK="${BLUE_NETMASK}"
35 DEVICE="${BLUE_DEV}"
36 elif [ "$(basename $0)" == "orange" ]; then
37 DEVICE="${ORANGE_DEV}"
38 ADDRESS="${ORANGE_ADDRESS}"
39 BROADCAST="${ORANGE_BROADCAST}"
40 NETADDRESS="${ORANGE_NETADDRESS}"
41 NETMASK="${ORANGE_NETMASK}"
42 DEVICE="${ORANGE_DEV}"
43 fi
44
45 if [ -z "${BROADCAST}" ]; then
46 boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE}
47 echo_failure
48 exit 1
49 fi
50
51 if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
52 PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
53 args="${args} ${ADDRESS}/${PREFIX} broadcast ${BROADCAST}"
54 else
55 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
56 echo_failure
57 exit 1
58 fi
59
60 case "${1}" in
61
62 start)
63 boot_mesg "Bringing up the ${DEVICE} interface..."
64 boot_mesg_flush
65
66 # Check if an interface is there...
67 if ip link show ${DEVICE} > /dev/null 2>&1; then
68 link_status=`ip link show ${DEVICE} 2> /dev/null`
69 if [ -n "${link_status}" ]; then
70 if ! echo "${link_status}" | grep -q UP; then
71 ip link set ${DEVICE} up
72 fi
73 fi
74 else
75 boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
76 echo_failure
77 exit 1
78 fi
79
80 # Create/Update vnstat database
81 /usr/bin/vnstat -u -i ${DEVICE} --force > /dev/null 2>&1
82
83 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
84 ip addr add ${args} dev ${DEVICE}
85 evaluate_retval
86 ;;
87
88 stop)
89 boot_mesg "Removing IPv4 address ${ADDRESS} from the ${DEVICE} interface..."
90 ip addr del ${args} dev ${DEVICE}
91 evaluate_retval
92
93 # Update vnstat database
94 /usr/bin/vnstat -u -i ${DEVICE} > /dev/null 2>&1
95 exit 0;
96 ;;
97 esac
98 # End