1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.ipsec
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2021-2024 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
|
/* parse the configuration and include all functions used below */
|
24
|
require_once("config.inc");
|
25
|
require_once("gwlb.inc");
|
26
|
require_once("ipsec.inc");
|
27
|
require_once("util.inc");
|
28
|
require_once("globals.inc");
|
29
|
|
30
|
/* make sure to wait until the boot scripts have finished */
|
31
|
if (is_platform_booting()) {
|
32
|
return;
|
33
|
}
|
34
|
|
35
|
$argument = (isset($_GET['interface'])) ? $_GET['interface'] : $argv[1];
|
36
|
$argument = trim($argument, "'\" \n");
|
37
|
|
38
|
$ipsec_reload = false;
|
39
|
if (empty($argument)) {
|
40
|
$ipsec_reload = true;
|
41
|
} else {
|
42
|
$arg_array = explode(",", $argument);
|
43
|
foreach ($arg_array as $arg_element) {
|
44
|
$gwgroups = array();
|
45
|
if ($arg_element == "all") {
|
46
|
$ipsec_reload = true;
|
47
|
break;
|
48
|
} else {
|
49
|
// e.g. $arg_element = "WANGW", $interface = "wan"
|
50
|
$interface = lookup_gateway_interface_by_name($arg_element);
|
51
|
if (empty($interface)) {
|
52
|
$interface = $arg_element;
|
53
|
} else {
|
54
|
// e.g. $arg_element = "WANGW", $gwgroups = array of gateway groups that use "wan"
|
55
|
$gwgroups = gateway_is_gwgroup_member($arg_element);
|
56
|
}
|
57
|
foreach (config_get_path('ipsec/phase1', []) as $phase1) {
|
58
|
if (isset($phase1['disabled']) || isset($phase1['mobile']) ||
|
59
|
($phase1['startaction'] == 'none')) {
|
60
|
continue;
|
61
|
}
|
62
|
if (substr($phase1['interface'], 0, 4) == "_vip") {
|
63
|
$phase1iface = get_configured_vip_interface($phase1['interface']);
|
64
|
if (substr($phase1iface, 0, 4) == "_vip") {
|
65
|
// vips are nested if its a ipalias with a carp parent
|
66
|
$phase1iface = get_configured_vip_interface($phase1iface);
|
67
|
}
|
68
|
} else {
|
69
|
$phase1iface = $phase1['interface'];
|
70
|
}
|
71
|
if (($phase1iface == $interface) ||
|
72
|
(!empty($gwgroups) && in_array($phase1iface, $gwgroups))) {
|
73
|
$ipsec_reload = true;
|
74
|
break 2;
|
75
|
}
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
}
|
80
|
|
81
|
if ($ipsec_reload) {
|
82
|
$ipseclck_pending = try_lock('ipsecdns_pending', 0);
|
83
|
if (!$ipseclck_pending) {
|
84
|
/* if a ipsec_configure() is still pending no need to stack up another one */
|
85
|
return;
|
86
|
}
|
87
|
$ipseclck = lock('ipsecdns', LOCK_EX);
|
88
|
sleep(12);
|
89
|
unlock($ipseclck_pending);
|
90
|
sleep(3);
|
91
|
log_error("IPSEC: One or more IPsec tunnel gateways have changed. Refreshing.");
|
92
|
ipsec_configure();
|
93
|
unlock($ipseclck);
|
94
|
ipsec_reload_package_hook();
|
95
|
}
|