Project

General

Profile

Download (5.71 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 1a0b04df Seth Mos
<?php
3
/*
4 ac24dc24 Renato Botelho
 * rc.newwanipv6
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7 b8f91b7c Luiz Souza
 * Copyright (c) 2006-2018 Rubicon Communications, LLC (Netgate)
8 ac24dc24 Renato Botelho
 * All rights reserved.
9
 *
10
 * Originally part of m0n0wall (http://m0n0.ch/wall)
11 c5d81585 Renato Botelho
 * Copyright (c) 2003-2005 Manuel Kasper <mk@neon1.net>.
12 ac24dc24 Renato Botelho
 * All rights reserved.
13
 *
14 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
15
 * you may not use this file except in compliance with the License.
16
 * You may obtain a copy of the License at
17 ac24dc24 Renato Botelho
 *
18 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
19 ac24dc24 Renato Botelho
 *
20 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
21
 * distributed under the License is distributed on an "AS IS" BASIS,
22
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
 * See the License for the specific language governing permissions and
24
 * limitations under the License.
25 ac24dc24 Renato Botelho
 */
26 1a0b04df Seth Mos
27
/* parse the configuration and include all functions used below */
28
require_once("globals.inc");
29
require_once("config.inc");
30
require_once("functions.inc");
31
require_once("filter.inc");
32
require_once("shaper.inc");
33
require_once("ipsec.inc");
34
require_once("vpn.inc");
35
require_once("openvpn.inc");
36 470fddb1 Renato Botelho
require_once("Net/IPv6.php");
37 5747a735 smos
require_once("services.inc");
38 83bbb0cd smos
require_once("rrd.inc");
39 1a0b04df Seth Mos
40
function restart_packages() {
41 4c45712f smos
	global $oldipv6, $curwanipv6, $g;
42 1a0b04df Seth Mos
43
	/* restart packages */
44 e173dd74 Phil Davis
	log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
45 4c45712f smos
	send_event("service reload packages");
46 d53a9a51 smos
}
47 65101877 smos
48 4c45712f smos
/* Interface IP address has changed */
49 e173dd74 Phil Davis
if (isset($_GET['interface'])) {
50 af8251cc Ermal
	$argument = $_GET['interface'];
51 e173dd74 Phil Davis
} else {
52 af8251cc Ermal
	$argument = trim($argv[1], " \n\t");
53 e173dd74 Phil Davis
}
54 4c45712f smos
55 002d286c Chris Buechler
log_error("rc.newwanipv6: Info: starting on {$argument}.");
56 4c45712f smos
57 91571af5 Ermal
if (empty($argument)) {
58 4c45712f smos
	$interface = "wan";
59 314b9b2c Ermal
	$interface_real = get_real_interface($interface, "inet6");
60 b6c1f22f Ermal
	$curwanipv6 = get_interface_ipv6($interface, true);
61 4c45712f smos
} else {
62
	$interface_real = $argument;
63
	$interface = convert_real_interface_to_friendly_interface_name($interface_real);
64 b6c1f22f Ermal
	$curwanipv6 = get_interface_ipv6($interface, true);
65 d53a9a51 smos
}
66 9d158467 Seth Mos
67 91571af5 Ermal
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
68
69 9cd6b950 Ermal
if (empty($interface)) {
70 ef945b86 Chris Buechler
	log_error("rc.newwanipv6 called with empty interface");
71 9cd6b950 Ermal
	filter_configure();
72 af8251cc Ermal
	return;
73 9cd6b950 Ermal
}
74
75 91571af5 Ermal
/*
76
 * NOTE: Take care of openvpn and similar if you generate the event to reconfigure an interface.
77
 *	i.e. OpenVPN might be in tap mode and not have an ip.
78
 */
79 faf20ee4 Ermal
if ((empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) && substr($interface_real, 0, 4) != "ovpn") {
80 c32b4917 Chris Buechler
	log_error("rc.newwanipv6: No IPv6 address found for interface {$interface_descr} [{$interface}].");
81 e173dd74 Phil Davis
	return;
82 9cd6b950 Ermal
}
83
84 e173dd74 Phil Davis
if (isset($_GET['dmips'])) {
85 af8251cc Ermal
	$new_domain_name_servers = $_GET['dmips'];
86 e173dd74 Phil Davis
} else {
87 af8251cc Ermal
	$new_domain_name_servers = getenv("new_domain_name_servers");
88 e173dd74 Phil Davis
}
89
90 362ec35d Ermal
if (!empty($new_domain_name_servers)) {
91
	$name_servers = explode(" ", $new_domain_name_servers);
92 e082d2f4 Ermal
	$valid_ns = array();
93 e173dd74 Phil Davis
	foreach ($name_servers as $ns) {
94
		if (is_ipaddrv6(trim($ns))) {
95 e082d2f4 Ermal
			$valid_ns[] = trim($ns);
96 e173dd74 Phil Davis
		}
97 e082d2f4 Ermal
	}
98 04aac151 bcyrill
99 90b3235d jim-p
	if (count($valid_ns) > 0) {
100 e082d2f4 Ermal
		file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
101 e173dd74 Phil Davis
	}
102 e082d2f4 Ermal
}
103 e173dd74 Phil Davis
if (isset($_GET['dmnames'])) {
104 af8251cc Ermal
	$new_domain_name = $_GET['dmnames'];
105 e173dd74 Phil Davis
} else {
106 af8251cc Ermal
	$new_domain_name = getenv("new_domain_name");
107 e173dd74 Phil Davis
}
108
109
if (!empty($new_domain_name)) {
110 362ec35d Ermal
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
111 e173dd74 Phil Davis
}
112 04aac151 bcyrill
113 7a04cd20 Ermal
/* write current WAN IPv6 to file */
114 e173dd74 Phil Davis
if (is_ipaddrv6($curwanipv6)) {
115 91571af5 Ermal
	@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
116 e173dd74 Phil Davis
}
117 7a04cd20 Ermal
118 8026f19c Ermal
log_error("rc.newwanipv6: on (IP address: {$curwanipv6}) (interface: {$interface}) (real interface: {$interface_real}).");
119 1a0b04df Seth Mos
120 68716545 Ermal LUÇI
$oldipv6 = '';
121 e173dd74 Phil Davis
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
122 1a0b04df Seth Mos
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
123 e173dd74 Phil Davis
}
124 1a0b04df Seth Mos
125
$grouptmp = link_interface_to_group($interface);
126 e173dd74 Phil Davis
if (!empty($grouptmp)) {
127 1a0b04df Seth Mos
	array_walk($grouptmp, 'interface_group_add_member');
128 e173dd74 Phil Davis
}
129 1a0b04df Seth Mos
130 7a04cd20 Ermal
link_interface_to_track6($interface, "update");
131
132 1a0b04df Seth Mos
/* regenerate resolv.conf if DNS overrides are allowed */
133
system_resolvconf_generate(true);
134
135 742cc9ae PiBa-NL
/* reconfigure our gateway monitor, dpinger results need to be 
136
 * available when configuring the default gateway */
137
setup_gateways_monitor();
138
139 1a0b04df Seth Mos
/* reconfigure static routes (kernel may have deleted them) */
140
system_routing_configure($interface);
141
142 b8735779 Chris Buechler
if (platform_booting()) {
143 c4b5c8be Chris Buechler
	// avoid race conditions in many of the below functions that occur during boot
144 881fb186 marjohn56
	touch("/tmp/{$interface_real}_dhcp6_complete");
145 c4b5c8be Chris Buechler
	exit;
146
}
147
148 1a0b04df Seth Mos
/* signal filter reload */
149
filter_configure();
150
151 68716545 Ermal LUÇI
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
152 f6461410 Renato Botelho
	if ($curwanipv6 == $oldipv6) {
153
		// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
154
		if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
155
			/* reconfigure IPsec tunnels */
156 aa752473 Renato Botelho
			vpn_ipsec_force_reload($interface);
157 f6461410 Renato Botelho
158
			/* start OpenVPN server & clients */
159 e173dd74 Phil Davis
			if (substr($interface_real, 0, 4) != "ovpn") {
160 8026f19c Ermal
				openvpn_resync_all($interface);
161 e173dd74 Phil Davis
			}
162 f6461410 Renato Botelho
		}
163 af8251cc Ermal
		return;
164 e173dd74 Phil Davis
	} else if (does_interface_exist($interface_real) && !empty($oldipv6)) {
165 8026f19c Ermal
		mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
166 e173dd74 Phil Davis
	}
167 1a0b04df Seth Mos
168 91571af5 Ermal
	file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
169
}
170 1a0b04df Seth Mos
171 36dbc3ae Chris Buechler
/* reload unbound */
172
services_unbound_configure();
173 e173dd74 Phil Davis
174 1a0b04df Seth Mos
/* perform RFC 2136 DNS update */
175
services_dnsupdate_process($interface);
176
177
/* signal dyndns update */
178
services_dyndns_configure($interface);
179
180
/* reconfigure IPsec tunnels */
181 aa752473 Renato Botelho
vpn_ipsec_force_reload($interface);
182 1a0b04df Seth Mos
183
/* start OpenVPN server & clients */
184 e173dd74 Phil Davis
if (substr($interface_real, 0, 4) != "ovpn") {
185 1a0b04df Seth Mos
	openvpn_resync_all($interface);
186 e173dd74 Phil Davis
}
187 1a0b04df Seth Mos
188
/* reload graphing functions */
189
enable_rrd_graphing();
190
191
/* reload igmpproxy */
192
services_igmpproxy_configure();
193
194
restart_packages();
195
196
?>