Project

General

Profile

Download (4.95 KB) Statistics
| Branch: | Tag: | Revision:
1 cb7d18d5 Renato Botelho
#!/usr/local/bin/php-cgi -f
2 1a978734 Scott Ullrich
<?php
3
/*
4 ce77a9c4 Phil Davis
	rc.linkup - devd hotplug actions
5
	part of pfSense
6
7
	Copyright (C) 2003-2005 Scott Ullrich <sullrich@gmail.com>.
8
	All rights reserved.
9
10
	Redistribution and use in source and binary forms, with or without
11
	modification, are permitted provided that the following conditions are met:
12
13
	1. Redistributions of source code must retain the above copyright notice,
14
	   this list of conditions and the following disclaimer.
15
16
	2. Redistributions in binary form must reproduce the above copyright
17
	   notice, this list of conditions and the following disclaimer in the
18
	   documentation and/or other materials provided with the distribution.
19
20
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
21
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
22
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
23
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
24
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29
	POSSIBILITY OF SUCH DAMAGE.
30 1a978734 Scott Ullrich
*/
31
32 4367b5f6 Ermal Luçi
/* parse the configuration and include all functions used below */
33
require_once("globals.inc");
34
require_once("config.inc");
35 e173dd74 Phil Davis
require_once("filter.inc");
36
require_once("shaper.inc");
37 a55e9c70 Ermal Lu?i
require_once("interfaces.inc");
38 1a978734 Scott Ullrich
39 e173dd74 Phil Davis
if (platform_booting()) {
40 7e677d85 Ermal LUÇI
	return;
41 e173dd74 Phil Davis
}
42 7e677d85 Ermal LUÇI
43 5b70c17e Ermal Lu?i
function handle_argument_group($iface, $argument2) {
44 e173dd74 Phil Davis
	global $config;
45 4476d447 Ermal Luçi
46 e8fa9843 Chris Buechler
	if (!is_array($config['interfaces'][$iface])) {
47
		log_error("Cannot find interface configuration for {$iface}");
48 7d2fedc9 Ermal
		return;
49 e8fa9843 Chris Buechler
	}
50 7d2fedc9 Ermal
51 5574e8d5 Ermal LUÇI
	if (!isset($config['interfaces'][$iface]['enable'])) {
52 e173dd74 Phil Davis
		if (!platform_booting()) {
53 e702e9ed Ermal LUÇI
			log_error("Linkup detected on disabled interface...Ignoring");
54 e173dd74 Phil Davis
		}
55 156a086d Ermal LUÇI
		return;
56
	}
57
58 5b70c17e Ermal Lu?i
	$ipaddr = $config['interfaces'][$iface]['ipaddr'];
59 7d2fedc9 Ermal
	$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
60 67864df7 Ermal
	$staticv4 = false;
61 e173dd74 Phil Davis
	if (empty($ipaddr)) {
62 67864df7 Ermal
		$staticv4 = true;
63 e173dd74 Phil Davis
	} else {
64 67864df7 Ermal
		$staticv4 = is_ipaddrv4($ipaddr);
65 e173dd74 Phil Davis
	}
66 67864df7 Ermal
	$staticv6 = false;
67 e173dd74 Phil Davis
	if (empty($ip6addr)) {
68 497841f5 Ermal
		$staticv6 = true;
69 e173dd74 Phil Davis
	} else {
70 67864df7 Ermal
		$staticv6 = is_ipaddrv6($ip6addr);
71 e173dd74 Phil Davis
	}
72 67864df7 Ermal
	if ($staticv4 === true && $staticv6 === true) {
73 7d2fedc9 Ermal
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
74
		log_error("Hotplug event detected for {$friendly}({$iface}) but ignoring since interface is configured with static IP ({$ipaddr} {$ip6addr})");
75 8ee623f3 jim-p
		interfaces_staticarp_configure($iface);
76 619cd0d6 Ermal LUÇI
		switch ($argument2) {
77 e173dd74 Phil Davis
			case 'start':
78
			case 'up':
79
				$iface = get_real_interface($iface);
80
				/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
81
				if (substr($iface, 0, 4) != "ovpn") {
82
					send_event("interface newip {$iface}");
83
				}
84
				break;
85 619cd0d6 Ermal LUÇI
		}
86 4367b5f6 Ermal Luçi
	} else {
87
		switch ($argument2) {
88 e173dd74 Phil Davis
			case "stop":
89
			case "down":
90
				log_error("DEVD Ethernet detached event for {$iface}");
91
				interface_bring_down($iface);
92
				break;
93
			case "start":
94
			case "up":
95
				log_error("DEVD Ethernet attached event for {$iface}");
96
				log_error("HOTPLUG: Configuring interface {$iface}");
97
				require_once("vpn.inc");
98
				require_once("captiveportal.inc");
99
				// Do not try to readd to bridge otherwise em(4) has problems
100
				interface_configure($iface, true, true);
101
				break;
102 a7b5cfbe Scott Ullrich
		}
103 4367b5f6 Ermal Luçi
	}
104
}
105 1a978734 Scott Ullrich
106 7e677d85 Ermal LUÇI
if (isset($_GET['interface'])) {
107 e173dd74 Phil Davis
	if (!empty($_GET['interface'])) {
108 7e677d85 Ermal LUÇI
		$realiface = $_GET['interface'];
109 e173dd74 Phil Davis
	}
110 7e677d85 Ermal LUÇI
	$action = $_GET['action'];
111
} else {
112
	if ($argc < 3) {
113
		log_error("HOTPLUG event: The required number of parameters not passed!");
114
		return;
115 7d2fedc9 Ermal
	}
116 7e677d85 Ermal LUÇI
	$action = $argv[1];
117
	$realiface = $argv[2];
118
}
119 2eb3efc2 Ermal LUÇI
120 086cf944 Phil Davis
switch ($action) {
121 e173dd74 Phil Davis
	case "start":
122
	case "stop":
123
		break;
124
	default:
125
		log_error("HOTPLUG event: Action parameter ($action) passed is wrong - only start/stop/up/down are allowed!");
126
		return;
127
		/* NOTREACHED */
128
		break;
129 7e677d85 Ermal LUÇI
}
130 2eb3efc2 Ermal LUÇI
131 7e677d85 Ermal LUÇI
if (!empty($realiface)) {
132
	if (substr($realiface, 0, 4) == 'ovpn') {
133
		log_error("Ignoring link event for ovpn interface");
134 6668e18f Ermal LUÇI
		return;
135 4367b5f6 Ermal Luçi
	}
136 2eb3efc2 Ermal LUÇI
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
137 7e677d85 Ermal LUÇI
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
138 e173dd74 Phil Davis
	if (!empty($interface)) {
139 7e677d85 Ermal LUÇI
		handle_argument_group($interface, $action);
140 e173dd74 Phil Davis
	}
141 7e677d85 Ermal LUÇI
	if ($action == 'start') {
142
		/* Check if there is any child on this one as ppp types and trigger them */
143
		if (is_array($config['ppps']['ppp'])) {
144
			foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
145 e173dd74 Phil Davis
				if ($ppp['type'] == 'ppp') {
146 7e677d85 Ermal LUÇI
					continue;
147 e173dd74 Phil Davis
				}
148 7e677d85 Ermal LUÇI
				$ports = explode(',', $ppp['ports']);
149
				foreach ($ports as $pid => $parent_if) {
150
					/* The loop here is because ppp types can have real and assigned interfaces as members */
151
					$tmpiface = get_real_interface($parent_if);
152 e173dd74 Phil Davis
					if ($tmpiface != $realiface) {
153 ab0e4080 Ermal LUÇI
						continue;
154 e173dd74 Phil Davis
					}
155 ab0e4080 Ermal LUÇI
					$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
156 e173dd74 Phil Davis
					if (!empty($tmpiface)) {
157 7e677d85 Ermal LUÇI
						interface_configure($tmpiface, true, true);
158 e173dd74 Phil Davis
					}
159 da145569 Ermal LUÇI
				}
160
			}
161
		}
162 6668e18f Ermal LUÇI
	}
163 2eb3efc2 Ermal LUÇI
	unlock($rclinkuplock);
164 4367b5f6 Ermal Luçi
}
165 a55e9c70 Ermal Lu?i
?>