Project

General

Profile

Download (4.65 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-2016 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("globals.inc");
25
require_once("config.inc");
26
require_once("filter.inc");
27
require_once("shaper.inc");
28
require_once("interfaces.inc");
29

    
30
if (platform_booting()) {
31
	return;
32
}
33

    
34
function handle_argument_group($iface, $argument2) {
35
	global $config;
36

    
37
	if (!is_array($config['interfaces'][$iface])) {
38
		log_error("Cannot find interface configuration for {$iface}");
39
		return;
40
	}
41

    
42
	if (!isset($config['interfaces'][$iface]['enable'])) {
43
		log_error("Linkup detected on disabled interface...Ignoring");
44
		return;
45
	}
46

    
47
	if (empty($config['interfaces'][$iface]['ipaddr'])) {
48
		$ipaddr = '';
49
	} else {
50
		$ipaddr = $config['interfaces'][$iface]['ipaddr'];
51
	}
52

    
53
	if (empty($config['interfaces'][$iface]['ipaddrv6'])) {
54
		$ip6addr = '';
55
	} else {
56
		$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
57
	}
58

    
59
	$staticv4 = false;
60
	if (empty($ipaddr)) {
61
		$staticv4 = true;
62
	} else {
63
		$staticv4 = is_ipaddrv4($ipaddr);
64
	}
65
	$staticv6 = false;
66
	if (empty($ip6addr)) {
67
		$staticv6 = true;
68
	} else {
69
		$staticv6 = is_ipaddrv6($ip6addr);
70
	}
71

    
72
	/* Take care of events on bridge members when IP is configured on bridge */
73
	$bridge_if = link_interface_to_bridge($iface);
74
	if (!empty($bridge_if) && empty($ipaddr) && empty($ip6addr)) {
75
		log_error("Ignoring link event for bridge member without IP config");
76

    
77
		return;
78
	}
79

    
80
	if ($staticv4 === true && $staticv6 === true) {
81
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
82
		log_error("Hotplug event detected for {$friendly}({$iface}) static IP ({$ipaddr} {$ip6addr})");
83
		interfaces_staticarp_configure($iface);
84
		switch ($argument2) {
85
			case 'start':
86
			case 'up':
87
				$iface = get_real_interface($iface);
88
				/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
89
				if (substr($iface, 0, 4) != "ovpn") {
90
					send_event("interface newip {$iface}");
91
				}
92
				break;
93
		}
94
	} else {
95
		switch ($argument2) {
96
			case "stop":
97
			case "down":
98
				log_error("DEVD Ethernet detached event for {$iface}");
99
				interface_bring_down($iface);
100
				break;
101
			case "start":
102
			case "up":
103
				log_error("DEVD Ethernet attached event for {$iface}");
104
				log_error("HOTPLUG: Configuring interface {$iface}");
105
				// Do not try to readd to bridge otherwise em(4) has problems
106
				interface_configure($iface, true, true);
107
				break;
108
		}
109
	}
110
}
111

    
112
if (isset($_GET['interface'])) {
113
	if (!empty($_GET['interface'])) {
114
		$realiface = $_GET['interface'];
115
	}
116
	$action = $_GET['action'];
117
} else {
118
	if ($argc < 3) {
119
		log_error("HOTPLUG event: The required number of parameters not passed!");
120
		return;
121
	}
122
	$action = $argv[1];
123
	$realiface = $argv[2];
124
}
125

    
126
switch ($action) {
127
	case "start":
128
	case "stop":
129
		break;
130
	default:
131
		log_error("HOTPLUG event: Action parameter ($action) passed is wrong - only start/stop/up/down are allowed!");
132
		return;
133
		/* NOTREACHED */
134
		break;
135
}
136

    
137
if (!empty($realiface)) {
138
	if (substr($realiface, 0, 4) == 'ovpn') {
139
		log_error("Ignoring link event for ovpn interface");
140
		return;
141
	}
142
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
143
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
144
	if (!empty($interface)) {
145
		handle_argument_group($interface, $action);
146
	}
147
	if ($action == 'start') {
148
		/* Check if there is any child on this one as ppp types and trigger them */
149
		if (is_array($config['ppps']['ppp'])) {
150
			foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
151
				if ($ppp['type'] == 'ppp') {
152
					continue;
153
				}
154
				$ports = explode(',', $ppp['ports']);
155
				foreach ($ports as $pid => $parent_if) {
156
					/* The loop here is because ppp types can have real and assigned interfaces as members */
157
					$tmpiface = get_real_interface($parent_if);
158
					if ($tmpiface != $realiface) {
159
						continue;
160
					}
161
					$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
162
					if (!empty($tmpiface)) {
163
						interface_configure($tmpiface, true, true);
164
					}
165
				}
166
			}
167
		}
168
	}
169
	filter_configure();
170
	unlock($rclinkuplock);
171
}
172
?>
(51-51/79)