Projet

Général

Profil

Télécharger (4,02 ko) Statistiques
| Branche: | Tag: | Révision:

univnautes / etc / rc.linkup @ master

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
function handle_argument_group($iface, $argument2) {
40
	global $config;	
41

    
42
	if (!is_array($config['interfaces'][$iface])) {
43
		log_error("Cannot find interface configuration for {$iface}");
44
		return;
45
	}
46

    
47
	$ipaddr = $config['interfaces'][$iface]['ipaddr'];
48
	$ip6addr = $config['interfaces'][$iface]['ipaddrv6'];
49
	$staticv4 = false;
50
	if (empty($ipaddr))
51
		$staticv4 = true;
52
	else
53
		$staticv4 = is_ipaddrv4($ipaddr);
54
	$staticv6 = false;
55
	if (empty($ip6addr))
56
		$staticv6 = true;
57
	else
58
		$staticv6 = is_ipaddrv6($ip6addr);
59
	if ($staticv4 === true && $staticv6 === true) {
60
		$friendly = convert_friendly_interface_to_friendly_descr($iface);
61
		log_error("Hotplug event detected for {$friendly}({$iface}) but ignoring since interface is configured with static IP ({$ipaddr} {$ip6addr})");
62
		interfaces_staticarp_configure($iface);
63
		$iface = get_real_interface($iface);
64
		interfaces_bring_up($iface);
65
		/* NOTE: Do not generate event for OpenVPN since the daemon does that for us. */
66
		if (($argument2 == "start" || $argument2 == "up") && substr($iface, 0, 4) != "ovpn")
67
			send_event("interface newip {$iface}");
68
	} else {
69
		switch ($argument2) {
70
		case "stop":
71
		case "down":
72
			log_error("DEVD Ethernet detached event for {$iface}");
73
			interface_bring_down($iface);
74
			break;
75
		case "start":
76
		case "up":
77
			log_error("DEVD Ethernet attached event for {$iface}");
78
			log_error("HOTPLUG: Configuring interface {$iface}");
79
			require_once("vpn.inc");
80
			require_once("captiveportal.inc");
81
			// Do not try to readd to bridge otherwise em(4) has problems
82
			interface_configure($iface, true, true); 
83
			break;
84
		}
85
	}
86
}
87

    
88
global $g;
89
if (!file_exists("{$g['varrun_path']}/booting") && empty($g['booting'])) {
90
if (isset($_GET['interface'])) {
91
	if (!empty($_GET['interface']))
92
		handle_argument_group(convert_real_interface_to_friendly_interface_name($_GET['interface']), $_GET['action']);
93
} else {
94
	if ($argc < 3) {
95
		log_error("HOTPLUG event: The required number of parameters not passed!");
96
		exit;
97
	}
98
	$action = $argv[1];
99
	switch($action) {
100
	case "start":
101
	case "stop":
102
		break;
103
	default:
104
		log_error("HOTPLUG event: Action parameter ($action) passed is wrong - only start/stop/up/down are allowed!");
105
		exit;
106
		/* NOTREACHED */
107
		break;
108
	}
109
	$interface = convert_real_interface_to_friendly_interface_name($argv[2]);
110
	if (!empty($interface))
111
		handle_argument_group($interface, $action);
112
}
113
}
114

    
115
?>
(70-70/103)