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