Project

General

Profile

Download (6.9 KB) Statistics
| Branch: | Tag: | Revision:
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-2013 BSD Perimeter
8
 * Copyright (c) 2013-2016 Electric Sheep Fencing
9
 * Copyright (c) 2014-2024 Rubicon Communications, LLC (Netgate)
10
 * All rights reserved.
11
 *
12
 * Originally part of m0n0wall (http://m0n0.ch/wall)
13
 * Copyright (c) 2003-2005 Manuel Kasper <mk@neon1.net>.
14
 * All rights reserved.
15
 *
16
 * Licensed under the Apache License, Version 2.0 (the "License");
17
 * you may not use this file except in compliance with the License.
18
 * You may obtain a copy of the License at
19
 *
20
 * http://www.apache.org/licenses/LICENSE-2.0
21
 *
22
 * Unless required by applicable law or agreed to in writing, software
23
 * distributed under the License is distributed on an "AS IS" BASIS,
24
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25
 * See the License for the specific language governing permissions and
26
 * limitations under the License.
27
 */
28

    
29
/* parse the configuration and include all functions used below */
30
require_once("globals.inc");
31
require_once("config.inc");
32
require_once("functions.inc");
33
require_once("filter.inc");
34
require_once("shaper.inc");
35
require_once("ipsec.inc");
36
require_once("vpn.inc");
37
require_once("openvpn.inc");
38
require_once("Net/IPv6.php");
39
require_once("services.inc");
40
require_once("rrd.inc");
41

    
42
function restart_packages() {
43
	global $oldipv6, $curwanipv6, $g;
44

    
45
	/* restart packages */
46
	log_error("{$g['product_label']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
47
	send_event("service reload packages");
48
}
49

    
50
/* Interface IP address has changed */
51
if (isset($_GET['interface'])) {
52
	$argument = $_GET['interface'];
53
} else {
54
	$argument = trim($argv[1], " \n\t");
55
}
56

    
57
log_error("rc.newwanipv6: Info: starting on {$argument}.");
58

    
59
if (empty($argument)) {
60
	$interface = "wan";
61
	$interface_real = get_real_interface($interface, "inet6");
62
	$curwanipv6 = get_interface_ipv6($interface, true);
63
} else {
64
	$interface_real = $argument;
65
	$interface = convert_real_interface_to_friendly_interface_name($interface_real);
66
	if (empty($interface)) {
67
		log_error("Interface is unassigned, nothing to do.");
68
		return;
69
	}
70
	$curwanipv6 = get_interface_ipv6($interface, true);
71
}
72

    
73
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
74

    
75
if (empty($interface)) {
76
	log_error("rc.newwanipv6 called with empty interface");
77
	filter_configure();
78
	return;
79
}
80

    
81
/*
82
 * NOTE: Take care of openvpn and similar if you generate the event to reconfigure an interface.
83
 *	i.e. OpenVPN might be in tap mode and not have an ip.
84
 */
85
if ((empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) && substr($interface_real, 0, 4) != "ovpn") {
86
	log_error("rc.newwanipv6: No IPv6 address found for interface {$interface_descr} [{$interface}].");
87
	return;
88
}
89

    
90
if (isset($_GET['dmips'])) {
91
	$new_domain_name_servers = $_GET['dmips'];
92
} else {
93
	$new_domain_name_servers = getenv("new_domain_name_servers");
94
}
95

    
96
if (!empty($new_domain_name_servers)) {
97
	$name_servers = explode(" ", $new_domain_name_servers);
98
	$valid_ns = array();
99
	foreach ($name_servers as $ns) {
100
		if (is_ipaddrv6(trim($ns))) {
101
			$valid_ns[] = trim($ns);
102
		}
103
	}
104

    
105
	if (count($valid_ns) > 0) {
106
		file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
107
	}
108
}
109
if (isset($_GET['dmnames'])) {
110
	$new_domain_name = $_GET['dmnames'];
111
} else {
112
	$new_domain_name = getenv("new_domain_name");
113
}
114

    
115
if (!empty($new_domain_name)) {
116
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
117
}
118

    
119
/* write current WAN IPv6 to file */
120
if (is_ipaddrv6($curwanipv6)) {
121
	@file_put_contents(g_get('vardb_path') . "/{$interface_real}_ipv6", $curwanipv6);
122
}
123

    
124
log_error("rc.newwanipv6: on (IP address: {$curwanipv6}) (interface: {$interface}) (real interface: {$interface_real}).");
125

    
126
$oldipv6 = '';
127
if (file_exists(g_get('vardb_path') . "/{$interface_real}_cacheipv6")) {
128
	$oldipv6 = file_get_contents(g_get('vardb_path') . "/{$interface_real}_cacheipv6");
129
}
130

    
131
$grouptmp = link_interface_to_group($interface);
132
if (!empty($grouptmp)) {
133
	array_walk($grouptmp, 'interface_group_add_member');
134
}
135

    
136
link_interface_to_track6($interface, "update");
137

    
138
/* regenerate resolv.conf if DNS overrides are allowed */
139
system_resolvconf_generate(true);
140

    
141
/* reconfigure our gateway monitor, dpinger results need to be 
142
 * available when configuring the default gateway */
143
setup_gateways_monitor();
144

    
145
/* reconfigure static routes (kernel may have deleted them) */
146
system_routing_configure($interface);
147

    
148
if (is_platform_booting()) {
149
	// avoid race conditions in many of the below functions that occur during boot
150
	touch("/tmp/{$interface_real}_dhcp6_complete");
151
	exit;
152
}
153

    
154
/* signal filter reload */
155
filter_configure();
156

    
157
$srvupdate = true;
158
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
159
	if (($curwanipv6 == $oldipv6) && !file_exists("{$g['tmp_path']}/{$interface}_upstart6")) {
160
		// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
161
		if (!in_array(config_get_path("interfaces/{$interface}/ipaddr"), array('pppoe', 'pptp', 'ppp'))) {
162
			return;
163
		} else {
164
			$srvupdate = false;
165
		}
166
	} elseif (does_interface_exist($interface_real) && !empty($oldipv6)) {
167
		mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
168
	}
169

    
170
	file_put_contents(g_get('vardb_path') . "/{$interface_real}_cacheipv6", $curwanipv6);
171
}
172

    
173
if ($srvupdate) {
174
	/* reload unbound */
175
	services_unbound_configure(true, $interface);
176

    
177
	/* perform RFC 2136 DNS update */
178
	services_dnsupdate_process($interface);
179

    
180
	/* signal dyndns update */
181
	services_dyndns_configure($interface);
182
}
183

    
184
/* reconfigure IPsec tunnels */
185
ipsec_force_reload($interface, 'inet6');
186

    
187
/* start OpenVPN server & clients */
188
if (substr($interface_real, 0, 4) != "ovpn") {
189
	openvpn_resync_all($interface, 'inet6');
190
}
191

    
192
/* reconfigure GRE/GIF tunnels */
193
$gre = link_interface_to_tunnelif($interface, 'gre', 'inet6');
194
array_walk($gre, 'interface_gre_configure');
195

    
196
$gif = link_interface_to_tunnelif($interface, 'gif', 'inet6');
197
array_walk($gif, 'interface_gif_configure');
198

    
199
foreach ($gif as $giftun) {
200
	$confif = convert_real_interface_to_friendly_interface_name($giftun['gifif']);
201
	if (!empty($confif)) {
202
		interface_configure($confif);
203
		system_routing_configure($confif);
204
	}
205
}
206
foreach ($gre as $gretun) {
207
	$confif = convert_real_interface_to_friendly_interface_name($gretun['greif']);
208
	if (!empty($confif)) {
209
		interface_configure($confif);
210
		system_routing_configure($confif);
211
	}
212
}
213

    
214
if ($srvupdate) {
215
	/* reload graphing functions */
216
	enable_rrd_graphing();
217

    
218
	restart_packages();
219
}
220

    
221
unlink_if_exists("{$g['tmp_path']}/{$interface}_upstart6");
222
if (empty(config_get_path("interfaces/{$interface}/ipaddr"))) {
223
	unlink_if_exists("{$g['tmp_path']}/{$interface}_upstart4");
224
}
225

    
226
/* Unconditional filter reload to ensure the correct rules and gateways are
227
 * active after this script has processed all changes.
228
 * See https://redmine.pfsense.org/issues/13228 */
229
filter_configure();
230
?>
(58-58/85)