Project

General

Profile

Download (3.65 KB) Statistics
| Branch: | Tag: | Revision:
1 1a978734 Scott Ullrich
#!/usr/local/bin/php -f
2
<?php
3
/*
4 7a221543 Scott Ullrich
        rc.linkup - devd hotplug actions
5 adab3c25 Scott Ullrich
        part of pfSense
6 1a978734 Scott Ullrich
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 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 5b70c17e Ermal Lu?i
function handle_argument_group($iface, $argument2) {
40 4367b5f6 Ermal Luçi
	global $config;	
41 4476d447 Ermal Luçi
42 7d2fedc9 Ermal
	if (!is_array($config['interfaces'][$iface]))
43
		return;
44
45 5b70c17e Ermal Lu?i
	$ipaddr = $config['interfaces'][$iface]['ipaddr'];
46 7d2fedc9 Ermal
	$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
47 67864df7 Ermal
	$staticv4 = false;
48
	if (empty($ipaddr))
49
		$staticv4 = true;
50
	else
51
		$staticv4 = is_ipaddrv4($ipaddr);
52
	$staticv6 = false;
53
	if (empty($ip6addr))
54 6f8cf553 Ermal
		$staticv6 = true;
55 67864df7 Ermal
	else
56
		$staticv6 = is_ipaddrv6($ip6addr);
57
	if ($staticv4 === true && $staticv6 === true) {
58 7d2fedc9 Ermal
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
59
		log_error("Hotplug event detected for {$friendly}({$iface}) but ignoring since interface is configured with static IP ({$ipaddr} {$ip6addr})");
60 8ee623f3 jim-p
		interfaces_staticarp_configure($iface);
61 5b70c17e Ermal Lu?i
		$iface = get_real_interface($iface);
62 a798fd3e Ermal
		interfaces_bring_up($iface);
63 b7d56b64 Ermal
		if ($argument2 == "start" || $argument2 == "up")
64
			send_event("interface newip {$iface}");
65 4367b5f6 Ermal Luçi
	} else {
66
		switch ($argument2) {
67
		case "stop":
68
		case "down":
69 5b70c17e Ermal Lu?i
			log_error("DEVD Ethernet detached event for {$iface}");
70
			interface_bring_down($iface);
71
			break;
72 4367b5f6 Ermal Luçi
		case "start":
73 67864df7 Ermal
		case "up":
74 ae39786e Chris Buechler
			log_error("DEVD Ethernet attached event for {$iface}");
75
			log_error("HOTPLUG: Configuring interface {$iface}");
76 982e004f Ermal
			require_once("vpn.inc");
77
			require_once("captiveportal.inc");
78 7413cbfd Ermal
			// Do not try to readd to bridge otherwise em(4) has problems
79 8e47f55b Phil Davis
			interface_configure($iface, true, true); 
80 ae39786e Chris Buechler
			break;
81 a7b5cfbe Scott Ullrich
		}
82 4367b5f6 Ermal Luçi
	}
83
}
84 1a978734 Scott Ullrich
85 24d5fc0a jim-p
global $g;
86 5ee53aa1 Ermal
if (!file_exists("{$g['varrun_path']}/booting") && empty($g['booting'])) {
87 7d2fedc9 Ermal
	if ($argc < 3) {
88
		log_error("HOTPLUG event: The number of required parameters not passed!");
89
		exit;
90
	}
91
	$action = $argv[1];
92
	switch($action) {
93
	case "start":
94
	case "stop":
95
		break;
96
	default:
97
		log_error("HOTPLUG event: The action parameter passed is wrong($action) only start/stop/up/down are allowed!");
98
		exit;
99
		/* NOTREACHED */
100
		break;
101 4367b5f6 Ermal Luçi
	}
102 7d2fedc9 Ermal
	$interface = convert_real_interface_to_friendly_interface_name($argv[2]);
103
	if (!empty($interface))
104
		handle_argument_group($interface, $action);
105 4367b5f6 Ermal Luçi
}
106 f4538770 Scott Ullrich
107 a55e9c70 Ermal Lu?i
?>