1
|
#!/usr/local/bin/php-cgi -f
|
2
|
<?php
|
3
|
/*
|
4
|
* rc.linkup
|
5
|
*
|
6
|
* part of pfSense (https://www.pfsense.org)
|
7
|
* Copyright (c) 2004-2013 BSD Perimeter
|
8
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
9
|
* Copyright (c) 2014-2022 Rubicon Communications, LLC (Netgate)
|
10
|
* All rights reserved.
|
11
|
*
|
12
|
* 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
|
*
|
16
|
* http://www.apache.org/licenses/LICENSE-2.0
|
17
|
*
|
18
|
* 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
|
*/
|
24
|
|
25
|
/* parse the configuration and include all functions used below */
|
26
|
require_once("globals.inc");
|
27
|
require_once("config.inc");
|
28
|
require_once("filter.inc");
|
29
|
require_once("shaper.inc");
|
30
|
require_once("interfaces.inc");
|
31
|
|
32
|
if (platform_booting()) {
|
33
|
return;
|
34
|
}
|
35
|
|
36
|
function handle_argument_group($iface, $argument2) {
|
37
|
global $g, $config;
|
38
|
|
39
|
if (!is_array($config['interfaces'][$iface])) {
|
40
|
log_error("Cannot find interface configuration for {$iface}");
|
41
|
return;
|
42
|
}
|
43
|
|
44
|
if (!isset($config['interfaces'][$iface]['enable'])) {
|
45
|
log_error("Linkup detected on disabled interface...Ignoring");
|
46
|
return;
|
47
|
}
|
48
|
|
49
|
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
|
$staticv4 = false;
|
62
|
if (empty($ipaddr)) {
|
63
|
$staticv4 = true;
|
64
|
} else {
|
65
|
$staticv4 = is_ipaddrv4($ipaddr);
|
66
|
}
|
67
|
$staticv6 = false;
|
68
|
if (empty($ip6addr)) {
|
69
|
$staticv6 = true;
|
70
|
} else {
|
71
|
$staticv6 = is_ipaddrv6($ip6addr);
|
72
|
}
|
73
|
|
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
|
/* 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
|
if ($staticv4 === true && $staticv6 === true) {
|
91
|
$friendly = convert_friendly_interface_to_friendly_descr($iface);
|
92
|
log_error("Hotplug event detected for {$friendly}({$iface}) static IP ({$ipaddr} {$ip6addr})");
|
93
|
interfaces_staticarp_configure($iface);
|
94
|
switch ($argument2) {
|
95
|
case 'start':
|
96
|
case 'up':
|
97
|
$realif = get_real_interface($iface);
|
98
|
/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
|
99
|
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
|
}
|
104
|
break;
|
105
|
}
|
106
|
} else {
|
107
|
switch ($argument2) {
|
108
|
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
|
/* 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
|
// Do not try to readd to bridge otherwise em(4) has problems
|
124
|
interface_configure($iface, true, true);
|
125
|
|
126
|
/* Make sure gw monitor is configured */
|
127
|
if ($ip6addr == 'slaac' ||
|
128
|
$ip6addr == 'dhcp6') {
|
129
|
setup_gateways_monitor();
|
130
|
}
|
131
|
/* restart unbound on interface recover,
|
132
|
* https://redmine.pfsense.org/issues/11547 */
|
133
|
services_unbound_configure(true, $iface);
|
134
|
break;
|
135
|
}
|
136
|
}
|
137
|
}
|
138
|
|
139
|
if (isset($_GET['interface'])) {
|
140
|
if (!empty($_GET['interface'])) {
|
141
|
$realiface = $_GET['interface'];
|
142
|
}
|
143
|
$action = $_GET['action'];
|
144
|
} else {
|
145
|
if ($argc < 3) {
|
146
|
log_error("HOTPLUG event: The required number of parameters not passed!");
|
147
|
return;
|
148
|
}
|
149
|
$action = $argv[1];
|
150
|
$realiface = $argv[2];
|
151
|
}
|
152
|
$action = ltrim($action, '$');
|
153
|
$realiface = ltrim($realiface, '$');
|
154
|
|
155
|
switch ($action) {
|
156
|
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
|
}
|
165
|
|
166
|
if (!empty($realiface)) {
|
167
|
if (substr($realiface, 0, 4) == 'ovpn') {
|
168
|
log_error("Ignoring link event for ovpn interface");
|
169
|
return;
|
170
|
}
|
171
|
$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
|
172
|
$interface = convert_real_interface_to_friendly_interface_name($realiface);
|
173
|
if (!empty($interface)) {
|
174
|
handle_argument_group($interface, $action);
|
175
|
}
|
176
|
/* 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
|
continue;
|
189
|
}
|
190
|
$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
|
191
|
if (!empty($tmpiface)) {
|
192
|
if (($action == 'start') || ($action == 'up')) {
|
193
|
interface_configure($tmpiface, true, true);
|
194
|
} elseif (($action == 'stop') || ($action == 'down')) {
|
195
|
interface_bring_down($tmpiface);
|
196
|
}
|
197
|
}
|
198
|
}
|
199
|
}
|
200
|
}
|
201
|
filter_configure();
|
202
|
unlock($rclinkuplock);
|
203
|
}
|
204
|
?>
|