Project

General

Profile

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