Project

General

Profile

Download (6.27 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -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
	system_ntp_configure(false);
52
	mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
53
	log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
54
	send_event("service reload packages");
55
}
56

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

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

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

    
76
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
77

    
78
if (empty($interface)) {
79
	filter_configure();
80
	// restart_packages();
81
	return;
82
}
83

    
84
//Do not process while booting
85
if (platform_booting() && $config['interfaces'][$interface]['ipaddrv6'] != "dhcp6") {
86
	return;
87
}
88

    
89
/*
90
 * NOTE: Take care of openvpn and similar if you generate the event to reconfigure an interface.
91
 *	i.e. OpenVPN might be in tap mode and not have an ip.
92
 */
93
if ((empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) && substr($interface_real, 0, 4) != "ovpn") {
94
	log_error("rc.newwanipv6: Failed to update {$interface_descr}[{$interface}] IPv6, restarting...");
95
	// send_event("interface reconfigure {$interface}");
96
	return;
97
}
98

    
99
if (isset($_GET['dmips'])) {
100
	$new_domain_name_servers = $_GET['dmips'];
101
} else {
102
	$new_domain_name_servers = getenv("new_domain_name_servers");
103
}
104

    
105
if (!empty($new_domain_name_servers)) {
106
	$name_servers = explode(" ", $new_domain_name_servers);
107
	$valid_ns = array();
108
	foreach ($name_servers as $ns) {
109
		if (is_ipaddrv6(trim($ns))) {
110
			$valid_ns[] = trim($ns);
111
		}
112
	}
113

    
114
	if (count($valid_ns > 0)) {
115
		file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
116
	}
117
}
118
if (isset($_GET['dmnames'])) {
119
	$new_domain_name = $_GET['dmnames'];
120
} else {
121
	$new_domain_name = getenv("new_domain_name");
122
}
123

    
124
if (!empty($new_domain_name)) {
125
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
126
}
127

    
128
/* write current WAN IPv6 to file */
129
if (is_ipaddrv6($curwanipv6)) {
130
	@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
131
}
132

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

    
135
$oldipv6 = '';
136
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
137
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
138
}
139

    
140
$grouptmp = link_interface_to_group($interface);
141
if (!empty($grouptmp)) {
142
	array_walk($grouptmp, 'interface_group_add_member');
143
}
144

    
145
link_interface_to_track6($interface, "update");
146

    
147
/* regenerate resolv.conf if DNS overrides are allowed */
148
system_resolvconf_generate(true);
149

    
150
/* reconfigure static routes (kernel may have deleted them) */
151
system_routing_configure($interface);
152

    
153
/* reconfigure our gateway monitor */
154
setup_gateways_monitor();
155

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

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

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

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

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

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

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

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

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

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

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

    
202
restart_packages();
203

    
204
?>
(77-77/105)