Project

General

Profile

Download (7.25 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-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("services.inc");
70
require_once("rrd.inc");
71

    
72
function restart_packages() {
73
	global $oldipv6, $curwanipv6, $g;
74

    
75
	/* restart packages */
76
	log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
77
	send_event("service reload packages");
78
}
79

    
80
/* Interface IP address has changed */
81
if (isset($_GET['interface'])) {
82
	$argument = $_GET['interface'];
83
} else {
84
	$argument = trim($argv[1], " \n\t");
85
}
86

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

    
89
if (empty($argument)) {
90
	$interface = "wan";
91
	$interface_real = get_real_interface($interface, "inet6");
92
	$curwanipv6 = get_interface_ipv6($interface, true);
93
} else {
94
	$interface_real = $argument;
95
	$interface = convert_real_interface_to_friendly_interface_name($interface_real);
96
	$curwanipv6 = get_interface_ipv6($interface, true);
97
}
98

    
99
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
100

    
101
if (empty($interface)) {
102
	log_error("rc.newwanipv6 called with empty interface");
103
	filter_configure();
104
	return;
105
}
106

    
107
/*
108
 * NOTE: Take care of openvpn and similar if you generate the event to reconfigure an interface.
109
 *	i.e. OpenVPN might be in tap mode and not have an ip.
110
 */
111
if ((empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) && substr($interface_real, 0, 4) != "ovpn") {
112
	log_error("rc.newwanipv6: No IPv6 address found for interface {$interface_descr} [{$interface}].");
113
	return;
114
}
115

    
116
if (isset($_GET['dmips'])) {
117
	$new_domain_name_servers = $_GET['dmips'];
118
} else {
119
	$new_domain_name_servers = getenv("new_domain_name_servers");
120
}
121

    
122
if (!empty($new_domain_name_servers)) {
123
	$name_servers = explode(" ", $new_domain_name_servers);
124
	$valid_ns = array();
125
	foreach ($name_servers as $ns) {
126
		if (is_ipaddrv6(trim($ns))) {
127
			$valid_ns[] = trim($ns);
128
		}
129
	}
130

    
131
	if (count($valid_ns > 0)) {
132
		file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
133
	}
134
}
135
if (isset($_GET['dmnames'])) {
136
	$new_domain_name = $_GET['dmnames'];
137
} else {
138
	$new_domain_name = getenv("new_domain_name");
139
}
140

    
141
if (!empty($new_domain_name)) {
142
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
143
}
144

    
145
/* write current WAN IPv6 to file */
146
if (is_ipaddrv6($curwanipv6)) {
147
	@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
148
}
149

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

    
152
$oldipv6 = '';
153
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
154
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
155
}
156

    
157
$grouptmp = link_interface_to_group($interface);
158
if (!empty($grouptmp)) {
159
	array_walk($grouptmp, 'interface_group_add_member');
160
}
161

    
162
link_interface_to_track6($interface, "update");
163

    
164
/* regenerate resolv.conf if DNS overrides are allowed */
165
system_resolvconf_generate(true);
166

    
167
/* reconfigure static routes (kernel may have deleted them) */
168
system_routing_configure($interface);
169

    
170
/* reconfigure our gateway monitor */
171
setup_gateways_monitor();
172

    
173
if (platform_booting()) {
174
	// avoid race conditions in many of the below functions that occur during boot
175
	exit;
176
}
177

    
178
/* signal filter reload */
179
filter_configure();
180

    
181
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
182
	if ($curwanipv6 == $oldipv6) {
183
		// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
184
		if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
185
			/* reconfigure IPsec tunnels */
186
			vpn_ipsec_force_reload($interface);
187

    
188
			/* start OpenVPN server & clients */
189
			if (substr($interface_real, 0, 4) != "ovpn") {
190
				openvpn_resync_all($interface);
191
			}
192
		}
193
		return;
194
	} else if (does_interface_exist($interface_real) && !empty($oldipv6)) {
195
		mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
196
	}
197

    
198
	file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
199
}
200

    
201
/* reload unbound */
202
services_unbound_configure();
203

    
204
/* perform RFC 2136 DNS update */
205
services_dnsupdate_process($interface);
206

    
207
/* signal dyndns update */
208
services_dyndns_configure($interface);
209

    
210
/* reconfigure IPsec tunnels */
211
vpn_ipsec_force_reload($interface);
212

    
213
/* start OpenVPN server & clients */
214
if (substr($interface_real, 0, 4) != "ovpn") {
215
	openvpn_resync_all($interface);
216
}
217

    
218
/* reload graphing functions */
219
enable_rrd_graphing();
220

    
221
/* reload igmpproxy */
222
services_igmpproxy_configure();
223

    
224
restart_packages();
225

    
226
?>
(68-68/94)