Project

General

Profile

Download (5.82 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 1a978734 Scott Ullrich
<?php
3
/*
4 ac24dc24 Renato Botelho
 * rc.linkup
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 8f2f85c3 Luiz Otavio O Souza
 * Copyright (c) 2014-2022 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 1a978734 Scott Ullrich
25 4367b5f6 Ermal Luçi
/* parse the configuration and include all functions used below */
26
require_once("globals.inc");
27
require_once("config.inc");
28 e173dd74 Phil Davis
require_once("filter.inc");
29
require_once("shaper.inc");
30 a55e9c70 Ermal Lu?i
require_once("interfaces.inc");
31 1a978734 Scott Ullrich
32 e173dd74 Phil Davis
if (platform_booting()) {
33 7e677d85 Ermal LUÇI
	return;
34 e173dd74 Phil Davis
}
35 7e677d85 Ermal LUÇI
36 5b70c17e Ermal Lu?i
function handle_argument_group($iface, $argument2) {
37 37194aa2 Renato Botelho do Couto
	global $g, $config;
38 4476d447 Ermal Luçi
39 e8fa9843 Chris Buechler
	if (!is_array($config['interfaces'][$iface])) {
40
		log_error("Cannot find interface configuration for {$iface}");
41 7d2fedc9 Ermal
		return;
42 e8fa9843 Chris Buechler
	}
43 7d2fedc9 Ermal
44 5574e8d5 Ermal LUÇI
	if (!isset($config['interfaces'][$iface]['enable'])) {
45 9e7cc828 Luiz Otavio O Souza
		log_error("Linkup detected on disabled interface...Ignoring");
46 156a086d Ermal LUÇI
		return;
47
	}
48
49 88871e26 Renato Botelho
	if (empty($config['interfaces'][$iface]['ipaddr'])) {
50
		$ipaddr = '';
51
	} else {
52
		$ipaddr = $config['interfaces'][$iface]['ipaddr'];
53
	}
54
55
	if (empty($config['interfaces'][$iface]['ipaddrv6'])) {
56
		$ip6addr = '';
57
	} else {
58
		$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
59
	}
60
61 67864df7 Ermal
	$staticv4 = false;
62 e173dd74 Phil Davis
	if (empty($ipaddr)) {
63 67864df7 Ermal
		$staticv4 = true;
64 e173dd74 Phil Davis
	} else {
65 67864df7 Ermal
		$staticv4 = is_ipaddrv4($ipaddr);
66 e173dd74 Phil Davis
	}
67 67864df7 Ermal
	$staticv6 = false;
68 e173dd74 Phil Davis
	if (empty($ip6addr)) {
69 497841f5 Ermal
		$staticv6 = true;
70 e173dd74 Phil Davis
	} else {
71 67864df7 Ermal
		$staticv6 = is_ipaddrv6($ip6addr);
72 e173dd74 Phil Davis
	}
73 88871e26 Renato Botelho
74
	/* Take care of events on bridge members when IP is configured on bridge */
75
	$bridge_if = link_interface_to_bridge($iface);
76
	if (!empty($bridge_if) && empty($ipaddr) && empty($ip6addr)) {
77
		log_error("Ignoring link event for bridge member without IP config");
78
79
		return;
80
	}
81
82 84422a37 Viktor Gurov
	/* Ignore events on LAGG members without IP address configuration */
83
	$lagg_if = link_interface_to_lagg($iface);
84
	if (!empty($lagg_if) && empty($ipaddr) && empty($ip6addr)) {
85
		log_error("Ignoring link event for LAGG member without IP address configuration");
86
87
		return;
88
	}
89
90 67864df7 Ermal
	if ($staticv4 === true && $staticv6 === true) {
91 7d2fedc9 Ermal
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
92 a20da2b6 Chris Buechler
		log_error("Hotplug event detected for {$friendly}({$iface}) static IP ({$ipaddr} {$ip6addr})");
93 8ee623f3 jim-p
		interfaces_staticarp_configure($iface);
94 619cd0d6 Ermal LUÇI
		switch ($argument2) {
95 e173dd74 Phil Davis
			case 'start':
96
			case 'up':
97 ec73bb89 Viktor G
				$realif = get_real_interface($iface);
98 e173dd74 Phil Davis
				/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
99 ec73bb89 Viktor G
				if (substr($realif, 0, 4) != "ovpn") {
100
					touch("{$g['tmp_path']}/{$iface}_upstart4");
101
					touch("{$g['tmp_path']}/{$iface}_upstart6");
102
					send_event("interface newip {$realif}");
103 e173dd74 Phil Davis
				}
104
				break;
105 619cd0d6 Ermal LUÇI
		}
106 4367b5f6 Ermal Luçi
	} else {
107
		switch ($argument2) {
108 e173dd74 Phil Davis
			case "stop":
109
			case "down":
110
				log_error("DEVD Ethernet detached event for {$iface}");
111
				interface_bring_down($iface);
112
				break;
113
			case "start":
114
			case "up":
115
				log_error("DEVD Ethernet attached event for {$iface}");
116
				log_error("HOTPLUG: Configuring interface {$iface}");
117 ec73bb89 Viktor G
				/* trigger services restart
118
				 * see https://redmine.pfsense.org/issues/11570 */
119
				if (!$staticv4) {
120
					touch("{$g['tmp_path']}/{$iface}_upstart4");
121
					touch("{$g['tmp_path']}/{$iface}_upstart6");
122
				}
123 e173dd74 Phil Davis
				// Do not try to readd to bridge otherwise em(4) has problems
124
				interface_configure($iface, true, true);
125 acb79de0 Renato Botelho do Couto
126
				/* Make sure gw monitor is configured */
127
				if ($ip6addr == 'slaac' ||
128
				    $ip6addr == 'dhcp6') {
129
					setup_gateways_monitor();
130 37194aa2 Renato Botelho do Couto
				}
131 a1fe8144 Viktor G
				/* restart unbound on interface recover,
132
				 * https://redmine.pfsense.org/issues/11547 */
133 6ac625e8 Viktor G
				services_unbound_configure(true, $iface);
134 e173dd74 Phil Davis
				break;
135 a7b5cfbe Scott Ullrich
		}
136 4367b5f6 Ermal Luçi
	}
137
}
138 1a978734 Scott Ullrich
139 7e677d85 Ermal LUÇI
if (isset($_GET['interface'])) {
140 e173dd74 Phil Davis
	if (!empty($_GET['interface'])) {
141 7e677d85 Ermal LUÇI
		$realiface = $_GET['interface'];
142 e173dd74 Phil Davis
	}
143 7e677d85 Ermal LUÇI
	$action = $_GET['action'];
144
} else {
145
	if ($argc < 3) {
146
		log_error("HOTPLUG event: The required number of parameters not passed!");
147
		return;
148 7d2fedc9 Ermal
	}
149 7e677d85 Ermal LUÇI
	$action = $argv[1];
150
	$realiface = $argv[2];
151
}
152 de9df940 jim-p
$action = ltrim($action, '$');
153
$realiface = ltrim($realiface, '$');
154 2eb3efc2 Ermal LUÇI
155 086cf944 Phil Davis
switch ($action) {
156 e173dd74 Phil Davis
	case "start":
157
	case "stop":
158
		break;
159
	default:
160
		log_error("HOTPLUG event: Action parameter ($action) passed is wrong - only start/stop/up/down are allowed!");
161
		return;
162
		/* NOTREACHED */
163
		break;
164 7e677d85 Ermal LUÇI
}
165 2eb3efc2 Ermal LUÇI
166 7e677d85 Ermal LUÇI
if (!empty($realiface)) {
167
	if (substr($realiface, 0, 4) == 'ovpn') {
168
		log_error("Ignoring link event for ovpn interface");
169 6668e18f Ermal LUÇI
		return;
170 4367b5f6 Ermal Luçi
	}
171 2eb3efc2 Ermal LUÇI
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
172 7e677d85 Ermal LUÇI
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
173 e173dd74 Phil Davis
	if (!empty($interface)) {
174 7e677d85 Ermal LUÇI
		handle_argument_group($interface, $action);
175 e173dd74 Phil Davis
	}
176 13720b18 Viktor G
	/* Check if there is any child on this one as ppp types and trigger them */
177
	init_config_arr(array('ppps', 'ppp'));
178
	if (is_array($config['ppps']['ppp'])) {
179
		foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
180
			if ($ppp['type'] == 'ppp') {
181
				continue;
182
			}
183
			$ports = explode(',', $ppp['ports']);
184
			foreach ($ports as $pid => $parent_if) {
185
				/* The loop here is because ppp types can have real and assigned interfaces as members */
186
				$tmpiface = get_real_interface($parent_if);
187
				if ($tmpiface != $realiface) {
188 7e677d85 Ermal LUÇI
					continue;
189 e173dd74 Phil Davis
				}
190 13720b18 Viktor G
				$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
191
				if (!empty($tmpiface)) {
192
					if (($action == 'start') || ($action == 'up')) {
193 7e677d85 Ermal LUÇI
						interface_configure($tmpiface, true, true);
194 13720b18 Viktor G
					} elseif (($action == 'stop') || ($action == 'down')) {
195
						interface_bring_down($tmpiface);
196 e173dd74 Phil Davis
					}
197 da145569 Ermal LUÇI
				}
198
			}
199
		}
200 6668e18f Ermal LUÇI
	}
201 e3bda4fa Chris Buechler
	filter_configure();
202 2eb3efc2 Ermal LUÇI
	unlock($rclinkuplock);
203 4367b5f6 Ermal Luçi
}
204 a55e9c70 Ermal Lu?i
?>