Project

General

Profile

Download (34.5 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
/* $Id$ */
3
/*
4
	interfaces.inc
5
	Copyright (C) 2004 Scott Ullrich
6
	All rights reserved.
7

    
8
	originally part of m0n0wall (http://m0n0.ch/wall)
9
	Copyright (C) 2003-2004 Manuel Kasper <mk@neon1.net>.
10
	All rights reserved.
11

    
12
	Redistribution and use in source and binary forms, with or without
13
	modification, are permitted provided that the following conditions are met:
14

    
15
	1. Redistributions of source code must retain the above copyright notice,
16
	   this list of conditions and the following disclaimer.
17

    
18
	2. Redistributions in binary form must reproduce the above copyright
19
	   notice, this list of conditions and the following disclaimer in the
20
	   documentation and/or other materials provided with the distribution.
21

    
22
	THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
23
	INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
24
	AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
	AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
26
	OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27
	SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28
	INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29
	CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30
	ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31
	POSSIBILITY OF SUCH DAMAGE.
32
*/
33

    
34
/* include all configuration functions */
35
require_once("functions.inc");
36

    
37
if(!is_numeric($bridges_total)) $bridges_total=0;
38

    
39
function interfaces_loopback_configure() {
40
	mwexec("/sbin/ifconfig lo0 127.0.0.1");
41

    
42
	return 0;
43
}
44

    
45
function interfaces_vlan_configure() {
46
	global $config;
47

    
48
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
49

    
50
		/* devices with native VLAN support */
51
		$vlan_native_supp = explode(" ", "bge em gx nge ti txp");
52

    
53
		/* devices with long frame support */
54
		$vlan_long_supp = explode(" ", "dc fxp sis ste tl tx xl");
55

    
56
		$i = 0;
57

    
58
		foreach ($config['vlans']['vlan'] as $vlan) {
59

    
60
			$cmd = "/sbin/ifconfig vlan{$i} create vlan " .
61
				escapeshellarg($vlan['tag']) . " vlandev " .
62
				escapeshellarg($vlan['if']);
63

    
64
			/* get driver name */
65
			for ($j = 0; $j < strlen($vlan['if']); $j++) {
66
				if ($vlan['if'][$j] >= '0' && $vlan['if'][$j] <= '9')
67
					break;
68
			}
69
			$drvname = substr($vlan['if'], 0, $j);
70

    
71
			if (in_array($drvname, $vlan_native_supp))
72
				$cmd .= " link0";
73
			else if (in_array($drvname, $vlan_long_supp))
74
				$cmd .= " mtu 1500";
75

    
76
			mwexec($cmd);
77

    
78
			/* make sure the parent interface is up */
79
			mwexec("/sbin/ifconfig " . escapeshellarg($vlan['if']) . " up");
80

    
81
			$i++;
82
		}
83
	}
84

    
85
	return 0;
86
}
87

    
88
function interfaces_lan_configure() {
89
	global $config, $g, $bridges_total;
90

    
91
	$lancfg = $config['interfaces']['lan'];
92

    
93
	/* wireless configuration? */
94
	if (is_array($lancfg['wireless']))
95
		interfaces_wireless_configure($lancfg['if'], $lancfg['wireless']);
96

    
97
	/* MAC spoofing? */
98
	if ($lancfg['spoofmac']) {
99
		mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) .
100
			" link " . escapeshellarg($lancfg['spoofmac']));
101
	} else {
102
		$mac = get_interface_mac_address($lancfg['if']);
103
		if($mac == "ff:ff:ff:ff:ff:ff") {
104
			/*   this is not a valid mac address.  generate a
105
			 *   temporary mac address so the machine can get online.
106
			 */
107
			echo "Generating new MAC address.";
108
			$random_mac = generate_random_mac_address();
109
			mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) .
110
				" link " . escapeshellarg($random_mac));
111
			$lancfg['spoofmac'] = $random_mac;
112
			write_config();
113
			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");
114
		}
115
	}	
116

    
117
	/* bridged? */
118
	
119
	if ($lancfg['bridge']) {
120
		// mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) . " delete up");
121
		/* use open/netBSD style bridge */
122
		mwexec("/sbin/ifconfig bridge{$bridges_total} create");
123
		mwexec("/sbin/ifconfig bridge{$bridges_total} addm {$lancfg['if']} addm {$config['interfaces'][$lancfg['bridge']]['if']} up");
124
		mwexec("/sbin/ifconfig bridge{$bridges_total} stp {$lancfg['if']} add {$config['interfaces'][$lancfg['bridge']]['if']}");
125
		
126
		$fd = fopen("{$g['tmp_path']}/bridge_config_{$lancfg['if']}", "w");
127
		fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} create\n");
128
		fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} addm {$lancfg['if']} addm {$config['interfaces'][$lancfg['bridge']]['if']} up\n");
129
		fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} stp {$lancfg['if']} add {$config['interfaces'][$lancfg['bridge']]['if']}\n");
130
		fclose($fd);
131
		
132
		/* lets keep track of the amount of bridges initialized */
133
		$bridges_total++;
134
	}
135
	
136
	/* media */
137
	if ($lancfg['media'] || $lancfg['mediaopt']) {
138
		$cmd = "/sbin/ifconfig " . escapeshellarg($lancfg['if']);
139
		if ($lancfg['media'])
140
			$cmd .= " media " . escapeshellarg($lancfg['media']);
141
		if ($lancfg['mediaopt'])
142
			$cmd .= " mediaopt " . escapeshellarg($lancfg['mediaopt']);
143
		mwexec($cmd);
144
	}
145

    
146
	mwexec("/sbin/ifconfig " . escapeshellarg($lancfg['if']) . " " .
147
		escapeshellarg($lancfg['ipaddr'] . "/" . $lancfg['subnet']));
148

    
149
	if (!$g['booting']) {
150
		/* make new hosts file */
151
		system_hosts_generate();
152

    
153
		/* reconfigure static routes (kernel may have deleted them) */
154
		system_routing_configure();
155

    
156
		/* set the reload filter dity flag */
157
		touch("{$g['tmp_path']}/filter_dirty");
158

    
159
		/* reload IPsec tunnels */
160
		vpn_ipsec_configure();
161

    
162
		/* reload dhcpd (gateway may have changed) */
163
		services_dhcpd_configure();
164

    
165
		/* reload dnsmasq */
166
		services_dnsmasq_configure();
167

    
168
		/* reload webgui */
169
		system_webgui_start();
170

    
171
		/* reload captive portal */
172
		captiveportal_configure();
173
	}
174

    
175
	return 0;
176
}
177

    
178
function interfaces_optional_configure() {
179
	global $config, $g;
180
	global $bridgeconfig;
181

    
182
	/* Reset bridge configuration.	Interfaces will add to it. */
183
	$bridgeconfig = "";
184

    
185
	for ($i = 1; isset($config['interfaces']['opt' . $i]); $i++) {
186
		interfaces_optional_configure_if($i);
187
	}
188

    
189
	if (!$g['booting']) {
190
		/* reconfigure static routes (kernel may have deleted them) */
191
		system_routing_configure();
192

    
193
		/* reload IPsec tunnels */
194
		vpn_ipsec_configure();
195

    
196
		/* reload dhcpd (interface enabled/disabled/bridged status may have changed) */
197
		services_dhcpd_configure();
198

    
199
		/* restart dnsmasq */
200
		services_dnsmasq_configure();
201

    
202
		/* set the reload filter dity flag */
203
		touch("{$g['tmp_path']}/filter_dirty");				
204
	}
205

    
206
	return 0;
207
}
208

    
209
function interfaces_optional_configure_if($opti) {
210
	global $config, $g;
211
	global $bridgeconfig;
212
	global $bridges_total;
213

    
214
	$optcfg = $config['interfaces']['opt' . $opti];
215

    
216
	if ($g['booting']) {
217
		$optdescr = "";
218
		if ($optcfg['descr'])
219
			$optdescr = " ({$optcfg['descr']})";
220
		print "\tOPT{$opti}{$optdescr}... ";
221
		mute_kernel_msgs();
222
	}
223

    
224
	if (isset($optcfg['enable'])) {
225
		/* wireless configuration? */
226
		if (is_array($optcfg['wireless']))
227
			interfaces_wireless_configure($optcfg['if'], $optcfg['wireless']);
228

    
229
		/* MAC spoofing? */
230
		if ($optcfg['spoofmac']) {
231
			mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
232
				" link " . escapeshellarg($optcfg['spoofmac']));
233
		} else {
234
			$mac = get_interface_mac_address($optcfg['if']);
235
			if($mac == "ff:ff:ff:ff:ff:ff") {
236
				/*   this is not a valid mac address.  generate a
237
				 *   temporary mac address so the machine can get online.
238
				 */
239
				echo "Generating new MAC address.";
240
				$random_mac = generate_random_mac_address();
241
				mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) .
242
					" link " . escapeshellarg($random_mac));
243
				$optcfg['spoofmac'] = $random_mac;
244
				write_config();
245
				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");
246
			}
247
		}
248

    
249
		/* media */
250
		if ($optcfg['media'] || $optcfg['mediaopt']) {
251
			$cmd = "/sbin/ifconfig " . escapeshellarg($optcfg['if']);
252
			if ($optcfg['media'])
253
				$cmd .= " media " . escapeshellarg($optcfg['media']);
254
			if ($optcfg['mediaopt'])
255
				$cmd .= " mediaopt " . escapeshellarg($optcfg['mediaopt']);
256
			mwexec($cmd);
257
		}
258

    
259
		/* OpenVPN configuration? */
260
 		if (isset($optcfg['ovpn'])) {
261
 			if (strstr($optcfg['if'], "tap"))
262
 				ovpn_link_tap();
263
 		}
264

    
265
		/* bridged? */
266
		if ($optcfg['bridge']) {
267
			mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " delete up");
268
                        /* use open/netBSD style bridge */
269
			mwexec("/sbin/ifconfig bridge{$bridges_total} create");
270
                        mwexec("/sbin/ifconfig bridge{$bridges_total} addm {$optcfg['if']} addm {$config['interfaces'][$optcfg['bridge']]['if']} up");
271
			mwexec("/sbin/ifconfig bridge{$bridges_total} stp {$optcfg['if']} add {$config['interfaces'][$optcfg['bridge']]['if']}");
272
			
273
			$fd = fopen("{$g['tmp_path']}/bridge_config_{$optcfg['if']}", "w");
274
			fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} create\n");
275
			fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} addm {$optcfg['if']} addm {$config['interfaces'][$optcfg['bridge']]['if']} up\n");
276
			fwrite($fd, "/sbin/ifconfig bridge{$bridges_total} stp {$optcfg['if']} add {$config['interfaces'][$optcfg['bridge']]['if']}\n");
277
			fclose($fd);
278
			
279
			/* lets keep track of the amount of bridges initialized */
280
			$bridges_total++;
281
		} else {
282
			/* if user has selected DHCP type then act accordingly */
283
			if($optcfg['ipaddr'] == "dhcp") {
284
				interfaces_opt_dhcp_configure("opt{$opti}");
285
			} else {			
286
				mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " " .
287
				escapeshellarg($optcfg['ipaddr'] . "/" . $optcfg['subnet']));
288
			}
289
		}
290
	} else {
291
		mwexec("/sbin/ifconfig " . escapeshellarg($optcfg['if']) . " delete down");
292
	}
293

    
294
	return 0;
295
}
296

    
297
function interfaces_carp_configure() {
298
	global $g, $config;
299
	if ($g['booting']) {
300
		echo "Configuring CARP interfaces...";
301
		mute_kernel_msgs();
302
	}
303
	unlink_if_exists("/usr/local/etc/rc.d/carp.sh");
304
	unlink_if_exists("/usr/local/pkg/pf/carp.sh");
305
	unlink_if_exists("/usr/local/pkg/pf/carp_rules.sh");
306
	$carp_instances_counter = 0;
307
	$pfsync_instances_counter = 0;
308
	$total_carp_interfaces_defined = find_number_of_created_carp_interfaces();
309
	if (is_array($config['virtualip']['vip'])) {
310
		if(is_array($config['installedpackages']['carpsettings']['config'])) {
311
			foreach($config['installedpackages']['carpsettings']['config'] as $carp)
312
			if($carp['pfsyncenabled'] != "") {
313
				if($carp['premption'] != "")
314
				mwexec("/sbin/sysctl net.inet.carp.preempt=1");
315
				if($carp['balancing'] != "")
316
				mwexec("/sbin/sysctl net.inet.arpbalance=1");
317
				$carp_sync_int = convert_friendly_interface_to_real_interface_name($carp['pfsyncinterface']);
318
				mwexec("/sbin/ifconfig pfsync0 create");
319
				mwexec("/sbin/ifconfig pfsync0 syncdev " . $carp_sync_int);
320
				mwexec("/sbin/ifconfig pfsync0 syncif " . $carp_sync_int);
321
				mwexec("/sbin/ifconfig {$carp_sync_int} up");
322
				mwexec("/sbin/ifconfig pfsync0 up");
323
				if($g['booting']) {
324
					/* install rules to alllow pfsync to sync up during boot
325
					* carp interfaces will remain down until the bootup sequence finishes
326
					*/
327
					exec("echo pass quick proto carp all keep state > /tmp/rules.boot");
328
					exec("echo pass quick proto pfsync all >> /tmp/rules.boot");
329
					exec("echo pass out proto { tcp, udp } from any to any port 53 keep state >> /tmp/rules.boot");
330
					exec("/sbin/pfctl -f /tmp/rules.boot");
331
				}
332
				$pfsync_instances_counter++;
333
			}
334
		}
335
		$viparr = &$config['virtualip']['vip'];
336
		foreach ($viparr as $vip) {
337
			if ($vip['mode'] == "carp") {
338
				/*
339
				*  create the carp interface
340
				*/
341
				mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " create");
342
				mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " down");
343
				$broadcast_address = gen_subnet_max($vip['subnet'], $vip['subnet_bits']);
344
				if($vip['password'] != "") {
345
					$password = " pass " . $vip['password'];
346
				}
347
				/* XXX: billm - carpdev not in our build?
348
				$carpdev = "";
349
				if(isset($vip['interface']) && ($vip['interface'] != "AUTO" && $vip['interface'] != "")) {
350
					$ci = filter_opt_interface_to_real($vip['interface']);
351
					$carpdev = " carpdev {$ci} ";
352
				}
353
				*/
354
				mwexec("/sbin/ifconfig carp" . $carp_instances_counter . " " . $vip['subnet'] . "/" . $vip['subnet_bits'] . " broadcast " . $broadcast_address . " vhid " . $vip['vhid'] . "{$carpdev} advskew " . $vip['advskew'] . $password);
355
				$carp_instances_counter++;
356
			}
357
		}
358
	} else {
359
		/* hush little pfsync, don't say a word.  GeekGod's gonna
360
		   buy you a mocking bird. */
361
		mwexec("/sbin/ifconfig pfsync0 syncdev lo0 up");
362
	}	
363
	/* remove any dangling carp references */
364
	for($x=$carp_instances_counter; $x<$total_carp_interfaces_defined; $x++) {
365
		mwexec("/sbin/ifconfig carp{$x} down");
366
	}
367
	unmute_kernel_msgs();
368
	if ($g['booting']) {
369
		unmute_kernel_msgs();
370
		echo "done.\n";
371
	}
372
}
373

    
374
function interfaces_carp_bringup() {
375
	global $g;
376
	/* lets bring the carp interfaces up now */
377
	if ($g['booting'])
378
		sleep(1);
379
	$carp_ints = find_number_of_created_carp_interfaces();
380
	for($x=0; $x<$carp_ints; $x++)
381
		mwexec("/sbin/ifconfig carp{$x} up");	
382
}
383

    
384
function interfaces_wireless_configure($if, $wlcfg) {
385
        global $config, $g;
386
	
387
	/* set values for /path/program */
388
	$hostapd = "/usr/sbin/hostapd";
389
	$wpa_supplicant = "/usr/sbin/wpa_supplicant";
390
	$ifconfig = "/sbin/ifconfig ";
391

    
392
	/*   set wireless channel value.  if we're using 0 then
393
	 *   convert the channel to -
394
	 */
395
	$channel = escapeshellarg($wlcfg['channel']);
396
	if($channel == "") 
397
		$channel = "";
398

    
399
        /* wireless configuration */
400
        $ifcargs = escapeshellarg($if) . " ssid " . escapeshellarg($wlcfg['ssid']) . " channel {$channel}";
401

    
402
        if ($wlcfg['stationname'])
403
                $ifcargs .= "stationname " . escapeshellarg($wlcfg['stationname']) . " ";
404
	
405
	if(!$wlcfg['mode']) {
406
		if (isset($wlcfg['wpa']['enable'])) {
407
		
408
	$wpa .= <<<EOD
409

    
410
ctrl_interface={$g['varrun_path']}/hostapd
411
ctrl_interface_group=0
412
ap_scan=1
413
#fast_reauth=1
414

    
415
network={
416
ssid={$wlcfg['ssid']}
417
scan_ssid=2
418
priority=5
419
key_mgmt={$wlcfg['wpa']['wpa_key_mgmt']}
420
psk={$wlcfg['wpa']['passphrase']}
421
pairwise={$wlcfg['wpa']['wpa_pairwise']}
422
group={$wlcfg['wpa']['wpa_pairwise']}
423
}
424

    
425
EOD;
426

    
427
		$fd = fopen("{$g['tmp_path']}/wpa_supplicant_{$if}.conf", "w");
428
		fwrite($fd, "{$wpa}");
429
		fclose($fd);
430

    
431
		if(is_process_running("wpa_supplicant")) {
432
			mwexec("$killall -HUP wpa_supplicant");
433
			} else {
434
			mwexec("$wpa_supplicant -i {$if} -c {$g['etc_path']}/wpa_supplicant_{$if}.conf"); 		}
435
		}
436
	}
437

    
438
        if (isset($wlcfg['wep']['enable']) && is_array($wlcfg['wep']['key'])) {
439
                $ifcargs .= "wepmode on ";
440

    
441
                $i = 1;
442
                foreach ($wlcfg['wep']['key'] as $wepkey) {
443
                        $ifcargs .= "wepkey " . escapeshellarg("{$i}:{$wepkey['value']}") . " ";
444
                        if (isset($wepkey['txkey'])) {
445
                                $ifcargs .= "weptxkey {$i} ";
446
                        }
447
                        $i++;
448
                }
449
        } else {
450
                $ifcargs .= "wepmode off ";
451
        }
452

    
453
	if(isset($wlcfg['pureg'])) {
454
		$ifcargs .= "mode 11g ";
455
	} else {
456
		if (preg_match($g['wireless_regex'], $if)) {
457
			if ($wlcfg['standard'])
458
				$ifcargs .= "mode {$wlcfg['standard']} ";
459
		}
460
	}
461

    
462
        switch ($wlcfg['mode']) {
463
                case 'hostap':
464
                        if (preg_match($g['wireless_regex'], $if)) 
465
                                $ifcargs .= "-mediaopt adhoc mediaopt hostap ";
466
                        else if (strstr($if, "wi"))
467
                                $ifcargs .= "-mediaopt ibss mediaopt hostap ";
468
				if (isset($wlcfg['wpa']['enable'])) {
469
$wpa .= <<<EOD
470

    
471
interface={$if}
472
driver=bsd
473
logger_syslog=-1
474
logger_syslog_level=0
475
logger_stdout=-1
476
logger_stdout_level=0
477
dump_file={$g['tmp_path']}/hostapd_{$if}.dump
478
ctrl_interface={$g['varrun_path']}/hostapd
479
ctrl_interface_group=wheel
480
#accept_mac_file={$g['tmp_path']}/hostapd_{$if}.accept
481
#deny_mac_file={$g['tmp_path']}/hostapd_{$if}.deny
482
ssid={$wlcfg['ssid']}
483
debug={$wlcfg['wpa']['debug_mode']}
484
#macaddr_acl={$wlcfg['wpa']['macaddr_acl']}
485
auth_algs={$wlcfg['wpa']['auth_algs']}
486
wpa={$wlcfg['wpa']['wpa_mode']}
487
wpa_key_mgmt={$wlcfg['wpa']['wpa_key_mgmt']}
488
wpa_pairwise={$wlcfg['wpa']['wpa_pairwise']}
489
#wpa_group_rekey={$wlcfg['wpa']['wpa_group_rekey']}
490
#wpa_gmk_rekey={$wlcfg['wpa']['wpa_gmk_rekey']}
491
#wpa_strict_rekey={$wlcfg['wpa']['wpa_strict_rekey']}
492
wpa_passphrase={$wlcfg['wpa']['passphrase']}
493
ieee8021x={$wlcfg['wpa']['ieee8021x']}
494

    
495
EOD;
496
					$fd = fopen("{$g['tmp_path']}/hostapd_{$if}.conf", "w");
497
					fwrite($fd, "{$wpa}");
498
					fclose($fd);
499
					if(is_process_running("hostapd")) {
500
						mwexec("$killall -HUP hostapd");
501
					} else {
502
						mwexec("$hostapd -B {$g['tmp_path']}/hostapd_{$if}.conf");
503
					}
504
				}
505
			break;
506

    
507
                case 'ibss':
508
                case 'IBSS':
509
                        if (preg_match($g['wireless_regex'], $if)) 
510
                                $ifcargs .= "-mediaopt hostap mediaopt adhoc ";
511
                        else if (strstr($if, "wi"))
512
                                $ifcargs .= "-mediaopt hostap mediaopt ibss ";
513
                        else if (strstr($if, "an"))
514
                                $ifcargs .= "mediaopt adhoc ";
515
                        break;
516
                case 'bss':
517
                case 'BSS':
518
                        if (preg_match($g['wireless_regex'], $if)) 
519
                                $ifcargs .= "-mediaopt hostap -mediaopt adhoc ";
520
                        else if (strstr($if, "wi"))
521
                                $ifcargs .= "-mediaopt hostap -mediaopt ibss ";
522
                        else if (strstr($if, "an"))
523
                                $ifcargs .= "-mediaopt adhoc ";
524
                        break;
525
        }
526
	
527
	/*   extra options during hostap mode
528
	 */
529
	if($wlcfg['mode'] == "hostap") {
530

    
531
		/* handle hide ssid option */
532
		if(isset($wlcfg['hidessid']))
533
			$ifcargs .= "hidessid ";
534
		else
535
			$ifcargs .= "-hidessid ";
536

    
537
		/* handle pureg (802.11g) only option */
538
		if(isset($wlcfg['pureg']['enable']))
539
			$ifcargs .= "pureg ";
540
		else
541
			$ifcargs .= "-pureg ";
542

    
543
		/* handle turbo option */
544
		if(isset($wlcfg['turbo']['enable']))
545
			$ifcargs .= "mediaopt turbo ";
546
		else
547
			$ifcargs .= "-mediaopt turbo ";
548

    
549
		/* handle txpower setting */
550
		if($wlcfg['txpower'] <> "")
551
			$ifcargs .= "txpower {$wlcfg['txpower']} ";
552
		
553
		/* handle wme option */
554
		if(isset($wlcfg['wme']['enable']))
555
			$ifcargs .= " wme";
556
		else
557
			$ifcargs .= " -wme";
558

    
559
	}
560

    
561
        
562
        mwexec($ifconfig . $if . " down"); 
563
	mwexec($ifconfig . $ifcargs);
564
	mwexec($ifconfig . " up");
565

    
566

    
567
	$fd = fopen("{$g['tmp_path']}/ifconfig_wireless", "w");
568
	fwrite($fd, "/sbin/ifconfig {$ifcargs}");
569
	fclose($fd);
570
	
571
	if(isset($wlcfg['useolsr']))
572
		setup_wireless_olsr(escapeshellarg($if));
573
	
574
        return 0;
575

    
576
}
577

    
578

    
579
function find_dhclient_process($interface) {
580
	if(filter_translate_type_to_real_interface($interface) <> "")
581
        	$realinterface = filter_translate_type_to_real_interface($interface);
582
	$pid = `ps ax | grep "[d]hclient" | grep {$realinterface} | awk -F" " '{print $1}'`;
583
	return $pid;
584
}
585

    
586
function interfaces_wan_configure() {
587
	global $config, $g;
588

    
589
	$wancfg = $config['interfaces']['wan'];
590

    
591
	if(!$g['booting']) {
592
		mute_kernel_msgs();
593

    
594
		/* find dhclient process for wan and kill it */
595
		killbypid(find_dhclient_process("wan"));
596

    
597
		/* kill PPPoE client (mpd) */
598
		killbypid("{$g['varrun_path']}/mpd.pid");
599

    
600
		/* wait for processes to die */
601
		sleep(1);
602

    
603
		unlink_if_exists("{$g['varetc_path']}/dhclient_wan.conf");
604
		unlink_if_exists("{$g['varetc_path']}/mpd.conf");
605
		unlink_if_exists("{$g['varetc_path']}/mpd.links");
606
		unlink_if_exists("{$g['vardb_path']}/wanip");
607
		unlink_if_exists("{$g['varetc_path']}/nameservers.conf");
608
	}
609

    
610
	/* remove all addresses first */
611
	while (mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " -alias") == 0);
612
	mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " down");
613

    
614
	/* wireless configuration? */
615
	if (is_array($wancfg['wireless']))
616
		interfaces_wireless_configure($wancfg['if'], $wancfg['wireless']);
617

    
618
	if ($wancfg['spoofmac']) {
619
		mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
620
			" link " . escapeshellarg($wancfg['spoofmac']));
621
	}  else {
622
		$mac = get_interface_mac_address($wancfg['if']);
623
		if($mac == "ff:ff:ff:ff:ff:ff") {
624
			/*   this is not a valid mac address.  generate a
625
			 *   temporary mac address so the machine can get online.
626
			 */
627
			echo "Generating new MAC address.";
628
			$random_mac = generate_random_mac_address();
629
			mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) .
630
				" link " . escapeshellarg($random_mac));
631
			$wancfg['spoofmac'] = $random_mac;
632
			write_config();
633
			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");
634
		}
635
	}
636

    
637
	/* media */
638
	if ($wancfg['media'] || $wancfg['mediaopt']) {
639
		$cmd = "/sbin/ifconfig " . escapeshellarg($wancfg['if']);
640
		if ($wancfg['media'])
641
			$cmd .= " media " . escapeshellarg($wancfg['media']);
642
		if ($wancfg['mediaopt'])
643
			$cmd .= " mediaopt " . escapeshellarg($wancfg['mediaopt']);
644
		mwexec($cmd);
645
	}
646

    
647
	switch ($wancfg['ipaddr']) {
648

    
649
		case 'dhcp':
650
			interfaces_wan_dhcp_configure();
651
			break;
652

    
653
		case 'pppoe':
654
			interfaces_wan_pppoe_configure();
655
			break;
656

    
657
		case 'pptp':
658
			interfaces_wan_pptp_configure();
659
			break;
660

    
661
		case 'bigpond':
662
			/* just configure DHCP for now; fire up bpalogin when we've got the lease */
663
			interfaces_wan_dhcp_configure();
664
			break;
665

    
666
		default:
667
			if (isset($wancfg['ispointtopoint']) && $wancfg['pointtopoint']) {
668
				mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
669
					escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']) .
670
					" " . escapeshellarg($wancfg['pointtopoint']) . " up");
671
			} else {
672
				mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
673
					escapeshellarg($wancfg['ipaddr'] . "/" . $wancfg['subnet']));
674
			}
675
			/* install default route */
676
			mwexec("/sbin/route delete default");
677
			mwexec("/sbin/route add default " . escapeshellarg($config['system']['gateway']));
678

    
679
			/* resync pf (done automatically for DHCP/PPPoE/PPTP) */
680
			filter_configure();
681
	}
682

    
683
	if (!$g['booting']) {
684
		/* reconfigure static routes (kernel may have deleted them) */
685
		system_routing_configure();
686

    
687
		/* set the reload filter dity flag */
688
		touch("{$g['tmp_path']}/filter_dirty");
689

    
690
		/* reload ipsec tunnels */
691
		vpn_ipsec_configure();
692

    
693
		/* restart ez-ipupdate */
694
		services_dyndns_configure();
695

    
696
		/* force DNS update */
697
		services_dnsupdate_process();
698

    
699
		/* restart dnsmasq */
700
		services_dnsmasq_configure();
701
	}
702

    
703
	unmute_kernel_msgs();
704

    
705
	return 0;
706
}
707

    
708
function interfaces_opt_dhcp_configure($interface) {
709
	global $config, $g;
710

    
711
	$optcfg = $config['interfaces'][$interface];
712
	$optif = $optcfg['if'];
713

    
714
	/* generate dhclient_wan.conf */
715
	$fd = fopen("{$g['varetc_path']}/dhclient_{$optif}.conf", "w");
716
	if (!$fd) {
717
		printf("Error: cannot open dhclient_{$optif}.conf in interfaces_opt_dhcp_configure({$optif}) for writing.\n");
718
		return 1;
719
	}
720

    
721
	if ($optcfg['dhcphostname']) {
722
		$dhclientconf_hostname = "send dhcp-client-identifier \"{$optcfg['dhcphostname']}\";\n";
723
		$dhclientconf_hostname = "	send dhcp-client-identifier \"{$optcfg['dhcphostname']}\";\n";
724
	} else {
725
		$dhclientconf_hostname = "";
726
	}
727

    
728
 	$dhclientconf = "";
729

    
730
	$dhclientconf .= <<<EOD
731
interface "{$optif}" {
732
	send host-name "{$optcfg['dhcphostname']}";
733
	script "/sbin/dhclient-script";
734
	{$dhclientconf_hostname}
735
}
736

    
737
EOD;
738

    
739
	fwrite($fd, $dhclientconf);
740
	fclose($fd);
741

    
742
        /* bring interface up before starting dhclient */
743
        mwexec("/sbin/ifconfig {$optif} up");
744

    
745
        /* fire up dhclient */
746
        mwexec_bg("/sbin/dhclient -d -c {$g['varetc_path']}/dhclient_{$optif}.conf {$optif}");
747

    
748
	return 0;
749
}
750

    
751
function interfaces_dhcp_configure($interface) {
752
	global $config, $g;
753

    
754
	if(filter_translate_type_to_real_interface($interface) <> "")
755
        	$realinterface = filter_translate_type_to_real_interface($interface);
756

    
757
	$optcfg = $config['interfaces'][$interface];
758

    
759
	/* generate dhclient_$interface.conf */
760
	$fd = fopen("{$g['varetc_path']}/dhclient_{$interface}.conf", "w");
761
	if (!$fd) {
762
		printf("Error: cannot open dhclient_{$interface}.conf in interfaces_dhcp_configure({$$interface}) for writing.\n");
763
		return 1;
764
	}
765

    
766
	if ($optcfg['dhcphostname']) {
767
		$dhclientconf_hostname = "send dhcp-client-identifier \"{$optcfg['dhcphostname']}\";\n";
768
		$dhclientconf_hostname = "	send dhcp-client-identifier \"{$optcfg['dhcphostname']}\";\n";
769
	} else {
770
		$dhclientconf_hostname = "";
771
	}
772

    
773
 	$dhclientconf = "";
774

    
775
	$dhclientconf .= <<<EOD
776
interface "{$realinterface}" {
777
	script "/sbin/dhclient-script";
778
	{$dhclientconf_hostname}
779
}
780

    
781
EOD;
782

    
783
	fwrite($fd, $dhclientconf);
784
	fclose($fd);
785
	
786
	$optif = $optcfg['if'];
787
	
788
        /* bring wan interface up before starting dhclient */
789
        mwexec("/sbin/ifconfig {$optif} up");
790

    
791
        /* fire up dhclient */
792
        mwexec_bg("/sbin/dhclient -d -c {$g['varetc_path']}/dhclient_{$optif}.conf {$optif} >/tmp/{$optif}_output >/tmp/{$optif}_error_output");
793

    
794
	$fout = fopen("/tmp/ifconfig_{$optif}","w");
795
	fwrite($fout, "/sbin/dhclient -d -c {$g['varetc_path']}/dhclient_{$optif}.conf {$optif}");
796
	fclose($fout);
797

    
798
	return 0;
799
}
800

    
801
function interfaces_wan_dhcp_configure() {
802
	global $config, $g;
803

    
804
	$wancfg = $config['interfaces']['wan'];
805

    
806
	/* generate dhclient_wan.conf */
807
	$fd = fopen("{$g['varetc_path']}/dhclient_wan.conf", "w");
808
	if (!$fd) {
809
		printf("Error: cannot open dhclient_wan.conf in interfaces_wan_dhcp_configure() for writing.\n");
810
		return 1;
811
	}
812
	
813
	if ($wancfg['dhcphostname']) {
814
		$dhclientconf_hostname = "send dhcp-client-identifier \"{$wancfg['dhcphostname']}\";\n";
815
		$dhclientconf_hostname = "	send dhcp-client-identifier \"{$wancfg['dhcphostname']}\";\n";
816
	} else {
817
		$dhclientconf_hostname = "";
818
	}
819

    
820
 	$dhclientconf = "";
821

    
822
	$dhclientconf .= <<<EOD
823
interface "{$wancfg['if']}" {
824
	script "/sbin/dhclient-script";
825
	{$dhclientconf_hostname}
826
}
827

    
828
EOD;
829

    
830
	fwrite($fd, $dhclientconf);
831
	fclose($fd);
832
	
833
	$wanif = $wancfg['if'];
834
	
835
        /* bring wan interface up before starting dhclient */
836
        mwexec("/sbin/ifconfig {$wanif} up");
837

    
838
        /* fire up dhclient */
839
        mwexec_bg("/sbin/dhclient -d -c {$g['varetc_path']}/dhclient_wan.conf {$wanif} >/tmp/{$wanif}_output >/tmp/{$wanif}_error_output");
840

    
841
	$fout = fopen("/tmp/ifconfig_{$wanif}","w");
842
	fwrite($fout, "/sbin/dhclient -d -c {$g['varetc_path']}/dhclient_wan.conf {$wanif}");
843
	fclose($fout);
844

    
845
	return 0;
846
}
847

    
848
function interfaces_wan_dhcp_down() {
849
	global $config;
850
	$wancfg = $config['interfaces']['wan'];
851
	$wanif = $wancfg['if'];
852
	mwexec("/sbin/ifconfig {$wanif} delete");
853
	sleep(1);
854
}
855

    
856
function interfaces_dhcp_down($interface) {
857
	global $config;
858
	if(filter_translate_type_to_real_interface($interface) <> "")
859
		$realinterface = filter_translate_type_to_real_interface($interface);
860
	mwexec("/sbin/ifconfig {$realinterface} down");
861
	sleep(1);
862
	$pid = find_dhclient_process($interface);
863
	if($pid)
864
		mwexec("kill {$pid}");
865
}
866

    
867
function interfaces_dhcp_up($interface) {
868
	interfaces_dhcp_configure($interface);
869
	sleep(1);
870
}
871

    
872
function interfaces_wan_dhcp_up() {
873
	interfaces_wan_dhcp_configure();
874
	sleep(1);
875
}
876

    
877
function interfaces_wan_pppoe_configure() {
878
	global $config, $g;
879

    
880
	$wancfg = $config['interfaces']['wan'];
881
	$pppoecfg = $config['pppoe'];
882

    
883
	/* generate mpd.conf */
884
	$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
885
	if (!$fd) {
886
		printf("Error: cannot open mpd.conf in interfaces_wan_pppoe_configure().\n");
887
		return 1;
888
	}
889

    
890
	$idle = 0;
891

    
892
	if (isset($pppoecfg['ondemand'])) {
893
		$ondemand = "enable";
894
		if ($pppoecfg['timeout'])
895
			$idle = $pppoecfg['timeout'];
896
	} else {
897
		$ondemand = "disable";
898
	}
899

    
900
	$mpdconf = <<<EOD
901
pppoe:
902
	new -i ng0 pppoe pppoe
903
	set iface route default
904
	set iface {$ondemand} on-demand
905
	set iface idle {$idle}
906
	set iface up-script /usr/local/sbin/ppp-linkup
907

    
908
EOD;
909

    
910
	if (isset($pppoecfg['ondemand'])) {
911
		$mpdconf .= <<<EOD
912
	set iface addrs 10.0.0.1 10.0.0.2
913

    
914
EOD;
915
	}
916

    
917
	$mpdconf .= <<<EOD
918
	set bundle disable multilink
919
	set bundle authname "{$pppoecfg['username']}"
920
	set bundle password "{$pppoecfg['password']}"
921
	set link keep-alive 10 60
922
	set link max-redial 0
923
	set link no acfcomp protocomp
924
	set link disable pap chap
925
	set link accept chap
926
	set link mtu 1492
927
	set ipcp yes vjcomp
928
	set ipcp ranges 0.0.0.0/0 0.0.0.0/0
929

    
930
EOD;
931

    
932
	if (isset($config['system']['dnsallowoverride'])) {
933
		$mpdconf .= <<<EOD
934
	set ipcp enable req-pri-dns
935

    
936
EOD;
937
	}
938

    
939
	$mpdconf .= <<<EOD
940
	open iface
941

    
942
EOD;
943

    
944
	fwrite($fd, $mpdconf);
945
	fclose($fd);
946

    
947
	/* generate mpd.links */
948
	$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
949
	if (!$fd) {
950
		printf("Error: cannot open mpd.links in interfaces_wan_pppoe_configure().\n");
951
		return 1;
952
	}
953

    
954
	$mpdconf = <<<EOD
955
pppoe:
956
	set link type pppoe
957
	set pppoe iface {$wancfg['if']}
958
	set pppoe service "{$pppoecfg['provider']}"
959
	set pppoe enable originate
960
	set pppoe disable incoming
961

    
962
EOD;
963

    
964
	fwrite($fd, $mpdconf);
965
	fclose($fd);
966

    
967
	/* if mpd is active, lets take it down */
968
	if(file_exists("{$g['varrun_path']}/mpd.pid")) {
969
		killbypid(file_get_contents("{$g['varrun_path']}/mpd.pid"));
970
		sleep(3);
971
	}
972

    
973
	/* fire up mpd */
974
	mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pppoe");
975

    
976
	return 0;
977
}
978

    
979
function interfaces_wan_pppoe_down() {
980
	global $g;
981
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
982
	sleep(1);
983
}
984

    
985
function interfaces_wan_pppoe_up() {
986
	global $g;
987
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
988
	sleep(1);
989
}
990

    
991
function interfaces_wan_pptp_configure() {
992
	global $config, $g;
993

    
994
	$wancfg = $config['interfaces']['wan'];
995
	$pptpcfg = $config['pptp'];
996

    
997
	/* generate mpd.conf */
998
	$fd = fopen("{$g['varetc_path']}/mpd.conf", "w");
999
	if (!$fd) {
1000
		printf("Error: cannot open mpd.conf in interfaces_wan_pptp_configure().\n");
1001
		return 1;
1002
	}
1003

    
1004
	$idle = 0;
1005

    
1006
	if (isset($pptpcfg['ondemand'])) {
1007
		$ondemand = "enable";
1008
		if ($pptpcfg['timeout'])
1009
			$idle = $pptpcfg['timeout'];
1010
	} else {
1011
		$ondemand = "disable";
1012
	}
1013

    
1014
	$mpdconf = <<<EOD
1015
pptp:
1016
	new -i ng0 pptp pptp
1017
	set iface route default
1018
	set iface {$ondemand} on-demand
1019
	set iface idle {$idle}
1020
	set iface up-script /usr/local/sbin/ppp-linkup
1021

    
1022
EOD;
1023

    
1024
	if (isset($pptpcfg['ondemand'])) {
1025
		$mpdconf .= <<<EOD
1026
	set iface addrs 10.0.0.1 10.0.0.2
1027

    
1028
EOD;
1029
	}
1030

    
1031
	$mpdconf .= <<<EOD
1032
	set bundle disable multilink
1033
	set bundle authname "{$pptpcfg['username']}"
1034
	set bundle password "{$pptpcfg['password']}"
1035
	set link keep-alive 10 60
1036
	set link max-redial 0
1037
	set link no acfcomp protocomp
1038
	set link disable pap chap
1039
	set link accept chap
1040
	set ipcp no vjcomp
1041
	set ipcp ranges 0.0.0.0/0 0.0.0.0/0
1042

    
1043
EOD;
1044

    
1045
	if (isset($config['system']['dnsallowoverride'])) {
1046
		$mpdconf .= <<<EOD
1047
	set ipcp enable req-pri-dns
1048

    
1049
EOD;
1050
	}
1051

    
1052
	$mpdconf .= <<<EOD
1053
	open
1054

    
1055
EOD;
1056

    
1057
	fwrite($fd, $mpdconf);
1058
	fclose($fd);
1059

    
1060
	/* generate mpd.links */
1061
	$fd = fopen("{$g['varetc_path']}/mpd.links", "w");
1062
	if (!$fd) {
1063
		printf("Error: cannot open mpd.links in interfaces_wan_pptp_configure().\n");
1064
		return 1;
1065
	}
1066

    
1067
	$mpdconf = <<<EOD
1068
pptp:
1069
	set link type pptp
1070
	set pptp enable originate outcall
1071
	set pptp disable windowing
1072
	set pptp self {$pptpcfg['local']}
1073
	set pptp peer {$pptpcfg['remote']}
1074

    
1075
EOD;
1076

    
1077
	fwrite($fd, $mpdconf);
1078
	fclose($fd);
1079

    
1080
	/* configure interface */
1081
	mwexec("/sbin/ifconfig " . escapeshellarg($wancfg['if']) . " " .
1082
		escapeshellarg($pptpcfg['local'] . "/" . $pptpcfg['subnet']));
1083

    
1084
	/* fire up mpd */
1085
	mwexec("/usr/local/sbin/mpd -b -d {$g['varetc_path']} -p {$g['varrun_path']}/mpd.pid pptp");
1086

    
1087
	return 0;
1088
}
1089

    
1090
function interfaces_wan_pptp_down() {
1091
	global $g;
1092
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR2");
1093
	sleep(1);
1094
}
1095

    
1096
function interfaces_wan_pptp_up() {
1097
	global $g;
1098
	sigkillbypid("{$g['varrun_path']}/mpd.pid", "SIGUSR1");
1099
	sleep(1);
1100
}
1101

    
1102
function interfaces_wan_bigpond_configure($curwanip) {
1103
	global $config, $g;
1104

    
1105
	$bpcfg = $config['bigpond'];
1106

    
1107
	if (!$curwanip) {
1108
		/* IP address not configured yet, exit */
1109
		return 0;
1110
	}
1111

    
1112
	/* kill bpalogin */
1113
	killbyname("bpalogin");
1114

    
1115
	/* wait a moment */
1116
	sleep(1);
1117

    
1118
	/* get the default domain */
1119
	$nfd = @fopen("{$g['varetc_path']}/defaultdomain.conf", "r");
1120
	if ($nfd) {
1121
		$defaultdomain = trim(fgets($nfd));
1122
		fclose($nfd);
1123
	}
1124

    
1125
	/* generate bpalogin.conf */
1126
	$fd = fopen("{$g['varetc_path']}/bpalogin.conf", "w");
1127
	if (!$fd) {
1128
		printf("Error: cannot open bpalogin.conf in interfaces_wan_bigpond_configure().\n");
1129
		return 1;
1130
	}
1131

    
1132
	if (!$bpcfg['authserver'])
1133
		$bpcfg['authserver'] = "dce-server";
1134
	if (!$bpcfg['authdomain'])
1135
		$bpcfg['authdomain'] = $defaultdomain;
1136

    
1137
	$bpconf = <<<EOD
1138
username {$bpcfg['username']}
1139
password {$bpcfg['password']}
1140
authserver {$bpcfg['authserver']}
1141
authdomain {$bpcfg['authdomain']}
1142
localport 5050
1143

    
1144
EOD;
1145

    
1146
	if ($bpcfg['minheartbeatinterval'])
1147
		$bpconf .= "minheartbeatinterval {$bpcfg['minheartbeatinterval']}\n";
1148

    
1149
	fwrite($fd, $bpconf);
1150
	fclose($fd);
1151

    
1152
	/* fire up bpalogin */
1153
	mwexec("/usr/local/sbin/bpalogin -c {$g['varetc_path']}/bpalogin.conf");
1154

    
1155
	return 0;
1156
}
1157

    
1158
function get_real_wan_interface() {
1159
	global $config, $g;
1160

    
1161
	$wancfg = $config['interfaces']['wan'];
1162

    
1163
	$wanif = $wancfg['if'];
1164
	if (($wancfg['ipaddr'] == "pppoe") || ($wancfg['ipaddr'] == "pptp")) {
1165
		$wanif = $g['pppoe_interface'];
1166
	}
1167

    
1168
	return $wanif;
1169
}
1170

    
1171
function get_current_wan_address() {
1172
	global $config, $g;
1173

    
1174
	$wancfg = $config['interfaces']['wan'];
1175

    
1176
	if (in_array($wancfg['ipaddr'], array('pppoe','dhcp','pptp','bigpond'))) {
1177
		/* dynamic WAN IP address, find out which one */
1178
		$wanif = get_real_wan_interface();
1179

    
1180
		/* get interface info with netstat */
1181
		exec("/usr/bin/netstat -nWI " . escapeshellarg($wanif) . " -f inet", $ifinfo);
1182

    
1183
		if (isset($ifinfo[1])) {
1184
			$aif = preg_split("/\s+/", $ifinfo[1]);
1185
			$curwanip = chop($aif[3]);
1186

    
1187
			if ($curwanip && is_ipaddr($curwanip) && ($curwanip != "0.0.0.0"))
1188
				return $curwanip;
1189
		}
1190

    
1191
		return null;
1192
	} else {
1193
		/* static WAN IP address */
1194
		return $wancfg['ipaddr'];
1195
	}
1196
}
1197

    
1198
/****f* interfaces/is_jumbo_capable
1199
 * NAME
1200
 *   is_jumbo_capable - Test if interface is jumbo frame capable.  Useful for determining VLAN capability.
1201
 * INPUTS
1202
 *   $int             - string containing interface name
1203
 * RESULT
1204
 *   boolean          - true or false
1205
 ******/
1206

    
1207
function is_jumbo_capable($int) {
1208
	/* Per:
1209
	 * http://www.freebsd.org/cgi/man.cgi?query=vlan&manpath=FreeBSD+6.0-current&format=html
1210
	 * Only the following drivers support large frames
1211
	 */
1212
	$capable = array("bfe", "dc", "de", "fxp", "hme", "rl", "sis", "ste",
1213
		"tl", "tx", "xl", "em");
1214
	
1215
	$int_family = preg_split("/[0-9]+/", $int);
1216

    
1217
	if (in_array($int_family[0], $capable))
1218
		return true;
1219
	else
1220
		return false;
1221
}
1222

    
1223
/****f* interfaces/is_altq_capable
1224
 * NAME
1225
 *   is_altq_capable - Test if interface is capable of using ALTQ
1226
 * INPUTS
1227
 *   $int            - string containing interface name
1228
 * RESULT
1229
 *   boolean         - true or false
1230
 ******/
1231

    
1232
function is_altq_capable($int) {
1233
        /* Per:
1234
         * http://www.freebsd.org/cgi/man.cgi?query=altq&manpath=FreeBSD+6.0-current&format=html
1235
         * Only the following drivers have ALTQ support
1236
         */
1237
        $capable = array("an", "ath", "awi", "bfe", "bge", "dc", "de", "ed",
1238
		"em", "fxp", "hme", "lnc", "ndis", "rl", "sf", "sis", "sk",
1239
		"tun", "vr", "wi", "xl");
1240

    
1241
        $int_family = preg_split("/[0-9]+/", $int);
1242

    
1243
        if (in_array($int_family[0], $capable))
1244
                return true;
1245
        else
1246
                return false;
1247
}
1248

    
1249

    
1250
?>
(8-8/23)