Project

General

Profile

Download (4.98 KB) Statistics
| Branch: | Tag: | Revision:
1 1a0b04df Seth Mos
#!/usr/local/bin/php -f
2
<?php
3
/*
4 9d158467 Seth Mos
        rc.newwanip
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 1a0b04df Seth Mos
46
// Do not process while booting
47
if($g['booting']) 
48
	exit;
49
50
51 9d158467 Seth Mos
// echo print_r($_ENV, true);
52
/*Array
53 1a0b04df Seth Mos
(
54
    [REASON] => NBI
55
    [new_domain_name_servers] => 2001:470:20::2
56
    [new_domain_name] => domain.nl.
57
)
58
*/
59
60
function restart_packages() {
61 46a7c9aa smos
	global $oldip, $curwanipv6, $g;
62 1a0b04df Seth Mos
63
	/* restart packages */
64
	system_ntp_configure();
65
	log_error("{$g['product_name']} package system has detected an ip change $oldip ->  $curwanip ... Restarting packages.");		
66
	mwexec_bg("/etc/rc.start_packages");
67
}
68
69
log_error("rc.newwanipv6: Informational is starting.");
70
71 46a7c9aa smos
$curwanipv6 = get_interface_ipv6();
72 1a0b04df Seth Mos
$interface = "wan";
73
$interface_real = get_real_interface();
74
75 46a7c9aa smos
if(is_ipaddrv6(trim($_ENV['new_domain_name_servers']))) {
76 9d158467 Seth Mos
	file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", trim($_ENV['new_domain_name_servers']));
77
}
78
if(!empty($_ENV['new_domain_name'])) {
79
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $_ENV['new_domain_name']);
80
}
81
82 1a0b04df Seth Mos
log_error("rc.newwanipv6: on (IP address: {$curwanipv6}) (interface: {$interface}) (real interface: {$interface_real}).");
83
84
if($curwanipv6 == "" || !is_ipaddrv6($curwanipv6)) {
85 46a7c9aa smos
        log_error("rc.newwanipv6: Failed to update {$interface} IPv6, restarting...");
86
	// send_event("interface reconfigure {$interface}");
87 1a0b04df Seth Mos
        exit;
88
}
89
90
if (empty($interface)) {
91
	filter_configure();
92 46a7c9aa smos
	// restart_packages();
93 1a0b04df Seth Mos
	exit;
94
}
95
96 46a7c9aa smos
$oldipv6 = "";
97 1a0b04df Seth Mos
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6"))
98
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
99
100
$grouptmp = link_interface_to_group($interface);
101
if (!empty($grouptmp))
102
	array_walk($grouptmp, 'interface_group_add_member');
103
104
/* regenerate resolv.conf if DNS overrides are allowed */
105
system_resolvconf_generate(true);
106
107 46a7c9aa smos
/* write current WAN IPv6 to file */
108 1a0b04df Seth Mos
file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
109
110
/* reconfigure static routes (kernel may have deleted them) */
111
system_routing_configure($interface);
112
113
/* reconfigure our gateway monitor */
114
setup_gateways_monitor();
115
116
/* signal filter reload */
117
filter_configure();
118
119
if (is_ipaddr($oldipv6) && $curwanipv6 == $oldipv6) {
120
	// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
121 46a7c9aa smos
	if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
122 1a0b04df Seth Mos
		/* reconfigure IPsec tunnels */
123
		vpn_ipsec_force_reload();
124
125
		/* start OpenVPN server & clients */
126
		openvpn_resync_all($interface);
127
	}
128
	exit;
129
}
130
131
file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
132
133
/* perform RFC 2136 DNS update */
134
services_dnsupdate_process($interface);
135
136
/* signal dyndns update */
137
services_dyndns_configure($interface);
138
139 82769dfe smos
/* wait for the dhcp6c process to configure the LAN interface */
140
sleep(5);
141
142 1a0b04df Seth Mos
/* reconfigure IPsec tunnels */
143
vpn_ipsec_force_reload();
144
145
/* start OpenVPN server & clients */
146
if (substr($interface_real, 0, 4) != "ovpn")
147
	openvpn_resync_all($interface);
148
149
/* reload graphing functions */
150
enable_rrd_graphing();
151
152
/* reload igmpproxy */
153
services_igmpproxy_configure();
154
155
restart_packages();
156
157
services_rtadvd_configure();
158
159
?>