]>
Commit | Line | Data |
---|---|---|
66c36198 PM |
1 | ############################################################################### |
2 | # # | |
3 | # IPFire.org - A linux based firewall # | |
4 | # Copyright (C) 2007-2022 IPFire Team <info@ipfire.org> # | |
5 | # # | |
6 | # This program is free software: you can redistribute it and/or modify # | |
7 | # it under the terms of the GNU General Public License as published by # | |
8 | # the Free Software Foundation, either version 3 of the License, or # | |
9 | # (at your option) any later version. # | |
10 | # # | |
11 | # This program is distributed in the hope that it will be useful, # | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of # | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # | |
14 | # GNU General Public License for more details. # | |
15 | # # | |
16 | # You should have received a copy of the GNU General Public License # | |
17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. # | |
18 | # # | |
19 | ############################################################################### | |
1393a0c8 | 20 | |
26617b09 AF |
21 | . /etc/sysconfig/rc |
22 | . $rc_functions | |
957863f7 | 23 | . /etc/init.d/networking/functions.network |
0e42072a | 24 | |
5ba06eb8 | 25 | eval $(/usr/local/bin/readhash /var/ipfire/ethernet/settings) |
26617b09 | 26 | |
21d1c72e | 27 | dhcpcd_up() |
26617b09 AF |
28 | { |
29 | set | grep "^new_" | sed "s|^new_||g" | \ | |
30 | sort > /var/ipfire/dhcpc/dhcpcd-$interface.info | |
31 | ||
0c719f93 AF |
32 | #Check if this was the Red device... |
33 | if [ ! "$interface" == "$RED_DEV" ]; then | |
34 | exit 0; | |
35 | fi | |
36 | ||
33d2aa6d MT |
37 | # Check if we have to restart the services at update |
38 | [ ! -e "/var/ipfire/red/active" ] && update=1; | |
39 | if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then | |
40 | update=1; | |
41 | fi | |
42 | if [ "$old_ip_address" != "$new_ip_address" ]; then | |
43 | update=1; | |
26617b09 | 44 | fi |
33d2aa6d MT |
45 | if [ "$old_routers" != "$new_routers" ]; then |
46 | update=1; | |
47 | fi | |
48 | ||
49 | # Get DNS from dhcp | |
50 | /etc/rc.d/helper/getdnsfromdhcpc.pl 1 > /var/run/dns1 | |
51 | /etc/rc.d/helper/getdnsfromdhcpc.pl 2 > /var/run/dns2 | |
52 | ||
53 | #Get IP Address | |
54 | echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress | |
55 | ||
36914cce MT |
56 | # Get default gateway |
57 | if [ -n "${new_routers}" ]; then | |
58 | grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts | |
59 | echo "$new_routers gateway" >> /tmp/hosts | |
60 | mv /tmp/hosts /etc/hosts | |
61 | fi | |
33d2aa6d | 62 | |
26617b09 | 63 | if [ $update ]; then |
7a67f77f MT |
64 | # Consider RED being active |
65 | touch /var/ipfire/red/active | |
4ffd18a7 MT |
66 | |
67 | if [ -n "${new_routers}" ]; then | |
68 | echo -n "${new_routers}" > /var/ipfire/red/remote-ipaddress | |
69 | fi | |
70 | ||
26617b09 | 71 | logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address" |
0e42072a | 72 | run_subdir ${rc_base}/init.d/networking/red.up/ |
26617b09 AF |
73 | fi |
74 | } | |
75 | ||
21d1c72e | 76 | dhcpcd_down() |
26617b09 | 77 | { |
21d1c72e AF |
78 | set | grep "^new_" | sed "s|^new_||g" | \ |
79 | sort > /var/ipfire/dhcpc/dhcpcd-$interface.info | |
5ba06eb8 | 80 | |
1434fa0d MT |
81 | # Remove DNS servers |
82 | rm -f /var/run/dns1 /var/run/dns2 | |
83 | ||
c2e2c282 MT |
84 | # Consider RED to be no longer active |
85 | rm -f /var/ipfire/red/active | |
86 | ||
87 | if [ ! $reason == "PREINIT" ]; then | |
88 | logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down ($reason)" | |
89 | run_subdir ${rc_base}/init.d/networking/red.down/ | |
21d1c72e | 90 | fi |
a22e3c8e MT |
91 | |
92 | # Remove any configured IP address from the device | |
93 | ip addr flush dev "${interface}" &>/dev/null | |
94 | ||
95 | return 0 | |
26617b09 | 96 | } |
1393a0c8 | 97 | |
e3da4912 MT |
98 | case "${reason}" in |
99 | BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) | |
100 | dhcpcd_up | |
101 | ;; | |
102 | PREINIT|EXPIRE|FAIL|IPV4LL|NAK|RELEASE|STOP) | |
103 | dhcpcd_down | |
104 | ;; | |
ece96c6f MT |
105 | # Ignored events where we do not need to do anything |
106 | STOPPED|CARRIER|NOCARRIER) | |
107 | ;; | |
e3da4912 MT |
108 | *) |
109 | logger -p "local0.info" -t "dhcpcd.exe[$$]" "Unhandled DHCP event: ${reason}" | |
110 | ;; | |
26617b09 | 111 | esac |