]>
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 | ||
5ba06eb8 | 37 | # Only if RED_TYPE=DHCP update /var/ipfire/red |
33d2aa6d MT |
38 | # Check if we have to restart the services at update |
39 | [ ! -e "/var/ipfire/red/active" ] && update=1; | |
40 | if [ "$old_domain_name_service" != "$new_domain_name_service" ]; then | |
41 | update=1; | |
42 | fi | |
43 | if [ "$old_ip_address" != "$new_ip_address" ]; then | |
44 | update=1; | |
26617b09 | 45 | fi |
33d2aa6d MT |
46 | if [ "$old_routers" != "$new_routers" ]; then |
47 | update=1; | |
48 | fi | |
49 | ||
50 | # Get DNS from dhcp | |
51 | /etc/rc.d/helper/getdnsfromdhcpc.pl 1 > /var/run/dns1 | |
52 | /etc/rc.d/helper/getdnsfromdhcpc.pl 2 > /var/run/dns2 | |
53 | ||
54 | #Get IP Address | |
55 | echo -n "$new_ip_address" > /var/ipfire/red/local-ipaddress | |
56 | ||
36914cce MT |
57 | # Get default gateway |
58 | if [ -n "${new_routers}" ]; then | |
59 | grep -v -E "\<gateway\>" /etc/hosts > /tmp/hosts | |
60 | echo "$new_routers gateway" >> /tmp/hosts | |
61 | mv /tmp/hosts /etc/hosts | |
62 | fi | |
33d2aa6d | 63 | |
26617b09 | 64 | if [ $update ]; then |
7a67f77f MT |
65 | # Consider RED being active |
66 | touch /var/ipfire/red/active | |
4ffd18a7 MT |
67 | |
68 | if [ -n "${new_routers}" ]; then | |
69 | echo -n "${new_routers}" > /var/ipfire/red/remote-ipaddress | |
70 | fi | |
71 | ||
26617b09 | 72 | logger -p local0.info -t dhcpcd.exe[$$] "$interface has been (re)configured with IP=$new_ip_address" |
0e42072a | 73 | run_subdir ${rc_base}/init.d/networking/red.up/ |
26617b09 AF |
74 | fi |
75 | } | |
76 | ||
21d1c72e | 77 | dhcpcd_down() |
26617b09 | 78 | { |
21d1c72e AF |
79 | set | grep "^new_" | sed "s|^new_||g" | \ |
80 | sort > /var/ipfire/dhcpc/dhcpcd-$interface.info | |
5ba06eb8 | 81 | |
1434fa0d MT |
82 | # Remove DNS servers |
83 | rm -f /var/run/dns1 /var/run/dns2 | |
84 | ||
5ba06eb8 AF |
85 | # Only if RED_TYPE=DHCP update /var/ipfire/red |
86 | if [ "$RED_TYPE" == "DHCP" ]; then | |
21d1c72e | 87 | rm -f /var/ipfire/red/active |
455291f9 | 88 | if [ ! $reason == "PREINIT" ]; then |
bedfda83 | 89 | logger -p local0.info -t dhcpcd.exe[$$] "${interface} has been brought down ($reason)" |
455291f9 AF |
90 | run_subdir ${rc_base}/init.d/networking/red.down/ |
91 | fi | |
21d1c72e | 92 | fi |
a22e3c8e MT |
93 | |
94 | # Remove any configured IP address from the device | |
95 | ip addr flush dev "${interface}" &>/dev/null | |
96 | ||
97 | return 0 | |
26617b09 | 98 | } |
1393a0c8 | 99 | |
957863f7 MT |
100 | # Called when dhcpcd relies on a third party to configure an IP address |
101 | dhcpcd_3rdparty() { | |
102 | local qmi_device="$(qmi_find_device "${interface}")" | |
103 | ||
104 | if [ -n "${qmi_device}" ]; then | |
105 | setup_qmi "${qmi_device}" || return $? | |
106 | fi | |
107 | ||
108 | return 0 | |
109 | } | |
110 | ||
111 | setup_qmi() { | |
112 | local device="${1}" | |
113 | ||
114 | local address | |
115 | local netmask | |
116 | local gateway | |
117 | local mtu=1500 | |
ccf36e9e MT |
118 | local dns1 |
119 | local dns2 | |
957863f7 MT |
120 | |
121 | local line | |
122 | while read -r line; do | |
123 | # Extract the value | |
124 | value="${line#*: }" | |
125 | ||
126 | case "${line}" in | |
127 | *IPv4\ address:*) | |
128 | address="${value}" | |
129 | ;; | |
130 | *IPv4\ subnet\ mask:*) | |
131 | netmask="${value}" | |
132 | ;; | |
133 | *IPv4\ gateway\ address:*) | |
134 | gateway="${value}" | |
135 | ;; | |
ccf36e9e MT |
136 | *IPv4\ primary\ DNS:*) |
137 | dns1="${value}" | |
138 | ;; | |
139 | *IPv4\ secondary\ DNS:*) | |
140 | dns2="${value}" | |
141 | ;; | |
957863f7 MT |
142 | *MTU:*) |
143 | mtu="${value}" | |
144 | ;; | |
145 | esac | |
146 | done <<< "$(qmicli --device="${device}" --wds-get-current-settings)" | |
147 | ||
148 | if [ -z "${address}" ] || [ -z "${netmask}" ] || [ -z "${gateway}" ]; then | |
149 | logger -p "local0.info" -t "dhcpcd.exe[$$]" \ | |
150 | "Could not retrieve all information from the QMI interface" | |
151 | return 1 | |
152 | fi | |
153 | ||
154 | # Flush any previous configuration | |
155 | ip addr flush dev "${interface}" | |
156 | ||
157 | # Configure the IP address | |
158 | ip addr add "${address}/${netmask}" dev "${interface}" | |
159 | ||
160 | # Configure the default route | |
26172743 MT |
161 | if [ -n "${gateway}" ]; then |
162 | # Store the default gateway | |
163 | echo -n "${gateway}" > /var/ipfire/red/remote-ipaddress | |
164 | ||
165 | # Configure the default route | |
166 | ip route add default via "${gateway}" mtu "${mtu}" | |
167 | fi | |
957863f7 | 168 | |
ccf36e9e MT |
169 | # Store and DNS servers |
170 | if [ -n "${dns1}" ]; then | |
171 | echo -n "${dns1}" > /var/ipfire/red/dns1 | |
172 | fi | |
173 | if [ -n "${dns2}" ]; then | |
174 | echo n "${dns2}" > /var/ipfire/red/dns2 | |
175 | fi | |
176 | ||
957863f7 MT |
177 | return 0 |
178 | } | |
179 | ||
26617b09 | 180 | case "$reason" in |
21d1c72e | 181 | BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT|STATIC) dhcpcd_up;; |
bedfda83 | 182 | PREINIT|EXPIRE|FAIL|IPV4LL|NAK|RELEASE|STOP) dhcpcd_down;; |
957863f7 MT |
183 | 3RDPARTY) |
184 | dhcpcd_3rdparty | |
185 | ;; | |
177ec167 MT |
186 | *) |
187 | logger -p "local0.info" -t "dhcpcd.exe[$$]" "Unhandled DHCP event: ${reason}" | |
188 | ;; | |
26617b09 | 189 | esac |