Project

General

Profile

Download (5.65 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/*
4
        rc.newwanip
5
        Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
6
        part of pfSense (http://www.pfsense.com)
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
// Do not process while booting
48
if($g['booting']) 
49
	exit;
50

    
51

    
52
// echo print_r($_ENV, true);
53
/*Array
54
(
55
    [REASON] => NBI
56
    [new_domain_name_servers] => 2001:470:20::2
57
    [new_domain_name] => domain.nl.
58
)
59
*/
60

    
61
function restart_packages() {
62
	global $oldip, $curwanipv6, $g;
63

    
64
	/* restart packages */
65
	system_ntp_configure(false);
66
	mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
67
	log_error("{$g['product_name']} package system has detected an ip change $oldip ->  $curwanip ... Restarting packages.");		
68
	mwexec_bg("/etc/rc.start_packages");
69
}
70

    
71
log_error("rc.newwanipv6: Informational is starting.");
72

    
73
/* FIXME: how can we find out about the correct interface name? */
74
/* switch to ISC dhcp6 client? */
75
$curwanipv6 = get_interface_ipv6();
76
$interface = "wan";
77
$interface_real = get_real_interface();
78

    
79
$name_servers = explode(" ", $_ENV['new_domain_name_servers']);
80
$valid_ns = array();
81
foreach($name_servers as $ns) {
82
	if(is_ipaddrv6(trim($ns)))
83
		$valid_ns[] = trim($ns);
84
}
85
if(count($valid_ns > 0))
86
	file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
87

    
88
if(!empty($_ENV['new_domain_name'])) {
89
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $_ENV['new_domain_name']);
90
}
91

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

    
94
if($curwanipv6 == "" || !is_ipaddrv6($curwanipv6)) {
95
        log_error("rc.newwanipv6: Failed to update {$interface} IPv6, restarting...");
96
	// send_event("interface reconfigure {$interface}");
97
        exit;
98
}
99

    
100
if (empty($interface)) {
101
	filter_configure();
102
	// restart_packages();
103
	exit;
104
}
105

    
106
$oldipv6 = "";
107
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6"))
108
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
109

    
110
$grouptmp = link_interface_to_group($interface);
111
if (!empty($grouptmp))
112
	array_walk($grouptmp, 'interface_group_add_member');
113

    
114
/* regenerate resolv.conf if DNS overrides are allowed */
115
system_resolvconf_generate(true);
116

    
117
/* write current WAN IPv6 to file */
118
file_put_contents("{$g['vardb_path']}/{$interface}_ipv6", $curwanipv6);
119

    
120
/* check native IPv6 interface tracking */
121
switch($config['interfaces'][$interface]['type6']) {
122
	case "dhcp6":
123
		foreach($config['interfaces'] as $iftrackname => $iftrack) {
124
			if($iftrack['track6-interface'] == $interface) {
125
				log_error("interface {%iftrackname} depends on {$interface}, configuring");
126
				interface_track6_configure($iftrackname);
127
			}
128
		}
129
		break;
130
}
131

    
132
/* reconfigure static routes (kernel may have deleted them) */
133
system_routing_configure($interface);
134

    
135
/* reconfigure our gateway monitor */
136
setup_gateways_monitor();
137

    
138
/* signal filter reload */
139
filter_configure();
140

    
141
if (is_ipaddr($oldipv6) && $curwanipv6 == $oldipv6) {
142
	// Still need to sync VPNs on PPPoE and such, as even with the same IP the VPN software is unhappy with the IP disappearing.
143
	if (in_array($config['interfaces'][$interface]['ipaddrv6'], array('pppoe', 'pptp', 'ppp'))) {
144
		/* reconfigure IPsec tunnels */
145
		vpn_ipsec_force_reload();
146

    
147
		/* start OpenVPN server & clients */
148
		openvpn_resync_all($interface);
149
	}
150
	exit;
151
}
152

    
153
file_put_contents("{$g['vardb_path']}/{$interface}_cacheipv6", $curwanipv6);
154

    
155
/* perform RFC 2136 DNS update */
156
services_dnsupdate_process($interface);
157

    
158
/* signal dyndns update */
159
services_dyndns_configure($interface);
160

    
161
/* wait for the dhcp6c process to configure the LAN interface */
162
sleep(5);
163

    
164
/* reconfigure IPsec tunnels */
165
vpn_ipsec_force_reload();
166

    
167
/* start OpenVPN server & clients */
168
if (substr($interface_real, 0, 4) != "ovpn")
169
	openvpn_resync_all($interface);
170

    
171
/* reload graphing functions */
172
enable_rrd_graphing();
173

    
174
/* reload igmpproxy */
175
services_igmpproxy_configure();
176

    
177
restart_packages();
178

    
179
services_radvd_configure();
180

    
181
?>
(78-78/107)