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("functions.inc");
|
36
|
|
37
|
if($g['booting'] == true) {
|
38
|
/* ignore all linkup events */
|
39
|
} else {
|
40
|
for ($i = 1; $i <= $ARGC; $i++)
|
41
|
$argspassed .= $ARGV[$i] . " ";
|
42
|
log_error("Arguments passed rc.linkup. '{$argspassed}'");
|
43
|
|
44
|
if ( $ARGC != 2 ) {
|
45
|
log_error("Incorrect number of arguments passed rc.linkup...exiting.");
|
46
|
exit;
|
47
|
}
|
48
|
|
49
|
log_error("Processing {$ARGV[1]} - {$ARGV[2]}");
|
50
|
$iface = convert_real_interface_to_friendly_interface_name($ARGV[1]);
|
51
|
/* XXX: billm - is this correct? we claim DHCP, but we're checking other types too */
|
52
|
if($config['interfaces'][$friendly_interface]['ipaddr'] <> "dhcp" and
|
53
|
$config['interfaces'][$iface]['ipaddr'] <> "pppoe" and
|
54
|
$config['interfaces'][$iface]['ipaddr'] <> "bigpond" and
|
55
|
$config['interfaces'][$iface]['ipaddr'] <> "pptp") {
|
56
|
log_error("Hotplug event detected for {$ARGV[1]} but ignoring since interface is not set for DHCP");
|
57
|
} else {
|
58
|
switch ($ARGV[1]) {
|
59
|
case "stop":
|
60
|
case "down":
|
61
|
{
|
62
|
log_error("DEVD Ethernet detached event for {$ARGV[1]}");
|
63
|
exec("/sbin/ifconfig {$ARGV[1]} delete");
|
64
|
exec("/usr/sbin/arp -da");
|
65
|
/* XXX: billm - this feels right, but is new and may be wrong */
|
66
|
exit;
|
67
|
break; /* LINT - NOT REACHED */
|
68
|
}
|
69
|
case "start":
|
70
|
case "up":
|
71
|
{
|
72
|
log_error("DEVD Ethernet attached event for {$ARGV[1]}");
|
73
|
exec("/sbin/ifconfig {$ARGV[1]} up");
|
74
|
exec("/usr/sbin/arp -da");
|
75
|
break;
|
76
|
}
|
77
|
}
|
78
|
|
79
|
switch ($iface) {
|
80
|
case "wan":
|
81
|
if($config['interfaces'][$iface]['ipaddr'] <> "pppoe") {
|
82
|
/* do not reconfigure on hotplug events when using pppoe */
|
83
|
log_error("HOTPLUG: Configuring wan interface {$ARGV[1]}");
|
84
|
interfaces_wan_configure();
|
85
|
}
|
86
|
break;
|
87
|
case "lan":
|
88
|
log_error("HOTPLUG: Configuring lan interface {$ARGV[1]}");
|
89
|
interfaces_lan_configure();
|
90
|
break;
|
91
|
default:
|
92
|
$int = str_replace("opt", "", $interface);
|
93
|
interfaces_optional_configure_if($int);
|
94
|
echo "interfaces_optional_configure_if($int);\n";
|
95
|
log_error("HOTPLUG: Configuring optional interface {$interface} - opt{$int}");
|
96
|
break;
|
97
|
}
|
98
|
}
|
99
|
}
|
100
|
|
101
|
?>
|