Project

General

Profile

Download (6.37 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
	rc.newwanipv6
5
	Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
6
	part of pfSense (https://www.pfsense.org)
7

    
8
	Originally part of m0n0wall (http://m0n0.ch)
9
	Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
/* parse the configuration and include all functions used below */
35
require_once("globals.inc");
36
require_once("config.inc");
37
require_once("functions.inc");
38
require_once("filter.inc");
39
require_once("shaper.inc");
40
require_once("ipsec.inc");
41
require_once("vpn.inc");
42
require_once("openvpn.inc");
43
require_once("IPv6.inc");
44
require_once("services.inc");
45
require_once("rrd.inc");
46

    
47
function restart_packages() {
48
	global $oldipv6, $curwanipv6, $g;
49

    
50
	/* restart packages */
51
	log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
52
	send_event("service reload packages");
53
}
54

    
55
/* Interface IP address has changed */
56
if (isset($_GET['interface'])) {
57
	$argument = $_GET['interface'];
58
} else {
59
	$argument = trim($argv[1], " \n\t");
60
}
61

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

    
64
if (empty($argument)) {
65
	$interface = "wan";
66
	$interface_real = get_real_interface($interface, "inet6");
67
	$curwanipv6 = get_interface_ipv6($interface, true);
68
} else {
69
	$interface_real = $argument;
70
	$interface = convert_real_interface_to_friendly_interface_name($interface_real);
71
	$curwanipv6 = get_interface_ipv6($interface, true);
72
}
73

    
74
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
75

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

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

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

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

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

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

    
120
/* write current WAN IPv6 to file */
121
if (is_ipaddrv6($curwanipv6)) {
122
	@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
123
}
124

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

    
127
$oldipv6 = '';
128
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
129
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
130
}
131

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

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

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

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

    
145
/* reconfigure our gateway monitor */
146
setup_gateways_monitor();
147

    
148
if (platform_booting) {
149
	// avoid race conditions in many of the below functions that occur during boot
150
	// setting up gateways monitor doesn't seem to have issues here, and fixes the
151
	// most commonly encountered bugs from earlier versions when everything below
152
	// was skipped during boot
153
	setup_gateways_monitor();
154
	exit;
155
}
156

    
157
/* signal filter reload */
158
filter_configure();
159

    
160
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
161
	if ($curwanipv6 == $oldipv6) {
162
		// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
163
		if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
164
			/* reconfigure IPsec tunnels */
165
			vpn_ipsec_force_reload($interface);
166

    
167
			/* start OpenVPN server & clients */
168
			if (substr($interface_real, 0, 4) != "ovpn") {
169
				openvpn_resync_all($interface);
170
			}
171
		}
172
		return;
173
	} else if (does_interface_exist($interface_real) && !empty($oldipv6)) {
174
		mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
175
	}
176

    
177
	file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
178
}
179

    
180
/* reload unbound */
181
services_unbound_configure();
182

    
183
/* perform RFC 2136 DNS update */
184
services_dnsupdate_process($interface);
185

    
186
/* signal dyndns update */
187
services_dyndns_configure($interface);
188

    
189
/* reconfigure IPsec tunnels */
190
vpn_ipsec_force_reload($interface);
191

    
192
/* start OpenVPN server & clients */
193
if (substr($interface_real, 0, 4) != "ovpn") {
194
	openvpn_resync_all($interface);
195
}
196

    
197
/* reload graphing functions */
198
enable_rrd_graphing();
199

    
200
/* reload igmpproxy */
201
services_igmpproxy_configure();
202

    
203
restart_packages();
204

    
205
?>
(68-68/94)