Project

General

Profile

Download (4.65 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 880ed461 jim-p
 * Copyright (c) 2004-2020 Rubicon Communications, LLC (Netgate)
8 ac24dc24 Renato Botelho
 * All rights reserved.
9
 *
10 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 *
14 b12ea3fb Renato Botelho
 * http://www.apache.org/licenses/LICENSE-2.0
15 ac24dc24 Renato Botelho
 *
16 b12ea3fb Renato Botelho
 * 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 ac24dc24 Renato Botelho
 */
22 1a978734 Scott Ullrich
23 4367b5f6 Ermal Luçi
/* parse the configuration and include all functions used below */
24
require_once("globals.inc");
25
require_once("config.inc");
26 e173dd74 Phil Davis
require_once("filter.inc");
27
require_once("shaper.inc");
28 a55e9c70 Ermal Lu?i
require_once("interfaces.inc");
29 1a978734 Scott Ullrich
30 e173dd74 Phil Davis
if (platform_booting()) {
31 7e677d85 Ermal LUÇI
	return;
32 e173dd74 Phil Davis
}
33 7e677d85 Ermal LUÇI
34 5b70c17e Ermal Lu?i
function handle_argument_group($iface, $argument2) {
35 e173dd74 Phil Davis
	global $config;
36 4476d447 Ermal Luçi
37 e8fa9843 Chris Buechler
	if (!is_array($config['interfaces'][$iface])) {
38
		log_error("Cannot find interface configuration for {$iface}");
39 7d2fedc9 Ermal
		return;
40 e8fa9843 Chris Buechler
	}
41 7d2fedc9 Ermal
42 5574e8d5 Ermal LUÇI
	if (!isset($config['interfaces'][$iface]['enable'])) {
43 9e7cc828 Luiz Otavio O Souza
		log_error("Linkup detected on disabled interface...Ignoring");
44 156a086d Ermal LUÇI
		return;
45
	}
46
47 88871e26 Renato Botelho
	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 67864df7 Ermal
	$staticv4 = false;
60 e173dd74 Phil Davis
	if (empty($ipaddr)) {
61 67864df7 Ermal
		$staticv4 = true;
62 e173dd74 Phil Davis
	} else {
63 67864df7 Ermal
		$staticv4 = is_ipaddrv4($ipaddr);
64 e173dd74 Phil Davis
	}
65 67864df7 Ermal
	$staticv6 = false;
66 e173dd74 Phil Davis
	if (empty($ip6addr)) {
67 497841f5 Ermal
		$staticv6 = true;
68 e173dd74 Phil Davis
	} else {
69 67864df7 Ermal
		$staticv6 = is_ipaddrv6($ip6addr);
70 e173dd74 Phil Davis
	}
71 88871e26 Renato Botelho
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 67864df7 Ermal
	if ($staticv4 === true && $staticv6 === true) {
81 7d2fedc9 Ermal
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
82 a20da2b6 Chris Buechler
		log_error("Hotplug event detected for {$friendly}({$iface}) static IP ({$ipaddr} {$ip6addr})");
83 8ee623f3 jim-p
		interfaces_staticarp_configure($iface);
84 619cd0d6 Ermal LUÇI
		switch ($argument2) {
85 e173dd74 Phil Davis
			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 619cd0d6 Ermal LUÇI
		}
94 4367b5f6 Ermal Luçi
	} else {
95
		switch ($argument2) {
96 e173dd74 Phil Davis
			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 a7b5cfbe Scott Ullrich
		}
109 4367b5f6 Ermal Luçi
	}
110
}
111 1a978734 Scott Ullrich
112 7e677d85 Ermal LUÇI
if (isset($_GET['interface'])) {
113 e173dd74 Phil Davis
	if (!empty($_GET['interface'])) {
114 7e677d85 Ermal LUÇI
		$realiface = $_GET['interface'];
115 e173dd74 Phil Davis
	}
116 7e677d85 Ermal LUÇI
	$action = $_GET['action'];
117
} else {
118
	if ($argc < 3) {
119
		log_error("HOTPLUG event: The required number of parameters not passed!");
120
		return;
121 7d2fedc9 Ermal
	}
122 7e677d85 Ermal LUÇI
	$action = $argv[1];
123
	$realiface = $argv[2];
124
}
125 2eb3efc2 Ermal LUÇI
126 086cf944 Phil Davis
switch ($action) {
127 e173dd74 Phil Davis
	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 7e677d85 Ermal LUÇI
}
136 2eb3efc2 Ermal LUÇI
137 7e677d85 Ermal LUÇI
if (!empty($realiface)) {
138
	if (substr($realiface, 0, 4) == 'ovpn') {
139
		log_error("Ignoring link event for ovpn interface");
140 6668e18f Ermal LUÇI
		return;
141 4367b5f6 Ermal Luçi
	}
142 2eb3efc2 Ermal LUÇI
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
143 7e677d85 Ermal LUÇI
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
144 e173dd74 Phil Davis
	if (!empty($interface)) {
145 7e677d85 Ermal LUÇI
		handle_argument_group($interface, $action);
146 e173dd74 Phil Davis
	}
147 7e677d85 Ermal LUÇI
	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 e173dd74 Phil Davis
				if ($ppp['type'] == 'ppp') {
152 7e677d85 Ermal LUÇI
					continue;
153 e173dd74 Phil Davis
				}
154 7e677d85 Ermal LUÇI
				$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 e173dd74 Phil Davis
					if ($tmpiface != $realiface) {
159 ab0e4080 Ermal LUÇI
						continue;
160 e173dd74 Phil Davis
					}
161 ab0e4080 Ermal LUÇI
					$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
162 e173dd74 Phil Davis
					if (!empty($tmpiface)) {
163 7e677d85 Ermal LUÇI
						interface_configure($tmpiface, true, true);
164 e173dd74 Phil Davis
					}
165 da145569 Ermal LUÇI
				}
166
			}
167
		}
168 6668e18f Ermal LUÇI
	}
169 e3bda4fa Chris Buechler
	filter_configure();
170 2eb3efc2 Ermal LUÇI
	unlock($rclinkuplock);
171 4367b5f6 Ermal Luçi
}
172 a55e9c70 Ermal Lu?i
?>