1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.newwanip
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2006-2016 Rubicon Communications, LLC (Netgate)
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Originally part of m0n0wall (http://m0n0.ch/wall)
|
11
|
* Copyright (c) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
12
|
* All rights reserved.
|
13
|
*
|
14
|
* Redistribution and use in source and binary forms, with or without
|
15
|
* modification, are permitted provided that the following conditions are met:
|
16
|
*
|
17
|
* 1. Redistributions of source code must retain the above copyright notice,
|
18
|
* this list of conditions and the following disclaimer.
|
19
|
*
|
20
|
* 2. Redistributions in binary form must reproduce the above copyright
|
21
|
* notice, this list of conditions and the following disclaimer in
|
22
|
* the documentation and/or other materials provided with the
|
23
|
* distribution.
|
24
|
*
|
25
|
* 3. All advertising materials mentioning features or use of this software
|
26
|
* must display the following acknowledgment:
|
27
|
* "This product includes software developed by the pfSense Project
|
28
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
29
|
*
|
30
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
31
|
* endorse or promote products derived from this software without
|
32
|
* prior written permission. For written permission, please contact
|
33
|
* coreteam@pfsense.org.
|
34
|
*
|
35
|
* 5. Products derived from this software may not be called "pfSense"
|
36
|
* nor may "pfSense" appear in their names without prior written
|
37
|
* permission of the Electric Sheep Fencing, LLC.
|
38
|
*
|
39
|
* 6. Redistributions of any form whatsoever must retain the following
|
40
|
* acknowledgment:
|
41
|
*
|
42
|
* "This product includes software developed by the pfSense Project
|
43
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
44
|
*
|
45
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
46
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
47
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
48
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
49
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
50
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
51
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
52
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
53
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
54
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
55
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
56
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
57
|
*/
|
58
|
|
59
|
/* parse the configuration and include all functions used below */
|
60
|
require_once("globals.inc");
|
61
|
require_once("config.inc");
|
62
|
require_once("functions.inc");
|
63
|
require_once("filter.inc");
|
64
|
require_once("shaper.inc");
|
65
|
require_once("ipsec.inc");
|
66
|
require_once("vpn.inc");
|
67
|
require_once("openvpn.inc");
|
68
|
require_once("IPv6.inc");
|
69
|
require_once("rrd.inc");
|
70
|
|
71
|
function restart_packages() {
|
72
|
global $oldip, $curwanip, $g;
|
73
|
|
74
|
/* restart packages */
|
75
|
log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldip -> $curwanip - Restarting packages.");
|
76
|
send_event("service reload packages");
|
77
|
}
|
78
|
|
79
|
/* Interface IP address has changed */
|
80
|
if (isset($_GET['interface'])) {
|
81
|
$argument = $_GET['interface'];
|
82
|
} else {
|
83
|
$argument = str_replace("\n", "", $argv[1]);
|
84
|
}
|
85
|
|
86
|
log_error("rc.newwanip: Info: starting on {$argument}.");
|
87
|
|
88
|
if (empty($argument)) {
|
89
|
$interface = "wan";
|
90
|
$interface_real = get_real_interface();
|
91
|
} else {
|
92
|
$interface = convert_real_interface_to_friendly_interface_name($argument);
|
93
|
$interface_real = $argument;
|
94
|
}
|
95
|
|
96
|
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
|
97
|
|
98
|
/* If the interface is configured and not enabled, bail. We do not need to change settings for disabled interfaces. #3313 */
|
99
|
if (is_array($config['interfaces'][$interface]) && !isset($config['interfaces'][$interface]['enable'])) {
|
100
|
log_error("Interface is disabled, nothing to do.");
|
101
|
return;
|
102
|
}
|
103
|
|
104
|
if (empty($argument)) {
|
105
|
$curwanip = get_interface_ip();
|
106
|
} else {
|
107
|
$curwanip = find_interface_ip($interface_real, true);
|
108
|
if ($curwanip == "") {
|
109
|
$curwanip = get_interface_ip($interface);
|
110
|
}
|
111
|
}
|
112
|
|
113
|
log_error("rc.newwanip: on (IP address: {$curwanip}) (interface: {$interface_descr}[{$interface}]) (real interface: {$interface_real}).");
|
114
|
|
115
|
/*
|
116
|
* NOTE: Take care of openvpn, no-ip or similar interfaces if you generate the event to reconfigure an interface.
|
117
|
* i.e. OpenVPN might be in tap mode and not have an ip.
|
118
|
*/
|
119
|
if ($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
|
120
|
if (substr($interface_real, 0, 4) != "ovpn") {
|
121
|
if (!empty($config['interfaces'][$interface]['ipaddr'])) {
|
122
|
log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
|
123
|
send_event("interface reconfigure {$interface}");
|
124
|
return;
|
125
|
}
|
126
|
}
|
127
|
}
|
128
|
|
129
|
/* XXX: This really possible? */
|
130
|
if (empty($interface)) {
|
131
|
if (platform_booting()) {
|
132
|
return;
|
133
|
}
|
134
|
log_error("rc.newwanip called with empty interface.");
|
135
|
filter_configure();
|
136
|
restart_packages();
|
137
|
return;
|
138
|
}
|
139
|
|
140
|
$oldip = "0.0.0.0";
|
141
|
if (file_exists("{$g['vardb_path']}/{$interface}_cacheip")) {
|
142
|
$oldip = file_get_contents("{$g['vardb_path']}/{$interface}_cacheip");
|
143
|
}
|
144
|
|
145
|
/* regenerate resolv.conf */
|
146
|
system_resolvconf_generate(true);
|
147
|
|
148
|
/* write the current interface IP to file */
|
149
|
if (is_ipaddr($curwanip)) {
|
150
|
@file_put_contents("{$g['vardb_path']}/{$interface}_ip", $curwanip);
|
151
|
}
|
152
|
|
153
|
link_interface_to_vips($interface, "update");
|
154
|
|
155
|
unset($gre);
|
156
|
$gre = link_interface_to_gre($interface);
|
157
|
if (!empty($gre)) {
|
158
|
array_walk($gre, 'interface_gre_configure');
|
159
|
}
|
160
|
|
161
|
unset($gif);
|
162
|
$gif = link_interface_to_gif($interface);
|
163
|
if (!empty($gif)) {
|
164
|
array_walk($gif, 'interface_gif_configure');
|
165
|
}
|
166
|
|
167
|
$grouptmp = link_interface_to_group($interface);
|
168
|
if (!empty($grouptmp)) {
|
169
|
array_walk($grouptmp, 'interface_group_add_member');
|
170
|
}
|
171
|
|
172
|
unset($bridgetmp);
|
173
|
$bridgetmp = link_interface_to_bridge($interface);
|
174
|
if (!empty($bridgetmp)) {
|
175
|
interface_bridge_add_member($bridgetmp, $interface_real);
|
176
|
}
|
177
|
|
178
|
/* make new hosts file */
|
179
|
system_hosts_generate();
|
180
|
|
181
|
/* check tunnelled IPv6 interface tracking */
|
182
|
switch ($config['interfaces'][$interface]['ipaddrv6']) {
|
183
|
case "6to4":
|
184
|
interface_6to4_configure($interface, $config['interfaces'][$interface]);
|
185
|
break;
|
186
|
case "6rd":
|
187
|
interface_6rd_configure($interface, $config['interfaces'][$interface]);
|
188
|
break;
|
189
|
case "dhcp6":
|
190
|
// N.B. PPP connections using PPP as the IPv6 parent interface are excluded because the ppp-ipv6 script calls
|
191
|
// interface_dhcpv6_configure() for these connections after IPv6CP is up
|
192
|
if (isset($config['interfaces'][$interface]['dhcp6usev4iface']) && !interface_isppp_type($interface)) {
|
193
|
interface_dhcpv6_configure($interface, $config['interfaces'][$interface]);
|
194
|
}
|
195
|
break;
|
196
|
}
|
197
|
|
198
|
/* Check Gif tunnels */
|
199
|
if (!empty($gif)) {
|
200
|
foreach ($gif as $giftun) {
|
201
|
$confif = convert_real_interface_to_friendly_interface_name($giftun['gifif']);
|
202
|
if (!empty($confif)) {
|
203
|
interface_configure($confif);
|
204
|
system_routing_configure($confif);
|
205
|
}
|
206
|
}
|
207
|
}
|
208
|
if (!empty($gre)) {
|
209
|
foreach ($gre as $gretun) {
|
210
|
$confif = convert_real_interface_to_friendly_interface_name($gretun['greif']);
|
211
|
if (!empty($confif)) {
|
212
|
interface_configure($confif);
|
213
|
system_routing_configure($confif);
|
214
|
}
|
215
|
}
|
216
|
}
|
217
|
|
218
|
if (platform_booting()) {
|
219
|
// avoid race conditions in many of the below functions that occur during boot
|
220
|
// setting up gateways monitor doesn't seem to have issues here, and fixes the
|
221
|
// most commonly encountered bugs from earlier versions when everything below
|
222
|
// was skipped during boot
|
223
|
setup_gateways_monitor();
|
224
|
exit;
|
225
|
}
|
226
|
|
227
|
/*
|
228
|
* We need to force sync VPNs on such even when the IP is the same for dynamic interfaces.
|
229
|
* Even with the same IP the VPN software is unhappy with the IP disappearing, and we
|
230
|
* could be failing back in which case we need to switch IPs back anyhow.
|
231
|
*/
|
232
|
if (!is_ipaddr($oldip) || $curwanip != $oldip || !is_ipaddrv4($config['interfaces'][$interface]['ipaddr'])) {
|
233
|
/* IP changed, kill states accordingly */
|
234
|
if ($curwanip != $oldip) {
|
235
|
log_error("IP has changed, killing states on former IP $oldip.");
|
236
|
pfSense_kill_states($oldip);
|
237
|
if (isset($config['system']['ip_change_kill_states'])) {
|
238
|
/* hidden config option to wipe all states if needed */
|
239
|
log_error("Killing all states post-IP change.");
|
240
|
filter_flush_state_table();
|
241
|
}
|
242
|
}
|
243
|
|
244
|
/*
|
245
|
* Some services (e.g. dyndns, see ticket #4066) depend on
|
246
|
* filter_configure() to be called before, otherwise pass out
|
247
|
* route-to rules have the old ip set in 'from' and connections
|
248
|
* do not go through the correct link
|
249
|
*/
|
250
|
filter_configure_sync();
|
251
|
|
252
|
/* reconfigure static routes (kernel may have deleted them) */
|
253
|
system_routing_configure($interface);
|
254
|
|
255
|
/* reconfigure our gateway monitor */
|
256
|
setup_gateways_monitor();
|
257
|
|
258
|
/* reload unbound */
|
259
|
services_unbound_configure();
|
260
|
|
261
|
if (is_ipaddr($curwanip)) {
|
262
|
@file_put_contents("{$g['vardb_path']}/{$interface}_cacheip", $curwanip);
|
263
|
}
|
264
|
|
265
|
/* perform RFC 2136 DNS update */
|
266
|
services_dnsupdate_process($interface);
|
267
|
|
268
|
/* signal dyndns update */
|
269
|
services_dyndns_configure($interface);
|
270
|
|
271
|
/* reconfigure IPsec tunnels */
|
272
|
vpn_ipsec_force_reload($interface);
|
273
|
|
274
|
/* start OpenVPN server & clients */
|
275
|
if (substr($interface_real, 0, 4) != "ovpn") {
|
276
|
openvpn_resync_all($interface);
|
277
|
}
|
278
|
|
279
|
/* reload graphing functions */
|
280
|
enable_rrd_graphing();
|
281
|
|
282
|
/* reload igmpproxy */
|
283
|
services_igmpproxy_configure();
|
284
|
|
285
|
/* restart snmp */
|
286
|
services_snmpd_configure();
|
287
|
|
288
|
restart_packages();
|
289
|
} else {
|
290
|
/* signal filter reload */
|
291
|
filter_configure();
|
292
|
}
|
293
|
|
294
|
?>
|