1
|
<?php
|
2
|
/* $Id$ */
|
3
|
/*
|
4
|
interfaces_lagg_edit.php
|
5
|
|
6
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
7
|
Copyright (C) 2008 Ermal Luçi
|
8
|
All rights reserved.
|
9
|
|
10
|
Redistribution and use in source and binary forms, with or without
|
11
|
modification, are permitted provided that the following conditions are met:
|
12
|
|
13
|
1. Redistributions of source code must retain the above copyright notice,
|
14
|
this list of conditions and the following disclaimer.
|
15
|
|
16
|
2. Redistributions in binary form must reproduce the above copyright
|
17
|
notice, this list of conditions and the following disclaimer in the
|
18
|
documentation and/or other materials provided with the distribution.
|
19
|
|
20
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
21
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
22
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
23
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
24
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
25
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
26
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
27
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
28
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
29
|
POSSIBILITY OF SUCH DAMAGE.
|
30
|
*/
|
31
|
/*
|
32
|
pfSense_MODULE: interfaces
|
33
|
*/
|
34
|
|
35
|
##|+PRIV
|
36
|
##|*IDENT=page-interfaces-lagg-edit
|
37
|
##|*NAME=Interfaces: LAGG: Edit page
|
38
|
##|*DESCR=Allow access to the 'Interfaces: LAGG: Edit' page.
|
39
|
##|*MATCH=interfaces_lagg_edit.php*
|
40
|
##|-PRIV
|
41
|
|
42
|
require("guiconfig.inc");
|
43
|
|
44
|
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_lagg.php');
|
45
|
|
46
|
if (!is_array($config['laggs']['lagg']))
|
47
|
$config['laggs']['lagg'] = array();
|
48
|
|
49
|
$a_laggs = &$config['laggs']['lagg'];
|
50
|
|
51
|
$portlist = get_interface_list();
|
52
|
$laggprotos = array("none", "lacp", "failover", "fec", "loadbalance", "roundrobin");
|
53
|
$laggprotosuc = array("NONE", "LACP", "FAILOVER", "FEC", "LOADBALANCE", "ROUNDROBIN");
|
54
|
|
55
|
$protohelp =
|
56
|
'<ul>' .
|
57
|
'<li>' .
|
58
|
'<strong>' . gettext($laggprotos[0]) . '</strong><br />' .
|
59
|
gettext('This protocol is intended to do nothing: it disables any ' .
|
60
|
'traffic without disabling the lagg interface itself') .
|
61
|
'</li>' .
|
62
|
'<li>' .
|
63
|
'<strong>' . gettext($laggprotos[1]) . '</strong><br />' .
|
64
|
gettext('Supports the IEEE 802.3ad Link Aggregation Control Protocol ' .
|
65
|
'(LACP) and the Marker Protocol. LACP will negotiate a set ' .
|
66
|
'of aggregable links with the peer in to one or more Link ' .
|
67
|
'Aggregated Groups. Each LAG is composed of ports of the ' .
|
68
|
'same speed, set to full-duplex operation. The traffic will ' .
|
69
|
'be balanced across the ports in the LAG with the greatest ' .
|
70
|
'total speed, in most cases there will only be one LAG which ' .
|
71
|
'contains all ports. In the event of changes in physical ' .
|
72
|
'connectivity, Link Aggregation will quickly converge to a ' .
|
73
|
'new configuration.') .
|
74
|
'</li>' .
|
75
|
'<li>' .
|
76
|
'<strong>' . gettext($laggprotos[2]) . '</strong><br />' .
|
77
|
gettext('Sends and receives traffic only through the master port. If ' .
|
78
|
'the master port becomes unavailable, the next active port is ' .
|
79
|
'used. The first interface added is the master port; any ' .
|
80
|
'interfaces added after that are used as failover devices.') .
|
81
|
'</li>' .
|
82
|
'<li>' .
|
83
|
'<strong>' . gettext($laggprotos[3]) . '</strong><br />' .
|
84
|
gettext('Supports Cisco EtherChannel. This is a static setup and ' .
|
85
|
'does not negotiate aggregation with the peer or exchange ' .
|
86
|
'frames to monitor the link.') .
|
87
|
'</li>' .
|
88
|
'<li>' .
|
89
|
'<strong>' . gettext($laggprotos[4]) . '</strong><br />' .
|
90
|
gettext('Balances outgoing traffic across the active ports based on ' .
|
91
|
'hashed protocol header information and accepts incoming ' .
|
92
|
'traffic from any active port. This is a static setup and ' .
|
93
|
'does not negotiate aggregation with the peer or exchange ' .
|
94
|
'frames to monitor the link. The hash includes the Ethernet ' .
|
95
|
'source and destination address, and, if available, the VLAN ' .
|
96
|
'tag, and the IP source and destination address') .
|
97
|
'</li>' .
|
98
|
'<li>' .
|
99
|
'<strong>' . gettext($laggprotos[5]) . '</strong><br />' .
|
100
|
gettext('Distributes outgoing traffic using a round-robin scheduler ' .
|
101
|
'through all active ports and accepts incoming traffic from ' .
|
102
|
'any active port') .
|
103
|
'</li>' .
|
104
|
'</ul>';
|
105
|
|
106
|
$realifchecklist = array();
|
107
|
/* add LAGG interfaces */
|
108
|
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
|
109
|
foreach ($config['laggs']['lagg'] as $lagg) {
|
110
|
unset($portlist[$lagg['laggif']]);
|
111
|
$laggiflist = explode(",", $lagg['members']);
|
112
|
|
113
|
foreach ($laggiflist as $tmpif)
|
114
|
$realifchecklist[get_real_interface($tmpif)] = $tmpif;
|
115
|
}
|
116
|
}
|
117
|
|
118
|
$checklist = get_configured_interface_list(false, true);
|
119
|
foreach ($checklist as $tmpif)
|
120
|
$realifchecklist[get_real_interface($tmpif)] = $tmpif;
|
121
|
|
122
|
if (is_numericint($_GET['id']))
|
123
|
$id = $_GET['id'];
|
124
|
|
125
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
126
|
$id = $_POST['id'];
|
127
|
|
128
|
if (isset($id) && $a_laggs[$id]) {
|
129
|
$pconfig['laggif'] = $a_laggs[$id]['laggif'];
|
130
|
$pconfig['members'] = $a_laggs[$id]['members'];
|
131
|
$laggiflist = explode(",", $a_laggs[$id]['members']);
|
132
|
|
133
|
foreach ($laggiflist as $tmpif)
|
134
|
unset($realifchecklist[get_real_interface($tmpif)]);
|
135
|
|
136
|
$pconfig['proto'] = $a_laggs[$id]['proto'];
|
137
|
$pconfig['descr'] = $a_laggs[$id]['descr'];
|
138
|
}
|
139
|
|
140
|
if ($_POST) {
|
141
|
unset($input_errors);
|
142
|
$pconfig = $_POST;
|
143
|
|
144
|
/* input validation */
|
145
|
$reqdfields = explode(" ", "members proto");
|
146
|
$reqdfieldsn = array(gettext("Member interfaces"), gettext("Lagg protocol"));
|
147
|
|
148
|
do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
|
149
|
|
150
|
if (is_array($_POST['members'])) {
|
151
|
foreach ($_POST['members'] as $member) {
|
152
|
if (!does_interface_exist($member))
|
153
|
$input_errors[] = gettext("Interface supplied as member is invalid");
|
154
|
}
|
155
|
} else if (!does_interface_exist($_POST['members']))
|
156
|
$input_errors[] = gettext("Interface supplied as member is invalid");
|
157
|
|
158
|
if (!in_array($_POST['proto'], $laggprotos))
|
159
|
$input_errors[] = gettext("Protocol supplied is invalid");
|
160
|
|
161
|
if (!$input_errors) {
|
162
|
$lagg = array();
|
163
|
$lagg['members'] = implode(',', $_POST['members']);
|
164
|
$lagg['descr'] = $_POST['descr'];
|
165
|
$lagg['laggif'] = $_POST['laggif'];
|
166
|
$lagg['proto'] = $_POST['proto'];
|
167
|
if (isset($id) && $a_laggs[$id])
|
168
|
$lagg['laggif'] = $a_laggs[$id]['laggif'];
|
169
|
|
170
|
$lagg['laggif'] = interface_lagg_configure($lagg);
|
171
|
if ($lagg['laggif'] == "" || !stristr($lagg['laggif'], "lagg"))
|
172
|
$input_errors[] = gettext("Error occurred creating interface, please retry.");
|
173
|
else {
|
174
|
if (isset($id) && $a_laggs[$id])
|
175
|
$a_laggs[$id] = $lagg;
|
176
|
else
|
177
|
$a_laggs[] = $lagg;
|
178
|
|
179
|
write_config();
|
180
|
|
181
|
$confif = convert_real_interface_to_friendly_interface_name($lagg['laggif']);
|
182
|
if ($confif != "")
|
183
|
interface_configure($confif);
|
184
|
|
185
|
header("Location: interfaces_lagg.php");
|
186
|
exit;
|
187
|
}
|
188
|
}
|
189
|
}
|
190
|
|
191
|
function build_member_list() {
|
192
|
global $pconfig, $portlist, $realifchecklist;
|
193
|
|
194
|
$memberlist = array('list' => array(),
|
195
|
'selected' => array());
|
196
|
|
197
|
$members_array = explode(',', $pconfig['members']);
|
198
|
foreach ($portlist as $ifn => $ifinfo) {
|
199
|
if (array_key_exists($ifn, $realifchecklist))
|
200
|
continue;
|
201
|
|
202
|
$memberlist['list'][$ifn] = $ifn . '(' . $ifinfo['mac'] . ')';
|
203
|
|
204
|
if (stristr($pconfig['members'], $ifn))
|
205
|
array_push($memberlist['selected'], $ifn);
|
206
|
}
|
207
|
|
208
|
return($memberlist);
|
209
|
}
|
210
|
|
211
|
$pgtitle = array(gettext("Interfaces"),gettext("LAGG"),gettext("Edit"));
|
212
|
$shortcut_section = "interfaces";
|
213
|
include("head.inc");
|
214
|
require('classes/Form.class.php');
|
215
|
|
216
|
$form = new Form();
|
217
|
|
218
|
$form->addGlobal(new Form_Button(
|
219
|
'cancel',
|
220
|
'Cancel',
|
221
|
$referer
|
222
|
));
|
223
|
|
224
|
$section = new Form_Section('LAGG Configuration');
|
225
|
|
226
|
$memberslist = build_member_list();
|
227
|
|
228
|
$section->addInput(new Form_Select(
|
229
|
'members[]',
|
230
|
'Parent Interfaces',
|
231
|
$memberslist['selected'],
|
232
|
$memberslist['list'],
|
233
|
true // Allow multiples
|
234
|
))->setHelp('Choose the members that will be used for the link aggregation.');
|
235
|
|
236
|
$section->addInput(new Form_Select(
|
237
|
'proto',
|
238
|
'LAGG Protocol',
|
239
|
$pconfig['proto'],
|
240
|
array_combine($laggprotos, $laggprotosuc)
|
241
|
))->setHelp($protohelp);
|
242
|
|
243
|
$section->addInput(new Form_Input(
|
244
|
'laggif',
|
245
|
null,
|
246
|
'hidden',
|
247
|
$pconfig['laggif']
|
248
|
));
|
249
|
|
250
|
if (isset($id) && $a_laggs[$id]) {
|
251
|
$section->addInput(new Form_Input(
|
252
|
'id',
|
253
|
null,
|
254
|
'hidden',
|
255
|
$id
|
256
|
));
|
257
|
}
|
258
|
|
259
|
$form->add($section);
|
260
|
print($form);
|
261
|
|
262
|
include("foot.inc");
|