]>
Commit | Line | Data |
---|---|---|
8ae238a5 | 1 | #!/bin/bash |
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} |
24 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) | |
25 | ||
64ff033d | 26 | if [ "$(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 | 33 | elif [ "$(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 | 40 | elif [ "$(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 |
47 | fi |
48 | ||
d1e90efc MT |
49 | if [ -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 |
52 | else |
53 | boot_mesg "ADDRESS and/or NETMASK variable missing from input, cannot continue." ${FAILURE} | |
54 | echo_failure | |
55 | exit 1 | |
56 | fi | |
57 | ||
64ff033d | 58 | case "${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 | ||
fa4762fb AF |
86 | if [ ! "${ADDRESS}" == "1.1.1.1" ]; then |
87 | boot_mesg "Adding IPv4 address ${ADDRESS} to the ${DEVICE} interface..." | |
88 | ip addr add ${args} dev ${DEVICE} | |
89 | evaluate_retval | |
90 | fi | |
d1e90efc MT |
91 | ;; |
92 | ||
93 | stop) | |
fa4762fb AF |
94 | if [ ! "${ADDRESS}" == "1.1.1.1" ]; then |
95 | boot_mesg "Removing IPv4 addresses from the ${DEVICE} interface..." | |
96 | ip addr flush dev ${DEVICE} | |
97 | evaluate_retval | |
98 | fi | |
6c33dc5c | 99 | |
6c33dc5c | 100 | exit 0; |
d1e90efc | 101 | ;; |
d1e90efc | 102 | esac |