Project

General

Profile

Download (6.79 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
	$curwanipv6 = get_interface_ipv6($interface, true);
67
}
68

    
69
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
70

    
71
if (empty($interface)) {
72
	log_error("rc.newwanipv6 called with empty interface");
73
	filter_configure();
74
	return;
75
}
76

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

    
86
if (isset($_GET['dmips'])) {
87
	$new_domain_name_servers = $_GET['dmips'];
88
} else {
89
	$new_domain_name_servers = getenv("new_domain_name_servers");
90
}
91

    
92
if (!empty($new_domain_name_servers)) {
93
	$name_servers = explode(" ", $new_domain_name_servers);
94
	$valid_ns = array();
95
	foreach ($name_servers as $ns) {
96
		if (is_ipaddrv6(trim($ns))) {
97
			$valid_ns[] = trim($ns);
98
		}
99
	}
100

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

    
111
if (!empty($new_domain_name)) {
112
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
113
}
114

    
115
/* write current WAN IPv6 to file */
116
if (is_ipaddrv6($curwanipv6)) {
117
	@file_put_contents(g_get('vardb_path') . "/{$interface_real}_ipv6", $curwanipv6);
118
}
119

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

    
122
$oldipv6 = '';
123
if (file_exists(g_get('vardb_path') . "/{$interface_real}_cacheipv6")) {
124
	$oldipv6 = file_get_contents(g_get('vardb_path') . "/{$interface_real}_cacheipv6");
125
}
126

    
127
$grouptmp = link_interface_to_group($interface);
128
if (!empty($grouptmp)) {
129
	array_walk($grouptmp, 'interface_group_add_member');
130
}
131

    
132
link_interface_to_track6($interface, "update");
133

    
134
/* regenerate resolv.conf if DNS overrides are allowed */
135
system_resolvconf_generate(true);
136

    
137
/* reconfigure our gateway monitor, dpinger results need to be 
138
 * available when configuring the default gateway */
139
setup_gateways_monitor();
140

    
141
/* reconfigure static routes (kernel may have deleted them) */
142
system_routing_configure($interface);
143

    
144
if (platform_booting()) {
145
	// avoid race conditions in many of the below functions that occur during boot
146
	touch("/tmp/{$interface_real}_dhcp6_complete");
147
	exit;
148
}
149

    
150
/* signal filter reload */
151
filter_configure();
152

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

    
166
	file_put_contents(g_get('vardb_path') . "/{$interface_real}_cacheipv6", $curwanipv6);
167
}
168

    
169
if ($srvupdate) {
170
	/* reload unbound */
171
	services_unbound_configure(true, $interface);
172

    
173
	/* perform RFC 2136 DNS update */
174
	services_dnsupdate_process($interface);
175

    
176
	/* signal dyndns update */
177
	services_dyndns_configure($interface);
178
}
179

    
180
/* reconfigure IPsec tunnels */
181
ipsec_force_reload($interface, 'inet6');
182

    
183
/* start OpenVPN server & clients */
184
if (substr($interface_real, 0, 4) != "ovpn") {
185
	openvpn_resync_all($interface, 'inet6');
186
}
187

    
188
/* reconfigure GRE/GIF tunnels */
189
$gre = link_interface_to_tunnelif($interface, 'gre', 'inet6');
190
array_walk($gre, 'interface_gre_configure');
191

    
192
$gif = link_interface_to_tunnelif($interface, 'gif', 'inet6');
193
array_walk($gif, 'interface_gif_configure');
194

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

    
210
if ($srvupdate) {
211
	/* reload graphing functions */
212
	enable_rrd_graphing();
213

    
214
	restart_packages();
215
}
216

    
217
unlink_if_exists("{$g['tmp_path']}/{$interface}_upstart6");
218
if (empty($config['interfaces'][$interface]['ipaddr'])) {
219
	unlink_if_exists("{$g['tmp_path']}/{$interface}_upstart4");
220
}
221

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