Project

General

Profile

Download (5.22 KB) Statistics
| Branch: | Tag: | Revision:
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-2021 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
				$iface = get_real_interface($iface);
98
				/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
99
				if (substr($iface, 0, 4) != "ovpn") {
100
					send_event("interface newip {$iface}");
101
				}
102
				break;
103
		}
104
	} else {
105
		switch ($argument2) {
106
			case "stop":
107
			case "down":
108
				log_error("DEVD Ethernet detached event for {$iface}");
109
				interface_bring_down($iface);
110
				break;
111
			case "start":
112
			case "up":
113
				log_error("DEVD Ethernet attached event for {$iface}");
114
				log_error("HOTPLUG: Configuring interface {$iface}");
115
				// Do not try to readd to bridge otherwise em(4) has problems
116
				interface_configure($iface, true, true);
117

    
118
				/* Make sure gw monitor is configured */
119
				if ($ip6addr == 'slaac' ||
120
				    $ip6addr == 'dhcp6') {
121
					setup_gateways_monitor();
122
				}
123
				break;
124
		}
125
	}
126
}
127

    
128
if (isset($_GET['interface'])) {
129
	if (!empty($_GET['interface'])) {
130
		$realiface = $_GET['interface'];
131
	}
132
	$action = $_GET['action'];
133
} else {
134
	if ($argc < 3) {
135
		log_error("HOTPLUG event: The required number of parameters not passed!");
136
		return;
137
	}
138
	$action = $argv[1];
139
	$realiface = $argv[2];
140
}
141
$action = ltrim($action, '$');
142
$realiface = ltrim($realiface, '$');
143

    
144
switch ($action) {
145
	case "start":
146
	case "stop":
147
		break;
148
	default:
149
		log_error("HOTPLUG event: Action parameter ($action) passed is wrong - only start/stop/up/down are allowed!");
150
		return;
151
		/* NOTREACHED */
152
		break;
153
}
154

    
155
if (!empty($realiface)) {
156
	if (substr($realiface, 0, 4) == 'ovpn') {
157
		log_error("Ignoring link event for ovpn interface");
158
		return;
159
	}
160
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
161
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
162
	if (!empty($interface)) {
163
		handle_argument_group($interface, $action);
164
	}
165
	if ($action == 'start') {
166
		/* Check if there is any child on this one as ppp types and trigger them */
167
		if (is_array($config['ppps']['ppp'])) {
168
			foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
169
				if ($ppp['type'] == 'ppp') {
170
					continue;
171
				}
172
				$ports = explode(',', $ppp['ports']);
173
				foreach ($ports as $pid => $parent_if) {
174
					/* The loop here is because ppp types can have real and assigned interfaces as members */
175
					$tmpiface = get_real_interface($parent_if);
176
					if ($tmpiface != $realiface) {
177
						continue;
178
					}
179
					$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
180
					if (!empty($tmpiface)) {
181
						interface_configure($tmpiface, true, true);
182
					}
183
				}
184
			}
185
		}
186
	}
187
	filter_configure();
188
	unlock($rclinkuplock);
189
}
190
?>
(51-51/82)