Project

General

Profile

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