1
|
<?php
|
2
|
/*
|
3
|
* config.console.inc
|
4
|
*
|
5
|
* part of pfSense (https://www.pfsense.org)
|
6
|
* Copyright (c) 2004-2013 BSD Perimeter
|
7
|
* Copyright (c) 2013-2016 Electric Sheep Fencing
|
8
|
* Copyright (c) 2014-2023 Rubicon Communications, LLC (Netgate)
|
9
|
* All rights reserved.
|
10
|
*
|
11
|
* originally part of m0n0wall (http://m0n0.ch/wall)
|
12
|
* Copyright (c) 2003-2004 Manuel Kasper <mk@neon1.net>.
|
13
|
* All rights reserved.
|
14
|
*
|
15
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
16
|
* you may not use this file except in compliance with the License.
|
17
|
* You may obtain a copy of the License at
|
18
|
*
|
19
|
* http://www.apache.org/licenses/LICENSE-2.0
|
20
|
*
|
21
|
* Unless required by applicable law or agreed to in writing, software
|
22
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
23
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
24
|
* See the License for the specific language governing permissions and
|
25
|
* limitations under the License.
|
26
|
*/
|
27
|
|
28
|
require_once("config.inc");
|
29
|
require_once("globals.inc");
|
30
|
require_once("interfaces.inc");
|
31
|
require_once("util.inc");
|
32
|
|
33
|
/*
|
34
|
* returns:
|
35
|
* -2: error
|
36
|
* -1: no interface found
|
37
|
* 0: interface(s) assigned
|
38
|
* 1: user quit
|
39
|
*/
|
40
|
function set_networking_interfaces_ports() {
|
41
|
global $config;
|
42
|
global $g;
|
43
|
global $fp;
|
44
|
|
45
|
$fp = fopen('php://stdin', 'r');
|
46
|
|
47
|
$memory = get_memory();
|
48
|
$physmem = $memory[0];
|
49
|
$realmem = $memory[1];
|
50
|
|
51
|
if ($physmem < g_get('minimum_ram_warning')) {
|
52
|
echo "\n\n\n";
|
53
|
echo gettext("DANGER! WARNING! ACHTUNG!") . "\n\n";
|
54
|
printf(gettext('%1$s requires *AT LEAST* %2$s RAM to function correctly.%3$s'), g_get('product_label'), g_get('minimum_ram_warning_text'), "\n");
|
55
|
printf(gettext('Only (%1$s) MB RAM has been detected, with (%2$s) available to %3$s.%4$s'), $realmem, $physmem, g_get('product_label'), "\n");
|
56
|
echo "\n" . gettext("Press ENTER to continue.") . " ";
|
57
|
fgets($fp);
|
58
|
echo "\n";
|
59
|
}
|
60
|
|
61
|
$iflist = get_interface_list('active', 'physical', true);
|
62
|
|
63
|
/* Function flow is based on $key or the lack thereof */
|
64
|
$key = null;
|
65
|
|
66
|
echo <<<EOD
|
67
|
|
68
|
Valid interfaces are:
|
69
|
|
70
|
|
71
|
EOD;
|
72
|
|
73
|
if (!is_array($iflist)) {
|
74
|
echo gettext("No interfaces found!") . "\n";
|
75
|
return (-1);
|
76
|
} else {
|
77
|
// ifsmallist is kept with spaces at the beginning and end to assist with str_replace() operations
|
78
|
$ifsmallist = " ";
|
79
|
foreach ($iflist as $iface => $ifa) {
|
80
|
$friendly = convert_real_interface_to_friendly_interface_name($iface);
|
81
|
$ifstatus = get_interface_addresses(config_get_path("interfaces/{$friendly}/if", ""));
|
82
|
if (is_array($ifstatus) && $ifstatus['linkstateup'])
|
83
|
$status = " (up)";
|
84
|
else
|
85
|
$status = "(down)";
|
86
|
$ifsmallist = $ifsmallist . $iface. " ";
|
87
|
echo sprintf("%-7s %s %s %s\n", $iface, $ifa['mac'],
|
88
|
$status, substr($ifa['dmesg'], 0, 46));
|
89
|
}
|
90
|
}
|
91
|
|
92
|
echo "\n" . gettext("Do VLANs need to be set up first?");
|
93
|
echo "\n" .
|
94
|
gettext(
|
95
|
"If VLANs will not be used, or only for optional interfaces, it is typical to\n" .
|
96
|
"say no here and use the webConfigurator to configure VLANs later, if required.") .
|
97
|
"\n";
|
98
|
echo "\n" . gettext("Should VLANs be set up now [y|n]?") . " ";
|
99
|
|
100
|
$key = chop(fgets($fp));
|
101
|
|
102
|
//Manually assign interfaces
|
103
|
if (in_array($key, array('y', 'Y'))) {
|
104
|
vlan_setup();
|
105
|
}
|
106
|
|
107
|
$vlans = config_get_path('vlans/vlan', []);
|
108
|
if (is_array($vlans) && count($vlans)) {
|
109
|
echo "\n\n" . gettext("VLAN interfaces:") . "\n\n";
|
110
|
foreach ($vlans as $vlan) {
|
111
|
echo sprintf("% -16s%s\n", vlan_interface($vlan),
|
112
|
"VLAN tag {$vlan['tag']}, parent interface {$vlan['if']}");
|
113
|
$iflist[vlan_interface($vlan)] = array();
|
114
|
$ifsmallist = $ifsmallist . vlan_interface($vlan) . " ";
|
115
|
}
|
116
|
}
|
117
|
|
118
|
echo <<<EOD
|
119
|
|
120
|
If the names of the interfaces are not known, auto-detection can
|
121
|
be used instead. To use auto-detection, please disconnect all
|
122
|
interfaces before pressing 'a' to begin the process.
|
123
|
|
124
|
EOD;
|
125
|
|
126
|
do {
|
127
|
echo "\n" . gettext("Enter the WAN interface name or 'a' for auto-detection") . " ";
|
128
|
printf(gettext('%1$s(%2$s or a): '), "\n", trim($ifsmallist));
|
129
|
$wanif = chop(fgets($fp));
|
130
|
if ($wanif === "") {
|
131
|
return (1);
|
132
|
}
|
133
|
if ($wanif === "a") {
|
134
|
$wanif = autodetect_interface("WAN", $fp);
|
135
|
} else if (!array_key_exists($wanif, $iflist)) {
|
136
|
printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $wanif, "\n");
|
137
|
unset($wanif);
|
138
|
continue;
|
139
|
}
|
140
|
$ifsmallist = str_replace(" " . $wanif . " ", " ", $ifsmallist);
|
141
|
} while (!$wanif);
|
142
|
|
143
|
do {
|
144
|
printf(gettext('%1$sEnter the LAN interface name or \'a\' for auto-detection %2$s' .
|
145
|
'NOTE: this enables full Firewalling/NAT mode.%3$s' .
|
146
|
'(%4$s a or nothing if finished):%5$s'), "\n", "\n", "\n", trim($ifsmallist), " ");
|
147
|
|
148
|
$lanif = chop(fgets($fp));
|
149
|
|
150
|
if ($lanif == "exit") {
|
151
|
exit;
|
152
|
}
|
153
|
|
154
|
if ($lanif == "") {
|
155
|
/* It is OK to have just a WAN, without a LAN so break if the user does not want LAN. */
|
156
|
break;
|
157
|
}
|
158
|
|
159
|
if ($lanif === "a") {
|
160
|
$lanif = autodetect_interface("LAN", $fp);
|
161
|
} else if (!array_key_exists($lanif, $iflist)) {
|
162
|
printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $lanif, "\n");
|
163
|
unset($lanif);
|
164
|
continue;
|
165
|
}
|
166
|
$ifsmallist = str_replace(" " . $lanif . " ", " ", $ifsmallist);
|
167
|
} while (!$lanif);
|
168
|
|
169
|
/* optional interfaces */
|
170
|
$i = 0;
|
171
|
$optif = array();
|
172
|
|
173
|
if ($lanif <> "") {
|
174
|
while (strlen(trim($ifsmallist)) > 0) {
|
175
|
if (!empty($optif[$i])) {
|
176
|
$i++;
|
177
|
}
|
178
|
$io = $i + 1;
|
179
|
|
180
|
if ($config['interfaces']['opt' . $io]['descr']) {
|
181
|
printf(gettext('%1$sOptional interface %2$s description found: %3$s'), "\n", $io, $config['interfaces']['opt' . $io]['descr']);
|
182
|
}
|
183
|
|
184
|
printf(gettext('%1$sEnter the Optional %2$s interface name or \'a\' for auto-detection%3$s' .
|
185
|
'(%4$s a or nothing if finished):%5$s'), "\n", $io, "\n", trim($ifsmallist), " ");
|
186
|
|
187
|
$optif[$i] = chop(fgets($fp));
|
188
|
|
189
|
if ($optif[$i]) {
|
190
|
if ($optif[$i] === "a") {
|
191
|
$ad = autodetect_interface(gettext("Optional") . " " . $io, $fp);
|
192
|
if ($ad) {
|
193
|
$optif[$i] = $ad;
|
194
|
} else {
|
195
|
unset($optif[$i]);
|
196
|
}
|
197
|
} else if (!array_key_exists($optif[$i], $iflist)) {
|
198
|
printf(gettext('%1$sInvalid interface name \'%2$s\'%3$s'), "\n", $optif[$i], "\n");
|
199
|
unset($optif[$i]);
|
200
|
continue;
|
201
|
}
|
202
|
$ifsmallist = str_replace(" " . $optif[$i] . " ", " ", $ifsmallist);
|
203
|
} else {
|
204
|
unset($optif[$i]);
|
205
|
break;
|
206
|
}
|
207
|
}
|
208
|
}
|
209
|
|
210
|
/* check for double assignments */
|
211
|
$ifarr = array_merge(array($lanif, $wanif), $optif);
|
212
|
|
213
|
for ($i = 0; $i < (count($ifarr)-1); $i++) {
|
214
|
for ($j = ($i+1); $j < count($ifarr); $j++) {
|
215
|
if ($ifarr[$i] == $ifarr[$j]) {
|
216
|
echo <<<EOD
|
217
|
|
218
|
Error: The same interface name cannot be assigned twice!
|
219
|
|
220
|
EOD;
|
221
|
fclose($fp);
|
222
|
return (-2);
|
223
|
}
|
224
|
}
|
225
|
}
|
226
|
|
227
|
echo "\n" . gettext("The interfaces will be assigned as follows:") . "\n\n";
|
228
|
|
229
|
echo "WAN -> " . $wanif . "\n";
|
230
|
if ($lanif != "") {
|
231
|
echo "LAN -> " . $lanif . "\n";
|
232
|
}
|
233
|
for ($i = 0; $i < count($optif); $i++) {
|
234
|
echo "OPT" . ($i+1) . " -> " . $optif[$i] . "\n";
|
235
|
}
|
236
|
|
237
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
238
|
$key = chop(fgets($fp));
|
239
|
|
240
|
if (in_array($key, array('y', 'Y'))) {
|
241
|
if ($lanif) {
|
242
|
if (is_array($config['interfaces']['lan'])) {
|
243
|
$upints = pfSense_interface_listget(IFF_UP);
|
244
|
if (in_array($config['interfaces']['lan']['if'], $upints))
|
245
|
interface_bring_down('lan', true);
|
246
|
}
|
247
|
if (!is_array($config['interfaces']['lan'])) {
|
248
|
$config['interfaces']['lan'] = array();
|
249
|
}
|
250
|
$config['interfaces']['lan']['if'] = $lanif;
|
251
|
$config['interfaces']['lan']['enable'] = true;
|
252
|
} elseif (!platform_booting()) {
|
253
|
|
254
|
echo "\n" . gettext("You have chosen to remove the LAN interface.") . "\n";
|
255
|
echo "\n" . gettext("Would you like to remove the LAN IP address and \nunload the interface now [y|n]?") . " ";
|
256
|
|
257
|
if (strcasecmp(chop(fgets($fp)), "y") == 0) {
|
258
|
if (isset($config['interfaces']['lan']) && $config['interfaces']['lan']['if']) {
|
259
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
260
|
}
|
261
|
}
|
262
|
if (isset($config['interfaces']['lan'])) {
|
263
|
config_del_path('interfaces/lan');
|
264
|
}
|
265
|
if (isset($config['dhcpd']['lan'])) {
|
266
|
config_del_path('dhcpd/lan');
|
267
|
}
|
268
|
if (isset($config['dhcpdv6']['lan'])) {
|
269
|
config_del_path('dhcpdv6/lan');
|
270
|
}
|
271
|
if (isset($config['interfaces']['lan']['if'])) {
|
272
|
config_del_path('interfaces/lan/if');
|
273
|
}
|
274
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
275
|
config_del_path('interfaces/wan/blockpriv');
|
276
|
}
|
277
|
if (isset($config['shaper'])) {
|
278
|
config_del_path('shaper');
|
279
|
}
|
280
|
if (isset($config['ezshaper'])) {
|
281
|
config_del_path('ezshaper');
|
282
|
}
|
283
|
if (isset($config['nat'])) {
|
284
|
config_del_path('nat');
|
285
|
}
|
286
|
} else {
|
287
|
if (isset($config['interfaces']['lan']['if'])) {
|
288
|
mwexec("/sbin/ifconfig " . $config['interfaces']['lan']['if'] . " delete");
|
289
|
}
|
290
|
if (isset($config['interfaces']['lan'])) {
|
291
|
config_del_path('interfaces/lan');
|
292
|
}
|
293
|
if (isset($config['dhcpd']['lan'])) {
|
294
|
config_del_path('dhcpd/lan');
|
295
|
}
|
296
|
if (isset($config['dhcpdv6']['lan'])) {
|
297
|
config_del_path('dhcpdv6/lan');
|
298
|
}
|
299
|
if (isset($config['interfaces']['lan']['if'])) {
|
300
|
config_del_path('interfaces/lan/if');
|
301
|
}
|
302
|
if (isset($config['interfaces']['wan']['blockpriv'])) {
|
303
|
config_del_path('interfaces/wan/blockpriv');
|
304
|
}
|
305
|
if (isset($config['shaper'])) {
|
306
|
config_del_path('shaper');
|
307
|
}
|
308
|
if (isset($config['ezshaper'])) {
|
309
|
config_del_path('ezshaper');
|
310
|
}
|
311
|
if (isset($config['nat'])) {
|
312
|
config_del_path('nat');
|
313
|
}
|
314
|
}
|
315
|
if (preg_match(g_get('wireless_regex'), $lanif)) {
|
316
|
if (is_array($config['interfaces']['lan']) &&
|
317
|
!is_array($config['interfaces']['lan']['wireless'])) {
|
318
|
$config['interfaces']['lan']['wireless'] = array();
|
319
|
}
|
320
|
} else {
|
321
|
if (isset($config['interfaces']['lan'])) {
|
322
|
config_del_path('interfaces/lan/wireless');
|
323
|
}
|
324
|
}
|
325
|
|
326
|
if (is_array($config['interfaces']['wan'])) {
|
327
|
$upints = pfSense_interface_listget(IFF_UP);
|
328
|
if (in_array($config['interfaces']['wan']['if'], $upints))
|
329
|
interface_bring_down('wan', true);
|
330
|
}
|
331
|
if (!is_array($config['interfaces']['wan'])) {
|
332
|
$config['interfaces']['wan'] = array();
|
333
|
}
|
334
|
$config['interfaces']['wan']['if'] = $wanif;
|
335
|
$config['interfaces']['wan']['enable'] = true;
|
336
|
if (preg_match(g_get('wireless_regex'), $wanif)) {
|
337
|
if (is_array($config['interfaces']['wan']) &&
|
338
|
!is_array($config['interfaces']['wan']['wireless'])) {
|
339
|
$config['interfaces']['wan']['wireless'] = array();
|
340
|
}
|
341
|
} else {
|
342
|
if (isset($config['interfaces']['wan'])) {
|
343
|
config_del_path('interfaces/wan/wireless');
|
344
|
}
|
345
|
}
|
346
|
|
347
|
for ($i = 0; $i < count($optif); $i++) {
|
348
|
if (is_array($config['interfaces']['opt' . ($i+1)])) {
|
349
|
$upints = pfSense_interface_listget(IFF_UP);
|
350
|
if (in_array($config['interfaces']['opt' . ($i+1)]['if'], $upints))
|
351
|
interface_bring_down('opt' . ($i+1), true);
|
352
|
}
|
353
|
if (!is_array($config['interfaces']['opt' . ($i+1)])) {
|
354
|
$config['interfaces']['opt' . ($i+1)] = array();
|
355
|
}
|
356
|
|
357
|
$config['interfaces']['opt' . ($i+1)]['if'] = $optif[$i];
|
358
|
|
359
|
/* wireless interface? */
|
360
|
if (preg_match(g_get('wireless_regex'), $optif[$i])) {
|
361
|
if (!is_array($config['interfaces']['opt' . ($i+1)]['wireless'])) {
|
362
|
$config['interfaces']['opt' . ($i+1)]['wireless'] = array();
|
363
|
}
|
364
|
} else {
|
365
|
config_del_path('interfaces/opt' . ($i+1) . '/wireless');
|
366
|
}
|
367
|
|
368
|
if (empty($config['interfaces']['opt' . ($i+1)]['descr'])) {
|
369
|
$config['interfaces']['opt' . ($i+1)]['descr'] = "OPT" . ($i+1);
|
370
|
config_del_path('interfaces/opt' . ($i+1) . '/enable');
|
371
|
}
|
372
|
}
|
373
|
|
374
|
/* remove all other (old) optional interfaces */
|
375
|
for (; isset($config['interfaces']['opt' . ($i+1)]); $i++) {
|
376
|
config_del_path('interfaces/opt' . ($i+1));
|
377
|
}
|
378
|
|
379
|
printf(gettext("%sWriting configuration..."), "\n");
|
380
|
write_config(gettext("Console assignment of interfaces"));
|
381
|
printf(gettext("done.%s"), "\n");
|
382
|
|
383
|
fclose($fp);
|
384
|
|
385
|
echo gettext("One moment while the settings are reloading...");
|
386
|
touch("{$g['tmp_path']}/assign_complete");
|
387
|
|
388
|
if (file_exists("{$g['conf_path']}/trigger_initial_wizard")) {
|
389
|
// Let the system know that the interface assign part of initial setup has been done.
|
390
|
touch("{$g['conf_path']}/assign_complete");
|
391
|
}
|
392
|
|
393
|
echo gettext(" done!") . "\n";
|
394
|
return (0);
|
395
|
}
|
396
|
return (1);
|
397
|
}
|
398
|
|
399
|
function autodetect_interface($ifname, $fp) {
|
400
|
$iflist_prev = get_interface_list("media");
|
401
|
echo <<<EOD
|
402
|
|
403
|
Connect the {$ifname} interface now and make sure that the link is up.
|
404
|
Then press ENTER to continue.
|
405
|
|
406
|
EOD;
|
407
|
fgets($fp);
|
408
|
$iflist = get_interface_list("media");
|
409
|
|
410
|
foreach ($iflist_prev as $ifn => $ifa) {
|
411
|
if (!$ifa['up'] && $iflist[$ifn]['up']) {
|
412
|
printf(gettext('Detected link-up on interface %1$s.%2$s'), $ifn, "\n");
|
413
|
return $ifn;
|
414
|
}
|
415
|
}
|
416
|
|
417
|
printf(gettext("No link-up detected.%s"), "\n");
|
418
|
|
419
|
return null;
|
420
|
}
|
421
|
|
422
|
function interfaces_setup() {
|
423
|
global $iflist;
|
424
|
|
425
|
$iflist = get_interface_list();
|
426
|
}
|
427
|
|
428
|
function vlan_setup() {
|
429
|
global $iflist, $config, $fp;
|
430
|
|
431
|
$iflist = get_interface_list();
|
432
|
|
433
|
$vlancfg = config_get_path('vlans/vlan');
|
434
|
if (is_array($vlancfg) && count($vlancfg)) {
|
435
|
echo "\n" . gettext("WARNING: all existing VLANs will be cleared if you proceed!") . "\n";
|
436
|
echo "\n" . gettext("Do you want to proceed [y|n]?") . " ";
|
437
|
|
438
|
if (strcasecmp(chop(fgets($fp)), "y") != 0) {
|
439
|
return;
|
440
|
}
|
441
|
}
|
442
|
|
443
|
init_config_arr(array('vlans', 'vlan'));
|
444
|
echo "\n";
|
445
|
|
446
|
$vlanif = 0;
|
447
|
|
448
|
while (1) {
|
449
|
$vlan = array();
|
450
|
|
451
|
echo "\n\n" . gettext("VLAN Capable interfaces:") . "\n\n";
|
452
|
if (!is_array($iflist)) {
|
453
|
echo gettext("No interfaces found!") . "\n";
|
454
|
} else {
|
455
|
$vlan_capable = 0;
|
456
|
foreach ($iflist as $iface => $ifa) {
|
457
|
echo sprintf("% -8s%s%s\n", $iface, $ifa['mac'],
|
458
|
$ifa['up'] ? " (up)" : "");
|
459
|
$vlan_capable++;
|
460
|
}
|
461
|
}
|
462
|
|
463
|
if ($vlan_capable == 0) {
|
464
|
echo gettext("No VLAN capable interfaces detected.") . "\n";
|
465
|
return;
|
466
|
}
|
467
|
|
468
|
echo "\n" . gettext("Enter the parent interface name for the new VLAN (or nothing if finished):") . " ";
|
469
|
$vlan['if'] = chop(fgets($fp));
|
470
|
|
471
|
if ($vlan['if']) {
|
472
|
if (!array_key_exists($vlan['if'], $iflist)) {
|
473
|
printf(gettext(
|
474
|
'%1$sInvalid interface name \'%2$s\'%3$s'),
|
475
|
"\n", $vlan['if'], "\n");
|
476
|
continue;
|
477
|
}
|
478
|
} else {
|
479
|
break;
|
480
|
}
|
481
|
|
482
|
echo gettext("Enter the VLAN tag (1-4094):") . " ";
|
483
|
$vlan['tag'] = chop(fgets($fp));
|
484
|
$vlan['vlanif'] = vlan_interface($vlan);
|
485
|
if (!is_numericint($vlan['tag']) || ($vlan['tag'] < 1) || ($vlan['tag'] > 4094)) {
|
486
|
printf(gettext('%1$sInvalid VLAN tag \'%2$s\'%3$s'), "\n", $vlan['tag'], "\n");
|
487
|
continue;
|
488
|
}
|
489
|
|
490
|
if (is_array($config['vlans']['vlan'])) {
|
491
|
foreach (config_get_path('vlans/vlan', []) as $existingvlan) {
|
492
|
if ($vlan['if'] == $existingvlan['if'] && $vlan['tag'] == $existingvlan['tag']) {
|
493
|
printf("\n\n" . gettext("This parent interface and VLAN already created."));
|
494
|
continue 2;
|
495
|
}
|
496
|
}
|
497
|
}
|
498
|
$config['vlans']['vlan'][] = $vlan;
|
499
|
$vlanif++;
|
500
|
}
|
501
|
}
|
502
|
|
503
|
function check_for_alternate_interfaces() {
|
504
|
global $config;
|
505
|
|
506
|
// If the WAN and/or LAN devices in the factory default config do not exist,
|
507
|
// then look for alternate devices.
|
508
|
// This lets many systems boot a factory default config without being
|
509
|
// forced to do interface assignment on the console.
|
510
|
|
511
|
$specplatform = system_identify_specific_platform();
|
512
|
$default_device = array();
|
513
|
|
514
|
// If we recognise the platform, then specify the devices directly.
|
515
|
switch ($specplatform['name']) {
|
516
|
case 'alix':
|
517
|
$default_device['wan'] = "vr1";
|
518
|
$default_device['lan'] = "vr0";
|
519
|
break;
|
520
|
case 'APU':
|
521
|
$default_device['wan'] = "re1";
|
522
|
$default_device['lan'] = "re2";
|
523
|
break;
|
524
|
case 'Turbot Dual-E':
|
525
|
$config['interfaces']['wan']['if'] = 'igb0';
|
526
|
$config['interfaces']['lan']['if'] = 'igb1';
|
527
|
break;
|
528
|
case 'C2758':
|
529
|
$config['interfaces']['wan']['if'] = 'igb0';
|
530
|
$config['interfaces']['lan']['if'] = 'igb1';
|
531
|
$config['interfaces']['opt1'] = array(
|
532
|
'if' => 'igb2',
|
533
|
'descr' => 'OPT1'
|
534
|
);
|
535
|
$config['interfaces']['opt2'] = array(
|
536
|
'if' => 'igb3',
|
537
|
'descr' => 'OPT2'
|
538
|
);
|
539
|
break;
|
540
|
case 'RCC-VE':
|
541
|
case 'SG-2220':
|
542
|
/* SG-4860 or SG-8860 */
|
543
|
if (does_interface_exist('igb4')) {
|
544
|
$config['interfaces']['wan']['if'] = 'igb1';
|
545
|
$config['interfaces']['lan']['if'] = 'igb0';
|
546
|
} else {
|
547
|
$config['interfaces']['wan']['if'] = 'igb0';
|
548
|
$config['interfaces']['lan']['if'] = 'igb1';
|
549
|
}
|
550
|
/* It has 4 ports */
|
551
|
if (does_interface_exist('igb3')) {
|
552
|
$config['interfaces']['opt1'] = array(
|
553
|
'if' => 'igb2',
|
554
|
'descr' => 'OPT1'
|
555
|
);
|
556
|
$config['interfaces']['opt2'] = array(
|
557
|
'if' => 'igb3',
|
558
|
'descr' => 'OPT2'
|
559
|
);
|
560
|
}
|
561
|
/* It has 6 ports */
|
562
|
if (does_interface_exist('igb5')) {
|
563
|
$config['interfaces']['opt3'] = array(
|
564
|
'if' => 'igb4',
|
565
|
'descr' => 'OPT3'
|
566
|
);
|
567
|
$config['interfaces']['opt4'] = array(
|
568
|
'if' => 'igb5',
|
569
|
'descr' => 'OPT4'
|
570
|
);
|
571
|
}
|
572
|
break;
|
573
|
case '1537':
|
574
|
if (does_interface_exist('cxl0')) {
|
575
|
/* It has 10G SFP+ addon */
|
576
|
$config['interfaces']['wan']['if'] = 'cxl0';
|
577
|
$config['interfaces']['lan']['if'] = 'cxl1';
|
578
|
$config['interfaces']['opt1'] = array(
|
579
|
'if' => 'igb0',
|
580
|
'descr' => 'OPT1'
|
581
|
);
|
582
|
$config['interfaces']['opt2'] = array(
|
583
|
'enable' => true,
|
584
|
'if' => 'ix0',
|
585
|
'descr' => 'OPT2'
|
586
|
);
|
587
|
$config['interfaces']['opt3'] = array(
|
588
|
'if' => 'igb1',
|
589
|
'descr' => 'OPT3'
|
590
|
);
|
591
|
$config['interfaces']['opt4'] = array(
|
592
|
'enable' => true,
|
593
|
'if' => 'ix1',
|
594
|
'descr' => 'OPT4'
|
595
|
);
|
596
|
} elseif (does_interface_exist('igb4')) {
|
597
|
/* It has 4 port ethernet addon */
|
598
|
$config['interfaces']['wan']['if'] = 'igb4';
|
599
|
$config['interfaces']['lan']['if'] = 'igb5';
|
600
|
$config['interfaces']['opt1'] = array(
|
601
|
'enable' => true,
|
602
|
'if' => 'ix0',
|
603
|
'descr' => 'OPT1'
|
604
|
);
|
605
|
$config['interfaces']['opt2'] = array(
|
606
|
'enable' => true,
|
607
|
'if' => 'ix1',
|
608
|
'descr' => 'OPT2'
|
609
|
);
|
610
|
$config['interfaces']['opt3'] = array(
|
611
|
'if' => 'igb3',
|
612
|
'descr' => 'OPT3'
|
613
|
);
|
614
|
$config['interfaces']['opt4'] = array(
|
615
|
'if' => 'igb2',
|
616
|
'descr' => 'OPT4'
|
617
|
);
|
618
|
$config['interfaces']['opt5'] = array(
|
619
|
'if' => 'igb1',
|
620
|
'descr' => 'OPT5'
|
621
|
);
|
622
|
$config['interfaces']['opt6'] = array(
|
623
|
'if' => 'igb0',
|
624
|
'descr' => 'OPT6'
|
625
|
);
|
626
|
} else {
|
627
|
$config['interfaces']['wan']['if'] = 'igb0';
|
628
|
$config['interfaces']['lan']['if'] = 'igb1';
|
629
|
$config['interfaces']['opt1'] = array(
|
630
|
'enable' => true,
|
631
|
'if' => 'ix0',
|
632
|
'descr' => 'OPT1'
|
633
|
);
|
634
|
$config['interfaces']['opt2'] = array(
|
635
|
'enable' => true,
|
636
|
'if' => 'ix1',
|
637
|
'descr' => 'OPT2'
|
638
|
);
|
639
|
}
|
640
|
break;
|
641
|
case '1540':
|
642
|
case '1541':
|
643
|
if (does_interface_exist('igb2')) {
|
644
|
/* It has 4 port Intel 1Gb expansion card */
|
645
|
$config['interfaces']['wan']['if'] = 'igb4';
|
646
|
$config['interfaces']['lan']['if'] = 'igb5';
|
647
|
$config['interfaces']['opt1'] = array(
|
648
|
'enable' => true,
|
649
|
'if' => 'ix0',
|
650
|
'descr' => 'OPT1'
|
651
|
);
|
652
|
$config['interfaces']['opt2'] = array(
|
653
|
'enable' => true,
|
654
|
'if' => 'ix1',
|
655
|
'descr' => 'OPT2'
|
656
|
);
|
657
|
$config['interfaces']['opt3'] = array(
|
658
|
'if' => 'igb3',
|
659
|
'descr' => 'OPT3'
|
660
|
);
|
661
|
$config['interfaces']['opt4'] = array(
|
662
|
'if' => 'igb2',
|
663
|
'descr' => 'OPT4'
|
664
|
);
|
665
|
$config['interfaces']['opt5'] = array(
|
666
|
'if' => 'igb1',
|
667
|
'descr' => 'OPT5'
|
668
|
);
|
669
|
$config['interfaces']['opt6'] = array(
|
670
|
'if' => 'igb0',
|
671
|
'descr' => 'OPT6'
|
672
|
);
|
673
|
} elseif (does_interface_exist('cxl0')) {
|
674
|
/* It has 2 port Chelsio 10Gb expansion card */
|
675
|
$config['interfaces']['wan']['if'] = 'cxl0';
|
676
|
$config['interfaces']['lan']['if'] = 'cxl1';
|
677
|
$config['interfaces']['opt1'] = array(
|
678
|
'if' => 'igb0',
|
679
|
'descr' => 'OPT1'
|
680
|
);
|
681
|
$config['interfaces']['opt2'] = array(
|
682
|
'enable' => true,
|
683
|
'if' => 'ix0',
|
684
|
'descr' => 'OPT2'
|
685
|
);
|
686
|
$config['interfaces']['opt3'] = array(
|
687
|
'if' => 'igb1',
|
688
|
'descr' => 'OPT3'
|
689
|
);
|
690
|
$config['interfaces']['opt4'] = array(
|
691
|
'enable' => true,
|
692
|
'if' => 'ix1',
|
693
|
'descr' => 'OPT4'
|
694
|
);
|
695
|
} else {
|
696
|
$config['interfaces']['wan']['if'] = 'ix0';
|
697
|
$config['interfaces']['lan']['if'] = 'ix1';
|
698
|
$config['interfaces']['opt1'] = array(
|
699
|
'if' => 'igb0',
|
700
|
'descr' => 'OPT1'
|
701
|
);
|
702
|
$config['interfaces']['opt2'] = array(
|
703
|
'if' => 'igb1',
|
704
|
'descr' => 'OPT2'
|
705
|
);
|
706
|
}
|
707
|
break;
|
708
|
case 'RCC':
|
709
|
if (does_interface_exist('igb7')) {
|
710
|
// has quad port expansion card
|
711
|
$config['interfaces']['opt5'] = array(
|
712
|
'if' => 'igb0',
|
713
|
'descr' => 'OPT5'
|
714
|
);
|
715
|
$config['interfaces']['opt6'] = array(
|
716
|
'if' => 'igb1',
|
717
|
'descr' => 'OPT6'
|
718
|
);
|
719
|
$config['interfaces']['opt7'] = array(
|
720
|
'if' => 'igb2',
|
721
|
'descr' => 'OPT7'
|
722
|
);
|
723
|
$config['interfaces']['opt8'] = array(
|
724
|
'if' => 'igb3',
|
725
|
'descr' => 'OPT8'
|
726
|
);
|
727
|
$config['interfaces']['wan']['if'] = 'igb4';
|
728
|
$config['interfaces']['lan']['if'] = 'igb6';
|
729
|
$config['interfaces']['opt1'] = array(
|
730
|
'if' => 'igb5',
|
731
|
'descr' => 'OPT1'
|
732
|
);
|
733
|
$config['interfaces']['opt2'] = array(
|
734
|
'if' => 'igb7',
|
735
|
'descr' => 'OPT2'
|
736
|
);
|
737
|
} else {
|
738
|
$config['interfaces']['wan']['if'] = 'igb0';
|
739
|
$config['interfaces']['lan']['if'] = 'igb2';
|
740
|
$config['interfaces']['opt1'] = array(
|
741
|
'if' => 'igb1',
|
742
|
'descr' => 'OPT1'
|
743
|
);
|
744
|
$config['interfaces']['opt2'] = array(
|
745
|
'if' => 'igb3',
|
746
|
'descr' => 'OPT2'
|
747
|
);
|
748
|
}
|
749
|
$config['interfaces']['opt3'] = array(
|
750
|
'enable' => true,
|
751
|
'if' => 'ix0',
|
752
|
'descr' => 'OPT3'
|
753
|
);
|
754
|
$config['interfaces']['opt4'] = array(
|
755
|
'enable' => true,
|
756
|
'if' => 'ix1',
|
757
|
'descr' => 'OPT4'
|
758
|
);
|
759
|
break;
|
760
|
case '5100':
|
761
|
$config['interfaces']['wan']['if'] = 'igb0';
|
762
|
$config['interfaces']['lan']['if'] = 'igb1';
|
763
|
$config['interfaces']['opt1'] = array(
|
764
|
'enable' => true,
|
765
|
'if' => 'ix0',
|
766
|
'descr' => 'OPT1'
|
767
|
);
|
768
|
$config['interfaces']['opt2'] = array(
|
769
|
'enable' => true,
|
770
|
'if' => 'ix1',
|
771
|
'descr' => 'OPT2'
|
772
|
);
|
773
|
$config['interfaces']['opt3'] = array(
|
774
|
'enable' => true,
|
775
|
'if' => 'ix2',
|
776
|
'descr' => 'OPT3'
|
777
|
);
|
778
|
$config['interfaces']['opt4'] = array(
|
779
|
'enable' => true,
|
780
|
'if' => 'ix3',
|
781
|
'descr' => 'OPT4'
|
782
|
);
|
783
|
break;
|
784
|
default:
|
785
|
$default_device['wan'] = "";
|
786
|
$default_device['lan'] = "";
|
787
|
break;
|
788
|
}
|
789
|
|
790
|
// Other common device names can be put here and will be looked for
|
791
|
// if the system was not one of the known platforms.
|
792
|
$other_devices_arr['wan'] = array("vr1", "re1", "igb0", "em0");
|
793
|
$other_devices_arr['lan'] = array("vr0", "re2", "igb1", "em1");
|
794
|
$interface_assignment_changed = false;
|
795
|
|
796
|
foreach ($other_devices_arr as $ifname => $other_devices) {
|
797
|
if (!does_interface_exist($config['interfaces'][$ifname]['if'])) {
|
798
|
if (does_interface_exist($default_device[$ifname])) {
|
799
|
$config['interfaces'][$ifname]['if'] = $default_device[$ifname];
|
800
|
$interface_assignment_changed = true;
|
801
|
} else {
|
802
|
foreach ($other_devices as $other_device) {
|
803
|
if (does_interface_exist($other_device)) {
|
804
|
$config['interfaces'][$ifname]['if'] = $other_device;
|
805
|
$interface_assignment_changed = true;
|
806
|
break;
|
807
|
}
|
808
|
}
|
809
|
}
|
810
|
}
|
811
|
}
|
812
|
|
813
|
if ($interface_assignment_changed) {
|
814
|
write_config("Factory default boot detected WAN " . $config['interfaces']['wan']['if'] . " and LAN " . $config['interfaces']['lan']['if']);
|
815
|
}
|
816
|
}
|
817
|
|
818
|
?>
|