Project

General

Profile

Download (6.47 KB) Statistics
| Branch: | Tag: | Revision:
1 5b237745 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3
/*
4 e7012ec3 Scott Ullrich
        rc.newwanip
5 0363c100 Scott Ullrich
        Copyright (C) 2006 Scott Ullrich (sullrich@gmail.com)
6
        part of pfSense (http://www.pfsense.com)
7 e7012ec3 Scott Ullrich
8 0363c100 Scott Ullrich
		Originally part of m0n0wall (http://m0n0.ch)
9 e7012ec3 Scott Ullrich
        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 5b237745 Scott Ullrich
*/
33
34 0363c100 Scott Ullrich
/* 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 5f2d078e Scott Ullrich
require_once("filter.inc");
39
require_once("shaper.inc");
40 f973148e Ermal
require_once("ipsec.inc");
41
require_once("vpn.inc");
42 c7f60193 Ermal
require_once("openvpn.inc");
43 76f5d95c Scott Ullrich
require_once("rrd.inc");
44 0363c100 Scott Ullrich
45 9e18b392 Scott Ullrich
// Do not process while booting
46
if($g['booting']) 
47
	exit;
48
49 9ccecb65 Ermal
function restart_packages() {
50
	global $oldip, $curwanipi, $g;
51
52
	/* restart packages */
53 0b8e9d38 jim-p
	system_ntp_configure(false);
54 b61e8960 jim-p
	mwexec_bg("/usr/local/sbin/ntpdate_sync_once.sh", true);
55 9ccecb65 Ermal
	log_error("{$g['product_name']} package system has detected an ip change $oldip ->  $curwanip ... Restarting packages.");		
56 0042f5d9 Ermal
	send_event("service reload packages");
57 9ccecb65 Ermal
}
58 0363c100 Scott Ullrich
59 9ccecb65 Ermal
/* Interface IP address has changed */
60 0363c100 Scott Ullrich
$argument = str_replace("\n", "", $argv[1]);
61
62 5e3ed9bc Ermal Lu?i
log_error("rc.newwanip: Informational is starting {$argument}.");
63 2aa80139 Scott Ullrich
64 67ee1ec5 Ermal Luçi
if(empty($argument)) {
65 85a5da13 Ermal Luçi
    $curwanip = get_interface_ip();
66 1cbc2a1c Scott Ullrich
    $interface = "wan";
67 85a5da13 Ermal Luçi
    $interface_real = get_real_interface();
68 67ee1ec5 Ermal Luçi
} else {
69
        $interface = convert_real_interface_to_friendly_interface_name($argument);
70
        $interface_real = $argument;
71 01f1b601 Ermal
        $curwanip = find_interface_ip($interface_real, true);
72 67ee1ec5 Ermal Luçi
        if($curwanip == "")
73 85a5da13 Ermal Luçi
                $curwanip = get_interface_ip($interface);
74 b1f7e75e Scott Ullrich
}
75
76 5e3ed9bc Ermal Lu?i
log_error("rc.newwanip: on (IP address: {$curwanip}) (interface: {$interface}) (real interface: {$interface_real}).");
77 a8840317 Scott Ullrich
78 40655051 Ermal
if($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
79 ba0be463 Ermal Lu?i
        log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
80 3c3ba8f0 Ermal
	send_event("interface reconfigure {$interface}");
81 5b4c9c6b Scott Ullrich
        exit;
82 45f2708c Scott Ullrich
}
83
84 9ccecb65 Ermal
if (empty($interface)) {
85
	filter_configure();
86
	restart_packages();
87
	exit;
88
}
89
90 40655051 Ermal
$oldip = "0.0.0.0";
91
if (file_exists("{$g['vardb_path']}/{$interface}_cacheip"))
92
	$oldip = file_get_contents("{$g['vardb_path']}/{$interface}_cacheip");
93
94 166c82ed Chris Buechler
/* regenerate resolv.conf if DNS overrides are allowed */
95 e7ee3bfe Ermal
system_resolvconf_generate(true);
96 0363c100 Scott Ullrich
97
/* write current WAN IP to file */
98 5e3ed9bc Ermal Lu?i
file_put_contents("{$g['vardb_path']}/{$interface}_ip", $curwanip);
99 0363c100 Scott Ullrich
100 b5264f22 Ermal
link_interface_to_vips($interface, "update");
101
102 48484aac Ermal
unset($gre);
103
$gre = link_interface_to_gre($interface);
104
if (!empty($gre))
105
	array_walk($gre, 'interface_gre_configure');
106
unset($gif);
107
$gif = link_interface_to_gif($interface);
108
if (!empty($gif))
109
	array_walk($gif, 'interface_gif_configure');
110
111 ed62880b Ermal
$grouptmp = link_interface_to_group($interface);
112
if (!empty($grouptmp))
113
	array_walk($grouptmp, 'interface_group_add_member');
114
115 b5264f22 Ermal
if ($linkupevent == false || substr($interface_real, 0, 4) == "ovpn") {
116
	unset($bridgetmp);
117
	$bridgetmp = link_interface_to_bridge($interface);
118
	if (!empty($bridgetmp))
119
		interface_bridge_add_member($bridgetmp, $interface_real);
120
}
121
122
/* make new hosts file */
123
if ($interface == "lan")
124
	system_hosts_generate();
125 8614f335 Ermal
126 b5191708 smos
/* check tunneled IPv6 interface tracking */
127
switch($config['interfaces'][$interface]['ipaddrv6']) {
128
	case "6to4":
129
		interface_6to4_configure($interface);
130
		break;
131
	case "6rd":
132
		interface_6rd_configure($interface);
133
		break;
134
}
135 b746dc61 Ermal
136 90c386ba jim-p
/* Check Gif tunnels */
137 29bf947e Phil Davis
if(is_array($config['gifs']['gif'])){
138 efb5b9f1 Phil Davis
	foreach($config['gifs']['gif'] as $gif) {
139
		if($gif['if'] == $interface) {
140
			foreach($config['interfaces'] as $ifname => $ifparent) {
141
				// echo "interface $ifparent, ifname $ifname, gif {$gif['gifif']}\n";
142
				if(($ifparent['if'] == $gif['gifif']) && (isset($ifparent['enable']))) {
143
					// echo "Running routing configure for $ifname\n";
144
					$gif['gifif'] = interface_gif_configure($gif);
145
					$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
146
					if ($confif <> "")
147
						interface_configure($confif);
148
					system_routing_configure($ifname);
149
				}
150 90c386ba jim-p
			}
151
		}
152
	}
153
}
154
155 b5191708 smos
/* reconfigure static routes (kernel may have deleted them) */
156
system_routing_configure($interface);
157 69b54cbe smos
158 da70dc36 jim-p
/* reconfigure our gateway monitor */
159
setup_gateways_monitor();
160
161 2c6b0d67 Ermal
/* signal filter reload */
162
filter_configure();
163
164 9c4c5e80 jim-p
if (is_ipaddr($oldip) && $curwanip == $oldip) {
165 611b65a8 jim-p
	/* We need to force sync VPNs on such even when the IP is the same. Even with 
166
	 * the same IP the VPN software is unhappy with the IP disappearing, and we 
167
	 * could be failing back in which case we need to switch IPs back anyhow. */
168 9c4c5e80 jim-p
169 611b65a8 jim-p
	/* reconfigure IPsec tunnels */
170
	vpn_ipsec_force_reload();
171
172
	/* start OpenVPN server & clients */
173 158f0e7d jim-p
	if (substr($interface, 0, 4) != "ovpn")
174
		openvpn_resync_all($interface);
175 611b65a8 jim-p
176
	/* perform RFC 2136 DNS update */
177
	services_dnsupdate_process($interface);
178
179
	/* signal dyndns update */
180
	services_dyndns_configure($interface);
181 3640c567 Ermal
	exit;
182 9c4c5e80 jim-p
}
183 3640c567 Ermal
184 3d9e9252 Ermal
file_put_contents("{$g['vardb_path']}/{$interface}_cacheip", $curwanip);
185
186 17649c87 Ermal
/* perform RFC 2136 DNS update */
187
services_dnsupdate_process($interface);
188
189 5e3ed9bc Ermal Lu?i
/* signal dyndns update */
190 db8e9e53 Ermal
services_dyndns_configure($interface);
191 0363c100 Scott Ullrich
192 ebbae443 jim-p
/* reconfigure IPsec tunnels */
193
vpn_ipsec_force_reload();
194
195
/* start OpenVPN server & clients */
196 55c51af7 Ermal
if (substr($interface_real, 0, 4) != "ovpn")
197
	openvpn_resync_all($interface);
198 ebbae443 jim-p
199 0363c100 Scott Ullrich
/* reload graphing functions */
200
enable_rrd_graphing();
201
202 f206afb5 Ermal
/* reload igmpproxy */
203
services_igmpproxy_configure();
204
205 9ccecb65 Ermal
restart_packages();
206 8f8f9721 Scott Ullrich
207 2c6b0d67 Ermal
?>