Project

General

Profile

Download (4.19 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 ae75bcb4 Scott Ullrich
<?php
3
/*
4 ac24dc24 Renato Botelho
 * rc.carpmaster
5
 *
6
 * part of pfSense (https://www.pfsense.org)
7 81299b5c Renato Botelho
 * Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
8 ac24dc24 Renato Botelho
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * Licensed under the Apache License, Version 2.0 (the "License");
11
 * you may not use this file except in compliance with the License.
12
 * You may obtain a copy of the License at
13 ac24dc24 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 ac24dc24 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * Unless required by applicable law or agreed to in writing, software
17
 * distributed under the License is distributed on an "AS IS" BASIS,
18
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19
 * See the License for the specific language governing permissions and
20
 * limitations under the License.
21 ac24dc24 Renato Botelho
 */
22 ae75bcb4 Scott Ullrich
23
require_once("functions.inc");
24
require_once("config.inc");
25
require_once("notices.inc");
26 9ea0cb90 jim-p
require_once("openvpn.inc");
27 e3449857 PiBa-NL
require_once("interfaces.inc");
28 ae75bcb4 Scott Ullrich
29 7de4474e Luiz Otavio O Souza
if (isset($_GET['interface'])) {
30 815f1f77 Ermal
	$argument = $_GET['interface'];
31 e173dd74 Phil Davis
} else {
32 815f1f77 Ermal
	$argument = str_replace("\n", "", $argv[1]);
33 e173dd74 Phil Davis
}
34
if (!strstr($argument, "@")) {
35 10e58a70 Chris Buechler
	log_error("CARP master event triggered from wrong source {$argument}");
36 7de4474e Luiz Otavio O Souza
	exit;
37 e173dd74 Phil Davis
}
38 77411fa7 Ermal
39
list($vhid, $iface) = explode("@", $argument);
40
41
$friendly = convert_real_interface_to_friendly_interface_name($iface);
42 34cd5348 Chris Buechler
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
43
$vips = link_interface_to_vips($friendly, '', $vhid);
44 7de4474e Luiz Otavio O Souza
if (!is_array($vips)) {
45
	log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs");
46
	exit;
47
}
48 34cd5348 Chris Buechler
foreach ($vips as $vip) {
49 7de4474e Luiz Otavio O Souza
	$notificationmsg = sprintf('HA cluster member "(%1$s@%2$s): (%3$s)" has resumed CARP state "MASTER" for vhid %4$s',
50
	    $vip['subnet'], $iface, $friendly_descr, $vhid);
51 ae75bcb4 Scott Ullrich
52 34cd5348 Chris Buechler
	notify_via_smtp($notificationmsg);
53
	notify_via_growl($notificationmsg);
54
	log_error($notificationmsg);
55
}
56 ae75bcb4 Scott Ullrich
57 9ea0cb90 jim-p
/* 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 d20dd658 Chris Buechler
$a_groups = return_gateway_groups_array();
60 2156f02a jim-p
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
61
	foreach ($config['openvpn']['openvpn-client'] as $settings) {
62 d20dd658 Chris Buechler
		if (substr($settings['interface'], 0, 4) == '_vip') {
63
			$openvpn_vip = $settings['interface'];
64
		} else if (is_array($a_groups[$settings['interface']])) {
65
			// interface is a gateway group, check CARP VIP
66
			if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
67
				$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
68
			}
69
		} else {
70
			// this OpenVPN instance not on a CARP IP
71
			continue;
72
		}
73 34cd5348 Chris Buechler
		foreach ($vips as $vip) {
74 d20dd658 Chris Buechler
			if ($openvpn_vip == "_vip{$vip['uniqid']}") {
75 89f171b0 Ermal LUÇI
				log_error("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
76
				openvpn_restart('client', $settings);
77
			}
78 2156f02a jim-p
		}
79 9ea0cb90 jim-p
	}
80
}
81 e61a6db2 jim-p
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
82
	foreach ($config['openvpn']['openvpn-server'] as $settings) {
83 f003f8db jim-p
		if (substr($settings['interface'], 0, 4) == '_vip') {
84
			$openvpn_vip = $settings['interface'];
85
		} else if (is_array($a_groups[$settings['interface']])) {
86
			// interface is a gateway group, check CARP VIP
87
			if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
88
				$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
89
			}
90
		} else {
91
			// this OpenVPN instance not on a CARP IP
92
			continue;
93
		}
94 7de4474e Luiz Otavio O Souza
		foreach ($vips as $vip) {
95 f003f8db jim-p
			if ($openvpn_vip == "_vip{$vip['uniqid']}") {
96
				log_error("Starting OpenVPN server instance on {$friendly_descr} because of transition to CARP master.");
97 7de4474e Luiz Otavio O Souza
				openvpn_restart('server', $settings);
98
			}
99 e173dd74 Phil Davis
		}
100
	}
101 52b5a223 Renato Botelho
}
102
103 fcac6e87 Chris Buechler
/* Reconfigure radvd when necessary */
104
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
105
	$rafound = false;
106
	foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
107
		foreach ($vips as $vip) {
108
			if ($dhcpv6ifconf['rainterface'] == "_vip{$vip['uniqid']}") {
109
				log_error("Starting radvd instance on {$friendly_descr} because of transition to CARP master.");
110
				$rafound = true;
111
			}
112
		}
113
	}
114
	if ($rafound) {
115
		services_radvd_configure();
116
	}
117
}
118
119 eaee3af6 PiBa-NL
$pluginparams = array();
120
$pluginparams['type'] = 'carp';
121
$pluginparams['event'] = 'rc.carpmaster';
122 eda14265 jim-p
$pluginparams['interface'] = $argument;
123 331166a8 PiBa-NL
pkg_call_plugins('plugin_carp', $pluginparams);
124 eaee3af6 PiBa-NL
125 34cd5348 Chris Buechler
?>