1 |
1a0b04df
|
Seth Mos
|
#!/usr/local/bin/php -f
|
2 |
|
|
<?php
|
3 |
|
|
/*
|
4 |
4c45712f
|
smos
|
rc.newwanipv6
|
5 |
1a0b04df
|
Seth Mos
|
Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
|
6 |
|
|
part of pfSense (http://www.pfsense.com)
|
7 |
|
|
|
8 |
9d158467
|
Seth Mos
|
Originally part of m0n0wall (http://m0n0.ch)
|
9 |
|
|
Copyright (C) 2003-2005 Manuel Kasper <mk@neon1.net>.
|
10 |
|
|
All rights reserved.
|
11 |
1a0b04df
|
Seth Mos
|
|
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 |
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 |
0b8e9d38
|
jim-p
|
system_ntp_configure(false);
|
52 |
b61e8960
|
jim-p
|
mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
|
53 |
4c45712f
|
smos
|
log_error("{$g['product_name']} package system has detected an ip change $oldipv6 -> $curwanipv6 ... Restarting packages.");
|
54 |
|
|
send_event("service reload packages");
|
55 |
d53a9a51
|
smos
|
}
|
56 |
65101877
|
smos
|
|
57 |
4c45712f
|
smos
|
/* Interface IP address has changed */
|
58 |
08efe4e6
|
Ermal
|
$argument = trim($argv[1], " \n\t");
|
59 |
4c45712f
|
smos
|
|
60 |
|
|
log_error("rc.newwanipv6: Informational is starting {$argument}.");
|
61 |
|
|
|
62 |
|
|
if(empty($argument)) {
|
63 |
|
|
$interface = "wan";
|
64 |
d90ea5ff
|
Ermal
|
$interface_real = get_real_interface($interface, "inet6");
|
65 |
b6c1f22f
|
Ermal
|
$curwanipv6 = get_interface_ipv6($interface, true);
|
66 |
4c45712f
|
smos
|
} else {
|
67 |
|
|
$interface_real = $argument;
|
68 |
|
|
$interface = convert_real_interface_to_friendly_interface_name($interface_real);
|
69 |
b6c1f22f
|
Ermal
|
$curwanipv6 = get_interface_ipv6($interface, true);
|
70 |
d53a9a51
|
smos
|
}
|
71 |
9d158467
|
Seth Mos
|
|
72 |
9cd6b950
|
Ermal
|
if (empty($interface)) {
|
73 |
|
|
filter_configure();
|
74 |
|
|
// restart_packages();
|
75 |
|
|
exit;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
673c2f8b
|
Ermal
|
//Do not process while booting
|
79 |
10ce1ac1
|
Ermal
|
if ($g['booting'] && $config['interfaces'][$interface]['ipaddrv6'] != "dhcp6")
|
80 |
673c2f8b
|
Ermal
|
exit;
|
81 |
|
|
|
82 |
10ce1ac1
|
Ermal
|
if (empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) {
|
83 |
9cd6b950
|
Ermal
|
log_error("rc.newwanipv6: Failed to update {$interface} IPv6, restarting...");
|
84 |
|
|
// send_event("interface reconfigure {$interface}");
|
85 |
|
|
exit;
|
86 |
|
|
}
|
87 |
|
|
|
88 |
e082d2f4
|
Ermal
|
if (!empty($_ENV['new_domain_name_servers'])) {
|
89 |
|
|
$name_servers = explode(" ", $_ENV['new_domain_name_servers']);
|
90 |
|
|
$valid_ns = array();
|
91 |
|
|
foreach($name_servers as $ns) {
|
92 |
10ce1ac1
|
Ermal
|
if (is_ipaddrv6(trim($ns)))
|
93 |
e082d2f4
|
Ermal
|
$valid_ns[] = trim($ns);
|
94 |
|
|
}
|
95 |
04aac151
|
bcyrill
|
|
96 |
10ce1ac1
|
Ermal
|
if (count($valid_ns > 0))
|
97 |
e082d2f4
|
Ermal
|
file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
|
98 |
|
|
}
|
99 |
10ce1ac1
|
Ermal
|
if (!empty($_ENV['new_domain_name']))
|
100 |
04aac151
|
bcyrill
|
file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $_ENV['new_domain_name']);
|
101 |
|
|
|
102 |
7a04cd20
|
Ermal
|
/* write current WAN IPv6 to file */
|
103 |
|
|
file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
|
104 |
|
|
|
105 |
10ce1ac1
|
Ermal
|
log_error("rc.newwanipv6: on (IP address: {$curwanipv6}) (interface: {$interface}) (real interface: {$interface_real}).");
|
106 |
1a0b04df
|
Seth Mos
|
|
107 |
46a7c9aa
|
smos
|
$oldipv6 = "";
|
108 |
1a0b04df
|
Seth Mos
|
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6"))
|
109 |
|
|
$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
|
110 |
|
|
|
111 |
|
|
$grouptmp = link_interface_to_group($interface);
|
112 |
|
|
if (!empty($grouptmp))
|
113 |
|
|
array_walk($grouptmp, 'interface_group_add_member');
|
114 |
|
|
|
115 |
7a04cd20
|
Ermal
|
link_interface_to_track6($interface, "update");
|
116 |
|
|
|
117 |
1a0b04df
|
Seth Mos
|
/* regenerate resolv.conf if DNS overrides are allowed */
|
118 |
|
|
system_resolvconf_generate(true);
|
119 |
|
|
|
120 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
121 |
|
|
system_routing_configure($interface);
|
122 |
|
|
|
123 |
|
|
/* reconfigure our gateway monitor */
|
124 |
|
|
setup_gateways_monitor();
|
125 |
|
|
|
126 |
|
|
/* signal filter reload */
|
127 |
|
|
filter_configure();
|
128 |
|
|
|
129 |
f6461410
|
Renato Botelho
|
if (is_ipaddrv6($oldipv6)) {
|
130 |
|
|
if ($curwanipv6 == $oldipv6) {
|
131 |
|
|
// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
|
132 |
|
|
if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
|
133 |
|
|
/* reconfigure IPsec tunnels */
|
134 |
aa752473
|
Renato Botelho
|
vpn_ipsec_force_reload($interface);
|
135 |
f6461410
|
Renato Botelho
|
|
136 |
|
|
/* start OpenVPN server & clients */
|
137 |
10ce1ac1
|
Ermal
|
if (substr($interface_real, 0, 4) != "ovpn")
|
138 |
|
|
openvpn_resync_all($interface);
|
139 |
f6461410
|
Renato Botelho
|
}
|
140 |
|
|
exit;
|
141 |
10ce1ac1
|
Ermal
|
} else if (does_interface_exist($interface_real))
|
142 |
|
|
mwexec("/sbin/ifconfig {$interface_real} inet6 {$oldipv6} delete");
|
143 |
f6461410
|
Renato Botelho
|
}
|
144 |
1a0b04df
|
Seth Mos
|
|
145 |
|
|
file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
|
146 |
|
|
|
147 |
|
|
/* perform RFC 2136 DNS update */
|
148 |
|
|
services_dnsupdate_process($interface);
|
149 |
|
|
|
150 |
|
|
/* signal dyndns update */
|
151 |
|
|
services_dyndns_configure($interface);
|
152 |
|
|
|
153 |
|
|
/* reconfigure IPsec tunnels */
|
154 |
aa752473
|
Renato Botelho
|
vpn_ipsec_force_reload($interface);
|
155 |
1a0b04df
|
Seth Mos
|
|
156 |
|
|
/* start OpenVPN server & clients */
|
157 |
|
|
if (substr($interface_real, 0, 4) != "ovpn")
|
158 |
|
|
openvpn_resync_all($interface);
|
159 |
|
|
|
160 |
|
|
/* reload graphing functions */
|
161 |
|
|
enable_rrd_graphing();
|
162 |
|
|
|
163 |
|
|
/* reload igmpproxy */
|
164 |
|
|
services_igmpproxy_configure();
|
165 |
|
|
|
166 |
|
|
restart_packages();
|
167 |
|
|
|
168 |
|
|
?>
|