1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.carpbackup
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2004-2016 Electric Sheep Fencing, LLC
|
8
|
* All rights reserved.
|
9
|
*
|
10
|
* Redistribution and use in source and binary forms, with or without
|
11
|
* modification, are permitted provided that the following conditions are met:
|
12
|
*
|
13
|
* 1. Redistributions of source code must retain the above copyright notice,
|
14
|
* this list of conditions and the following disclaimer.
|
15
|
*
|
16
|
* 2. Redistributions in binary form must reproduce the above copyright
|
17
|
* notice, this list of conditions and the following disclaimer in
|
18
|
* the documentation and/or other materials provided with the
|
19
|
* distribution.
|
20
|
*
|
21
|
* 3. All advertising materials mentioning features or use of this software
|
22
|
* must display the following acknowledgment:
|
23
|
* "This product includes software developed by the pfSense Project
|
24
|
* for use in the pfSense® software distribution. (http://www.pfsense.org/).
|
25
|
*
|
26
|
* 4. The names "pfSense" and "pfSense Project" must not be used to
|
27
|
* endorse or promote products derived from this software without
|
28
|
* prior written permission. For written permission, please contact
|
29
|
* coreteam@pfsense.org.
|
30
|
*
|
31
|
* 5. Products derived from this software may not be called "pfSense"
|
32
|
* nor may "pfSense" appear in their names without prior written
|
33
|
* permission of the Electric Sheep Fencing, LLC.
|
34
|
*
|
35
|
* 6. Redistributions of any form whatsoever must retain the following
|
36
|
* acknowledgment:
|
37
|
*
|
38
|
* "This product includes software developed by the pfSense Project
|
39
|
* for use in the pfSense software distribution (http://www.pfsense.org/).
|
40
|
*
|
41
|
* THIS SOFTWARE IS PROVIDED BY THE pfSense PROJECT ``AS IS'' AND ANY
|
42
|
* EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
43
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
44
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE pfSense PROJECT OR
|
45
|
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
46
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
47
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
48
|
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
49
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
50
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
51
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
52
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
53
|
*/
|
54
|
|
55
|
require_once("functions.inc");
|
56
|
require_once("config.inc");
|
57
|
require_once("notices.inc");
|
58
|
require_once("openvpn.inc");
|
59
|
require_once("interfaces.inc");
|
60
|
|
61
|
if (isset($_GET['interface'])) {
|
62
|
$argument = $_GET['interface'];
|
63
|
} else {
|
64
|
$argument = str_replace("\n", "", $argv[1]);
|
65
|
}
|
66
|
if (!strstr($argument, "@")) {
|
67
|
log_error("CARP master event triggered from wrong source {$argument}");
|
68
|
exit;
|
69
|
}
|
70
|
|
71
|
list($vhid, $iface) = explode("@", $argument);
|
72
|
|
73
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
74
|
$friendly_descr = convert_friendly_interface_to_friendly_descr($friendly);
|
75
|
$vips = link_interface_to_vips($friendly, '', $vhid);
|
76
|
if (!is_array($vips)) {
|
77
|
log_error("CARP master event triggered from wrong source {$argument} - no associated VIPs");
|
78
|
exit;
|
79
|
}
|
80
|
foreach ($vips as $vip) {
|
81
|
$notificationmsg = sprintf('HA cluster member "(%1$s@%2$s): (%3$s)" has resumed CARP state "BACKUP" for vhid %4$s',
|
82
|
$vip['subnet'], $iface, $friendly_descr, $vhid);
|
83
|
|
84
|
notify_via_smtp($notificationmsg);
|
85
|
notify_via_growl($notificationmsg);
|
86
|
log_error($notificationmsg);
|
87
|
}
|
88
|
|
89
|
/* Stop OpenVPN clients running on this VIP, since multiple active OpenVPN clients on a CARP cluster can be problematic. */
|
90
|
global $config;
|
91
|
$a_groups = return_gateway_groups_array();
|
92
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-client'])) {
|
93
|
foreach ($config['openvpn']['openvpn-client'] as $settings) {
|
94
|
if (substr($settings['interface'], 0, 4) == '_vip') {
|
95
|
$openvpn_vip = $settings['interface'];
|
96
|
} else if (is_array($a_groups[$settings['interface']])) {
|
97
|
// interface is a gateway group, check CARP VIP
|
98
|
if (substr($a_groups[$settings['interface']][0]['vip'], 0, 4) == '_vip') {
|
99
|
$openvpn_vip = $a_groups[$settings['interface']][0]['vip'];
|
100
|
}
|
101
|
} else {
|
102
|
// this OpenVPN instance not on a CARP IP
|
103
|
continue;
|
104
|
}
|
105
|
foreach ($vips as $vip) {
|
106
|
if ($openvpn_vip == "_vip{$vip['uniqid']}") {
|
107
|
log_error("Stopping OpenVPN client instance on {$friendly_descr} because of transition to CARP backup.");
|
108
|
openvpn_restart('client', $settings);
|
109
|
}
|
110
|
}
|
111
|
}
|
112
|
}
|
113
|
|
114
|
if (is_array($config['openvpn']) && is_array($config['openvpn']['openvpn-server'])) {
|
115
|
foreach ($config['openvpn']['openvpn-server'] as $settings) {
|
116
|
foreach ($vips as $vip) {
|
117
|
if ($settings['interface'] == "_vip{$vip['uniqid']}") {
|
118
|
log_error("Stopping OpenVPN instance on {$friendly_descr} because of transition to CARP backup.");
|
119
|
openvpn_restart('server', $settings);
|
120
|
}
|
121
|
}
|
122
|
}
|
123
|
}
|
124
|
|
125
|
/* Reconfigure radvd when necessary */
|
126
|
if (isset($config['dhcpdv6']) && is_array($config['dhcpdv6'])) {
|
127
|
$rafound = false;
|
128
|
foreach ($config['dhcpdv6'] as $dhcpv6if => $dhcpv6ifconf) {
|
129
|
foreach ($vips as $vip) {
|
130
|
if ($dhcpv6ifconf['rainterface'] == "_vip{$vip['uniqid']}") {
|
131
|
log_error("Stopping radvd instance on {$friendly_descr} because of transition to CARP master.");
|
132
|
$rafound = true;
|
133
|
}
|
134
|
}
|
135
|
}
|
136
|
if ($rafound) {
|
137
|
services_radvd_configure();
|
138
|
}
|
139
|
}
|
140
|
|
141
|
$pluginparams = array();
|
142
|
$pluginparams['type'] = 'carp';
|
143
|
$pluginparams['event'] = 'rc.carpbackup';
|
144
|
$pluginparams['interface'] = $argument;
|
145
|
pkg_call_plugins('plugin_carp', $pluginparams);
|
146
|
|
147
|
?>
|