Project

General

Profile

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

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

    
49
function restart_packages() {
50
	global $oldip, $curwanipi, $g;
51

    
52
	/* restart packages */
53
	system_ntp_configure();
54
	log_error("{$g['product_name']} package system has detected an ip change $oldip ->  $curwanip ... Restarting packages.");		
55
	send_event("service reload packages");
56
}
57

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

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

    
63
if(empty($argument)) {
64
    $curwanip = get_interface_ip();
65
    $interface = "wan";
66
    $interface_real = get_real_interface();
67
} else {
68
        $interface = convert_real_interface_to_friendly_interface_name($argument);
69
        $interface_real = $argument;
70
        $curwanip = find_interface_ip($interface_real, true);
71
        if($curwanip == "")
72
                $curwanip = get_interface_ip($interface);
73
}
74

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

    
77
if($curwanip == "0.0.0.0" || !is_ipaddr($curwanip)) {
78
        log_error("rc.newwanip: Failed to update {$interface} IP, restarting...");
79
	send_event("interface reconfigure {$interface}");
80
        exit;
81
}
82

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

    
89
$oldip = "0.0.0.0";
90
if (file_exists("{$g['vardb_path']}/{$interface}_cacheip"))
91
	$oldip = file_get_contents("{$g['vardb_path']}/{$interface}_cacheip");
92

    
93
/* regenerate resolv.conf if DNS overrides are allowed */
94
system_resolvconf_generate(true);
95

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

    
99
unset($gre);
100
$gre = link_interface_to_gre($interface);
101
if (!empty($gre))
102
	array_walk($gre, 'interface_gre_configure');
103
unset($gif);
104
$gif = link_interface_to_gif($interface);
105
if (!empty($gif))
106
	array_walk($gif, 'interface_gif_configure');
107

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

    
112
unset($bridgetmp);
113
$bridgetmp = link_interface_to_bridge($interface);
114
if (!empty($bridgetmp))
115
	interface_bridge_add_member($bridgetmp, $interface_real);
116

    
117
/* reconfigure static routes (kernel may have deleted them) */
118
system_routing_configure($interface);
119

    
120
/* Check Gif tunnels */
121
if(is_array($config['gifs']['gif'])){
122
	foreach($config['gifs']['gif'] as $gif) {
123
		if($gif['if'] == $interface) {
124
			foreach($config['interfaces'] as $ifname => $ifparent) {
125
				// echo "interface $ifparent, ifname $ifname, gif {$gif['gifif']}\n";
126
				if(($ifparent['if'] == $gif['gifif']) && (isset($ifparent['enable']))) {
127
					// echo "Running routing configure for $ifname\n";
128
					$gif['gifif'] = interface_gif_configure($gif);
129
					$confif = convert_real_interface_to_friendly_interface_name($gif['gifif']);
130
					if ($confif <> "")
131
						interface_configure($confif);
132
					system_routing_configure($ifname);
133
				}
134
			}
135
		}
136
	}
137
}
138

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

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

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

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

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

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

    
162
/* signal dyndns update */
163
services_dyndns_configure($interface);
164

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

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

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

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

    
178
restart_packages();
179

    
180
?>
(77-77/107)