1 |
cb7d18d5
|
Renato Botelho
|
#!/usr/local/bin/php-cgi -f
|
2 |
1a0b04df
|
Seth Mos
|
<?php
|
3 |
|
|
/*
|
4 |
ce77a9c4
|
Phil Davis
|
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 |
1a0b04df
|
Seth Mos
|
*/
|
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 |
9d158467
|
Seth Mos
|
require_once("IPv6.inc");
|
44 |
5747a735
|
smos
|
require_once("services.inc");
|
45 |
83bbb0cd
|
smos
|
require_once("rrd.inc");
|
46 |
1a0b04df
|
Seth Mos
|
|
47 |
|
|
function restart_packages() {
|
48 |
4c45712f
|
smos
|
global $oldipv6, $curwanipv6, $g;
|
49 |
1a0b04df
|
Seth Mos
|
|
50 |
|
|
/* restart packages */
|
51 |
e173dd74
|
Phil Davis
|
log_error("{$g['product_name']} package system has detected an IP change or dynamic WAN reconnection - $oldipv6 -> $curwanipv6 - Restarting packages.");
|
52 |
4c45712f
|
smos
|
send_event("service reload packages");
|
53 |
d53a9a51
|
smos
|
}
|
54 |
65101877
|
smos
|
|
55 |
4c45712f
|
smos
|
/* Interface IP address has changed */
|
56 |
e173dd74
|
Phil Davis
|
if (isset($_GET['interface'])) {
|
57 |
af8251cc
|
Ermal
|
$argument = $_GET['interface'];
|
58 |
e173dd74
|
Phil Davis
|
} else {
|
59 |
af8251cc
|
Ermal
|
$argument = trim($argv[1], " \n\t");
|
60 |
e173dd74
|
Phil Davis
|
}
|
61 |
4c45712f
|
smos
|
|
62 |
002d286c
|
Chris Buechler
|
log_error("rc.newwanipv6: Info: starting on {$argument}.");
|
63 |
4c45712f
|
smos
|
|
64 |
91571af5
|
Ermal
|
if (empty($argument)) {
|
65 |
4c45712f
|
smos
|
$interface = "wan";
|
66 |
314b9b2c
|
Ermal
|
$interface_real = get_real_interface($interface, "inet6");
|
67 |
b6c1f22f
|
Ermal
|
$curwanipv6 = get_interface_ipv6($interface, true);
|
68 |
4c45712f
|
smos
|
} else {
|
69 |
|
|
$interface_real = $argument;
|
70 |
|
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
71 |
b6c1f22f
|
Ermal
|
$curwanipv6 = get_interface_ipv6($interface, true);
|
72 |
d53a9a51
|
smos
|
}
|
73 |
9d158467
|
Seth Mos
|
|
74 |
91571af5
|
Ermal
|
$interface_descr = convert_friendly_interface_to_friendly_descr($interface);
|
75 |
|
|
|
76 |
9cd6b950
|
Ermal
|
if (empty($interface)) {
|
77 |
|
|
filter_configure();
|
78 |
af8251cc
|
Ermal
|
return;
|
79 |
9cd6b950
|
Ermal
|
}
|
80 |
|
|
|
81 |
91571af5
|
Ermal
|
/*
|
82 |
|
|
* NOTE: Take care of openvpn and similar if you generate the event to reconfigure an interface.
|
83 |
|
|
* i.e. OpenVPN might be in tap mode and not have an ip.
|
84 |
|
|
*/
|
85 |
faf20ee4
|
Ermal
|
if ((empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) && substr($interface_real, 0, 4) != "ovpn") {
|
86 |
c32b4917
|
Chris Buechler
|
log_error("rc.newwanipv6: No IPv6 address found for interface {$interface_descr} [{$interface}].");
|
87 |
e173dd74
|
Phil Davis
|
return;
|
88 |
9cd6b950
|
Ermal
|
}
|
89 |
|
|
|
90 |
e173dd74
|
Phil Davis
|
if (isset($_GET['dmips'])) {
|
91 |
af8251cc
|
Ermal
|
$new_domain_name_servers = $_GET['dmips'];
|
92 |
e173dd74
|
Phil Davis
|
} else {
|
93 |
af8251cc
|
Ermal
|
$new_domain_name_servers = getenv("new_domain_name_servers");
|
94 |
e173dd74
|
Phil Davis
|
}
|
95 |
|
|
|
96 |
362ec35d
|
Ermal
|
if (!empty($new_domain_name_servers)) {
|
97 |
|
|
$name_servers = explode(" ", $new_domain_name_servers);
|
98 |
e082d2f4
|
Ermal
|
$valid_ns = array();
|
99 |
e173dd74
|
Phil Davis
|
foreach ($name_servers as $ns) {
|
100 |
|
|
if (is_ipaddrv6(trim($ns))) {
|
101 |
e082d2f4
|
Ermal
|
$valid_ns[] = trim($ns);
|
102 |
e173dd74
|
Phil Davis
|
}
|
103 |
e082d2f4
|
Ermal
|
}
|
104 |
04aac151
|
bcyrill
|
|
105 |
e173dd74
|
Phil Davis
|
if (count($valid_ns > 0)) {
|
106 |
e082d2f4
|
Ermal
|
file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
|
107 |
e173dd74
|
Phil Davis
|
}
|
108 |
e082d2f4
|
Ermal
|
}
|
109 |
e173dd74
|
Phil Davis
|
if (isset($_GET['dmnames'])) {
|
110 |
af8251cc
|
Ermal
|
$new_domain_name = $_GET['dmnames'];
|
111 |
e173dd74
|
Phil Davis
|
} else {
|
112 |
af8251cc
|
Ermal
|
$new_domain_name = getenv("new_domain_name");
|
113 |
e173dd74
|
Phil Davis
|
}
|
114 |
|
|
|
115 |
|
|
if (!empty($new_domain_name)) {
|
116 |
362ec35d
|
Ermal
|
file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $new_domain_name);
|
117 |
e173dd74
|
Phil Davis
|
}
|
118 |
04aac151
|
bcyrill
|
|
119 |
7a04cd20
|
Ermal
|
/* write current WAN IPv6 to file */
|
120 |
e173dd74
|
Phil Davis
|
if (is_ipaddrv6($curwanipv6)) {
|
121 |
91571af5
|
Ermal
|
@file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
|
122 |
e173dd74
|
Phil Davis
|
}
|
123 |
7a04cd20
|
Ermal
|
|
124 |
8026f19c
|
Ermal
|
log_error("rc.newwanipv6: on (IP address: {$curwanipv6}) (interface: {$interface}) (real interface: {$interface_real}).");
|
125 |
1a0b04df
|
Seth Mos
|
|
126 |
68716545
|
Ermal LUÇI
|
$oldipv6 = '';
|
127 |
e173dd74
|
Phil Davis
|
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6")) {
|
128 |
1a0b04df
|
Seth Mos
|
$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
|
129 |
e173dd74
|
Phil Davis
|
}
|
130 |
1a0b04df
|
Seth Mos
|
|
131 |
|
|
$grouptmp = link_interface_to_group($interface);
|
132 |
e173dd74
|
Phil Davis
|
if (!empty($grouptmp)) {
|
133 |
1a0b04df
|
Seth Mos
|
array_walk($grouptmp, 'interface_group_add_member');
|
134 |
e173dd74
|
Phil Davis
|
}
|
135 |
1a0b04df
|
Seth Mos
|
|
136 |
7a04cd20
|
Ermal
|
link_interface_to_track6($interface, "update");
|
137 |
|
|
|
138 |
1a0b04df
|
Seth Mos
|
/* regenerate resolv.conf if DNS overrides are allowed */
|
139 |
|
|
system_resolvconf_generate(true);
|
140 |
|
|
|
141 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
142 |
|
|
system_routing_configure($interface);
|
143 |
|
|
|
144 |
|
|
/* reconfigure our gateway monitor */
|
145 |
|
|
setup_gateways_monitor();
|
146 |
|
|
|
147 |
|
|
/* signal filter reload */
|
148 |
|
|
filter_configure();
|
149 |
|
|
|
150 |
68716545
|
Ermal LUÇI
|
if (empty($oldipv6) || is_ipaddrv6($oldipv6)) {
|
151 |
f6461410
|
Renato Botelho
|
if ($curwanipv6 == $oldipv6) {
|
152 |
|
|
// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
|
153 |
|
|
if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
|
154 |
|
|
/* reconfigure IPsec tunnels */
|
155 |
aa752473
|
Renato Botelho
|
vpn_ipsec_force_reload($interface);
|
156 |
f6461410
|
Renato Botelho
|
|
157 |
|
|
/* start OpenVPN server & clients */
|
158 |
e173dd74
|
Phil Davis
|
if (substr($interface_real, 0, 4) != "ovpn") {
|
159 |
8026f19c
|
Ermal
|
openvpn_resync_all($interface);
|
160 |
e173dd74
|
Phil Davis
|
}
|
161 |
f6461410
|
Renato Botelho
|
}
|
162 |
af8251cc
|
Ermal
|
return;
|
163 |
e173dd74
|
Phil Davis
|
} else if (does_interface_exist($interface_real) && !empty($oldipv6)) {
|
164 |
8026f19c
|
Ermal
|
mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
|
165 |
e173dd74
|
Phil Davis
|
}
|
166 |
1a0b04df
|
Seth Mos
|
|
167 |
91571af5
|
Ermal
|
file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
|
168 |
|
|
}
|
169 |
1a0b04df
|
Seth Mos
|
|
170 |
36dbc3ae
|
Chris Buechler
|
/* reload unbound */
|
171 |
|
|
services_unbound_configure();
|
172 |
e173dd74
|
Phil Davis
|
|
173 |
1a0b04df
|
Seth Mos
|
/* perform RFC 2136 DNS update */
|
174 |
|
|
services_dnsupdate_process($interface);
|
175 |
|
|
|
176 |
|
|
/* signal dyndns update */
|
177 |
|
|
services_dyndns_configure($interface);
|
178 |
|
|
|
179 |
|
|
/* reconfigure IPsec tunnels */
|
180 |
aa752473
|
Renato Botelho
|
vpn_ipsec_force_reload($interface);
|
181 |
1a0b04df
|
Seth Mos
|
|
182 |
|
|
/* start OpenVPN server & clients */
|
183 |
e173dd74
|
Phil Davis
|
if (substr($interface_real, 0, 4) != "ovpn") {
|
184 |
1a0b04df
|
Seth Mos
|
openvpn_resync_all($interface);
|
185 |
e173dd74
|
Phil Davis
|
}
|
186 |
1a0b04df
|
Seth Mos
|
|
187 |
|
|
/* reload graphing functions */
|
188 |
|
|
enable_rrd_graphing();
|
189 |
|
|
|
190 |
|
|
/* reload igmpproxy */
|
191 |
|
|
services_igmpproxy_configure();
|
192 |
|
|
|
193 |
|
|
restart_packages();
|
194 |
|
|
|
195 |
|
|
?>
|