Project

General

Profile

Download (8.26 KB) Statistics
| Branch: | Tag: | Revision:
1 94be2ccf Ermal Luçi
<?php
2
/* $Id$ */
3
/*
4
	interfaces_lagg_edit.php
5
6 ce77a9c4 Phil Davis
	Copyright (C) 2013-2015 Electric Sheep Fencing, LP
7 1d7ba683 ayvis
	Copyright (C) 2008 Ermal Luçi
8 94be2ccf Ermal Luçi
	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 7ac5a4cb Scott Ullrich
/*
32 922bf65c sbeaver
	pfSense_MODULE: interfaces
33 7ac5a4cb Scott Ullrich
*/
34
35
##|+PRIV
36 7997ed44 Renato Botelho
##|*IDENT=page-interfaces-lagg-edit
37 7ac5a4cb Scott Ullrich
##|*NAME=Interfaces: LAGG: Edit page
38 7997ed44 Renato Botelho
##|*DESCR=Allow access to the 'Interfaces: LAGG: Edit' page.
39 7ac5a4cb Scott Ullrich
##|*MATCH=interfaces_lagg_edit.php*
40
##|-PRIV
41 94be2ccf Ermal Luçi
42
require("guiconfig.inc");
43
44 62424bdb Renato Botelho
$referer = (isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '/interfaces_lagg.php');
45
46 94be2ccf Ermal Luçi
if (!is_array($config['laggs']['lagg']))
47
	$config['laggs']['lagg'] = array();
48
49
$a_laggs = &$config['laggs']['lagg'];
50
51 6c6a618a Ermal Luçi
$portlist = get_interface_list();
52 922bf65c sbeaver
$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 94be2ccf Ermal Luçi
106 0a1eabbe Ermal
$realifchecklist = array();
107 d58d04c3 Ermal Luci
/* add LAGG interfaces */
108
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
109 f5e81794 Renato Botelho
	foreach ($config['laggs']['lagg'] as $lagg) {
110
		unset($portlist[$lagg['laggif']]);
111 0a1eabbe Ermal
		$laggiflist = explode(",", $lagg['members']);
112 e6844dd9 sbeaver
		
113 0a1eabbe Ermal
		foreach ($laggiflist as $tmpif)
114
			$realifchecklist[get_real_interface($tmpif)] = $tmpif;
115
	}
116 d58d04c3 Ermal Luci
}
117
118 4318cee1 Ermal Luçi
$checklist = get_configured_interface_list(false, true);
119
foreach ($checklist as $tmpif)
120 85a5da13 Ermal Luçi
	$realifchecklist[get_real_interface($tmpif)] = $tmpif;
121 4318cee1 Ermal Luçi
122 e41ec584 Renato Botelho
if (is_numericint($_GET['id']))
123
	$id = $_GET['id'];
124 e6844dd9 sbeaver
	
125 e41ec584 Renato Botelho
if (isset($_POST['id']) && is_numericint($_POST['id']))
126 94be2ccf Ermal Luçi
	$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 d1f48a88 Ermal
	$laggiflist = explode(",", $a_laggs[$id]['members']);
132 e6844dd9 sbeaver
	
133 d1f48a88 Ermal
	foreach ($laggiflist as $tmpif)
134
		unset($realifchecklist[get_real_interface($tmpif)]);
135 922bf65c sbeaver
136 94be2ccf Ermal Luçi
	$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 1634524d Erik Fonnesbeck
	$reqdfieldsn = array(gettext("Member interfaces"), gettext("Lagg protocol"));
147 94be2ccf Ermal Luçi
148 1e9b4611 Renato Botelho
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
149 94be2ccf Ermal Luçi
150 0e22dda5 Ermal
	if (is_array($_POST['members'])) {
151
		foreach ($_POST['members'] as $member) {
152 cdad45cd bcyrill
			if (!does_interface_exist($member))
153 0e22dda5 Ermal
				$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 94be2ccf Ermal Luçi
	if (!$input_errors) {
162
		$lagg = array();
163 6c6a618a Ermal Luçi
		$lagg['members'] = implode(',', $_POST['members']);
164 94be2ccf Ermal Luçi
		$lagg['descr'] = $_POST['descr'];
165
		$lagg['laggif'] = $_POST['laggif'];
166 39fbee97 Ermal Lu?i
		$lagg['proto'] = $_POST['proto'];
167 4f4e85df Ermal
		if (isset($id) && $a_laggs[$id])
168
			$lagg['laggif'] = $a_laggs[$id]['laggif'];
169 94be2ccf Ermal Luçi
170 f5e81794 Renato Botelho
		$lagg['laggif'] = interface_lagg_configure($lagg);
171
		if ($lagg['laggif'] == "" || !stristr($lagg['laggif'], "lagg"))
172 ab9dc5be Chris Buechler
			$input_errors[] = gettext("Error occurred creating interface, please retry.");
173 f5e81794 Renato Botelho
		else {
174
			if (isset($id) && $a_laggs[$id])
175
				$a_laggs[$id] = $lagg;
176
			else
177
				$a_laggs[] = $lagg;
178 94be2ccf Ermal Luçi
179 f5e81794 Renato Botelho
			write_config();
180 94be2ccf Ermal Luçi
181 5efc5b6f Ermal Luçi
			$confif = convert_real_interface_to_friendly_interface_name($lagg['laggif']);
182 922bf65c sbeaver
			if ($confif != "")
183 f5e81794 Renato Botelho
				interface_configure($confif);
184 5efc5b6f Ermal Luçi
185 94be2ccf Ermal Luçi
			header("Location: interfaces_lagg.php");
186
			exit;
187
		}
188
	}
189
}
190
191 922bf65c sbeaver
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 baca83aa gnhb
$pgtitle = array(gettext("Interfaces"),gettext("LAGG"),gettext("Edit"));
212 b32dd0a6 jim-p
$shortcut_section = "interfaces";
213 94be2ccf Ermal Luçi
include("head.inc");
214 922bf65c sbeaver
require('classes/Form.class.php');
215 94be2ccf Ermal Luçi
216 922bf65c sbeaver
$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 e6844dd9 sbeaver
		$id
256 922bf65c sbeaver
	));
257
}
258
259
$form->add($section);
260
print($form);
261
262
include("foot.inc");