Project

General

Profile

Download (4.47 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/* $Id$ */
4
/*
5
    rc.carpmaster
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 "MASTER" for vhid %s', $argument, $friendly_descr, $vhid);
52

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

    
57
/* Start OpenVPN clients running on this VIP, since they should be in the stopped state while the VIP is CARP Backup. */
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("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
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("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
71
				openvpn_restart('client', $settings);
72
			}
73
		}
74
	}
75
}
76
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
77
	foreach ($config['openvpn']['openvpn-server'] as $settings) {
78
		if ($settings['interface'] == $carp_iface) {
79
			log_error("Starting OpenVPN instance on {$friendly_descr} because of transition to CARP master.");
80
			openvpn_restart('server', $settings);
81
		}
82
		// check for gateway groups specifying CARP IPs 
83
		$a_groups = return_gateway_groups_array();
84
		if (is_array($a_groups[$settings['interface']])) {
85
			// interface of this instance is a gateway group, check for CARP VIP
86
			if (strstr($a_groups[$settings['interface']][0]['vip'], "_vip")) {
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

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

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

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

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

    
115
?>
(36-36/104)