Project

General

Profile

Download (6.71 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("rrd.inc");
45

    
46
// Do not process while booting
47
if($g['booting'])
48
	exit;
49

    
50
function restart_packages() {
51
	global $oldip, $curwanip, $g;
52

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

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

    
63
log_error("rc.newwanip: Informational is starting {$argument}.");
64

    
65
if(empty($argument)) {
66
	$interface = "wan";
67
	$interface_real = get_real_interface();
68
} else {
69
	$interface = convert_real_interface_to_friendly_interface_name($argument);
70
	$interface_real = $argument;
71
}
72

    
73
/* If the interface is configured and not enabled, bail. We do not need to change settings for disabled interfaces. #3313 */
74
if (is_array($config['interfaces'][$interface]) && !isset($config['interfaces'][$interface]['enable'])) {
75
	log_error("Interface is disabled, nothing to do.");
76
	return;
77
}
78

    
79
if(empty($argument))
80
	$curwanip = get_interface_ip();
81
else {
82
	$curwanip = find_interface_ip($interface_real, true);
83
	if($curwanip == "")
84
		$curwanip = get_interface_ip($interface);
85
	if (($curwanip == "") && empty($config['interfaces'][$interface]['ipaddr'])) {
86
		log_error("Interface does not have an IP address, nothing to do.");
87
		return;
88
	}
89
}
90

    
91
log_error("rc.newwanip: on (IP address: {$curwanip}) (interface: {$interface}) (real interface: {$interface_real}).");
92

    
93
if($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
94
	log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
95
	send_event("interface reconfigure {$interface}");
96
	exit;
97
}
98

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

    
105
$oldip = "0.0.0.0";
106
if (file_exists("{$g['vardb_path']}/{$interface}_cacheip"))
107
	$oldip = file_get_contents("{$g['vardb_path']}/{$interface}_cacheip");
108

    
109
/* regenerate resolv.conf if DNS overrides are allowed */
110
system_resolvconf_generate(true);
111

    
112
/* write current WAN IP to file */
113
file_put_contents("{$g['vardb_path']}/{$interface}_ip", $curwanip);
114

    
115
link_interface_to_vips($interface, "update");
116

    
117
unset($gre);
118
$gre = link_interface_to_gre($interface);
119
if (!empty($gre))
120
	array_walk($gre, 'interface_gre_configure');
121
unset($gif);
122
$gif = link_interface_to_gif($interface);
123
if (!empty($gif))
124
	array_walk($gif, 'interface_gif_configure');
125

    
126
$grouptmp = link_interface_to_group($interface);
127
if (!empty($grouptmp))
128
	array_walk($grouptmp, 'interface_group_add_member');
129

    
130
unset($bridgetmp);
131
$bridgetmp = link_interface_to_bridge($interface);
132
if (!empty($bridgetmp))
133
	interface_bridge_add_member($bridgetmp, $interface_real);
134

    
135
/* make new hosts file */
136
system_hosts_generate();
137

    
138
/* check tunneled IPv6 interface tracking */
139
switch($config['interfaces'][$interface]['ipaddrv6']) {
140
	case "6to4":
141
		interface_6to4_configure($interface, $config['interfaces'][$interface]);
142
		break;
143
	case "6rd":
144
		interface_6rd_configure($interface, $config['interfaces'][$interface]);
145
		break;
146
	case "dhcp6":
147
		if (isset($config['interfaces'][$interface]['dhcp6usev4iface']))
148
			interface_dhcpv6_configure($interface, $config['interfaces'][$interface]);
149
		break;
150
}
151

    
152
/* Check Gif tunnels */
153
if(is_array($config['gifs']['gif'])){
154
	foreach($config['gifs']['gif'] as $gif) {
155
		if($gif['if'] == $interface) {
156
			foreach($config['interfaces'] as $ifname => $ifparent) {
157
				// echo "interface $ifparent, ifname $ifname, gif {$gif['gifif']}\n";
158
				if(($ifparent['if'] == $gif['gifif']) && (isset($ifparent['enable']))) {
159
					// echo "Running routing configure for $ifname\n";
160
					$gif['gifif'] = interface_gif_configure($gif);
161
					$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
162
					if ($confif <> "")
163
						interface_configure($confif);
164
					system_routing_configure($ifname);
165
				}
166
			}
167
		}
168
	}
169
}
170

    
171
/*
172
 * We need to force sync VPNs on such even when the IP is the same for dynamic interfaces.
173
 * Even with the same IP the VPN software is unhappy with the IP disappearing, and we
174
 * could be failing back in which case we need to switch IPs back anyhow.
175
 */
176
if (!is_ipaddr($oldip) || $curwanip != $oldip || !is_ipaddrv4($config['interfaces'][$interface]['ipaddr'])) {
177
	/* reconfigure static routes (kernel may have deleted them) */
178
	system_routing_configure($interface);
179

    
180
	/* reconfigure our gateway monitor */
181
	setup_gateways_monitor();
182

    
183
	file_put_contents("{$g['vardb_path']}/{$interface}_cacheip", $curwanip);
184

    
185
	/* perform RFC 2136 DNS update */
186
	services_dnsupdate_process($interface);
187

    
188
	/* signal dyndns update */
189
	services_dyndns_configure($interface);
190

    
191
	/* reconfigure IPsec tunnels */
192
	vpn_ipsec_force_reload($interface);
193

    
194
	/* start OpenVPN server & clients */
195
	if (substr($interface_real, 0, 4) != "ovpn")
196
		openvpn_resync_all($interface);
197

    
198
	/* reload graphing functions */
199
	enable_rrd_graphing();
200

    
201
	/* reload igmpproxy */
202
	services_igmpproxy_configure();
203

    
204
	/* restart snmp */
205
	services_snmpd_configure();
206

    
207
	restart_packages();
208
}
209

    
210
/* signal filter reload */
211
filter_configure();
212

    
213
?>
(79-79/110)