1 |
5b237745
|
Scott Ullrich
|
<?php
|
2 |
307cd525
|
Bill Marquette
|
/* $Id$ */
|
3 |
5b237745
|
Scott Ullrich
|
/*
|
4 |
|
|
interfaces.inc
|
5 |
0e16b9ca
|
Scott Ullrich
|
Copyright (C) 2004-2006 Scott Ullrich
|
6 |
ac3f8318
|
Espen Johansen
|
All rights reserved.
|
7 |
|
|
|
8 |
|
|
function interfaces_wireless_configure is
|
9 |
|
|
Copyright (C) 2005 Espen Johansen
|
10 |
cfc707f7
|
Scott Ullrich
|
All rights reserved.
|
11 |
|
|
|
12 |
|
|
originally part of m0n0wall (http://m0n0.ch/wall)
|
13 |
5b237745
|
Scott Ullrich
|
Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
14 |
|
|
All rights reserved.
|
15 |
cfc707f7
|
Scott Ullrich
|
|
16 |
5b237745
|
Scott Ullrich
|
Redistribution and use in source and binary forms, with or without
|
17 |
|
|
modification, are permitted provided that the following conditions are met:
|
18 |
cfc707f7
|
Scott Ullrich
|
|
19 |
ac3f8318
|
Espen Johansen
|
1. Redistributions of source code must retain the above copyright notices,
|
20 |
5b237745
|
Scott Ullrich
|
this list of conditions and the following disclaimer.
|
21 |
cfc707f7
|
Scott Ullrich
|
|
22 |
5b237745
|
Scott Ullrich
|
2. Redistributions in binary form must reproduce the above copyright
|
23 |
ac3f8318
|
Espen Johansen
|
notices, this list of conditions and the following disclaimer in the
|
24 |
5b237745
|
Scott Ullrich
|
documentation and/or other materials provided with the distribution.
|
25 |
cfc707f7
|
Scott Ullrich
|
|
26 |
5b237745
|
Scott Ullrich
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
27 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
28 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
29 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
30 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
31 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
32 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
33 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
34 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
35 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
36 |
|
|
*/
|
37 |
|
|
|
38 |
|
|
/* include all configuration functions */
|
39 |
|
|
require_once("functions.inc");
|
40 |
|
|
|
41 |
|
|
function interfaces_loopback_configure() {
|
42 |
|
|
mwexec("/sbin/ifconfig lo0 127.0.0.1");
|
43 |
cfc707f7
|
Scott Ullrich
|
|
44 |
5b237745
|
Scott Ullrich
|
return 0;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
|
|
function interfaces_vlan_configure() {
|
48 |
669e1adb
|
Bill Marquette
|
global $config;
|
49 |
cfc707f7
|
Scott Ullrich
|
|
50 |
5b237745
|
Scott Ullrich
|
if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
|
51 |
cfc707f7
|
Scott Ullrich
|
|
52 |
5b237745
|
Scott Ullrich
|
/* devices with native VLAN support */
|
53 |
0d55818d
|
Scott Ullrich
|
$vlan_native_supp = explode(" ", "bge em ixgb nge re ti txp vge");
|
54 |
cfc707f7
|
Scott Ullrich
|
|
55 |
5b237745
|
Scott Ullrich
|
/* devices with long frame support */
|
56 |
0d55818d
|
Scott Ullrich
|
$vlan_long_supp = explode(" ", "bfe dc fxp gem hme le rl sis sk ste tl tx xl");
|
57 |
cfc707f7
|
Scott Ullrich
|
|
58 |
161040eb
|
Scott Ullrich
|
/* sweep through and axe old interfaces */
|
59 |
|
|
$vlan_count = get_number_of_vlan_interfaces();
|
60 |
|
|
for($x=0; $x<$vlan_count; $x++)
|
61 |
c0b131a5
|
Scott Ullrich
|
exec("/sbin/ifconfig vlan{$x} down delete");
|
62 |
161040eb
|
Scott Ullrich
|
|
63 |
5b237745
|
Scott Ullrich
|
$i = 0;
|
64 |
cfc707f7
|
Scott Ullrich
|
|
65 |
5b237745
|
Scott Ullrich
|
foreach ($config['vlans']['vlan'] as $vlan) {
|
66 |
cfc707f7
|
Scott Ullrich
|
|
67 |
|
|
$cmd = "/sbin/ifconfig vlan{$i} create vlan " .
|
68 |
|
|
escapeshellarg($vlan['tag']) . " vlandev " .
|
69 |
5b237745
|
Scott Ullrich
|
escapeshellarg($vlan['if']);
|
70 |
cfc707f7
|
Scott Ullrich
|
|
71 |
5b237745
|
Scott Ullrich
|
/* get driver name */
|
72 |
|
|
for ($j = 0; $j < strlen($vlan['if']); $j++) {
|
73 |
|
|
if ($vlan['if'][$j] >= '0' && $vlan['if'][$j] <= '9')
|
74 |
|
|
break;
|
75 |
|
|
}
|
76 |
|
|
$drvname = substr($vlan['if'], 0, $j);
|
77 |
cfc707f7
|
Scott Ullrich
|
|
78 |
5b237745
|
Scott Ullrich
|
if (in_array($drvname, $vlan_native_supp))
|
79 |
|
|
$cmd .= " link0";
|
80 |
|
|
else if (in_array($drvname, $vlan_long_supp))
|
81 |
|
|
$cmd .= " mtu 1500";
|
82 |
cfc707f7
|
Scott Ullrich
|
|
83 |
5b237745
|
Scott Ullrich
|
mwexec($cmd);
|
84 |
cfc707f7
|
Scott Ullrich
|
|
85 |
3f7d2120
|
Bill Marquette
|
/* invalidate interface cache */
|
86 |
|
|
get_interface_arr(true);
|
87 |
|
|
|
88 |
c5af8bf9
|
Scott Ullrich
|
/* all vlans need to spoof their parent mac address, too. see
|
89 |
|
|
* ticket #1514: http://cvstrac.pfsense.com/tktview?tn=1514,33
|
90 |
|
|
*/
|
91 |
|
|
foreach($config['interfaces'] as $interfaces) {
|
92 |
|
|
if($interfaces['if'] == $vlan['if']) {
|
93 |
|
|
if($interfaces['spoofmac']) {
|
94 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($interfaces['if']) .
|
95 |
|
|
" link " . escapeshellarg($interfaces['spoofmac']));
|
96 |
|
|
}
|
97 |
|
|
}
|
98 |
|
|
}
|
99 |
|
|
|
100 |
5b237745
|
Scott Ullrich
|
/* make sure the parent interface is up */
|
101 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($vlan['if']) . " up");
|
102 |
cfc707f7
|
Scott Ullrich
|
|
103 |
5b237745
|
Scott Ullrich
|
$i++;
|
104 |
|
|
}
|
105 |
|
|
}
|
106 |
cfc707f7
|
Scott Ullrich
|
|
107 |
5b237745
|
Scott Ullrich
|
return 0;
|
108 |
|
|
}
|
109 |
|
|
|
110 |
|
|
function interfaces_lan_configure() {
|
111 |
6ee83b6e
|
Scott Ullrich
|
global $config, $g;
|
112 |
|
|
|
113 |
|
|
$bridges_total = get_next_available_bridge_interface();
|
114 |
cfc707f7
|
Scott Ullrich
|
|
115 |
5b237745
|
Scott Ullrich
|
$lancfg = $config['interfaces']['lan'];
|
116 |
cfc707f7
|
Scott Ullrich
|
|
117 |
7cc7e84d
|
Scott Ullrich
|
/* if user has removed ip address, clear it*/
|
118 |
|
|
if($lancfg['ipaddr'] == "")
|
119 |
|
|
mwexec("/sbin/ifconfig {$lancfg['if']} delete");
|
120 |
|
|
|
121 |
5b237745
|
Scott Ullrich
|
/* wireless configuration? */
|
122 |
|
|
if (is_array($lancfg['wireless']))
|
123 |
|
|
interfaces_wireless_configure($lancfg['if'], $lancfg['wireless']);
|
124 |
cfc707f7
|
Scott Ullrich
|
|
125 |
5b237745
|
Scott Ullrich
|
/* MAC spoofing? */
|
126 |
f36d4bd2
|
Scott Ullrich
|
if ($lancfg['spoofmac']) {
|
127 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) .
|
128 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($lancfg['spoofmac']));
|
129 |
f36d4bd2
|
Scott Ullrich
|
} else {
|
130 |
|
|
$mac = get_interface_mac_address($lancfg['if']);
|
131 |
|
|
if($mac == "ff:ff:ff:ff:ff:ff") {
|
132 |
|
|
/* this is not a valid mac address. generate a
|
133 |
|
|
* temporary mac address so the machine can get online.
|
134 |
|
|
*/
|
135 |
9315ef83
|
Scott Ullrich
|
echo "Generating new MAC address.";
|
136 |
f36d4bd2
|
Scott Ullrich
|
$random_mac = generate_random_mac_address();
|
137 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) .
|
138 |
|
|
" link " . escapeshellarg($random_mac));
|
139 |
|
|
$lancfg['spoofmac'] = $random_mac;
|
140 |
|
|
write_config();
|
141 |
da86dd6f
|
Scott Ullrich
|
file_notice("MAC Address altered", "The INVALID MAC address (ff:ff:ff:ff:ff:ff) on interface {$lancfg['if']} has been automatically replaced with {$random_mac}", "Interfaces");
|
142 |
f36d4bd2
|
Scott Ullrich
|
}
|
143 |
eb772abd
|
Scott Ullrich
|
}
|
144 |
a4d9f914
|
Scott Ullrich
|
|
145 |
|
|
/* bridged? */
|
146 |
eb772abd
|
Scott Ullrich
|
|
147 |
6065fd77
|
Scott Ullrich
|
if ($lancfg['bridge']) {
|
148 |
a4d9f914
|
Scott Ullrich
|
/* use open/netBSD style bridge */
|
149 |
|
|
mwexec("/sbin/ifconfig bridge{$bridges_total} create");
|
150 |
eb772abd
|
Scott Ullrich
|
|
151 |
96812f11
|
Scott Ullrich
|
/* force all bridged interfaces to use same mtu */
|
152 |
51535829
|
Scott Ullrich
|
$mtu = get_interface_mtu($config['interfaces'][$lancfg['bridge']]['if']);
|
153 |
96812f11
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$lancfg['if']} mtu {$mtu}");
|
154 |
|
|
mwexec("/sbin/ifconfig {$config['interfaces'][$lancfg['bridge']]['if']} mtu {$mtu}");
|
155 |
51535829
|
Scott Ullrich
|
|
156 |
|
|
/* assign items to a bridge */
|
157 |
a591b9cb
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} addm {$lancfg['if']} addm {$config['interfaces'][$lancfg['bridge']]['if']}");
|
158 |
eb772abd
|
Scott Ullrich
|
|
159 |
e7aa7560
|
Scott Ullrich
|
if(!is_interface_wireless($lancfg['if']) and
|
160 |
eb772abd
|
Scott Ullrich
|
!is_interface_wireless($config['interfaces'][$lancfg['bridge']]['if']))
|
161 |
3789e4df
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} stp {$config['interfaces'][$lancfg['bridge']]['if']} stp {$lancfg['if']}");
|
162 |
51535829
|
Scott Ullrich
|
|
163 |
|
|
/* log commands run for debugging in /tmp/ */
|
164 |
6065fd77
|
Scott Ullrich
|
$fd = fopen("{$g['tmp_path']}/bridge_config_{$lancfg['if']}", "w");
|
165 |
51535829
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig {$lancfg['if']} mtu {$mtu}\n");
|
166 |
|
|
fwrite($fd, "/sbin/ifconfig {$config['interfaces'][$lancfg['bridge']]['if']} mtu {$mtu}\n");
|
167 |
a4d9f914
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} create\n");
|
168 |
b3a66d90
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} addm {$lancfg['if']} addm {$config['interfaces'][$lancfg['bridge']]['if']}\n");
|
169 |
12fea2f7
|
Scott Ullrich
|
if(!is_interface_wireless($lancfg['if']) and
|
170 |
|
|
!is_interface_wireless($config['interfaces'][$lancfg['bridge']]['if']))
|
171 |
|
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} stp {$lancfg['if']} stp {$config['interfaces'][$lancfg['bridge']]['if']}\n");
|
172 |
a4d9f914
|
Scott Ullrich
|
fclose($fd);
|
173 |
eb772abd
|
Scott Ullrich
|
|
174 |
f70c887f
|
Scott Ullrich
|
/* bring up interfaces */
|
175 |
77712c1e
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} down");
|
176 |
|
|
usleep(100);
|
177 |
f70c887f
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$config['interfaces'][$lancfg['bridge']]['if']} up");
|
178 |
77712c1e
|
Scott Ullrich
|
usleep(5);
|
179 |
f70c887f
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$lancfg['if']} up");
|
180 |
77712c1e
|
Scott Ullrich
|
usleep(5);
|
181 |
43715f8b
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} up");
|
182 |
eb772abd
|
Scott Ullrich
|
|
183 |
c60e4f51
|
Scott Ullrich
|
$bridges_total++;
|
184 |
547a126d
|
Bill Marquette
|
/* update cache */
|
185 |
3f7d2120
|
Bill Marquette
|
if ($bridges_total != find_number_of_created_bridges())
|
186 |
|
|
find_number_of_created_bridges(true);
|
187 |
a4d9f914
|
Scott Ullrich
|
}
|
188 |
eb772abd
|
Scott Ullrich
|
|
189 |
5b237745
|
Scott Ullrich
|
/* media */
|
190 |
|
|
if ($lancfg['media'] || $lancfg['mediaopt']) {
|
191 |
|
|
$cmd = "/sbin/ifconfig " . escapeshellarg($lancfg['if']);
|
192 |
|
|
if ($lancfg['media'])
|
193 |
|
|
$cmd .= " media " . escapeshellarg($lancfg['media']);
|
194 |
|
|
if ($lancfg['mediaopt'])
|
195 |
|
|
$cmd .= " mediaopt " . escapeshellarg($lancfg['mediaopt']);
|
196 |
|
|
mwexec($cmd);
|
197 |
|
|
}
|
198 |
cfc707f7
|
Scott Ullrich
|
|
199 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) . " " .
|
200 |
5b237745
|
Scott Ullrich
|
escapeshellarg($lancfg['ipaddr'] . "/" . $lancfg['subnet']));
|
201 |
cfc707f7
|
Scott Ullrich
|
|
202 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
203 |
|
|
/* make new hosts file */
|
204 |
|
|
system_hosts_generate();
|
205 |
cfc707f7
|
Scott Ullrich
|
|
206 |
5b237745
|
Scott Ullrich
|
/* reconfigure static routes (kernel may have deleted them) */
|
207 |
|
|
system_routing_configure();
|
208 |
cfc707f7
|
Scott Ullrich
|
|
209 |
e239df5a
|
Scott Ullrich
|
/* set the reload filter dity flag */
|
210 |
f229e20f
|
Scott Ullrich
|
touch("{$g['tmp_path']}/filter_dirty");
|
211 |
cfc707f7
|
Scott Ullrich
|
|
212 |
5b237745
|
Scott Ullrich
|
/* reload IPsec tunnels */
|
213 |
|
|
vpn_ipsec_configure();
|
214 |
cfc707f7
|
Scott Ullrich
|
|
215 |
5b237745
|
Scott Ullrich
|
/* reload dhcpd (gateway may have changed) */
|
216 |
|
|
services_dhcpd_configure();
|
217 |
cfc707f7
|
Scott Ullrich
|
|
218 |
5b237745
|
Scott Ullrich
|
/* reload dnsmasq */
|
219 |
|
|
services_dnsmasq_configure();
|
220 |
cfc707f7
|
Scott Ullrich
|
|
221 |
6a669fb0
|
Scott Ullrich
|
/* reload captive portal */
|
222 |
|
|
captiveportal_configure();
|
223 |
cfc707f7
|
Scott Ullrich
|
|
224 |
5b237745
|
Scott Ullrich
|
}
|
225 |
cfc707f7
|
Scott Ullrich
|
|
226 |
5b237745
|
Scott Ullrich
|
return 0;
|
227 |
|
|
}
|
228 |
|
|
|
229 |
|
|
function interfaces_optional_configure() {
|
230 |
|
|
global $config, $g;
|
231 |
|
|
global $bridgeconfig;
|
232 |
cfc707f7
|
Scott Ullrich
|
|
233 |
5b237745
|
Scott Ullrich
|
for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
|
234 |
|
|
interfaces_optional_configure_if($i);
|
235 |
|
|
}
|
236 |
cfc707f7
|
Scott Ullrich
|
|
237 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
238 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
239 |
|
|
system_routing_configure();
|
240 |
cfc707f7
|
Scott Ullrich
|
|
241 |
5b237745
|
Scott Ullrich
|
/* reload IPsec tunnels */
|
242 |
|
|
vpn_ipsec_configure();
|
243 |
cfc707f7
|
Scott Ullrich
|
|
244 |
5b237745
|
Scott Ullrich
|
/* reload dhcpd (interface enabled/disabled/bridged status may have changed) */
|
245 |
|
|
services_dhcpd_configure();
|
246 |
cfc707f7
|
Scott Ullrich
|
|
247 |
5b237745
|
Scott Ullrich
|
/* restart dnsmasq */
|
248 |
|
|
services_dnsmasq_configure();
|
249 |
4d18de6a
|
Scott Ullrich
|
|
250 |
c597d50f
|
Scott Ullrich
|
/* reload captive portal */
|
251 |
|
|
captiveportal_configure();
|
252 |
|
|
|
253 |
4d18de6a
|
Scott Ullrich
|
/* set the reload filter dity flag */
|
254 |
eb772abd
|
Scott Ullrich
|
touch("{$g['tmp_path']}/filter_dirty");
|
255 |
5b237745
|
Scott Ullrich
|
}
|
256 |
cfc707f7
|
Scott Ullrich
|
|
257 |
5b237745
|
Scott Ullrich
|
return 0;
|
258 |
|
|
}
|
259 |
|
|
|
260 |
|
|
function interfaces_optional_configure_if($opti) {
|
261 |
|
|
global $config, $g;
|
262 |
6008210b
|
Scott Ullrich
|
global $bridgeconfig, $debugging;
|
263 |
6ee83b6e
|
Scott Ullrich
|
|
264 |
|
|
$bridges_total = get_next_available_bridge_interface();
|
265 |
cfc707f7
|
Scott Ullrich
|
|
266 |
5b237745
|
Scott Ullrich
|
$optcfg = $config['interfaces']['opt' . $opti];
|
267 |
cfc707f7
|
Scott Ullrich
|
|
268 |
5b237745
|
Scott Ullrich
|
if ($g['booting']) {
|
269 |
|
|
$optdescr = "";
|
270 |
|
|
if ($optcfg['descr'])
|
271 |
|
|
$optdescr = " ({$optcfg['descr']})";
|
272 |
5c6d0f65
|
Colin Smith
|
print "\tOPT{$opti}{$optdescr}... ";
|
273 |
5b237745
|
Scott Ullrich
|
}
|
274 |
cfc707f7
|
Scott Ullrich
|
|
275 |
5b237745
|
Scott Ullrich
|
if (isset($optcfg['enable'])) {
|
276 |
|
|
/* wireless configuration? */
|
277 |
|
|
if (is_array($optcfg['wireless']))
|
278 |
|
|
interfaces_wireless_configure($optcfg['if'], $optcfg['wireless']);
|
279 |
cfc707f7
|
Scott Ullrich
|
|
280 |
5b237745
|
Scott Ullrich
|
/* MAC spoofing? */
|
281 |
f36d4bd2
|
Scott Ullrich
|
if ($optcfg['spoofmac']) {
|
282 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
283 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($optcfg['spoofmac']));
|
284 |
0ed77c51
|
Scott Ullrich
|
} else {
|
285 |
|
|
$mac = get_interface_mac_address($optcfg['if']);
|
286 |
|
|
if($mac == "ff:ff:ff:ff:ff:ff") {
|
287 |
|
|
/* this is not a valid mac address. generate a
|
288 |
|
|
* temporary mac address so the machine can get online.
|
289 |
|
|
*/
|
290 |
9315ef83
|
Scott Ullrich
|
echo "Generating new MAC address.";
|
291 |
0ed77c51
|
Scott Ullrich
|
$random_mac = generate_random_mac_address();
|
292 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
|
293 |
|
|
" link " . escapeshellarg($random_mac));
|
294 |
|
|
$optcfg['spoofmac'] = $random_mac;
|
295 |
|
|
write_config();
|
296 |
|
|
file_notice("MAC Address altered", "The INVALID MAC address (ff:ff:ff:ff:ff:ff) on interface {$optcfg['if']} has been automatically replaced with {$random_mac}", "Interfaces");
|
297 |
|
|
}
|
298 |
f36d4bd2
|
Scott Ullrich
|
}
|
299 |
cfc707f7
|
Scott Ullrich
|
|
300 |
5b237745
|
Scott Ullrich
|
/* media */
|
301 |
|
|
if ($optcfg['media'] || $optcfg['mediaopt']) {
|
302 |
|
|
$cmd = "/sbin/ifconfig " . escapeshellarg($optcfg['if']);
|
303 |
|
|
if ($optcfg['media'])
|
304 |
|
|
$cmd .= " media " . escapeshellarg($optcfg['media']);
|
305 |
|
|
if ($optcfg['mediaopt'])
|
306 |
|
|
$cmd .= " mediaopt " . escapeshellarg($optcfg['mediaopt']);
|
307 |
|
|
mwexec($cmd);
|
308 |
|
|
}
|
309 |
cfc707f7
|
Scott Ullrich
|
|
310 |
5b237745
|
Scott Ullrich
|
/* bridged? */
|
311 |
|
|
if ($optcfg['bridge']) {
|
312 |
5a66117a
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " delete up");
|
313 |
38226b19
|
Scott Ullrich
|
/* use open/netBSD style bridge */
|
314 |
5a66117a
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} create");
|
315 |
3f7d2120
|
Bill Marquette
|
|
316 |
|
|
/* invalidate interface cache */
|
317 |
|
|
get_interface_arr(true);
|
318 |
eb772abd
|
Scott Ullrich
|
|
319 |
96812f11
|
Scott Ullrich
|
/* force all bridged interfaces to use same mtu */
|
320 |
51535829
|
Scott Ullrich
|
$mtu = get_interface_mtu($config['interfaces'][$optcfg['bridge']]['if']);
|
321 |
96812f11
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$optcfg['if']} mtu {$mtu}");
|
322 |
eb772abd
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$config['interfaces'][$optcfg['bridge']]['if']} mtu {$mtu}");
|
323 |
51535829
|
Scott Ullrich
|
|
324 |
|
|
/* assign items to a bridge */
|
325 |
a591b9cb
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} addm {$optcfg['if']} addm {$config['interfaces'][$optcfg['bridge']]['if']}");
|
326 |
df792110
|
Scott Ullrich
|
|
327 |
e7aa7560
|
Scott Ullrich
|
if(!is_interface_wireless($optcfg['if']) and
|
328 |
eb772abd
|
Scott Ullrich
|
!is_interface_wireless($config['interfaces'][$optcfg['bridge']]['if']))
|
329 |
3789e4df
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} stp {$config['interfaces'][$optcfg['bridge']]['if']} stp {$optcfg['if']}");
|
330 |
51535829
|
Scott Ullrich
|
|
331 |
|
|
/* log commands run for debugging in /tmp/ */
|
332 |
bc1746b5
|
Scott Ullrich
|
$fd = fopen("{$g['tmp_path']}/bridge_config_{$optcfg['if']}", "w");
|
333 |
51535829
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig {$optcfg['if']} mtu {$mtu}\n");
|
334 |
|
|
fwrite($fd, "/sbin/ifconfig {$config['interfaces'][$optcfg['bridge']]['if']} mtu {$mtu}\n");
|
335 |
bc1746b5
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} create\n");
|
336 |
|
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} addm {$optcfg['if']} addm {$config['interfaces'][$optcfg['bridge']]['if']} up\n");
|
337 |
12fea2f7
|
Scott Ullrich
|
if(!is_interface_wireless($optcfg['if']) and
|
338 |
|
|
!is_interface_wireless($config['interfaces'][$optcfg['bridge']]['if']))
|
339 |
|
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} stp {$optcfg['if']} stp {$config['interfaces'][$optcfg['bridge']]['if']}\n");
|
340 |
bc1746b5
|
Scott Ullrich
|
fclose($fd);
|
341 |
eb772abd
|
Scott Ullrich
|
|
342 |
f70c887f
|
Scott Ullrich
|
/* bring up interfaces */
|
343 |
fafdfe28
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} down");
|
344 |
77712c1e
|
Scott Ullrich
|
usleep(100);
|
345 |
|
|
mwexec("/sbin/ifconfig {$config['interfaces'][$optcfg['bridge']]['if']} up");
|
346 |
|
|
usleep(5);
|
347 |
82a7eb4a
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$optcfg['if']} up");
|
348 |
77712c1e
|
Scott Ullrich
|
usleep(5);
|
349 |
6651e3ec
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} up");
|
350 |
eb772abd
|
Scott Ullrich
|
|
351 |
c60e4f51
|
Scott Ullrich
|
$bridges_total++;
|
352 |
547a126d
|
Bill Marquette
|
/* update cache */
|
353 |
3f7d2120
|
Bill Marquette
|
if ($bridges_total != find_number_of_created_bridges())
|
354 |
|
|
find_number_of_created_bridges(true);
|
355 |
5b237745
|
Scott Ullrich
|
} else {
|
356 |
0311dbd5
|
Scott Ullrich
|
/* if user has selected DHCP type then act accordingly */
|
357 |
d3ce564b
|
Scott Ullrich
|
if($optcfg['ipaddr'] == "dhcp") {
|
358 |
1223f922
|
Scott Ullrich
|
interfaces_opt_dhcp_configure("opt{$opti}");
|
359 |
eb772abd
|
Scott Ullrich
|
} else {
|
360 |
0311dbd5
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
|
361 |
77317f2b
|
Colin Smith
|
escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
|
362 |
0311dbd5
|
Scott Ullrich
|
}
|
363 |
5b237745
|
Scott Ullrich
|
}
|
364 |
|
|
} else {
|
365 |
5a66117a
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " delete down");
|
366 |
5b237745
|
Scott Ullrich
|
}
|
367 |
|
|
return 0;
|
368 |
|
|
}
|
369 |
|
|
|
370 |
9f6b1429
|
Scott Ullrich
|
function interfaces_carp_configure() {
|
371 |
6008210b
|
Scott Ullrich
|
global $g, $config, $debugging;
|
372 |
2b9747b9
|
Scott Ullrich
|
$balanacing = "";
|
373 |
|
|
$pfsyncinterface = "";
|
374 |
|
|
$pfsyncenabled = "";
|
375 |
b932ef16
|
Scott Ullrich
|
if(isset($config['system']['developerspew'])) {
|
376 |
|
|
$mt = microtime();
|
377 |
|
|
echo "interfaces_carp_configure() being called $mt\n";
|
378 |
|
|
}
|
379 |
6008210b
|
Scott Ullrich
|
$carp_instances_counter = 0;
|
380 |
|
|
$total_carp_interfaces_defined = find_number_of_created_carp_interfaces();
|
381 |
467c2c89
|
Scott Ullrich
|
/* destroy previous interfaces */
|
382 |
eb772abd
|
Scott Ullrich
|
for($x=0; $x<$total_carp_interfaces_defined; $x++)
|
383 |
|
|
mwexec("/sbin/ifconfig carp{$x} delete");
|
384 |
b932ef16
|
Scott Ullrich
|
if ($g['booting']) {
|
385 |
7d0f4544
|
Scott Ullrich
|
echo "Configuring CARP interfaces...";
|
386 |
|
|
mute_kernel_msgs();
|
387 |
a5250ebc
|
Scott Ullrich
|
}
|
388 |
b932ef16
|
Scott Ullrich
|
/* suck in configuration items */
|
389 |
|
|
if($config['installedpackages']['carpsettings']['config']) {
|
390 |
|
|
foreach($config['installedpackages']['carpsettings']['config'] as $carp) {
|
391 |
|
|
$pfsyncenabled = $carp['pfsyncenabled'];
|
392 |
|
|
$balanacing = $carp['balancing'];
|
393 |
|
|
$pfsyncinterface = $carp['pfsyncinterface'];
|
394 |
b42ad736
|
Scott Ullrich
|
$pfsyncpeerip = $carp['pfsyncpeerip'];
|
395 |
9f6b1429
|
Scott Ullrich
|
}
|
396 |
b932ef16
|
Scott Ullrich
|
} else {
|
397 |
|
|
unset($pfsyncinterface);
|
398 |
|
|
unset($balanacing);
|
399 |
|
|
unset($pfsyncenabled);
|
400 |
6008210b
|
Scott Ullrich
|
}
|
401 |
b932ef16
|
Scott Ullrich
|
if($balanacing) {
|
402 |
|
|
mwexec("/sbin/sysctl net.inet.carp.arpbalance=1");
|
403 |
|
|
mwexec("/sbin/sysctl net.inet.carp.preempt=0");
|
404 |
|
|
} else {
|
405 |
|
|
mwexec("/sbin/sysctl net.inet.carp.preempt=1");
|
406 |
|
|
}
|
407 |
|
|
$carp_sync_int = convert_friendly_interface_to_real_interface_name($pfsyncinterface);
|
408 |
|
|
if($g['booting']) {
|
409 |
|
|
/* install rules to alllow pfsync to sync up during boot
|
410 |
|
|
* carp interfaces will remain down until the bootup sequence finishes
|
411 |
|
|
*/
|
412 |
|
|
exec("echo pass quick proto carp all keep state > /tmp/rules.boot");
|
413 |
|
|
exec("echo pass quick proto pfsync all >> /tmp/rules.boot");
|
414 |
|
|
exec("echo pass out proto { tcp, udp } from any to any port 53 keep state >> /tmp/rules.boot");
|
415 |
|
|
exec("/sbin/pfctl -f /tmp/rules.boot");
|
416 |
eb772abd
|
Scott Ullrich
|
}
|
417 |
b932ef16
|
Scott Ullrich
|
/* setup pfsync interface */
|
418 |
b42ad736
|
Scott Ullrich
|
if($carp_sync_int and $pfsyncenabled) {
|
419 |
|
|
if($pfsyncpeerip) {
|
420 |
|
|
mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} syncpeer {$pfsyncpeerip} up");
|
421 |
|
|
} else {
|
422 |
|
|
mwexec("/sbin/ifconfig pfsync0 syncdev {$carp_sync_int} up");
|
423 |
|
|
}
|
424 |
|
|
} else {
|
425 |
b932ef16
|
Scott Ullrich
|
mwexec("/sbin/ifconfig pfsync0 syncdev lo0 up");
|
426 |
b42ad736
|
Scott Ullrich
|
}
|
427 |
f6189feb
|
Scott Ullrich
|
$fd = fopen("/tmp/carp.sh", "w");
|
428 |
eb772abd
|
Scott Ullrich
|
if($config['virtualip']['vip']) {
|
429 |
b932ef16
|
Scott Ullrich
|
$viparr = &$config['virtualip']['vip'];
|
430 |
|
|
mwexec("/sbin/sysctl net.inet.carp.allow=1");
|
431 |
|
|
} else {
|
432 |
|
|
$viparr = array();
|
433 |
|
|
mwexec("/sbin/sysctl net.inet.carp.allow=0");
|
434 |
|
|
}
|
435 |
6008210b
|
Scott Ullrich
|
foreach ($viparr as $vip) {
|
436 |
|
|
if ($vip['mode'] == "carp") {
|
437 |
8a573737
|
Scott Ullrich
|
$vip_password = $vip['password'];
|
438 |
eb772abd
|
Scott Ullrich
|
$vip_password = str_replace(" ", "", $vip_password);
|
439 |
b932ef16
|
Scott Ullrich
|
/* create the carp interface and setup */
|
440 |
6008210b
|
Scott Ullrich
|
mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " create");
|
441 |
3f7d2120
|
Bill Marquette
|
|
442 |
|
|
/* invalidate interface cache */
|
443 |
|
|
get_interface_arr(true);
|
444 |
|
|
|
445 |
6008210b
|
Scott Ullrich
|
$broadcast_address = gen_subnet_max($vip['subnet'], $vip['subnet_bits']);
|
446 |
eb772abd
|
Scott Ullrich
|
if($vip['password'] != "")
|
447 |
8a573737
|
Scott Ullrich
|
$password = " pass \"" . $vip_password . "\"";
|
448 |
6008210b
|
Scott Ullrich
|
if($debugging)
|
449 |
|
|
echo "Configuring carp{$carp_instances_counter}.\n";
|
450 |
f6189feb
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig carp" . $carp_instances_counter . " " . $vip['subnet'] . "/" . $vip['subnet_bits'] . " broadcast " . $broadcast_address . " vhid " . $vip['vhid'] . "{$carpdev} advskew 200 " . $password . "\n");
|
451 |
9669a414
|
Scott Ullrich
|
mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " " . $vip['subnet'] . "/" . $vip['subnet_bits'] . " broadcast " . $broadcast_address . " vhid " . $vip['vhid'] . "{$carpdev} advskew 200 " . $password);
|
452 |
94b636a6
|
Scott Ullrich
|
mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " up");
|
453 |
be606e9a
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig carp" . $carp_instances_counter . " up\n");
|
454 |
b932ef16
|
Scott Ullrich
|
usleep(10);
|
455 |
6008210b
|
Scott Ullrich
|
$carp_instances_counter++;
|
456 |
|
|
}
|
457 |
75f2c22c
|
Scott Ullrich
|
}
|
458 |
f6189feb
|
Scott Ullrich
|
fclose($fd);
|
459 |
b932ef16
|
Scott Ullrich
|
mwexec("/bin/sh /tmp/carp.sh");
|
460 |
3c18fbc9
|
Scott Ullrich
|
if ($g['booting']) {
|
461 |
deebaae1
|
Scott Ullrich
|
unmute_kernel_msgs();
|
462 |
74dbce1f
|
Scott Ullrich
|
echo "done.\n";
|
463 |
669e1adb
|
Bill Marquette
|
}
|
464 |
7b2d4769
|
Bill Marquette
|
|
465 |
|
|
/* update cache */
|
466 |
9e097ada
|
Bill Marquette
|
if ($carp_instances_counter != find_number_of_created_carp_interfaces())
|
467 |
eb772abd
|
Scott Ullrich
|
find_number_of_created_carp_interfaces(true);
|
468 |
9f6b1429
|
Scott Ullrich
|
}
|
469 |
|
|
|
470 |
04c5bd17
|
Scott Ullrich
|
function interfaces_carp_bring_up_final() {
|
471 |
6008210b
|
Scott Ullrich
|
global $config, $g, $debugging;
|
472 |
|
|
if(isset($config['system']['developerspew'])) {
|
473 |
|
|
$mt = microtime();
|
474 |
|
|
echo "interfaces_carp_bring_up_final() being called $mt\n";
|
475 |
|
|
}
|
476 |
d0556634
|
Scott Ullrich
|
if(!$config['virtualip']['vip'])
|
477 |
cb77ff27
|
Scott Ullrich
|
return;
|
478 |
04c5bd17
|
Scott Ullrich
|
$viparr = &$config['virtualip']['vip'];
|
479 |
6008210b
|
Scott Ullrich
|
/* could not locate an array, return */
|
480 |
eb772abd
|
Scott Ullrich
|
if(!is_array($viparr))
|
481 |
5b0272bf
|
Scott Ullrich
|
return;
|
482 |
6008210b
|
Scott Ullrich
|
$carp_instances_counter = 0;
|
483 |
25530ad8
|
Scott Ullrich
|
$counter = 0;
|
484 |
0c6ee817
|
Scott Ullrich
|
if($g['booting'])
|
485 |
|
|
echo "Waiting for final CARP interface bringup...";
|
486 |
512fa4d7
|
Scott Ullrich
|
$supress = intval(`/sbin/sysctl net.inet.carp.suppress_preempt | cut -d" " -f2`);
|
487 |
44837e6b
|
Scott Ullrich
|
if($g['booting']) {
|
488 |
|
|
while($supress > 0) {
|
489 |
|
|
sleep(2);
|
490 |
|
|
$supress = intval(`/sbin/sysctl net.inet.carp.suppress_preempt | cut -d" " -f2`);
|
491 |
|
|
if($counter > 15)
|
492 |
9123cef8
|
Scott Ullrich
|
$supress = 0;
|
493 |
44837e6b
|
Scott Ullrich
|
$counter++;
|
494 |
|
|
echo ".";
|
495 |
|
|
}
|
496 |
2d1e01b0
|
Scott Ullrich
|
for($x=0; $x<23; $x++) {
|
497 |
|
|
sleep(2);
|
498 |
|
|
echo ".";
|
499 |
|
|
}
|
500 |
|
|
echo " done.\n";
|
501 |
44837e6b
|
Scott Ullrich
|
}
|
502 |
04c5bd17
|
Scott Ullrich
|
foreach ($viparr as $vip) {
|
503 |
6e42e038
|
Bill Marquette
|
/* bail if this isn't a carp VIP */
|
504 |
|
|
if ($vip['mode'] != "carp")
|
505 |
|
|
continue;
|
506 |
|
|
|
507 |
6008210b
|
Scott Ullrich
|
if($debugging)
|
508 |
|
|
echo "Upping interface carp{$carp_instances_counter}.\n";
|
509 |
|
|
$broadcast_address = gen_subnet_max($vip['subnet'], $vip['subnet_bits']);
|
510 |
eb772abd
|
Scott Ullrich
|
if($vip['password'] != "")
|
511 |
6008210b
|
Scott Ullrich
|
$password = " pass " . $vip['password'];
|
512 |
|
|
if($debugging)
|
513 |
|
|
echo "/sbin/ifconfig carp" . $carp_instances_counter . " " . $vip['subnet'] . "/" . $vip['subnet_bits'] . " broadcast " . $broadcast_address . " vhid " . $vip['vhid'] . "{$carpdev} advskew " . $vip['advskew'] . $password . "\n";
|
514 |
|
|
mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " " . $vip['subnet'] . "/" . $vip['subnet_bits'] . " broadcast " . $broadcast_address . " vhid " . $vip['vhid'] . "{$carpdev} advskew " . $vip['advskew'] . $password);
|
515 |
5f2ad497
|
Scott Ullrich
|
sleep(1);
|
516 |
|
|
mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " up");
|
517 |
04c5bd17
|
Scott Ullrich
|
$carp_instances_counter++;
|
518 |
|
|
}
|
519 |
0c6ee817
|
Scott Ullrich
|
if($g['booting'])
|
520 |
eb772abd
|
Scott Ullrich
|
echo " done.\n";
|
521 |
04c5bd17
|
Scott Ullrich
|
}
|
522 |
|
|
|
523 |
5b237745
|
Scott Ullrich
|
function interfaces_wireless_configure($if, $wlcfg) {
|
524 |
ac3f8318
|
Espen Johansen
|
global $config, $g;
|
525 |
eb772abd
|
Scott Ullrich
|
|
526 |
4742e927
|
Scott Ullrich
|
/* open up a shell script that will be used to output the commands.
|
527 |
|
|
* since wireless is changing a lot, these series of commands are fragile
|
528 |
|
|
* and will sometimes need to be verified by a operator by executing the command
|
529 |
|
|
* and returning the output of the command to the developers for inspection. please
|
530 |
|
|
* do not change this routine from a shell script to individul exec commands. -sullrich
|
531 |
|
|
*/
|
532 |
eb772abd
|
Scott Ullrich
|
|
533 |
8a958125
|
Scott Ullrich
|
conf_mount_rw();
|
534 |
eb772abd
|
Scott Ullrich
|
|
535 |
490b8b2a
|
Scott Ullrich
|
unlink_if_exists("{$g['tmp_path']}/{$if}_setup.sh");
|
536 |
eb772abd
|
Scott Ullrich
|
|
537 |
4742e927
|
Scott Ullrich
|
$fd_set = fopen("/tmp/{$if}_setup.sh","w");
|
538 |
|
|
fwrite($fd_set, "#!/bin/sh\n");
|
539 |
36d0358b
|
Scott Ullrich
|
fwrite($fd_set, "# {$g['product_name']} wireless configuration script.\n\n");
|
540 |
eb772abd
|
Scott Ullrich
|
|
541 |
4742e927
|
Scott Ullrich
|
fwrite($fd_set, "# enable shell debugging\n");
|
542 |
|
|
fwrite($fd_set, "set -x\n");
|
543 |
eb772abd
|
Scott Ullrich
|
|
544 |
2ac908dd
|
Espen Johansen
|
/* set values for /path/program */
|
545 |
|
|
$hostapd = "/usr/sbin/hostapd";
|
546 |
|
|
$wpa_supplicant = "/usr/sbin/wpa_supplicant";
|
547 |
4742e927
|
Scott Ullrich
|
$ifconfig = "/sbin/ifconfig";
|
548 |
|
|
$killall = "/usr/bin/killall";
|
549 |
2ac908dd
|
Espen Johansen
|
|
550 |
a59abc65
|
Scott Ullrich
|
/* Set all wireless ifconfig variables (splitt up to get rid of needed checking) */
|
551 |
5508cf57
|
Scott Ullrich
|
|
552 |
ac3f8318
|
Espen Johansen
|
/* Set a/b/g standard */
|
553 |
f4c9d138
|
Scott Ullrich
|
$standard = "mode " . escapeshellarg($wlcfg['standard']);
|
554 |
5508cf57
|
Scott Ullrich
|
|
555 |
0856c4ac
|
Scott Ullrich
|
/* Set 802.11g protection mode */
|
556 |
|
|
$protmode = "protmode " . escapeshellarg($wlcfg['protmode']);
|
557 |
|
|
|
558 |
ac3f8318
|
Espen Johansen
|
/* set wireless channel value */
|
559 |
ea9d29fa
|
Scott Ullrich
|
if(isset($wlcfg['channel']))
|
560 |
f4c9d138
|
Scott Ullrich
|
$channel = "channel " . escapeshellarg($wlcfg['channel']);
|
561 |
2ac908dd
|
Espen Johansen
|
|
562 |
f134033e
|
Scott Ullrich
|
/* set Distance value */
|
563 |
eb772abd
|
Scott Ullrich
|
if($wlcfg['distance'])
|
564 |
f134033e
|
Scott Ullrich
|
$distance = escapeshellarg($wlcfg['distance']);
|
565 |
|
|
|
566 |
ac3f8318
|
Espen Johansen
|
/* Set ssid */
|
567 |
eb772abd
|
Scott Ullrich
|
if($wlcfg['ssid'])
|
568 |
191a8175
|
Scott Ullrich
|
$ssid = "ssid " . escapeshellarg($wlcfg['ssid']);
|
569 |
eb772abd
|
Scott Ullrich
|
|
570 |
ac3f8318
|
Espen Johansen
|
/* Set wireless hostap mode */
|
571 |
a59abc65
|
Scott Ullrich
|
if ($wlcfg['mode'] == "hostap")
|
572 |
ac3f8318
|
Espen Johansen
|
$hostapmode = "mediaopt hostap";
|
573 |
|
|
else
|
574 |
|
|
$hostapmode = "-mediaopt hostap";
|
575 |
|
|
|
576 |
|
|
/* Set wireless adhoc mode */
|
577 |
a59abc65
|
Scott Ullrich
|
if ($wlcfg['mode'] == "adhoc")
|
578 |
ac3f8318
|
Espen Johansen
|
$adhocmode = "mediaopt adhoc";
|
579 |
|
|
else
|
580 |
|
|
$adhocmode = "-mediaopt adhoc";
|
581 |
|
|
|
582 |
|
|
/* Not neccesary to set BSS mode as this is default if adhoc and/or hostap is NOT set */
|
583 |
|
|
|
584 |
|
|
/* handle hide ssid option */
|
585 |
|
|
if(isset($wlcfg['hidessid']['enable']))
|
586 |
|
|
$hidessid = "hidessid";
|
587 |
|
|
else
|
588 |
|
|
$hidessid = "-hidessid";
|
589 |
|
|
|
590 |
|
|
/* handle pureg (802.11g) only option */
|
591 |
|
|
if(isset($wlcfg['pureg']['enable']))
|
592 |
|
|
$pureg = "mode 11g pureg";
|
593 |
|
|
else
|
594 |
|
|
$pureg = "-pureg";
|
595 |
|
|
|
596 |
|
|
/* enable apbridge option */
|
597 |
|
|
if(isset($wlcfg['apbridge']['enable']))
|
598 |
|
|
$apbridge = "apbridge";
|
599 |
|
|
else
|
600 |
|
|
$apbridge = "-apbridge";
|
601 |
|
|
|
602 |
|
|
/* handle turbo option */
|
603 |
|
|
if(isset($wlcfg['turbo']['enable']))
|
604 |
|
|
$turbo = "mediaopt turbo";
|
605 |
|
|
else
|
606 |
|
|
$turbo = "-mediaopt turbo";
|
607 |
|
|
|
608 |
|
|
/* handle txpower setting */
|
609 |
|
|
if($wlcfg['txpower'] <> "")
|
610 |
f4c9d138
|
Scott Ullrich
|
$txpower = "txpower " . escapeshellarg($wlcfg['txpower']);
|
611 |
eb772abd
|
Scott Ullrich
|
|
612 |
ac3f8318
|
Espen Johansen
|
/* handle wme option */
|
613 |
|
|
if(isset($wlcfg['wme']['enable']))
|
614 |
|
|
$wme = "wme";
|
615 |
|
|
else
|
616 |
|
|
$wme = "-wme";
|
617 |
eb772abd
|
Scott Ullrich
|
|
618 |
ac3f8318
|
Espen Johansen
|
/* set up wep if enabled */
|
619 |
2f19fa14
|
Scott Ullrich
|
if (isset($wlcfg['wep']['enable']) && is_array($wlcfg['wep']['key'])) {
|
620 |
eb772abd
|
Scott Ullrich
|
if($wlcfg['wpa']['auth_algs'] == "1")
|
621 |
2f19fa14
|
Scott Ullrich
|
$wepset .= "authmode open wepmode on ";
|
622 |
|
|
else if($wlcfg['wpa']['auth_algs'] == "2")
|
623 |
|
|
$wepset .= "authmode shared wepmode on ";
|
624 |
|
|
else if($wlcfg['wpa']['auth_algs'] == "3")
|
625 |
eb772abd
|
Scott Ullrich
|
$wepset .= "authmode mixed wepmode on ";
|
626 |
2f19fa14
|
Scott Ullrich
|
$i = 1;
|
627 |
|
|
foreach ($wlcfg['wep']['key'] as $wepkey) {
|
628 |
|
|
$wepset .= "wepkey " . escapeshellarg("{$i}:{$wepkey['value']}") . " ";
|
629 |
eb772abd
|
Scott Ullrich
|
if (isset($wepkey['txkey']))
|
630 |
2f19fa14
|
Scott Ullrich
|
$wepset .= "weptxkey {$i} ";
|
631 |
|
|
$i++;
|
632 |
|
|
}
|
633 |
|
|
} else {
|
634 |
|
|
$wepset .= "authmode open wepmode off ";
|
635 |
ac3f8318
|
Espen Johansen
|
}
|
636 |
|
|
|
637 |
|
|
/* generate wpa_supplicant/hostap config if wpa is enabled */
|
638 |
|
|
|
639 |
|
|
switch ($wlcfg['mode']) {
|
640 |
b67d192d
|
Scott Ullrich
|
case 'bss':
|
641 |
ac3f8318
|
Espen Johansen
|
if (isset($wlcfg['wpa']['enable'])) {
|
642 |
|
|
|
643 |
|
|
$wpa .= <<<EOD
|
644 |
454756b9
|
Scott Ullrich
|
ctrl_interface={$g['varrun_path']}/wpa_supplicant
|
645 |
50ad3b7c
|
Scott Ullrich
|
ctrl_interface_group=0
|
646 |
|
|
ap_scan=1
|
647 |
2ac908dd
|
Espen Johansen
|
#fast_reauth=1
|
648 |
249558a2
|
Scott Ullrich
|
network={
|
649 |
454756b9
|
Scott Ullrich
|
ssid="{$wlcfg['ssid']}"
|
650 |
|
|
scan_ssid=1
|
651 |
2ac908dd
|
Espen Johansen
|
priority=5
|
652 |
|
|
key_mgmt={$wlcfg['wpa']['wpa_key_mgmt']}
|
653 |
454756b9
|
Scott Ullrich
|
psk="{$wlcfg['wpa']['passphrase']}"
|
654 |
2ac908dd
|
Espen Johansen
|
pairwise={$wlcfg['wpa']['wpa_pairwise']}
|
655 |
|
|
group={$wlcfg['wpa']['wpa_pairwise']}
|
656 |
50ad3b7c
|
Scott Ullrich
|
}
|
657 |
|
|
EOD;
|
658 |
|
|
|
659 |
80ec5eaa
|
Scott Ullrich
|
$fd = fopen("{$g['varetc_path']}/wpa_supplicant_{$if}.conf", "w");
|
660 |
ac3f8318
|
Espen Johansen
|
fwrite($fd, "{$wpa}");
|
661 |
|
|
fclose($fd);
|
662 |
8d27a5fe
|
Espen Johansen
|
|
663 |
99e72ce8
|
Scott Ullrich
|
fwrite($fd_set, kill_wpasupplicant($if));
|
664 |
ac3f8318
|
Espen Johansen
|
}
|
665 |
|
|
break;
|
666 |
459d6351
|
Scott Ullrich
|
|
667 |
ac3f8318
|
Espen Johansen
|
case 'hostap':
|
668 |
|
|
if (isset($wlcfg['wpa']['enable'])) {
|
669 |
|
|
$wpa .= <<<EOD
|
670 |
459d6351
|
Scott Ullrich
|
interface={$if}
|
671 |
|
|
driver=bsd
|
672 |
|
|
logger_syslog=-1
|
673 |
|
|
logger_syslog_level=0
|
674 |
|
|
logger_stdout=-1
|
675 |
|
|
logger_stdout_level=0
|
676 |
2ac908dd
|
Espen Johansen
|
dump_file={$g['tmp_path']}/hostapd_{$if}.dump
|
677 |
|
|
ctrl_interface={$g['varrun_path']}/hostapd
|
678 |
459d6351
|
Scott Ullrich
|
ctrl_interface_group=wheel
|
679 |
2ac908dd
|
Espen Johansen
|
#accept_mac_file={$g['tmp_path']}/hostapd_{$if}.accept
|
680 |
|
|
#deny_mac_file={$g['tmp_path']}/hostapd_{$if}.deny
|
681 |
b67d192d
|
Scott Ullrich
|
#macaddr_acl={$wlcfg['wpa']['macaddr_acl']}
|
682 |
459d6351
|
Scott Ullrich
|
ssid={$wlcfg['ssid']}
|
683 |
2ac908dd
|
Espen Johansen
|
debug={$wlcfg['wpa']['debug_mode']}
|
684 |
|
|
auth_algs={$wlcfg['wpa']['auth_algs']}
|
685 |
|
|
wpa={$wlcfg['wpa']['wpa_mode']}
|
686 |
|
|
wpa_key_mgmt={$wlcfg['wpa']['wpa_key_mgmt']}
|
687 |
|
|
wpa_pairwise={$wlcfg['wpa']['wpa_pairwise']}
|
688 |
ac3f8318
|
Espen Johansen
|
wpa_group_rekey={$wlcfg['wpa']['wpa_group_rekey']}
|
689 |
|
|
wpa_gmk_rekey={$wlcfg['wpa']['wpa_gmk_rekey']}
|
690 |
|
|
wpa_strict_rekey={$wlcfg['wpa']['wpa_strict_rekey']}
|
691 |
2ac908dd
|
Espen Johansen
|
wpa_passphrase={$wlcfg['wpa']['passphrase']}
|
692 |
|
|
ieee8021x={$wlcfg['wpa']['ieee8021x']}
|
693 |
53dfd34e
|
Espen Johansen
|
#Enable the next lines for preauth when roaming. Interface = wired or wireless interface talking to the AP you want to roam from/to
|
694 |
|
|
#rsn_preauth=1
|
695 |
|
|
#rsn_preauth_interfaces=eth0
|
696 |
459d6351
|
Scott Ullrich
|
EOD;
|
697 |
2ac908dd
|
Espen Johansen
|
|
698 |
80ec5eaa
|
Scott Ullrich
|
$fd = fopen("{$g['varetc_path']}/hostapd_{$if}.conf", "w");
|
699 |
ac3f8318
|
Espen Johansen
|
fwrite($fd, "{$wpa}");
|
700 |
|
|
fclose($fd);
|
701 |
2ac908dd
|
Espen Johansen
|
|
702 |
99e72ce8
|
Scott Ullrich
|
fwrite($fd_set, kill_hostapd($if));
|
703 |
ac3f8318
|
Espen Johansen
|
}
|
704 |
|
|
break;
|
705 |
5508cf57
|
Scott Ullrich
|
|
706 |
ac3f8318
|
Espen Johansen
|
case 'adhoc':
|
707 |
99e72ce8
|
Scott Ullrich
|
fwrite($fd_set, kill_hostapd($if));
|
708 |
|
|
fwrite($fd_set, kill_wpasupplicant($if));
|
709 |
ac3f8318
|
Espen Johansen
|
break;
|
710 |
eb772abd
|
Scott Ullrich
|
}
|
711 |
ac3f8318
|
Espen Johansen
|
|
712 |
4742e927
|
Scott Ullrich
|
/*
|
713 |
|
|
* all variables are set, lets start up everything
|
714 |
|
|
*/
|
715 |
eb772abd
|
Scott Ullrich
|
|
716 |
78922914
|
Scott Ullrich
|
/* set ack timers according to users preference (if he/she has any) */
|
717 |
|
|
if($distance) {
|
718 |
4742e927
|
Scott Ullrich
|
fwrite($fd_set, "# Enable ATH distance settings\n");
|
719 |
|
|
fwrite($fd_set, "/sbin/athctrl.sh -i {$if} -d {$distance}\n");
|
720 |
78922914
|
Scott Ullrich
|
}
|
721 |
eb772abd
|
Scott Ullrich
|
|
722 |
4d857dcf
|
Scott Ullrich
|
$standard_no_turbo = str_replace(" Turbo", "", $standard);
|
723 |
eb772abd
|
Scott Ullrich
|
|
724 |
4742e927
|
Scott Ullrich
|
$settings = <<<EOD
|
725 |
|
|
|
726 |
2f19fa14
|
Scott Ullrich
|
{$ifconfig} {$if} down
|
727 |
4742e927
|
Scott Ullrich
|
{$ifconfig} {$if} {$hostapmode}
|
728 |
490b8b2a
|
Scott Ullrich
|
{$ifconfig} {$if} {$standard_no_turbo}
|
729 |
8a958125
|
Scott Ullrich
|
{$ifconfig} {$if} {$channel}
|
730 |
4742e927
|
Scott Ullrich
|
{$ifconfig} {$if} {$turbo}
|
731 |
8a958125
|
Scott Ullrich
|
{$ifconfig} {$if} {$ssid}
|
732 |
4742e927
|
Scott Ullrich
|
{$ifconfig} {$if} {$hidessid}
|
733 |
8a958125
|
Scott Ullrich
|
{$ifconfig} {$if} {$adhocmode}
|
734 |
|
|
{$ifconfig} {$if} {$protmode}
|
735 |
4742e927
|
Scott Ullrich
|
{$ifconfig} {$if} {$pureg}
|
736 |
|
|
{$ifconfig} {$if} {$apbridge}
|
737 |
|
|
{$ifconfig} {$if} {$wme}
|
738 |
|
|
{$ifconfig} {$if} {$wepset}
|
739 |
|
|
{$ifconfig} {$if} {$txpower}
|
740 |
|
|
{$ifconfig} {$if} up
|
741 |
|
|
|
742 |
|
|
EOD;
|
743 |
eb772abd
|
Scott Ullrich
|
|
744 |
4742e927
|
Scott Ullrich
|
/* write out above <<EOD stuff */
|
745 |
|
|
fwrite($fd_set, $settings);
|
746 |
da1dab20
|
Scott Ullrich
|
|
747 |
ac3f8318
|
Espen Johansen
|
if (isset($wlcfg['wpa']['enable'])) {
|
748 |
eb772abd
|
Scott Ullrich
|
if ($wlcfg['mode'] == "bss")
|
749 |
4742e927
|
Scott Ullrich
|
fwrite($fd_set, "{$wpa_supplicant} -B -i {$if} -c {$g['varetc_path']}/wpa_supplicant_{$if}.conf\n");
|
750 |
eb772abd
|
Scott Ullrich
|
if ($wlcfg['mode'] == "hostap")
|
751 |
4742e927
|
Scott Ullrich
|
fwrite($fd_set, "{$hostapd} -B {$g['varetc_path']}/hostapd_{$if}.conf\n");
|
752 |
ac3f8318
|
Espen Johansen
|
}
|
753 |
191a8175
|
Scott Ullrich
|
|
754 |
4742e927
|
Scott Ullrich
|
fclose($fd_set);
|
755 |
|
|
|
756 |
8a958125
|
Scott Ullrich
|
conf_mount_ro();
|
757 |
|
|
|
758 |
4742e927
|
Scott Ullrich
|
/* execute commands now in shell */
|
759 |
|
|
mwexec("/bin/sh /tmp/{$if}_setup.sh");
|
760 |
99e72ce8
|
Scott Ullrich
|
sleep(2);
|
761 |
490b8b2a
|
Scott Ullrich
|
mwexec("/bin/sh /tmp/{$if}_setup.sh");
|
762 |
191a8175
|
Scott Ullrich
|
|
763 |
ac3f8318
|
Espen Johansen
|
return 0;
|
764 |
cfc707f7
|
Scott Ullrich
|
|
765 |
5b237745
|
Scott Ullrich
|
}
|
766 |
|
|
|
767 |
4b2a6180
|
Scott Ullrich
|
function kill_hostapd($interface) {
|
768 |
99e72ce8
|
Scott Ullrich
|
return "/bin/ps awwuxx | grep hostapd | grep $interface | awk '{ print \$2 }' | xargs kill\n";
|
769 |
4b2a6180
|
Scott Ullrich
|
}
|
770 |
|
|
|
771 |
|
|
function kill_wpasupplicant($interface) {
|
772 |
99e72ce8
|
Scott Ullrich
|
return "/bin/ps awwuxx | grep wpa_supplicant | grep $interface | awk '{ print \$2 }' | xargs kill\n";
|
773 |
4b2a6180
|
Scott Ullrich
|
}
|
774 |
|
|
|
775 |
0311dbd5
|
Scott Ullrich
|
function find_dhclient_process($interface) {
|
776 |
2305d4c5
|
Scott Ullrich
|
if(filter_translate_type_to_real_interface($interface) <> "")
|
777 |
|
|
$realinterface = filter_translate_type_to_real_interface($interface);
|
778 |
9aa9d624
|
Scott Ullrich
|
$pid = `ps awwwux | grep dhclient | grep -v grep | grep {$realinterface} | awk '{ print \$2 }'`;
|
779 |
0311dbd5
|
Scott Ullrich
|
return $pid;
|
780 |
|
|
}
|
781 |
|
|
|
782 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_configure() {
|
783 |
0831bc86
|
Scott Ullrich
|
global $config, $g, $bridges_total;
|
784 |
cfc707f7
|
Scott Ullrich
|
|
785 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
786 |
cfc707f7
|
Scott Ullrich
|
|
787 |
5c6d0f65
|
Colin Smith
|
if(!$g['booting']) {
|
788 |
c1627786
|
Scott Ullrich
|
mute_kernel_msgs();
|
789 |
0311dbd5
|
Scott Ullrich
|
|
790 |
|
|
/* find dhclient process for wan and kill it */
|
791 |
2305d4c5
|
Scott Ullrich
|
killbypid(find_dhclient_process("wan"));
|
792 |
cfc707f7
|
Scott Ullrich
|
|
793 |
d7a6517a
|
Scott Ullrich
|
/* remove wanup file if it exists */
|
794 |
|
|
unlink_if_exists("{$g['tmp_path']}/wanup");
|
795 |
|
|
|
796 |
5b237745
|
Scott Ullrich
|
/* kill PPPoE client (mpd) */
|
797 |
|
|
killbypid("{$g['varrun_path']}/mpd.pid");
|
798 |
cfc707f7
|
Scott Ullrich
|
|
799 |
5b237745
|
Scott Ullrich
|
/* wait for processes to die */
|
800 |
d7a6517a
|
Scott Ullrich
|
sleep(3);
|
801 |
cfc707f7
|
Scott Ullrich
|
|
802 |
0311dbd5
|
Scott Ullrich
|
unlink_if_exists("{$g['varetc_path']}/dhclient_wan.conf");
|
803 |
a23d7248
|
Scott Ullrich
|
unlink_if_exists("{$g['varetc_path']}/mpd.conf");
|
804 |
|
|
unlink_if_exists("{$g['varetc_path']}/mpd.links");
|
805 |
|
|
unlink_if_exists("{$g['vardb_path']}/wanip");
|
806 |
|
|
unlink_if_exists("{$g['varetc_path']}/nameservers.conf");
|
807 |
5b237745
|
Scott Ullrich
|
}
|
808 |
cfc707f7
|
Scott Ullrich
|
|
809 |
5b237745
|
Scott Ullrich
|
/* remove all addresses first */
|
810 |
|
|
while (mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " -alias") == 0);
|
811 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " down");
|
812 |
cfc707f7
|
Scott Ullrich
|
|
813 |
5b237745
|
Scott Ullrich
|
/* wireless configuration? */
|
814 |
|
|
if (is_array($wancfg['wireless']))
|
815 |
|
|
interfaces_wireless_configure($wancfg['if'], $wancfg['wireless']);
|
816 |
cfc707f7
|
Scott Ullrich
|
|
817 |
f36d4bd2
|
Scott Ullrich
|
if ($wancfg['spoofmac']) {
|
818 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
|
819 |
5b237745
|
Scott Ullrich
|
" link " . escapeshellarg($wancfg['spoofmac']));
|
820 |
f36d4bd2
|
Scott Ullrich
|
} else {
|
821 |
|
|
$mac = get_interface_mac_address($wancfg['if']);
|
822 |
|
|
if($mac == "ff:ff:ff:ff:ff:ff") {
|
823 |
|
|
/* this is not a valid mac address. generate a
|
824 |
|
|
* temporary mac address so the machine can get online.
|
825 |
|
|
*/
|
826 |
9315ef83
|
Scott Ullrich
|
echo "Generating new MAC address.";
|
827 |
f36d4bd2
|
Scott Ullrich
|
$random_mac = generate_random_mac_address();
|
828 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
|
829 |
|
|
" link " . escapeshellarg($random_mac));
|
830 |
|
|
$wancfg['spoofmac'] = $random_mac;
|
831 |
|
|
write_config();
|
832 |
da86dd6f
|
Scott Ullrich
|
file_notice("MAC Address altered", "The INVALID MAC address (ff:ff:ff:ff:ff:ff) on interface {$wancfg['if']} has been automatically replaced with {$random_mac}", "Interfaces");
|
833 |
f36d4bd2
|
Scott Ullrich
|
}
|
834 |
|
|
}
|
835 |
cfc707f7
|
Scott Ullrich
|
|
836 |
5b237745
|
Scott Ullrich
|
/* media */
|
837 |
|
|
if ($wancfg['media'] || $wancfg['mediaopt']) {
|
838 |
|
|
$cmd = "/sbin/ifconfig " . escapeshellarg($wancfg['if']);
|
839 |
|
|
if ($wancfg['media'])
|
840 |
|
|
$cmd .= " media " . escapeshellarg($wancfg['media']);
|
841 |
|
|
if ($wancfg['mediaopt'])
|
842 |
|
|
$cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']);
|
843 |
|
|
mwexec($cmd);
|
844 |
|
|
}
|
845 |
cfc707f7
|
Scott Ullrich
|
|
846 |
5b237745
|
Scott Ullrich
|
switch ($wancfg['ipaddr']) {
|
847 |
cfc707f7
|
Scott Ullrich
|
|
848 |
5b237745
|
Scott Ullrich
|
case 'dhcp':
|
849 |
|
|
interfaces_wan_dhcp_configure();
|
850 |
|
|
break;
|
851 |
cfc707f7
|
Scott Ullrich
|
|
852 |
5b237745
|
Scott Ullrich
|
case 'pppoe':
|
853 |
|
|
interfaces_wan_pppoe_configure();
|
854 |
|
|
break;
|
855 |
cfc707f7
|
Scott Ullrich
|
|
856 |
5b237745
|
Scott Ullrich
|
case 'pptp':
|
857 |
|
|
interfaces_wan_pptp_configure();
|
858 |
|
|
break;
|
859 |
cfc707f7
|
Scott Ullrich
|
|
860 |
5b237745
|
Scott Ullrich
|
case 'bigpond':
|
861 |
|
|
/* just configure DHCP for now; fire up bpalogin when we've got the lease */
|
862 |
|
|
interfaces_wan_dhcp_configure();
|
863 |
|
|
break;
|
864 |
cfc707f7
|
Scott Ullrich
|
|
865 |
5b237745
|
Scott Ullrich
|
default:
|
866 |
a23d7248
|
Scott Ullrich
|
if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) {
|
867 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
868 |
|
|
escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']) .
|
869 |
|
|
" " . escapeshellarg($wancfg['pointtopoint']) . " up");
|
870 |
|
|
} else {
|
871 |
|
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
872 |
|
|
escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']));
|
873 |
|
|
}
|
874 |
cfc707f7
|
Scott Ullrich
|
|
875 |
3c9daf99
|
Scott Ullrich
|
/* resync pf (done automatically for DHCP/PPPoE/PPTP) */
|
876 |
|
|
filter_configure();
|
877 |
5b237745
|
Scott Ullrich
|
}
|
878 |
cfc707f7
|
Scott Ullrich
|
|
879 |
77712c1e
|
Scott Ullrich
|
if ($wancfg['bridge']) {
|
880 |
|
|
/* use open/netBSD style bridge */
|
881 |
|
|
mwexec("/sbin/ifconfig bridge{$bridges_total} create");
|
882 |
3f7d2120
|
Bill Marquette
|
|
883 |
|
|
/* invalidate interface cache */
|
884 |
|
|
get_interface_arr(true);
|
885 |
eb772abd
|
Scott Ullrich
|
|
886 |
77712c1e
|
Scott Ullrich
|
/* force all bridged interfaces to use same mtu */
|
887 |
|
|
$mtu = get_interface_mtu($config['interfaces'][$wancfg['bridge']]['if']);
|
888 |
|
|
mwexec("/sbin/ifconfig {$wancfg['if']} mtu {$mtu}");
|
889 |
|
|
mwexec("/sbin/ifconfig {$config['interfaces'][$wancfg['bridge']]['if']} mtu {$mtu}");
|
890 |
eb772abd
|
Scott Ullrich
|
|
891 |
77712c1e
|
Scott Ullrich
|
/* assign items to a bridge */
|
892 |
a591b9cb
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} addm {$wancfg['if']} addm {$config['interfaces'][$wancfg['bridge']]['if']}");
|
893 |
df792110
|
Scott Ullrich
|
|
894 |
e7aa7560
|
Scott Ullrich
|
if(!is_interface_wireless($wancfg['if']) and
|
895 |
eb772abd
|
Scott Ullrich
|
!is_interface_wireless($config['interfaces'][$wancfg['bridge']]['if']))
|
896 |
3789e4df
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridges_total} stp {$config['interfaces'][$wancfg['bridge']]['if']} stp {$wancfg['if']}");
|
897 |
eb772abd
|
Scott Ullrich
|
|
898 |
77712c1e
|
Scott Ullrich
|
/* log commands run for debugging in /tmp/ */
|
899 |
|
|
$fd = fopen("{$g['tmp_path']}/bridge_config_{$wancfg['if']}", "w");
|
900 |
|
|
fwrite($fd, "/sbin/ifconfig {$wancfg['if']} mtu {$mtu}\n");
|
901 |
|
|
fwrite($fd, "/sbin/ifconfig {$config['interfaces'][$wancfg['bridge']]['if']} mtu {$mtu}\n");
|
902 |
|
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} create\n");
|
903 |
b3a66d90
|
Scott Ullrich
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} addm {$wancfg['if']} addm {$config['interfaces'][$wancfg['bridge']]['if']}\n");
|
904 |
12fea2f7
|
Scott Ullrich
|
if(!is_interface_wireless($wancfg['if']) and
|
905 |
|
|
!is_interface_wireless($config['interfaces'][$wancfg['bridge']]['if']))
|
906 |
|
|
fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} stp {$wancfg['if']} stp {$config['interfaces'][$wancfg['bridge']]['if']}\n");
|
907 |
77712c1e
|
Scott Ullrich
|
fclose($fd);
|
908 |
eb772abd
|
Scott Ullrich
|
|
909 |
77712c1e
|
Scott Ullrich
|
/* bring up interfaces */
|
910 |
|
|
mwexec("/sbin/ifconfig bridge{$bridges_total} down");
|
911 |
|
|
usleep(100);
|
912 |
|
|
mwexec("/sbin/ifconfig {$config['interfaces'][$wancfg['bridge']]['if']} up");
|
913 |
|
|
usleep(5);
|
914 |
|
|
mwexec("/sbin/ifconfig {$wancfg['if']} up");
|
915 |
|
|
usleep(5);
|
916 |
|
|
mwexec("/sbin/ifconfig bridge{$bridges_total} up");
|
917 |
eb772abd
|
Scott Ullrich
|
|
918 |
c60e4f51
|
Scott Ullrich
|
$bridges_total++;
|
919 |
547a126d
|
Bill Marquette
|
/* update cache */
|
920 |
3f7d2120
|
Bill Marquette
|
if ($bridges_total != find_number_of_created_bridges())
|
921 |
|
|
find_number_of_created_bridges(true);
|
922 |
77712c1e
|
Scott Ullrich
|
}
|
923 |
|
|
|
924 |
5b237745
|
Scott Ullrich
|
if (!$g['booting']) {
|
925 |
|
|
/* reconfigure static routes (kernel may have deleted them) */
|
926 |
|
|
system_routing_configure();
|
927 |
cfc707f7
|
Scott Ullrich
|
|
928 |
e239df5a
|
Scott Ullrich
|
/* set the reload filter dity flag */
|
929 |
f229e20f
|
Scott Ullrich
|
touch("{$g['tmp_path']}/filter_dirty");
|
930 |
cfc707f7
|
Scott Ullrich
|
|
931 |
5b237745
|
Scott Ullrich
|
/* reload ipsec tunnels */
|
932 |
|
|
vpn_ipsec_configure();
|
933 |
cfc707f7
|
Scott Ullrich
|
|
934 |
5b237745
|
Scott Ullrich
|
/* restart ez-ipupdate */
|
935 |
|
|
services_dyndns_configure();
|
936 |
cfc707f7
|
Scott Ullrich
|
|
937 |
a23d7248
|
Scott Ullrich
|
/* force DNS update */
|
938 |
|
|
services_dnsupdate_process();
|
939 |
|
|
|
940 |
5b237745
|
Scott Ullrich
|
/* restart dnsmasq */
|
941 |
|
|
services_dnsmasq_configure();
|
942 |
eb772abd
|
Scott Ullrich
|
|
943 |
c597d50f
|
Scott Ullrich
|
/* reload captive portal */
|
944 |
|
|
captiveportal_configure();
|
945 |
5b237745
|
Scott Ullrich
|
}
|
946 |
cfc707f7
|
Scott Ullrich
|
|
947 |
5e99d81a
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$wancfg['if']} up");
|
948 |
|
|
|
949 |
c1627786
|
Scott Ullrich
|
unmute_kernel_msgs();
|
950 |
|
|
|
951 |
5b237745
|
Scott Ullrich
|
return 0;
|
952 |
|
|
}
|
953 |
|
|
|
954 |
0311dbd5
|
Scott Ullrich
|
function interfaces_opt_dhcp_configure($interface) {
|
955 |
|
|
global $config, $g;
|
956 |
|
|
|
957 |
1223f922
|
Scott Ullrich
|
$optcfg = $config['interfaces'][$interface];
|
958 |
45870464
|
Scott Ullrich
|
$optif = $optcfg['if'];
|
959 |
0311dbd5
|
Scott Ullrich
|
|
960 |
|
|
/* generate dhclient_wan.conf */
|
961 |
aab78cf6
|
Scott Ullrich
|
$fd = fopen("{$g['varetc_path']}/dhclient_{$optif}.conf", "w");
|
962 |
0311dbd5
|
Scott Ullrich
|
if (!$fd) {
|
963 |
aab78cf6
|
Scott Ullrich
|
printf("Error: cannot open dhclient_{$optif}.conf in interfaces_opt_dhcp_configure({$optif}) for writing.\n");
|
964 |
0311dbd5
|
Scott Ullrich
|
return 1;
|
965 |
|
|
}
|
966 |
|
|
|
967 |
2305d4c5
|
Scott Ullrich
|
if ($optcfg['dhcphostname']) {
|
968 |
|
|
$dhclientconf_hostname = "send dhcp-client-identifier \"{$optcfg['dhcphostname']}\";\n";
|
969 |
|
|
$dhclientconf_hostname .= "\tsend host-name \"{$optcfg['dhcphostname']}\";\n";
|
970 |
|
|
} else {
|
971 |
|
|
$dhclientconf_hostname = "";
|
972 |
|
|
}
|
973 |
|
|
|
974 |
0311dbd5
|
Scott Ullrich
|
$dhclientconf = "";
|
975 |
|
|
|
976 |
6d76590c
|
Scott Ullrich
|
$dhclientconf .= <<<EOD
|
977 |
0709cd0b
|
Scott Ullrich
|
timeout 1200;
|
978 |
|
|
retry 1;
|
979 |
|
|
select-timeout 0;
|
980 |
|
|
initial-interval 1;
|
981 |
6d76590c
|
Scott Ullrich
|
interface "{$optif}" {
|
982 |
2305d4c5
|
Scott Ullrich
|
script "/sbin/dhclient-script";
|
983 |
|
|
{$dhclientconf_hostname}
|
984 |
0311dbd5
|
Scott Ullrich
|
}
|
985 |
|
|
|
986 |
|
|
EOD;
|
987 |
|
|
|
988 |
bc40d758
|
Seth Mos
|
if(is_ipaddr($optcfg['alias-address'])) {
|
989 |
|
|
$subnetmask = gen_subnet_mask($optcfg['alias-subnet']);
|
990 |
|
|
$dhclientconf .= <<<EOD
|
991 |
|
|
alias {
|
992 |
|
|
interface "{$optif}";
|
993 |
|
|
fixed-address {$optcfg['alias-address']};
|
994 |
|
|
option subnet-mask {$subnetmask};
|
995 |
|
|
}
|
996 |
|
|
|
997 |
|
|
EOD;
|
998 |
|
|
}
|
999 |
0311dbd5
|
Scott Ullrich
|
fwrite($fd, $dhclientconf);
|
1000 |
|
|
fclose($fd);
|
1001 |
45870464
|
Scott Ullrich
|
|
1002 |
0f1b5370
|
Scott Ullrich
|
/* bring interface up before starting dhclient */
|
1003 |
0311dbd5
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$optif} up");
|
1004 |
|
|
|
1005 |
|
|
/* fire up dhclient */
|
1006 |
2305d4c5
|
Scott Ullrich
|
mwexec("/sbin/dhclient -c {$g['varetc_path']}/dhclient_{$optif}.conf {$optif}");
|
1007 |
0311dbd5
|
Scott Ullrich
|
|
1008 |
|
|
return 0;
|
1009 |
|
|
}
|
1010 |
|
|
|
1011 |
8c3e8725
|
Scott Ullrich
|
function interfaces_dhcp_configure($interface) {
|
1012 |
|
|
global $config, $g;
|
1013 |
|
|
|
1014 |
84cec030
|
Scott Ullrich
|
if(filter_translate_type_to_real_interface($interface) <> "")
|
1015 |
|
|
$realinterface = filter_translate_type_to_real_interface($interface);
|
1016 |
6d76590c
|
Scott Ullrich
|
|
1017 |
8c3e8725
|
Scott Ullrich
|
$optcfg = $config['interfaces'][$interface];
|
1018 |
|
|
|
1019 |
|
|
/* generate dhclient_$interface.conf */
|
1020 |
|
|
$fd = fopen("{$g['varetc_path']}/dhclient_{$interface}.conf", "w");
|
1021 |
|
|
if (!$fd) {
|
1022 |
|
|
printf("Error: cannot open dhclient_{$interface}.conf in interfaces_dhcp_configure({$$interface}) for writing.\n");
|
1023 |
|
|
return 1;
|
1024 |
|
|
}
|
1025 |
|
|
|
1026 |
2305d4c5
|
Scott Ullrich
|
if ($optcfg['dhcphostname']) {
|
1027 |
|
|
$dhclientconf_hostname = "send dhcp-client-identifier \"{$optcfg['dhcphostname']}\";\n";
|
1028 |
|
|
$dhclientconf_hostname .= "\tsend host-name \"{$optcfg['dhcphostname']}\";\n";
|
1029 |
|
|
} else {
|
1030 |
|
|
$dhclientconf_hostname = "";
|
1031 |
|
|
}
|
1032 |
|
|
|
1033 |
8c3e8725
|
Scott Ullrich
|
$dhclientconf = "";
|
1034 |
|
|
|
1035 |
6d76590c
|
Scott Ullrich
|
$dhclientconf .= <<<EOD
|
1036 |
0709cd0b
|
Scott Ullrich
|
timeout 1200;
|
1037 |
|
|
retry 1;
|
1038 |
|
|
select-timeout 0;
|
1039 |
|
|
initial-interval 1;
|
1040 |
84cec030
|
Scott Ullrich
|
interface "{$realinterface}" {
|
1041 |
2305d4c5
|
Scott Ullrich
|
{$dhclientconf_hostname}
|
1042 |
|
|
script "/sbin/dhclient-script";
|
1043 |
8c3e8725
|
Scott Ullrich
|
}
|
1044 |
|
|
|
1045 |
|
|
EOD;
|
1046 |
|
|
|
1047 |
bc40d758
|
Seth Mos
|
if(is_ipaddr($optcfg['alias-address'])) {
|
1048 |
|
|
$subnetmask = gen_subnet_mask($optcfg['alias-subnet']);
|
1049 |
|
|
$dhclientconf .= <<<EOD
|
1050 |
|
|
alias {
|
1051 |
|
|
interface "{$optif}";
|
1052 |
|
|
fixed-address {$optcfg['alias-address']};
|
1053 |
|
|
option subnet-mask {$subnetmask};
|
1054 |
|
|
}
|
1055 |
|
|
|
1056 |
|
|
EOD;
|
1057 |
|
|
}
|
1058 |
|
|
|
1059 |
8c3e8725
|
Scott Ullrich
|
fwrite($fd, $dhclientconf);
|
1060 |
|
|
fclose($fd);
|
1061 |
eb772abd
|
Scott Ullrich
|
|
1062 |
8c3e8725
|
Scott Ullrich
|
$optif = $optcfg['if'];
|
1063 |
eb772abd
|
Scott Ullrich
|
|
1064 |
8c3e8725
|
Scott Ullrich
|
/* bring wan interface up before starting dhclient */
|
1065 |
|
|
mwexec("/sbin/ifconfig {$optif} up");
|
1066 |
|
|
|
1067 |
|
|
/* fire up dhclient */
|
1068 |
2305d4c5
|
Scott Ullrich
|
mwexec("/sbin/dhclient -c {$g['varetc_path']}/dhclient_{$optif}.conf {$optif} >/tmp/{$optif}_output >/tmp/{$optif}_error_output");
|
1069 |
8c3e8725
|
Scott Ullrich
|
|
1070 |
|
|
$fout = fopen("/tmp/ifconfig_{$optif}","w");
|
1071 |
2305d4c5
|
Scott Ullrich
|
fwrite($fout, "/sbin/dhclient -c {$g['varetc_path']}/dhclient_{$optif}.conf {$optif}");
|
1072 |
8c3e8725
|
Scott Ullrich
|
fclose($fout);
|
1073 |
|
|
|
1074 |
|
|
return 0;
|
1075 |
|
|
}
|
1076 |
|
|
|
1077 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_dhcp_configure() {
|
1078 |
|
|
global $config, $g;
|
1079 |
cfc707f7
|
Scott Ullrich
|
|
1080 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
1081 |
|
|
|
1082 |
0311dbd5
|
Scott Ullrich
|
/* generate dhclient_wan.conf */
|
1083 |
|
|
$fd = fopen("{$g['varetc_path']}/dhclient_wan.conf", "w");
|
1084 |
5b237745
|
Scott Ullrich
|
if (!$fd) {
|
1085 |
0311dbd5
|
Scott Ullrich
|
printf("Error: cannot open dhclient_wan.conf in interfaces_wan_dhcp_configure() for writing.\n");
|
1086 |
5b237745
|
Scott Ullrich
|
return 1;
|
1087 |
|
|
}
|
1088 |
eb772abd
|
Scott Ullrich
|
|
1089 |
2305d4c5
|
Scott Ullrich
|
if ($wancfg['dhcphostname']) {
|
1090 |
|
|
$dhclientconf_hostname = "send dhcp-client-identifier \"{$wancfg['dhcphostname']}\";\n";
|
1091 |
|
|
$dhclientconf_hostname .= "\tsend host-name \"{$wancfg['dhcphostname']}\";\n";
|
1092 |
|
|
} else {
|
1093 |
|
|
$dhclientconf_hostname = "";
|
1094 |
|
|
}
|
1095 |
|
|
|
1096 |
5b237745
|
Scott Ullrich
|
$dhclientconf = "";
|
1097 |
cfc707f7
|
Scott Ullrich
|
|
1098 |
6d76590c
|
Scott Ullrich
|
$dhclientconf .= <<<EOD
|
1099 |
d19cc554
|
Scott Ullrich
|
interface "{$wancfg['if']}" {
|
1100 |
ce69a638
|
Scott Ullrich
|
timeout 1200;
|
1101 |
|
|
retry 1;
|
1102 |
|
|
select-timeout 0;
|
1103 |
|
|
initial-interval 1;
|
1104 |
2305d4c5
|
Scott Ullrich
|
{$dhclientconf_hostname}
|
1105 |
|
|
script "/sbin/dhclient-script";
|
1106 |
5b237745
|
Scott Ullrich
|
}
|
1107 |
|
|
|
1108 |
|
|
EOD;
|
1109 |
|
|
|
1110 |
bc40d758
|
Seth Mos
|
if(is_ipaddr($wancfg['alias-address'])) {
|
1111 |
|
|
$subnetmask = gen_subnet_mask($wancfg['alias-subnet']);
|
1112 |
|
|
$dhclientconf .= <<<EOD
|
1113 |
|
|
alias {
|
1114 |
|
|
interface "{$wancfg['if']}";
|
1115 |
|
|
fixed-address {$wancfg['alias-address']};
|
1116 |
|
|
option subnet-mask {$subnetmask};
|
1117 |
|
|
}
|
1118 |
|
|
|
1119 |
|
|
EOD;
|
1120 |
|
|
}
|
1121 |
5b237745
|
Scott Ullrich
|
fwrite($fd, $dhclientconf);
|
1122 |
|
|
fclose($fd);
|
1123 |
eb772abd
|
Scott Ullrich
|
|
1124 |
0521b82d
|
Scott Ullrich
|
$wanif = $wancfg['if'];
|
1125 |
eb772abd
|
Scott Ullrich
|
|
1126 |
eacc8c14
|
Scott Ullrich
|
/* bring wan interface up before starting dhclient */
|
1127 |
0521b82d
|
Scott Ullrich
|
mwexec("/sbin/ifconfig {$wanif} up");
|
1128 |
eacc8c14
|
Scott Ullrich
|
|
1129 |
0521b82d
|
Scott Ullrich
|
/* fire up dhclient */
|
1130 |
2305d4c5
|
Scott Ullrich
|
mwexec("/sbin/dhclient -c {$g['varetc_path']}/dhclient_wan.conf {$wanif} >/tmp/{$wanif}_output >/tmp/{$wanif}_error_output");
|
1131 |
cfc707f7
|
Scott Ullrich
|
|
1132 |
fdca0ea8
|
Scott Ullrich
|
$fout = fopen("/tmp/ifconfig_{$wanif}","w");
|
1133 |
2305d4c5
|
Scott Ullrich
|
fwrite($fout, "/sbin/dhclient -c {$g['varetc_path']}/dhclient_wan.conf {$wanif}");
|
1134 |
0119d2f7
|
Scott Ullrich
|
fclose($fout);
|
1135 |
|
|
|
1136 |
5b237745
|
Scott Ullrich
|
return 0;
|
1137 |
|
|
}
|
1138 |
|
|
|
1139 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_dhcp_down() {
|
1140 |
2305d4c5
|
Scott Ullrich
|
global $config;
|
1141 |
|
|
$wancfg = $config['interfaces']['wan'];
|
1142 |
|
|
$wanif = $wancfg['if'];
|
1143 |
|
|
mwexec("/sbin/ifconfig {$wanif} delete");
|
1144 |
|
|
sleep(1);
|
1145 |
a23d7248
|
Scott Ullrich
|
}
|
1146 |
|
|
|
1147 |
468cee8d
|
Scott Ullrich
|
function interfaces_dhcp_down($interface) {
|
1148 |
2305d4c5
|
Scott Ullrich
|
global $config;
|
1149 |
|
|
if(filter_translate_type_to_real_interface($interface) <> "")
|
1150 |
|
|
$realinterface = filter_translate_type_to_real_interface($interface);
|
1151 |
|
|
mwexec("/sbin/ifconfig {$realinterface} down");
|
1152 |
|
|
sleep(1);
|
1153 |
|
|
$pid = find_dhclient_process($interface);
|
1154 |
|
|
if($pid)
|
1155 |
|
|
mwexec("kill {$pid}");
|
1156 |
468cee8d
|
Scott Ullrich
|
}
|
1157 |
|
|
|
1158 |
8c3e8725
|
Scott Ullrich
|
function interfaces_dhcp_up($interface) {
|
1159 |
|
|
interfaces_dhcp_configure($interface);
|
1160 |
|
|
sleep(1);
|
1161 |
|
|
}
|
1162 |
|
|
|
1163 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_dhcp_up() {
|
1164 |
|
|
interfaces_wan_dhcp_configure();
|
1165 |
8551d2ef
|
Scott Ullrich
|
sleep(1);
|
1166 |
a23d7248
|
Scott Ullrich
|
}
|
1167 |
|
|
|
1168 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_pppoe_configure() {
|
1169 |
|
|
global $config, $g;
|
1170 |
cfc707f7
|
Scott Ullrich
|
|
1171 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
1172 |
|
|
$pppoecfg = $config['pppoe'];
|
1173 |
cfc707f7
|
Scott Ullrich
|
|
1174 |
5b237745
|
Scott Ullrich
|
/* generate mpd.conf */
|
1175 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
|
1176 |
|
|
if (!$fd) {
|
1177 |
|
|
printf("Error: cannot open mpd.conf in interfaces_wan_pppoe_configure().\n");
|
1178 |
|
|
return 1;
|
1179 |
|
|
}
|
1180 |
cfc707f7
|
Scott Ullrich
|
|
1181 |
5b237745
|
Scott Ullrich
|
$idle = 0;
|
1182 |
cfc707f7
|
Scott Ullrich
|
|
1183 |
5b237745
|
Scott Ullrich
|
if (isset($pppoecfg['ondemand'])) {
|
1184 |
|
|
$ondemand = "enable";
|
1185 |
|
|
if ($pppoecfg['timeout'])
|
1186 |
|
|
$idle = $pppoecfg['timeout'];
|
1187 |
|
|
} else {
|
1188 |
|
|
$ondemand = "disable";
|
1189 |
|
|
}
|
1190 |
cfc707f7
|
Scott Ullrich
|
|
1191 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
1192 |
07cae4b2
|
Scott Ullrich
|
startup:
|
1193 |
|
|
pppoeclient:
|
1194 |
|
|
new -i ng0 pppoeclient pppoeclient
|
1195 |
5b237745
|
Scott Ullrich
|
set iface route default
|
1196 |
|
|
set iface {$ondemand} on-demand
|
1197 |
|
|
set iface idle {$idle}
|
1198 |
|
|
set iface up-script /usr/local/sbin/ppp-linkup
|
1199 |
cc936773
|
Scott Ullrich
|
|
1200 |
5b237745
|
Scott Ullrich
|
EOD;
|
1201 |
389741e5
|
Scott Ullrich
|
|
1202 |
|
|
/* Check for ppp-linkdown Script in /usr/local/sbin
|
1203 |
|
|
* Create reference in mpd.conf
|
1204 |
|
|
*/
|
1205 |
|
|
if ( file_exists("/usr/local/sbin/ppp-linkdown") ){
|
1206 |
|
|
$mpdconf .= <<<EOD
|
1207 |
|
|
set iface down-script /usr/local/sbin/ppp-linkdown
|
1208 |
|
|
|
1209 |
|
|
EOD;
|
1210 |
|
|
}
|
1211 |
|
|
|
1212 |
5b237745
|
Scott Ullrich
|
if (isset($pppoecfg['ondemand'])) {
|
1213 |
41404ef1
|
Scott Ullrich
|
if (isset($pppoecfg['local-ip']) && isset($pppoecfg['remote-ip'])) {
|
1214 |
|
|
$mpdconf .= <<<EOD
|
1215 |
|
|
set iface addrs {$pppoecfg['local-ip']} {$pppoecfg['remote-ip']}
|
1216 |
5b237745
|
Scott Ullrich
|
|
1217 |
|
|
EOD;
|
1218 |
41404ef1
|
Scott Ullrich
|
} else {
|
1219 |
|
|
$mpdconf .= <<<EOD
|
1220 |
|
|
set iface addrs 192.0.2.112 192.0.2.113
|
1221 |
|
|
|
1222 |
|
|
EOD;
|
1223 |
|
|
}
|
1224 |
5b237745
|
Scott Ullrich
|
}
|
1225 |
cfc707f7
|
Scott Ullrich
|
|
1226 |
5b237745
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
1227 |
|
|
set bundle disable multilink
|
1228 |
07cae4b2
|
Scott Ullrich
|
set auth authname "{$pppoecfg['username']}"
|
1229 |
|
|
set auth password "{$pppoecfg['password']}"
|
1230 |
5b237745
|
Scott Ullrich
|
set link keep-alive 10 60
|
1231 |
|
|
set link max-redial 0
|
1232 |
|
|
set link no acfcomp protocomp
|
1233 |
|
|
set link disable pap chap
|
1234 |
|
|
set link accept chap
|
1235 |
|
|
set link mtu 1492
|
1236 |
|
|
set ipcp yes vjcomp
|
1237 |
|
|
set ipcp ranges 0.0.0.0/0 0.0.0.0/0
|
1238 |
a23d7248
|
Scott Ullrich
|
|
1239 |
07cae4b2
|
Scott Ullrich
|
|
1240 |
|
|
|
1241 |
a23d7248
|
Scott Ullrich
|
EOD;
|
1242 |
|
|
|
1243 |
|
|
if (isset($config['system']['dnsallowoverride'])) {
|
1244 |
|
|
$mpdconf .= <<<EOD
|
1245 |
5b237745
|
Scott Ullrich
|
set ipcp enable req-pri-dns
|
1246 |
a23d7248
|
Scott Ullrich
|
|
1247 |
|
|
EOD;
|
1248 |
|
|
}
|
1249 |
a0ff9696
|
Scott Ullrich
|
|
1250 |
98e392c5
|
Scott Ullrich
|
if (!isset($config['pppoe']['dnsnosec'])) {
|
1251 |
|
|
$mpdconf .= <<<EOD
|
1252 |
|
|
set ipcp enable req-sec-dns
|
1253 |
|
|
|
1254 |
|
|
EOD;
|
1255 |
|
|
}
|
1256 |
|
|
|
1257 |
a23d7248
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
1258 |
07cae4b2
|
Scott Ullrich
|
open
|
1259 |
5b237745
|
Scott Ullrich
|
|
1260 |
|
|
EOD;
|
1261 |
|
|
|
1262 |
|
|
fwrite($fd, $mpdconf);
|
1263 |
|
|
fclose($fd);
|
1264 |
cfc707f7
|
Scott Ullrich
|
|
1265 |
5b237745
|
Scott Ullrich
|
/* generate mpd.links */
|
1266 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
|
1267 |
|
|
if (!$fd) {
|
1268 |
|
|
printf("Error: cannot open mpd.links in interfaces_wan_pppoe_configure().\n");
|
1269 |
|
|
return 1;
|
1270 |
|
|
}
|
1271 |
cfc707f7
|
Scott Ullrich
|
|
1272 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
1273 |
07cae4b2
|
Scott Ullrich
|
pppoeclient:
|
1274 |
5b237745
|
Scott Ullrich
|
set link type pppoe
|
1275 |
|
|
set pppoe iface {$wancfg['if']}
|
1276 |
|
|
set pppoe service "{$pppoecfg['provider']}"
|
1277 |
|
|
set pppoe enable originate
|
1278 |
|
|
set pppoe disable incoming
|
1279 |
|
|
|
1280 |
|
|
EOD;
|
1281 |
|
|
|
1282 |
|
|
fwrite($fd, $mpdconf);
|
1283 |
|
|
fclose($fd);
|
1284 |
eb772abd
|
Scott Ullrich
|
|
1285 |
07cae4b2
|
Scott Ullrich
|
if(file_exists("{$g['varrun_path']}/mpdpppoe.pid") and $g['booting']) {
|
1286 |
d7a6517a
|
Scott Ullrich
|
/* if we are booting and mpd has already been started then don't start again. */
|
1287 |
|
|
} else {
|
1288 |
|
|
/* if mpd is active, lets take it down */
|
1289 |
07cae4b2
|
Scott Ullrich
|
if(file_exists("{$g['varrun_path']}/mpdpppoe.pid")) {
|
1290 |
|
|
killbypid("{$g['varrun_path']}/mpdpppoe.pid");
|
1291 |
d7a6517a
|
Scott Ullrich
|
sleep(3);
|
1292 |
|
|
}
|
1293 |
eb772abd
|
Scott Ullrich
|
/* fire up mpd */
|
1294 |
07cae4b2
|
Scott Ullrich
|
mwexec("/usr/local/sbin/mpd4 -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpdpppoe.pid pppoeclient");
|
1295 |
ec11a1ad
|
Scott Ullrich
|
}
|
1296 |
|
|
|
1297 |
a205d904
|
Scott Ullrich
|
/* sleep until wan is up - or 30 seconds, whichever comes first */
|
1298 |
|
|
for ($count = 0; $count < 30; $count++) {
|
1299 |
|
|
if(file_exists("{$g['tmp_path']}/wanup")) {
|
1300 |
|
|
break;
|
1301 |
|
|
}
|
1302 |
|
|
sleep(1);
|
1303 |
|
|
}
|
1304 |
d7a6517a
|
Scott Ullrich
|
|
1305 |
a205d904
|
Scott Ullrich
|
unlink_if_exists("{$g['tmp_path']}/wanup");
|
1306 |
e1c8cdf5
|
Scott Ullrich
|
|
1307 |
5b237745
|
Scott Ullrich
|
return 0;
|
1308 |
|
|
}
|
1309 |
|
|
|
1310 |
58af5941
|
Scott Ullrich
|
function interfaces_wan_pppoe_restart() {
|
1311 |
|
|
interfaces_wan_pppoe_down();
|
1312 |
|
|
sleep(1);
|
1313 |
|
|
interfaces_wan_pppoe_up();
|
1314 |
|
|
}
|
1315 |
|
|
|
1316 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_pppoe_down() {
|
1317 |
|
|
global $g;
|
1318 |
07cae4b2
|
Scott Ullrich
|
sigkillbypid("{$g['varrun_path']}/mpdpppoe.pid", "SIGUSR2");
|
1319 |
8551d2ef
|
Scott Ullrich
|
sleep(1);
|
1320 |
a23d7248
|
Scott Ullrich
|
}
|
1321 |
|
|
|
1322 |
|
|
function interfaces_wan_pppoe_up() {
|
1323 |
|
|
global $g;
|
1324 |
07cae4b2
|
Scott Ullrich
|
sigkillbypid("{$g['varrun_path']}/mpdpppoe.pid", "SIGUSR1");
|
1325 |
8551d2ef
|
Scott Ullrich
|
sleep(1);
|
1326 |
a23d7248
|
Scott Ullrich
|
}
|
1327 |
|
|
|
1328 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_pptp_configure() {
|
1329 |
|
|
global $config, $g;
|
1330 |
cfc707f7
|
Scott Ullrich
|
|
1331 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
1332 |
|
|
$pptpcfg = $config['pptp'];
|
1333 |
cfc707f7
|
Scott Ullrich
|
|
1334 |
5b237745
|
Scott Ullrich
|
/* generate mpd.conf */
|
1335 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
|
1336 |
|
|
if (!$fd) {
|
1337 |
|
|
printf("Error: cannot open mpd.conf in interfaces_wan_pptp_configure().\n");
|
1338 |
|
|
return 1;
|
1339 |
|
|
}
|
1340 |
cfc707f7
|
Scott Ullrich
|
|
1341 |
5b237745
|
Scott Ullrich
|
$idle = 0;
|
1342 |
cfc707f7
|
Scott Ullrich
|
|
1343 |
5b237745
|
Scott Ullrich
|
if (isset($pptpcfg['ondemand'])) {
|
1344 |
|
|
$ondemand = "enable";
|
1345 |
|
|
if ($pptpcfg['timeout'])
|
1346 |
|
|
$idle = $pptpcfg['timeout'];
|
1347 |
|
|
} else {
|
1348 |
|
|
$ondemand = "disable";
|
1349 |
|
|
}
|
1350 |
cfc707f7
|
Scott Ullrich
|
|
1351 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
1352 |
|
|
pptp:
|
1353 |
|
|
new -i ng0 pptp pptp
|
1354 |
|
|
set iface route default
|
1355 |
|
|
set iface {$ondemand} on-demand
|
1356 |
|
|
set iface idle {$idle}
|
1357 |
|
|
set iface up-script /usr/local/sbin/ppp-linkup
|
1358 |
|
|
|
1359 |
|
|
EOD;
|
1360 |
cfc707f7
|
Scott Ullrich
|
|
1361 |
389741e5
|
Scott Ullrich
|
/* Check for ppp-linkdown Script in /usr/local/sbin
|
1362 |
|
|
* Create reference in mpd.conf
|
1363 |
|
|
*/
|
1364 |
|
|
if ( file_exists("/usr/local/sbin/ppp-linkdown") ){
|
1365 |
|
|
$mpdconf .= <<<EOD
|
1366 |
|
|
set iface down-script /usr/local/sbin/ppp-linkdown
|
1367 |
|
|
|
1368 |
|
|
EOD;
|
1369 |
|
|
}
|
1370 |
|
|
|
1371 |
5b237745
|
Scott Ullrich
|
if (isset($pptpcfg['ondemand'])) {
|
1372 |
|
|
$mpdconf .= <<<EOD
|
1373 |
a23d7248
|
Scott Ullrich
|
set iface addrs 10.0.0.1 10.0.0.2
|
1374 |
5b237745
|
Scott Ullrich
|
|
1375 |
|
|
EOD;
|
1376 |
|
|
}
|
1377 |
cfc707f7
|
Scott Ullrich
|
|
1378 |
5b237745
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
1379 |
|
|
set bundle disable multilink
|
1380 |
|
|
set bundle authname "{$pptpcfg['username']}"
|
1381 |
|
|
set bundle password "{$pptpcfg['password']}"
|
1382 |
|
|
set link keep-alive 10 60
|
1383 |
|
|
set link max-redial 0
|
1384 |
|
|
set link no acfcomp protocomp
|
1385 |
|
|
set link disable pap chap
|
1386 |
|
|
set link accept chap
|
1387 |
|
|
set ipcp no vjcomp
|
1388 |
|
|
set ipcp ranges 0.0.0.0/0 0.0.0.0/0
|
1389 |
a23d7248
|
Scott Ullrich
|
|
1390 |
|
|
EOD;
|
1391 |
|
|
if (isset($config['system']['dnsallowoverride'])) {
|
1392 |
|
|
$mpdconf .= <<<EOD
|
1393 |
5b237745
|
Scott Ullrich
|
set ipcp enable req-pri-dns
|
1394 |
a23d7248
|
Scott Ullrich
|
|
1395 |
|
|
EOD;
|
1396 |
|
|
}
|
1397 |
a0ff9696
|
Scott Ullrich
|
|
1398 |
a23d7248
|
Scott Ullrich
|
$mpdconf .= <<<EOD
|
1399 |
5b237745
|
Scott Ullrich
|
open
|
1400 |
|
|
|
1401 |
|
|
EOD;
|
1402 |
|
|
|
1403 |
|
|
fwrite($fd, $mpdconf);
|
1404 |
|
|
fclose($fd);
|
1405 |
cfc707f7
|
Scott Ullrich
|
|
1406 |
5b237745
|
Scott Ullrich
|
/* generate mpd.links */
|
1407 |
|
|
$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
|
1408 |
|
|
if (!$fd) {
|
1409 |
|
|
printf("Error: cannot open mpd.links in interfaces_wan_pptp_configure().\n");
|
1410 |
|
|
return 1;
|
1411 |
|
|
}
|
1412 |
cfc707f7
|
Scott Ullrich
|
|
1413 |
5b237745
|
Scott Ullrich
|
$mpdconf = <<<EOD
|
1414 |
|
|
pptp:
|
1415 |
|
|
set link type pptp
|
1416 |
|
|
set pptp enable originate outcall
|
1417 |
|
|
set pptp disable windowing
|
1418 |
|
|
set pptp self {$pptpcfg['local']}
|
1419 |
|
|
set pptp peer {$pptpcfg['remote']}
|
1420 |
|
|
|
1421 |
|
|
EOD;
|
1422 |
|
|
|
1423 |
|
|
fwrite($fd, $mpdconf);
|
1424 |
|
|
fclose($fd);
|
1425 |
cfc707f7
|
Scott Ullrich
|
|
1426 |
5b237745
|
Scott Ullrich
|
/* configure interface */
|
1427 |
cfc707f7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
|
1428 |
5b237745
|
Scott Ullrich
|
escapeshellarg($pptpcfg['local'] . "/" . $pptpcfg['subnet']));
|
1429 |
cfc707f7
|
Scott Ullrich
|
|
1430 |
5b237745
|
Scott Ullrich
|
/* fire up mpd */
|
1431 |
|
|
mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pptp");
|
1432 |
cfc707f7
|
Scott Ullrich
|
|
1433 |
5b237745
|
Scott Ullrich
|
return 0;
|
1434 |
|
|
}
|
1435 |
|
|
|
1436 |
58af5941
|
Scott Ullrich
|
function interfaces_wan_pptp_restart() {
|
1437 |
|
|
interfaces_wan_pptp_down();
|
1438 |
|
|
sleep(1);
|
1439 |
|
|
interfaces_wan_pptp_up();
|
1440 |
|
|
}
|
1441 |
|
|
|
1442 |
a23d7248
|
Scott Ullrich
|
function interfaces_wan_pptp_down() {
|
1443 |
|
|
global $g;
|
1444 |
|
|
sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
|
1445 |
8551d2ef
|
Scott Ullrich
|
sleep(1);
|
1446 |
a23d7248
|
Scott Ullrich
|
}
|
1447 |
|
|
|
1448 |
|
|
function interfaces_wan_pptp_up() {
|
1449 |
|
|
global $g;
|
1450 |
|
|
sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
|
1451 |
8551d2ef
|
Scott Ullrich
|
sleep(1);
|
1452 |
a23d7248
|
Scott Ullrich
|
}
|
1453 |
|
|
|
1454 |
5b237745
|
Scott Ullrich
|
function interfaces_wan_bigpond_configure($curwanip) {
|
1455 |
|
|
global $config, $g;
|
1456 |
cfc707f7
|
Scott Ullrich
|
|
1457 |
5b237745
|
Scott Ullrich
|
$bpcfg = $config['bigpond'];
|
1458 |
cfc707f7
|
Scott Ullrich
|
|
1459 |
5b237745
|
Scott Ullrich
|
if (!$curwanip) {
|
1460 |
|
|
/* IP address not configured yet, exit */
|
1461 |
|
|
return 0;
|
1462 |
|
|
}
|
1463 |
cfc707f7
|
Scott Ullrich
|
|
1464 |
5b237745
|
Scott Ullrich
|
/* kill bpalogin */
|
1465 |
|
|
killbyname("bpalogin");
|
1466 |
cfc707f7
|
Scott Ullrich
|
|
1467 |
5b237745
|
Scott Ullrich
|
/* wait a moment */
|
1468 |
|
|
sleep(1);
|
1469 |
cfc707f7
|
Scott Ullrich
|
|
1470 |
5b237745
|
Scott Ullrich
|
/* get the default domain */
|
1471 |
|
|
$nfd = @fopen("{$g['varetc_path']}/defaultdomain.conf", "r");
|
1472 |
|
|
if ($nfd) {
|
1473 |
|
|
$defaultdomain = trim(fgets($nfd));
|
1474 |
|
|
fclose($nfd);
|
1475 |
|
|
}
|
1476 |
cfc707f7
|
Scott Ullrich
|
|
1477 |
5b237745
|
Scott Ullrich
|
/* generate bpalogin.conf */
|
1478 |
|
|
$fd = fopen("{$g['varetc_path']}/bpalogin.conf", "w");
|
1479 |
|
|
if (!$fd) {
|
1480 |
|
|
printf("Error: cannot open bpalogin.conf in interfaces_wan_bigpond_configure().\n");
|
1481 |
|
|
return 1;
|
1482 |
|
|
}
|
1483 |
cfc707f7
|
Scott Ullrich
|
|
1484 |
5b237745
|
Scott Ullrich
|
if (!$bpcfg['authserver'])
|
1485 |
|
|
$bpcfg['authserver'] = "dce-server";
|
1486 |
|
|
if (!$bpcfg['authdomain'])
|
1487 |
|
|
$bpcfg['authdomain'] = $defaultdomain;
|
1488 |
cfc707f7
|
Scott Ullrich
|
|
1489 |
5b237745
|
Scott Ullrich
|
$bpconf = <<<EOD
|
1490 |
|
|
username {$bpcfg['username']}
|
1491 |
|
|
password {$bpcfg['password']}
|
1492 |
|
|
authserver {$bpcfg['authserver']}
|
1493 |
|
|
authdomain {$bpcfg['authdomain']}
|
1494 |
|
|
localport 5050
|
1495 |
|
|
|
1496 |
|
|
EOD;
|
1497 |
|
|
|
1498 |
|
|
if ($bpcfg['minheartbeatinterval'])
|
1499 |
|
|
$bpconf .= "minheartbeatinterval {$bpcfg['minheartbeatinterval']}\n";
|
1500 |
|
|
|
1501 |
|
|
fwrite($fd, $bpconf);
|
1502 |
|
|
fclose($fd);
|
1503 |
cfc707f7
|
Scott Ullrich
|
|
1504 |
5b237745
|
Scott Ullrich
|
/* fire up bpalogin */
|
1505 |
|
|
mwexec("/usr/local/sbin/bpalogin -c {$g['varetc_path']}/bpalogin.conf");
|
1506 |
cfc707f7
|
Scott Ullrich
|
|
1507 |
5b237745
|
Scott Ullrich
|
return 0;
|
1508 |
|
|
}
|
1509 |
|
|
|
1510 |
|
|
function get_real_wan_interface() {
|
1511 |
|
|
global $config, $g;
|
1512 |
cfc707f7
|
Scott Ullrich
|
|
1513 |
5b237745
|
Scott Ullrich
|
$wancfg = $config['interfaces']['wan'];
|
1514 |
cfc707f7
|
Scott Ullrich
|
|
1515 |
5b237745
|
Scott Ullrich
|
$wanif = $wancfg['if'];
|
1516 |
|
|
if (($wancfg['ipaddr'] == "pppoe") || ($wancfg['ipaddr'] == "pptp")) {
|
1517 |
|
|
$wanif = $g['pppoe_interface'];
|
1518 |
|
|
}
|
1519 |
cfc707f7
|
Scott Ullrich
|
|
1520 |
5b237745
|
Scott Ullrich
|
return $wanif;
|
1521 |
|
|
}
|
1522 |
|
|
|
1523 |
1675c73f
|
Scott Ullrich
|
function get_current_wan_address($interface = "wan") {
|
1524 |
5b237745
|
Scott Ullrich
|
global $config, $g;
|
1525 |
cfc707f7
|
Scott Ullrich
|
|
1526 |
1675c73f
|
Scott Ullrich
|
$wancfg = $config['interfaces'][$interface];
|
1527 |
cfc707f7
|
Scott Ullrich
|
|
1528 |
a8a7325e
|
Scott Ullrich
|
$interface = filter_translate_type_to_real_interface($interface);
|
1529 |
767a716e
|
Scott Ullrich
|
$ifinfo = "";
|
1530 |
bc76c771
|
Scott Ullrich
|
if(in_array($wancfg['ipaddr'], array('dhcp'))) {
|
1531 |
|
|
/* get interface info with netstat */
|
1532 |
|
|
exec("/usr/bin/netstat -nWI " . escapeshellarg($interface) . " -f inet", $ifinfo);
|
1533 |
|
|
|
1534 |
|
|
if (isset($ifinfo[1])) {
|
1535 |
|
|
$aif = preg_split("/\s+/", $ifinfo[1]);
|
1536 |
|
|
$curwanip = chop($aif[3]);
|
1537 |
|
|
|
1538 |
|
|
if ($curwanip && is_ipaddr($curwanip) && ($curwanip != "0.0.0.0"))
|
1539 |
|
|
return $curwanip;
|
1540 |
|
|
}
|
1541 |
|
|
|
1542 |
eb772abd
|
Scott Ullrich
|
return null;
|
1543 |
bc76c771
|
Scott Ullrich
|
} else if (in_array($wancfg['ipaddr'], array('pppoe','pptp','bigpond'))) {
|
1544 |
5b237745
|
Scott Ullrich
|
/* dynamic WAN IP address, find out which one */
|
1545 |
|
|
$wanif = get_real_wan_interface();
|
1546 |
cfc707f7
|
Scott Ullrich
|
|
1547 |
5b237745
|
Scott Ullrich
|
/* get interface info with netstat */
|
1548 |
|
|
exec("/usr/bin/netstat -nWI " . escapeshellarg($wanif) . " -f inet", $ifinfo);
|
1549 |
cfc707f7
|
Scott Ullrich
|
|
1550 |
5b237745
|
Scott Ullrich
|
if (isset($ifinfo[1])) {
|
1551 |
|
|
$aif = preg_split("/\s+/", $ifinfo[1]);
|
1552 |
|
|
$curwanip = chop($aif[3]);
|
1553 |
cfc707f7
|
Scott Ullrich
|
|
1554 |
5b237745
|
Scott Ullrich
|
if ($curwanip && is_ipaddr($curwanip) && ($curwanip != "0.0.0.0"))
|
1555 |
|
|
return $curwanip;
|
1556 |
|
|
}
|
1557 |
cfc707f7
|
Scott Ullrich
|
|
1558 |
5b237745
|
Scott Ullrich
|
return null;
|
1559 |
|
|
} else {
|
1560 |
|
|
/* static WAN IP address */
|
1561 |
|
|
return $wancfg['ipaddr'];
|
1562 |
|
|
}
|
1563 |
|
|
}
|
1564 |
|
|
|
1565 |
a57b119e
|
Bill Marquette
|
/****f* interfaces/is_altq_capable
|
1566 |
|
|
* NAME
|
1567 |
|
|
* is_altq_capable - Test if interface is capable of using ALTQ
|
1568 |
|
|
* INPUTS
|
1569 |
|
|
* $int - string containing interface name
|
1570 |
|
|
* RESULT
|
1571 |
|
|
* boolean - true or false
|
1572 |
|
|
******/
|
1573 |
|
|
|
1574 |
|
|
function is_altq_capable($int) {
|
1575 |
|
|
/* Per:
|
1576 |
|
|
* http://www.freebsd.org/cgi/man.cgi?query=altq&manpath=FreeBSD+6.0-current&format=html
|
1577 |
|
|
* Only the following drivers have ALTQ support
|
1578 |
|
|
*/
|
1579 |
|
|
$capable = array("an", "ath", "awi", "bfe", "bge", "dc", "de", "ed",
|
1580 |
4b31e652
|
Scott Ullrich
|
"em", "fxp", "hme", "lnc", "le", "nve", "re", "rl", "ndis", "sf", "sis", "sk",
|
1581 |
a262450f
|
Scott Ullrich
|
"tun", "vr", "wi", "xl", "vlan", "ste");
|
1582 |
a57b119e
|
Bill Marquette
|
|
1583 |
|
|
$int_family = preg_split("/[0-9]+/", $int);
|
1584 |
|
|
|
1585 |
|
|
if (in_array($int_family[0], $capable))
|
1586 |
|
|
return true;
|
1587 |
|
|
else
|
1588 |
|
|
return false;
|
1589 |
|
|
}
|
1590 |
|
|
|
1591 |
015bb1cc
|
Scott Ullrich
|
function get_number_of_bridged_interfaces() {
|
1592 |
ce33da32
|
Scott Ullrich
|
$bridges_total = 0;
|
1593 |
|
|
$bridges = split("\n", `/sbin/ifconfig -a | /usr/bin/grep bridge | grep flags`);
|
1594 |
|
|
foreach($bridges as $bridge) {
|
1595 |
767a716e
|
Scott Ullrich
|
$match_array = "";
|
1596 |
ce33da32
|
Scott Ullrich
|
preg_match_all("/bridge(.*):/",$bridge,$match_array);
|
1597 |
7370613f
|
Scott Ullrich
|
if($match_array[1][0] <> "") {
|
1598 |
|
|
if($match_array[1][0] > $bridges_total)
|
1599 |
|
|
$bridges_total = $match_array[1][0];
|
1600 |
|
|
}
|
1601 |
ce33da32
|
Scott Ullrich
|
}
|
1602 |
|
|
return "{$bridges_total}";
|
1603 |
015bb1cc
|
Scott Ullrich
|
}
|
1604 |
|
|
|
1605 |
161040eb
|
Scott Ullrich
|
function get_number_of_vlan_interfaces() {
|
1606 |
|
|
$vlans_total = 0;
|
1607 |
|
|
$vlans = split("\n", `/sbin/ifconfig -a | /usr/bin/grep vlan | grep flags`);
|
1608 |
|
|
foreach($vlans as $bridge) {
|
1609 |
|
|
$match_array = "";
|
1610 |
|
|
preg_match_all("/vlan(.*):/",$bridge,$match_array);
|
1611 |
|
|
if($match_array[1][0] <> "") {
|
1612 |
|
|
if($match_array[1][0] > $vlans_total)
|
1613 |
|
|
$vlans_total = $match_array[1][0];
|
1614 |
|
|
}
|
1615 |
|
|
}
|
1616 |
|
|
return "{$vlans_total}";
|
1617 |
|
|
}
|
1618 |
|
|
|
1619 |
015bb1cc
|
Scott Ullrich
|
function get_next_available_bridge_interface() {
|
1620 |
38a3e74e
|
Scott Ullrich
|
$bridges_total = get_number_of_bridged_interfaces();
|
1621 |
0d429e43
|
Scott Ullrich
|
$interfaces = `/sbin/ifconfig -l`;
|
1622 |
26eb3795
|
Scott Ullrich
|
$x=0;
|
1623 |
f78d2412
|
Scott Ullrich
|
for($x=0; $x<$bridges_total; $x++) {
|
1624 |
0d429e43
|
Scott Ullrich
|
if(!stristr($interfaces, "bridge{$x}")) {
|
1625 |
|
|
return "{$x}";
|
1626 |
dba4049f
|
Scott Ullrich
|
}
|
1627 |
015bb1cc
|
Scott Ullrich
|
}
|
1628 |
0d429e43
|
Scott Ullrich
|
return "{$x}";
|
1629 |
015bb1cc
|
Scott Ullrich
|
}
|
1630 |
|
|
|
1631 |
ba0e11c7
|
Scott Ullrich
|
function destroy_bridge($bridge_num) {
|
1632 |
e2f56f0d
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridge_num} down");
|
1633 |
f9118d49
|
Scott Ullrich
|
sleep(1);
|
1634 |
ba0e11c7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridge_num} delete");
|
1635 |
0d429e43
|
Scott Ullrich
|
sleep(1);
|
1636 |
ba0e11c7
|
Scott Ullrich
|
mwexec("/sbin/ifconfig bridge{$bridge_num} destroy");
|
1637 |
f9118d49
|
Scott Ullrich
|
sleep(1);
|
1638 |
ba0e11c7
|
Scott Ullrich
|
return;
|
1639 |
|
|
}
|
1640 |
|
|
|
1641 |
|
|
function discover_bridge($interface1, $interface2) {
|
1642 |
7370613f
|
Scott Ullrich
|
if(!$interface1) return;
|
1643 |
|
|
if(!$interface2) return;
|
1644 |
ba0e11c7
|
Scott Ullrich
|
$total_bridges = get_number_of_bridged_interfaces();
|
1645 |
51e4bb37
|
Scott Ullrich
|
$total_bridges++;
|
1646 |
4f9a78d9
|
Scott Ullrich
|
$interfaces = `/sbin/ifconfig -l`;
|
1647 |
26eb3795
|
Scott Ullrich
|
$x=0;
|
1648 |
ba0e11c7
|
Scott Ullrich
|
for($x=0; $x<$total_bridges; $x++) {
|
1649 |
4f9a78d9
|
Scott Ullrich
|
$bridge_text = "NA";
|
1650 |
eb772abd
|
Scott Ullrich
|
if(!stristr($interfaces, "bridge{$x}"))
|
1651 |
7370613f
|
Scott Ullrich
|
continue;
|
1652 |
|
|
$bridge_text = `/sbin/ifconfig bridge{$x} | grep member`;
|
1653 |
51e4bb37
|
Scott Ullrich
|
if(stristr($bridge_text, $interface1))
|
1654 |
|
|
if(stristr($bridge_text, $interface2))
|
1655 |
|
|
return $x;
|
1656 |
ba0e11c7
|
Scott Ullrich
|
}
|
1657 |
0d429e43
|
Scott Ullrich
|
return "-1";
|
1658 |
ba0e11c7
|
Scott Ullrich
|
}
|
1659 |
a57b119e
|
Bill Marquette
|
|
1660 |
d8c67d69
|
Scott Ullrich
|
function get_wireless_modes($interface)
|
1661 |
|
|
{
|
1662 |
|
|
/* return wireless modes and channels */
|
1663 |
|
|
if(is_interface_wireless($interface)) {
|
1664 |
|
|
$wi = 1;
|
1665 |
|
|
$ifconfig = "/sbin/ifconfig";
|
1666 |
|
|
$awk = "/usr/bin/awk";
|
1667 |
|
|
$chan_list = "$ifconfig $interface list chan";
|
1668 |
4066776d
|
Scott Ullrich
|
$stack_list = "$awk -F\"Channel \" '{ gsub(/\\*/, \" \"); print \$2 \"\\\n\" \$3 }'";
|
1669 |
d8c67d69
|
Scott Ullrich
|
$format_list = "$awk '{print \$5 \" \" \$6 \",\" \$1}'";
|
1670 |
|
|
|
1671 |
4b0e71db
|
Scott Ullrich
|
$interface_channels = "";
|
1672 |
d8c67d69
|
Scott Ullrich
|
exec("$chan_list | $stack_list | sort -u | $format_list 2>&1", $interface_channels);
|
1673 |
|
|
$interface_channel_count = count($interface_channels);
|
1674 |
|
|
|
1675 |
|
|
$c = 0;
|
1676 |
|
|
while ($c < $interface_channel_count)
|
1677 |
|
|
{
|
1678 |
|
|
$channel_line = explode(",", $interface_channels["$c"]);
|
1679 |
|
|
$wireless_mode = trim($channel_line[0]);
|
1680 |
|
|
$wireless_channel = trim($channel_line[1]);
|
1681 |
4066776d
|
Scott Ullrich
|
if(trim($wireless_mode) != "") {
|
1682 |
|
|
/* if we only have 11g also set 11b channels */
|
1683 |
|
|
if($wireless_mode == "11g") {
|
1684 |
|
|
$wireless_modes["11b"] = array();
|
1685 |
|
|
}
|
1686 |
|
|
$wireless_modes["$wireless_mode"]["$c"] = $wireless_channel;
|
1687 |
|
|
}
|
1688 |
d8c67d69
|
Scott Ullrich
|
$c++;
|
1689 |
|
|
}
|
1690 |
|
|
}
|
1691 |
4066776d
|
Scott Ullrich
|
return($wireless_modes);
|
1692 |
d8c67d69
|
Scott Ullrich
|
}
|
1693 |
|
|
|
1694 |
b7ec2b9e
|
Scott Ullrich
|
function get_interface_mac($interface) {
|
1695 |
|
|
|
1696 |
|
|
/* build interface list with netstat */
|
1697 |
84e5047d
|
Scott Ullrich
|
$linkinfo = "";
|
1698 |
b7ec2b9e
|
Scott Ullrich
|
exec("/usr/bin/netstat -I $interface -nW -f link", $linkinfo);
|
1699 |
|
|
array_shift($linkinfo);
|
1700 |
|
|
$alink = preg_split("/\s+/", $linkinfo[0]);
|
1701 |
|
|
$mac = chop($alink[3]);
|
1702 |
|
|
return $mac;
|
1703 |
|
|
}
|
1704 |
|
|
|
1705 |
bc40d758
|
Seth Mos
|
?>
|