Project

General

Profile

Download (5.83 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-2020 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_name']} 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
openlog("", LOG_PID, LOG_LOCAL0);
58
log_error("rc.newwanipv6: Info: starting on {$argument}.");
59

    
60
if (empty($argument)) {
61
	$interface = "wan";
62
	$interface_real = get_real_interface($interface, "inet6");
63
	$curwanipv6 = get_interface_ipv6($interface, true);
64
} else {
65
	$interface_real = $argument;
66
	$interface = convert_real_interface_to_friendly_interface_name($interface_real);
67
	$curwanipv6 = get_interface_ipv6($interface, true);
68
}
69

    
70
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
71

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

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

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

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

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

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

    
116
/* write current WAN IPv6 to file */
117
if (is_ipaddrv6($curwanipv6)) {
118
	@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
119
}
120

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

    
123
$oldipv6 = '';
124
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
125
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
126
}
127

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

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

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

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

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

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

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

    
154
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
155
	if ($curwanipv6 == $oldipv6) {
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]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
158
			/* reconfigure IPsec tunnels */
159
			ipsec_force_reload($interface);
160

    
161
			/* start OpenVPN server & clients */
162
			if (substr($interface_real, 0, 4) != "ovpn") {
163
				openvpn_resync_all($interface);
164
			}
165
		}
166
		return;
167
	} else if (does_interface_exist($interface_real) && !empty($oldipv6)) {
168
		mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
169
	}
170

    
171
	file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
172
}
173

    
174
/* reload unbound */
175
services_unbound_configure();
176

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

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

    
183
/* reconfigure IPsec tunnels */
184
ipsec_force_reload($interface);
185

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

    
191
/* reload graphing functions */
192
enable_rrd_graphing();
193

    
194
/* reload igmpproxy */
195
services_igmpproxy_configure();
196

    
197
restart_packages();
198

    
199
?>
(55-55/82)