Project

General

Profile

Download (5.8 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/*
4
        rc.newwanipv6
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
function restart_packages() {
53
	global $oldipv6, $curwanipv6, $g;
54

    
55
	/* restart packages */
56
	system_ntp_configure(false);
57
	mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
58
	log_error("{$g['product_name']} package system has detected an ip change $oldipv6 ->  $curwanipv6 ... Restarting packages.");		
59
	send_event("service reload packages");
60
}
61

    
62
/* Interface IP address has changed */
63
$argument = str_replace("\n", "", $argv[1]);
64

    
65
log_error("rc.newwanipv6: Informational is starting {$argument}.");
66

    
67
/* wait for the dhcp6c process to configure the LAN interface */
68
sleep(5);
69

    
70
if(empty($argument)) {
71
	$interface = "wan";
72
	$interface_real = get_real_interface($interface);
73
	$curwanipv6 = get_interface_ipv6($interface);
74
} else {
75
	$interface_real = $argument;
76
	$interface = convert_real_interface_to_friendly_interface_name($interface_real);
77
	$curwanipv6 = find_interface_ipv6($interface_real, true);
78
	if (empty($curwanipv6))
79
		$curwanipv6 = get_interface_ipv6($interface);
80
}
81

    
82
if (empty($interface)) {
83
	filter_configure();
84
	// restart_packages();
85
	exit;
86
}
87

    
88
if(empty($curwanipv6) || !is_ipaddrv6($curwanipv6)) {
89
        log_error("rc.newwanipv6: Failed to update {$interface} IPv6, restarting...");
90
	// send_event("interface reconfigure {$interface}");
91
        exit;
92
}
93

    
94
$name_servers = explode(" ", $_ENV['new_domain_name_servers']);
95
$valid_ns = array();
96
foreach($name_servers as $ns) {
97
	if(is_ipaddrv6(trim($ns)))
98
		$valid_ns[] = trim($ns);
99
}
100

    
101
if(count($valid_ns > 0))
102
	file_put_contents("{$g['varetc_path']}/nameserver_v6{$interface}", implode("\n", $valid_ns));
103

    
104
if(!empty($_ENV['new_domain_name']))
105
	file_put_contents("{$g['varetc_path']}/searchdomain_v6{$interface}", $_ENV['new_domain_name']);
106

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

    
109
$oldipv6 = "";
110
if (file_exists("{$g['vardb_path']}/{$interface}_cacheipv6"))
111
	$oldipv6 = file_get_contents("{$g['vardb_path']}/{$interface}_cacheipv6");
112

    
113
$grouptmp = link_interface_to_group($interface);
114
if (!empty($grouptmp))
115
	array_walk($grouptmp, 'interface_group_add_member');
116

    
117
/* regenerate resolv.conf if DNS overrides are allowed */
118
system_resolvconf_generate(true);
119

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

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

    
135
/* reconfigure static routes (kernel may have deleted them) */
136
system_routing_configure($interface);
137

    
138
/* reconfigure our gateway monitor */
139
setup_gateways_monitor();
140

    
141
/* signal filter reload */
142
filter_configure();
143

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

    
150
		/* start OpenVPN server & clients */
151
		openvpn_resync_all($interface);
152
	}
153
	exit;
154
}
155

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

    
158
/* perform RFC 2136 DNS update */
159
services_dnsupdate_process($interface);
160

    
161
/* signal dyndns update */
162
services_dyndns_configure($interface);
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/108)