Project

General

Profile

Download (3.33 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 ae75bcb4 Scott Ullrich
<?php
3
/* $Id$ */
4
/*
5 e173dd74 Phil Davis
	rc.carpbackup
6
	part of pfSense (https://www.pfsense.org)
7
	Copyright (C) 2004 Scott Ullrich
8
	All rights reserved.
9 ae75bcb4 Scott Ullrich
10 e173dd74 Phil Davis
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12 ae75bcb4 Scott Ullrich
13 e173dd74 Phil Davis
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15 ae75bcb4 Scott Ullrich
16 e173dd74 Phil Davis
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19 ae75bcb4 Scott Ullrich
20 e173dd74 Phil Davis
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30 ae75bcb4 Scott Ullrich
*/
31
32
require_once("functions.inc");
33
require_once("config.inc");
34
require_once("notices.inc");
35 9ea0cb90 jim-p
require_once("openvpn.inc");
36 e3449857 PiBa-NL
require_once("interfaces.inc");
37 ae75bcb4 Scott Ullrich
38 e173dd74 Phil Davis
if (isset($_GET)) {
39
	$argument = $_GET['interface'];
40
} else {
41 815f1f77 Ermal
	$argument = str_replace("\n", "", $argv[1]);
42 e173dd74 Phil Davis
}
43
if (!strstr($argument, "@")) {
44
	log_error("Carp MASTER event triggered from wrong source {$argument}");
45
}
46 77411fa7 Ermal
47
list($vhid, $iface) = explode("@", $argument);
48
49
$friendly = convert_real_interface_to_friendly_interface_name($iface);
50 89f171b0 Ermal LUÇI
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
51
$vips = link_interface_to_vips($friendly, '', $vhid);
52 0c21eb70 Ermal
$carp_iface = "{$friendly}_vip{$vhid}";
53 89f171b0 Ermal LUÇI
foreach ($vips as $vip) {
54
	$notificationmsg = sprintf('Carp cluster member "{$friendly_descr)(%2$s): {$vip['subnet']} (%1$s)" has resumed the state "BACKUP" for vhid %s', $argument, $vip['descr'], $vhid);
55 ae75bcb4 Scott Ullrich
56 89f171b0 Ermal LUÇI
	notify_via_smtp($notificationmsg);
57
	notify_via_growl($notificationmsg);
58
	log_error($notificationmsg);
59
}
60 ae75bcb4 Scott Ullrich
61 9ea0cb90 jim-p
/* Stop OpenVPN clients running on this VIP, since multiple active OpenVPN clients on a CARP cluster can be problematic. */
62
global $config;
63 2156f02a jim-p
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
64
	foreach ($config['openvpn']['openvpn-client'] as $settings) {
65 89f171b0 Ermal LUÇI
		foreach ($vips as $vip) {
66
			if ($settings['interface'] == "_vip{$vip['uniqid']}") {
67
				log_error("Stopping OpenVPN client instance on {$friendly_descr} because of transition to CARP backup.");
68
				openvpn_restart('client', $settings);
69
			}
70 2156f02a jim-p
		}
71 9ea0cb90 jim-p
	}
72
}
73
74 52b5a223 Renato Botelho
/* Reconfigure radvd when necessary */
75
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
76
	$found = false;
77
	foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
78 e173dd74 Phil Davis
		if ($dhcpv6ifconf['rainterface'] != $carp_iface) {
79 52b5a223 Renato Botelho
			continue;
80 e173dd74 Phil Davis
		}
81 52b5a223 Renato Botelho
82
		$found = true;
83
		break;
84
	}
85
86 e173dd74 Phil Davis
	if ($found === true) {
87 52b5a223 Renato Botelho
		services_radvd_configure();
88 e173dd74 Phil Davis
	}
89 52b5a223 Renato Botelho
}
90
91 eaee3af6 PiBa-NL
$pluginparams = array();
92
$pluginparams['type'] = 'carp';
93
$pluginparams['event'] = 'rc.carpbackup';
94 eda14265 jim-p
$pluginparams['interface'] = $argument;
95 331166a8 PiBa-NL
pkg_call_plugins('plugin_carp', $pluginparams);
96 2156f02a jim-p
97 77411fa7 Ermal
?>