1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.newwanipv6
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2006-2018 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
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
15
|
* you may not use this file except in compliance with the License.
|
16
|
* You may obtain a copy of the License at
|
17
|
*
|
18
|
* http://www.apache.org/licenses/LICENSE-2.0
|
19
|
*
|
20
|
* Unless required by applicable law or agreed to in writing, software
|
21
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
22
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
23
|
* See the License for the specific language governing permissions and
|
24
|
* limitations under the License.
|
25
|
*/
|
26
|
|
27
|
/* parse the configuration and include all functions used below */
|
28
|
require_once("globals.inc");
|
29
|
require_once("config.inc");
|
30
|
require_once("functions.inc");
|
31
|
require_once("filter.inc");
|
32
|
require_once("shaper.inc");
|
33
|
require_once("ipsec.inc");
|
34
|
require_once("vpn.inc");
|
35
|
require_once("openvpn.inc");
|
36
|
require_once("Net/IPv6.php");
|
37
|
require_once("services.inc");
|
38
|
require_once("rrd.inc");
|
39
|
|
40
|
function restart_packages() {
|
41
|
global $oldipv6, $curwanipv6, $g;
|
42
|
|
43
|
/* restart packages */
|
44
|
log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
|
45
|
send_event("service reload packages");
|
46
|
}
|
47
|
|
48
|
/* Interface IP address has changed */
|
49
|
if (isset($_GET['interface'])) {
|
50
|
$argument = $_GET['interface'];
|
51
|
} else {
|
52
|
$argument = trim($argv[1], " \n\t");
|
53
|
}
|
54
|
|
55
|
log_error("rc.newwanipv6: Info: starting on {$argument}.");
|
56
|
|
57
|
if (empty($argument)) {
|
58
|
$interface = "wan";
|
59
|
$interface_real = get_real_interface($interface, "inet6");
|
60
|
$curwanipv6 = get_interface_ipv6($interface, true);
|
61
|
} else {
|
62
|
$interface_real = $argument;
|
63
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
64
|
$curwanipv6 = get_interface_ipv6($interface, true);
|
65
|
}
|
66
|
|
67
|
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
|
68
|
|
69
|
if (empty($interface)) {
|
70
|
log_error("rc.newwanipv6 called with empty interface");
|
71
|
filter_configure();
|
72
|
return;
|
73
|
}
|
74
|
|
75
|
/*
|
76
|
* NOTE: Take care of openvpn and similar if you generate the event to reconfigure an interface.
|
77
|
* i.e. OpenVPN might be in tap mode and not have an ip.
|
78
|
*/
|
79
|
if ((empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) && substr($interface_real, 0, 4) != "ovpn") {
|
80
|
log_error("rc.newwanipv6: No IPv6 address found for interface {$interface_descr} [{$interface}].");
|
81
|
return;
|
82
|
}
|
83
|
|
84
|
if (isset($_GET['dmips'])) {
|
85
|
$new_domain_name_servers = $_GET['dmips'];
|
86
|
} else {
|
87
|
$new_domain_name_servers = getenv("new_domain_name_servers");
|
88
|
}
|
89
|
|
90
|
if (!empty($new_domain_name_servers)) {
|
91
|
$name_servers = explode(" ", $new_domain_name_servers);
|
92
|
$valid_ns = array();
|
93
|
foreach ($name_servers as $ns) {
|
94
|
if (is_ipaddrv6(trim($ns))) {
|
95
|
$valid_ns[] = trim($ns);
|
96
|
}
|
97
|
}
|
98
|
|
99
|
if (count($valid_ns) > 0) {
|
100
|
file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
|
101
|
}
|
102
|
}
|
103
|
if (isset($_GET['dmnames'])) {
|
104
|
$new_domain_name = $_GET['dmnames'];
|
105
|
} else {
|
106
|
$new_domain_name = getenv("new_domain_name");
|
107
|
}
|
108
|
|
109
|
if (!empty($new_domain_name)) {
|
110
|
file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
|
111
|
}
|
112
|
|
113
|
/* write current WAN IPv6 to file */
|
114
|
if (is_ipaddrv6($curwanipv6)) {
|
115
|
@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
|
116
|
}
|
117
|
|
118
|
log_error("rc.newwanipv6: on (IP address: {$curwanipv6}) (interface: {$interface}) (real interface: {$interface_real}).");
|
119
|
|
120
|
$oldipv6 = '';
|
121
|
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
|
122
|
$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
|
123
|
}
|
124
|
|
125
|
$grouptmp = link_interface_to_group($interface);
|
126
|
if (!empty($grouptmp)) {
|
127
|
array_walk($grouptmp, 'interface_group_add_member');
|
128
|
}
|
129
|
|
130
|
link_interface_to_track6($interface, "update");
|
131
|
|
132
|
/* regenerate resolv.conf if DNS overrides are allowed */
|
133
|
system_resolvconf_generate(true);
|
134
|
|
135
|
/* reconfigure our gateway monitor, dpinger results need to be
|
136
|
* available when configuring the default gateway */
|
137
|
setup_gateways_monitor();
|
138
|
|
139
|
/* reconfigure static routes (kernel may have deleted them) */
|
140
|
system_routing_configure($interface);
|
141
|
|
142
|
if (platform_booting()) {
|
143
|
// avoid race conditions in many of the below functions that occur during boot
|
144
|
touch("/tmp/{$interface_real}_dhcp6_complete");
|
145
|
exit;
|
146
|
}
|
147
|
|
148
|
/* signal filter reload */
|
149
|
filter_configure();
|
150
|
|
151
|
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
|
152
|
if ($curwanipv6 == $oldipv6) {
|
153
|
// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
|
154
|
if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
|
155
|
/* reconfigure IPsec tunnels */
|
156
|
vpn_ipsec_force_reload($interface);
|
157
|
|
158
|
/* start OpenVPN server & clients */
|
159
|
if (substr($interface_real, 0, 4) != "ovpn") {
|
160
|
openvpn_resync_all($interface);
|
161
|
}
|
162
|
}
|
163
|
return;
|
164
|
} else if (does_interface_exist($interface_real) && !empty($oldipv6)) {
|
165
|
mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
|
166
|
}
|
167
|
|
168
|
file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
|
169
|
}
|
170
|
|
171
|
/* reload unbound */
|
172
|
services_unbound_configure();
|
173
|
|
174
|
/* perform RFC 2136 DNS update */
|
175
|
services_dnsupdate_process($interface);
|
176
|
|
177
|
/* signal dyndns update */
|
178
|
services_dyndns_configure($interface);
|
179
|
|
180
|
/* reconfigure IPsec tunnels */
|
181
|
vpn_ipsec_force_reload($interface);
|
182
|
|
183
|
/* start OpenVPN server & clients */
|
184
|
if (substr($interface_real, 0, 4) != "ovpn") {
|
185
|
openvpn_resync_all($interface);
|
186
|
}
|
187
|
|
188
|
/* reload graphing functions */
|
189
|
enable_rrd_graphing();
|
190
|
|
191
|
/* reload igmpproxy */
|
192
|
services_igmpproxy_configure();
|
193
|
|
194
|
restart_packages();
|
195
|
|
196
|
?>
|