Project

General

Profile

Download (4.94 KB) Statistics
| Branch: | Tag: | Revision:
1
#!/usr/local/bin/php -f
2
<?php
3
/*
4
	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
*/
31

    
32
/* parse the configuration and include all functions used below */
33
require_once("globals.inc");
34
require_once("config.inc");
35
require_once("filter.inc");
36
require_once("shaper.inc");
37
require_once("interfaces.inc");
38

    
39
if (platform_booting()) {
40
	return;
41
}
42

    
43
function handle_argument_group($iface, $argument2) {
44
	global $config;
45

    
46
	if (!is_array($config['interfaces'][$iface])) {
47
		log_error("Cannot find interface configuration for {$iface}");
48
		return;
49
	}
50

    
51
	if (!isset($config['interfaces'][$iface]['enable'])) {
52
		if (!platform_booting()) {
53
			log_error("Linkup detected on disabled interface...Ignoring");
54
		}
55
		return;
56
	}
57

    
58
	$ipaddr = $config['interfaces'][$iface]['ipaddr'];
59
	$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
60
	$staticv4 = false;
61
	if (empty($ipaddr)) {
62
		$staticv4 = true;
63
	} else {
64
		$staticv4 = is_ipaddrv4($ipaddr);
65
	}
66
	$staticv6 = false;
67
	if (empty($ip6addr)) {
68
		$staticv6 = true;
69
	} else {
70
		$staticv6 = is_ipaddrv6($ip6addr);
71
	}
72
	if ($staticv4 === true && $staticv6 === true) {
73
		$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
		interfaces_staticarp_configure($iface);
76
		switch ($argument2) {
77
			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
		}
86
	} else {
87
		switch ($argument2) {
88
			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
		}
103
	}
104
}
105

    
106
if (isset($_GET['interface'])) {
107
	if (!empty($_GET['interface'])) {
108
		$realiface = $_GET['interface'];
109
	}
110
	$action = $_GET['action'];
111
} else {
112
	if ($argc < 3) {
113
		log_error("HOTPLUG event: The required number of parameters not passed!");
114
		return;
115
	}
116
	$action = $argv[1];
117
	$realiface = $argv[2];
118
}
119

    
120
switch($action) {
121
	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
}
130

    
131
if (!empty($realiface)) {
132
	if (substr($realiface, 0, 4) == 'ovpn') {
133
		log_error("Ignoring link event for ovpn interface");
134
		return;
135
	}
136
	$rclinkuplock = lock("rclinkup{$realiface}", LOCK_EX);
137
	$interface = convert_real_interface_to_friendly_interface_name($realiface);
138
	if (!empty($interface)) {
139
		handle_argument_group($interface, $action);
140
	}
141
	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
				if ($ppp['type'] == 'ppp') {
146
					continue;
147
				}
148
				$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
					if ($tmpiface != $realiface) {
153
						continue;
154
					}
155
					$tmpiface = convert_real_interface_to_friendly_interface_name($ppp['if']);
156
					if (!empty($tmpiface)) {
157
						interface_configure($tmpiface, true, true);
158
					}
159
				}
160
			}
161
		}
162
	}
163
	unlock($rclinkuplock);
164
}
165
?>
(71-71/104)