]> git.ipfire.org Git - people/mfischer/ipfire-2.x.git/blame - src/initscripts/networking/any
Merge branch 'master' of ssh://git.ipfire.org/pub/git/ipfire-2.x
[people/mfischer/ipfire-2.x.git] / src / initscripts / networking / any
CommitLineData
d1e90efc 1#!/bin/sh
66c36198
PM
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
5# Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> #
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
d1e90efc 21
66c36198 22. /etc/sysconfig/rc
d1e90efc
MT
23. ${rc_functions}
24eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings)
25
64ff033d 26if [ "$(basename $0)" == "green" ]; then
d1e90efc
MT
27 DEVICE="${GREEN_DEV}"
28 ADDRESS="${GREEN_ADDRESS}"
d1e90efc
MT
29 NETADDRESS="${GREEN_NETADDRESS}"
30 NETMASK="${GREEN_NETMASK}"
31 DEVICE="${GREEN_DEV}"
9bdf5e71 32 MTU="${GREEN_MTU}"
64ff033d 33elif [ "$(basename $0)" == "blue" ]; then
d1e90efc
MT
34 DEVICE="${BLUE_DEV}"
35 ADDRESS="${BLUE_ADDRESS}"
d1e90efc
MT
36 NETADDRESS="${BLUE_NETADDRESS}"
37 NETMASK="${BLUE_NETMASK}"
38 DEVICE="${BLUE_DEV}"
e43c3206 39 MTU="${BLUE_MTU}"
64ff033d 40elif [ "$(basename $0)" == "orange" ]; then
d1e90efc
MT
41 DEVICE="${ORANGE_DEV}"
42 ADDRESS="${ORANGE_ADDRESS}"
d1e90efc
MT
43 NETADDRESS="${ORANGE_NETADDRESS}"
44 NETMASK="${ORANGE_NETMASK}"
45 DEVICE="${ORANGE_DEV}"
9bdf5e71 46 MTU="${ORANGE_MTU}"
d1e90efc
MT
47fi
48
d1e90efc
MT
49if [ -n "${ADDRESS}" -a -n "${NETMASK}" ]; then
50 PREFIX=`whatmask ${NETMASK} | grep -e ^CIDR | awk -F': ' '{ print $2 }' | cut -c 2-`
b67f02d5 51 args="${args} ${ADDRESS}/${PREFIX}"
d1e90efc
MT
52else
53 boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE}
54 echo_failure
55 exit 1
56fi
57
64ff033d 58case "${1}" in
d1e90efc
MT
59
60 start)
61 boot_mesg "Bringing up the ${DEVICE} interface..."
62 boot_mesg_flush
66c36198 63
d1e90efc
MT
64 # Check if an interface is there...
65 if ip link show ${DEVICE} > /dev/null 2>&1; then
66 link_status=`ip link show ${DEVICE} 2> /dev/null`
67 if [ -n "${link_status}" ]; then
68 if ! echo "${link_status}" | grep -q UP; then
69 ip link set ${DEVICE} up
70 fi
71 fi
72 else
73 boot_mesg "Interface ${DEVICE} doesn't exist." ${FAILURE}
74 echo_failure
75 exit 1
76 fi
6c33dc5c 77
9bdf5e71
MT
78 # Set the MTU
79 if [ -n "${MTU}" ]; then
80 if ! ip link set dev "${DEVICE}" mtu "${MTU}" &>/dev/null; then
81 boot_mesg "Could not set MTU of ${MTU} to ${DEVICE}..."
82 echo_warning
83 fi
84 fi
85
1e4656cd
AF
86 # Create & Enable vnstat data collection
87 /usr/bin/vnstat -u -i ${DEVICE} -r --enable --force > /dev/null 2>&1
66c36198 88
fa4762fb
AF
89 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
90 boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..."
91 ip addr add ${args} dev ${DEVICE}
92 evaluate_retval
93 fi
d1e90efc
MT
94 ;;
95
96 stop)
fa4762fb
AF
97 if [ ! "${ADDRESS}" == "1.1.1.1" ]; then
98 boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..."
99 ip addr flush dev ${DEVICE}
100 evaluate_retval
101 fi
6c33dc5c 102
1e4656cd
AF
103 # Disable vnstat collection
104 /usr/bin/vnstat -u -i ${DEVICE} -r --disable > /dev/null 2>&1
6c33dc5c 105 exit 0;
d1e90efc 106 ;;
d1e90efc 107esac