]> git.ipfire.org Git - ipfire-2.x.git/blame - src/initscripts/networking/any
Suricata: Start service on red.up event if requested
[ipfire-2.x.git] / src / initscripts / networking / any
CommitLineData
d1e90efc
MT
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}
20eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
21
64ff033d 22if [ "$(basename $0)" == "green" ]; then
d1e90efc
MT
23 DEVICE="${GREEN_DEV}"
24 ADDRESS="${GREEN_ADDRESS}"
25 BROADCAST="${GREEN_BROADCAST}"
26 NETADDRESS="${GREEN_NETADDRESS}"
27 NETMASK="${GREEN_NETMASK}"
28 DEVICE="${GREEN_DEV}"
64ff033d 29elif [ "$(basename $0)" == "blue" ]; then
d1e90efc
MT
30 DEVICE="${BLUE_DEV}"
31 ADDRESS="${BLUE_ADDRESS}"
32 BROADCAST="${BLUE_BROADCAST}"
33 NETADDRESS="${BLUE_NETADDRESS}"
34 NETMASK="${BLUE_NETMASK}"
35 DEVICE="${BLUE_DEV}"
64ff033d 36elif [ "$(basename $0)" == "orange" ]; then
d1e90efc
MT
37 DEVICE="${ORANGE_DEV}"
38 ADDRESS="${ORANGE_ADDRESS}"
39 BROADCAST="${ORANGE_BROADCAST}"
40 NETADDRESS="${ORANGE_NETADDRESS}"
41 NETMASK="${ORANGE_NETMASK}"
42 DEVICE="${ORANGE_DEV}"
43fi
44
45if [ -z "${BROADCAST}" ]; then
46 boot_mesg "BROADCAST variable missing from input, cannot continue." ${FAILURE}
47 echo_failure
48 exit 1
49fi
50
51if [ -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}"
54else
55 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
56 echo_failure
57 exit 1
58fi
59
64ff033d 60case "${1}" in
d1e90efc
MT
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
6c33dc5c 79
1e4656cd
AF
80 # Create & Enable vnstat data collection
81 /usr/bin/vnstat -u -i ${DEVICE} -r --enable --force > /dev/null 2>&1
d1e90efc 82
fa4762fb
AF
83 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
84 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
85 ip addr add ${args} dev ${DEVICE}
86 evaluate_retval
87 fi
d1e90efc
MT
88 ;;
89
90 stop)
fa4762fb
AF
91 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
92 boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..."
93 ip addr flush dev ${DEVICE}
94 evaluate_retval
95 fi
6c33dc5c 96
1e4656cd
AF
97 # Disable vnstat collection
98 /usr/bin/vnstat -u -i ${DEVICE} -r --disable > /dev/null 2>&1
6c33dc5c 99 exit 0;
d1e90efc 100 ;;
d1e90efc 101esac
d1e90efc 102# End