1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.carpmaster
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2004-2016 Rubicon Communications, LLC (Netgate)
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* 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
|
*
|
14
|
* http://www.apache.org/licenses/LICENSE-2.0
|
15
|
*
|
16
|
* 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
|
*/
|
22
|
|
23
|
require_once("functions.inc");
|
24
|
require_once("config.inc");
|
25
|
require_once("notices.inc");
|
26
|
require_once("openvpn.inc");
|
27
|
require_once("interfaces.inc");
|
28
|
|
29
|
if (isset($_GET['interface'])) {
|
30
|
$argument = $_GET['interface'];
|
31
|
} else {
|
32
|
$argument = str_replace("\n", "", $argv[1]);
|
33
|
}
|
34
|
if (!strstr($argument, "@")) {
|
35
|
log_error("CARP master event triggered from wrong source {$argument}");
|
36
|
exit;
|
37
|
}
|
38
|
|
39
|
list($vhid, $iface) = explode("@", $argument);
|
40
|
|
41
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
42
|
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
|
43
|
$vips = link_interface_to_vips($friendly, '', $vhid);
|
44
|
if (!is_array($vips)) {
|
45
|
log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs");
|
46
|
exit;
|
47
|
}
|
48
|
foreach ($vips as $vip) {
|
49
|
$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
|
|
52
|
notify_via_smtp($notificationmsg);
|
53
|
notify_via_growl($notificationmsg);
|
54
|
log_error($notificationmsg);
|
55
|
}
|
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
|
$a_groups = return_gateway_groups_array();
|
60
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
|
61
|
foreach ($config['openvpn']['openvpn-client'] as $settings) {
|
62
|
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
|
foreach ($vips as $vip) {
|
74
|
if ($openvpn_vip == "_vip{$vip['uniqid']}") {
|
75
|
log_error("Starting OpenVPN client instance on {$friendly_descr} because of transition to CARP master.");
|
76
|
openvpn_restart('client', $settings);
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
}
|
81
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
|
82
|
foreach ($config['openvpn']['openvpn-server'] as $settings) {
|
83
|
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
|
foreach ($vips as $vip) {
|
95
|
if ($openvpn_vip == "_vip{$vip['uniqid']}") {
|
96
|
log_error("Starting OpenVPN server instance on {$friendly_descr} because of transition to CARP master.");
|
97
|
openvpn_restart('server', $settings);
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
}
|
102
|
|
103
|
/* 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
|
$pluginparams = array();
|
120
|
$pluginparams['type'] = 'carp';
|
121
|
$pluginparams['event'] = 'rc.carpmaster';
|
122
|
$pluginparams['interface'] = $argument;
|
123
|
pkg_call_plugins('plugin_carp', $pluginparams);
|
124
|
|
125
|
?>
|