Project

General

Profile

Download (3.71 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
    rc.carpbackup
6
    part of pfSense (https://www.pfsense.org)
7
    Copyright (C) 2004-2015 Electric Sheep Fencing LLC
8
    Copyright (C) 2004 Scott Ullrich
9
    All rights reserved.
10

    
11
    Redistribution and use in source and binary forms, with or without
12
    modification, are permitted provided that the following conditions are met:
13

    
14
    1. Redistributions of source code must retain the above copyright notice,
15
       this list of conditions and the following disclaimer.
16

    
17
    2. Redistributions in binary form must reproduce the above copyright
18
       notice, this list of conditions and the following disclaimer in the
19
       documentation and/or other materials provided with the distribution.
20

    
21
    THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
22
    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
23
    AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24
    AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
25
    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26
    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27
    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28
    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29
    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30
    POSSIBILITY OF SUCH DAMAGE.
31
*/
32

    
33
require_once("functions.inc");
34
require_once("config.inc");
35
require_once("notices.inc");
36
require_once("openvpn.inc");
37
require_once("interfaces.inc");
38

    
39
if (isset($_GET))
40
        $argument = $_GET['interface'];
41
else
42
	$argument = str_replace("\n", "", $argv[1]);
43
if (!strstr($argument, "@"))
44
        log_error("Carp MASTER event triggered from wrong source {$argument}");
45

    
46
list($vhid, $iface) = explode("@", $argument);
47

    
48
$friendly = convert_real_interface_to_friendly_interface_name($iface);
49
$carp_iface = "{$friendly}_vip{$vhid}";
50
$friendly_descr = convert_friendly_interface_to_friendly_descr($carp_iface);
51
$notificationmsg = sprintf('Carp cluster member "%2$s (%1$s)" has resumed the state "BACKUP" for vhid %s', $argument, $friendly_descr, $vhid);
52

    
53
notify_via_smtp($notificationmsg);
54
notify_via_growl($notificationmsg);
55
log_error($notificationmsg);
56

    
57
/* Stop OpenVPN clients running on this VIP, since multiple active OpenVPN clients on a CARP cluster can be problematic. */
58
global $config;
59
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
60
	foreach ($config['openvpn']['openvpn-client'] as $settings) {
61
		if ($settings['interface'] == $carp_iface) {
62
			log_error("Stopping OpenVPN client instance on {$friendly_descr} because of transition to CARP backup.");
63
			openvpn_restart('client', $settings);
64
		}
65
		// check for gateway groups specifying CARP IPs 
66
		$a_groups = return_gateway_groups_array();
67
		if (is_array($a_groups[$settings['interface']])) {
68
			// interface of this instance is a gateway group, check for CARP VIP
69
			if (strstr($a_groups[$settings['interface']][0]['vip'], "_vip")) {
70
				log_error("Stopping OpenVPN client instance on {$friendly_descr} because of transition to CARP backup.");
71
				openvpn_restart('client', $settings);
72
			}
73
		}
74
	}
75
}
76

    
77
/* Reconfigure radvd when necessary */
78
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
79
	$found = false;
80
	foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
81
		if ($dhcpv6ifconf['rainterface'] != $carp_iface)
82
			continue;
83

    
84
		$found = true;
85
		break;
86
	}
87

    
88
	if ($found === true)
89
		services_radvd_configure();
90
}
91

    
92
$pluginparams = array();
93
$pluginparams['type'] = 'carp';
94
$pluginparams['event'] = 'rc.carpbackup';
95
$pluginparams['interface'] = $argument;
96
pkg_call_plugins('plugin_carp', $pluginparams);
97

    
98
?>
(35-35/104)