Project

General

Profile

Download (4.85 KB) Statistics
| Branch: | Tag: | Revision:
1 1a978734 Scott Ullrich
#!/usr/local/bin/php -f
2
<?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 5f2d078e Scott Ullrich
require_once("filter.inc");	
36
require_once("shaper.inc");	
37 a55e9c70 Ermal Lu?i
require_once("interfaces.inc");
38 1a978734 Scott Ullrich
39 7e677d85 Ermal LUÇI
if (platform_booting())
40
	return;
41
42 5b70c17e Ermal Lu?i
function handle_argument_group($iface, $argument2) {
43 4367b5f6 Ermal Luçi
	global $config;	
44 4476d447 Ermal Luçi
45 e8fa9843 Chris Buechler
	if (!is_array($config['interfaces'][$iface])) {
46
		log_error("Cannot find interface configuration for {$iface}");
47 7d2fedc9 Ermal
		return;
48 e8fa9843 Chris Buechler
	}
49 7d2fedc9 Ermal
50 5574e8d5 Ermal LUÇI
	if (!isset($config['interfaces'][$iface]['enable'])) {
51 e702e9ed Ermal LUÇI
		if (!platform_booting())
52
			log_error("Linkup detected on disabled interface...Ignoring");
53 156a086d Ermal LUÇI
		return;
54
	}
55
56 5b70c17e Ermal Lu?i
	$ipaddr = $config['interfaces'][$iface]['ipaddr'];
57 7d2fedc9 Ermal
	$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
58 67864df7 Ermal
	$staticv4 = false;
59
	if (empty($ipaddr))
60
		$staticv4 = true;
61
	else
62
		$staticv4 = is_ipaddrv4($ipaddr);
63
	$staticv6 = false;
64
	if (empty($ip6addr))
65 497841f5 Ermal
		$staticv6 = true;
66 67864df7 Ermal
	else
67
		$staticv6 = is_ipaddrv6($ip6addr);
68
	if ($staticv4 === true && $staticv6 === true) {
69 7d2fedc9 Ermal
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
70
		log_error("Hotplug event detected for {$friendly}({$iface}) but ignoring since interface is configured with static IP ({$ipaddr} {$ip6addr})");
71 8ee623f3 jim-p
		interfaces_staticarp_configure($iface);
72 619cd0d6 Ermal LUÇI
		switch ($argument2) {
73
		case 'start':
74
		case 'up':
75
			$iface = get_real_interface($iface);
76
			/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
77
			if (substr($iface, 0, 4) != "ovpn")
78
				send_event("interface newip {$iface}");
79
			break;
80
		}
81 4367b5f6 Ermal Luçi
	} else {
82
		switch ($argument2) {
83
		case "stop":
84
		case "down":
85 5b70c17e Ermal Lu?i
			log_error("DEVD Ethernet detached event for {$iface}");
86
			interface_bring_down($iface);
87
			break;
88 4367b5f6 Ermal Luçi
		case "start":
89 67864df7 Ermal
		case "up":
90 ae39786e Chris Buechler
			log_error("DEVD Ethernet attached event for {$iface}");
91
			log_error("HOTPLUG: Configuring interface {$iface}");
92 982e004f Ermal
			require_once("vpn.inc");
93
			require_once("captiveportal.inc");
94 7413cbfd Ermal
			// Do not try to readd to bridge otherwise em(4) has problems
95 8e47f55b Phil Davis
			interface_configure($iface, true, true); 
96 ae39786e Chris Buechler
			break;
97 a7b5cfbe Scott Ullrich
		}
98 4367b5f6 Ermal Luçi
	}
99
}
100 1a978734 Scott Ullrich
101 7e677d85 Ermal LUÇI
if (isset($_GET['interface'])) {
102
	if (!empty($_GET['interface']))
103
		$realiface = $_GET['interface'];
104
	$action = $_GET['action'];
105
} else {
106
	if ($argc < 3) {
107
		log_error("HOTPLUG event: The required number of parameters not passed!");
108
		return;
109 7d2fedc9 Ermal
	}
110 7e677d85 Ermal LUÇI
	$action = $argv[1];
111
	$realiface = $argv[2];
112
}
113 2eb3efc2 Ermal LUÇI
114 7e677d85 Ermal LUÇI
switch($action) {
115
case "start":
116
case "stop":
117
	break;
118
default:
119
	log_error("HOTPLUG event: Action parameter ($action) passed is wrong - only start/stop/up/down are allowed!");
120
	return;
121
	/* NOTREACHED */
122
	break;
123
}
124 2eb3efc2 Ermal LUÇI
125 7e677d85 Ermal LUÇI
if (!empty($realiface)) {
126
	if (substr($realiface, 0, 4) == 'ovpn') {
127
		log_error("Ignoring link event for ovpn interface");
128 6668e18f Ermal LUÇI
		return;
129 4367b5f6 Ermal Luçi
	}
130 2eb3efc2 Ermal LUÇI
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
131 7e677d85 Ermal LUÇI
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
132
	if (!empty($interface))
133
		handle_argument_group($interface, $action);
134
	if ($action == 'start') {
135
		/* Check if there is any child on this one as ppp types and trigger them */
136
		if (is_array($config['ppps']['ppp'])) {
137
			foreach ($config['ppps']['ppp'] as $pppidx => $ppp) {
138
				if ($ppp['type'] == 'ppp')
139
					continue;
140
				$ports = explode(',', $ppp['ports']);
141
				foreach ($ports as $pid => $parent_if) {
142
					/* The loop here is because ppp types can have real and assigned interfaces as members */
143
					$tmpiface = get_real_interface($parent_if);
144 ab0e4080 Ermal LUÇI
					if ($tmpiface != $realiface)
145
						continue;
146
					$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
147 7e677d85 Ermal LUÇI
					if (!empty($tmpiface))
148
						interface_configure($tmpiface, true, true);
149 da145569 Ermal LUÇI
				}
150
			}
151
		}
152 6668e18f Ermal LUÇI
	}
153 2eb3efc2 Ermal LUÇI
	unlock($rclinkuplock);
154 4367b5f6 Ermal Luçi
}
155 a55e9c70 Ermal Lu?i
?>