Project

General

Profile

Download (2.83 KB) Statistics
| Branch: | Tag: | Revision:
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']) || ($phase1['startaction'] == 'none')) {
59
					continue;
60
				}
61
				if (substr($phase1['interface'], 0, 4) == "_vip") {
62
					$phase1iface = get_configured_vip_interface($phase1['interface']);
63
					if (substr($phase1iface, 0, 4) == "_vip") {
64
						// vips are nested if its a ipalias with a carp parent
65
						$phase1iface = get_configured_vip_interface($phase1iface);
66
					}
67
				} else {
68
					$phase1iface = $phase1['interface'];
69
				}
70
				if (($phase1iface == $interface) ||
71
				    (!empty($gwgroups) && in_array($phase1iface, $gwgroups))) {
72
					$ipsec_reload = true;
73
					break 2;
74
				}
75
			}
76
		}
77
	}
78
}
79

    
80
if ($ipsec_reload) {
81
	$ipseclck_pending = try_lock('ipsecdns_pending', 0);
82
	if (!$ipseclck_pending) {
83
		/* if a ipsec_configure() is still pending no need to stack up another one */
84
		return;
85
	}
86
	$ipseclck = lock('ipsecdns', LOCK_EX);
87
	sleep(12);
88
	unlock($ipseclck_pending);
89
	sleep(3);
90
	log_error("IPSEC: One or more IPsec tunnel gateways have changed. Refreshing.");
91
	ipsec_configure();
92
	unlock($ipseclck);
93
	ipsec_reload_package_hook();
94
}
(52-52/85)