Project

General

Profile

Download (4.08 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php-cgi -f
2
<?php
3
/*
4
	rc.carpmaster
5
	part of pfSense (https://www.pfsense.org)
6
	Copyright (C) 2004 Scott Ullrich
7
	All rights reserved.
8

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

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

    
15
	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

    
19
	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
*/
30

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

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

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

    
48
$friendly = convert_real_interface_to_friendly_interface_name($iface);
49
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
50
$vips = link_interface_to_vips($friendly, '', $vhid);
51
$carp_iface = "{$friendly}_vip{$vhid}";
52
foreach ($vips as $vip) {
53
	$notificationmsg = sprintf('HA cluster member "(%1$s): (%2$s)" has resumed CARP state "MASTER" for vhid %3$s', $argument, $friendly_descr, $vhid);
54

    
55
	notify_via_smtp($notificationmsg);
56
	notify_via_growl($notificationmsg);
57
	log_error($notificationmsg);
58
}
59

    
60
/* Start OpenVPN clients running on this VIP, since they should be in the stopped state while the VIP is CARP Backup. */
61
global $config;
62
$a_groups = return_gateway_groups_array();
63
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
64
	foreach ($config['openvpn']['openvpn-client'] as $settings) {
65
		if (substr($settings['interface'], 0, 4) == '_vip') {
66
			$openvpn_vip = $settings['interface'];
67
		} else if (is_array($a_groups[$settings['interface']])) {
68
			// interface is a gateway group, check CARP VIP
69
			if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
70
				$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
71
			}
72
		} else {
73
			// this OpenVPN instance not on a CARP IP
74
			continue;
75
		}
76
		foreach ($vips as $vip) {
77
			if ($openvpn_vip == "_vip{$vip['uniqid']}") {
78
				log_error("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
79
				openvpn_restart('client', $settings);
80
			}
81
		}
82
	}
83
}
84
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
85
	foreach ($config['openvpn']['openvpn-server'] as $settings) {
86
		if ($settings['interface'] == $carp_iface) {
87
			log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master.");
88
			openvpn_restart('server', $settings);
89
		}
90
	}
91
}
92

    
93
/* Reconfigure radvd when necessary */
94
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
95
	$found = false;
96
	foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
97
		if ($dhcpv6ifconf['rainterface'] != $carp_iface) {
98
			continue;
99
		}
100

    
101
		$found = true;
102
		break;
103
	}
104

    
105
	if ($found === true) {
106
		services_radvd_configure();
107
	}
108
}
109

    
110
$pluginparams = array();
111
$pluginparams['type'] = 'carp';
112
$pluginparams['event'] = 'rc.carpmaster';
113
$pluginparams['interface'] = $argument;
114
pkg_call_plugins('plugin_carp', $pluginparams);
115

    
116
?>
(31-31/94)