Project

General

Profile

« Previous | Next » 

Revision 8bd84082

Added by Luiz Souza over 9 years ago

Add support for multiple span ports on bridge.

While here, fix and improve the error detection for the selected ports.

Inspired by pull request #2613 from heper/patch-1

Ticket #5871

View differences:

src/etc/inc/interfaces.inc
617 617
	if ($bridge['timeout'] <> "") {
618 618
		mwexec("/sbin/ifconfig {$bridgeif} timeout " . escapeshellarg($bridge['timeout']));
619 619
	}
620
	if ($bridge['span'] <> "") {
621
		$realif = get_real_interface($bridge['span']);
622
		mwexec("/sbin/ifconfig {$bridgeif} span {$realif}");
620
	if (!empty($bridge['span'])) {
621
		$spanifs = explode(",", $bridge['span']);
622
		foreach ($spanifs as $spanif) {
623
			$realif = get_real_interface($spanif);
624
			mwexec("/sbin/ifconfig {$bridgeif} span {$realif}");
625
		}
623 626
	}
624 627
	if (!empty($bridge['edge'])) {
625 628
		$edgeifs = explode(',', $bridge['edge']);
src/usr/local/www/interfaces_bridge_edit.php
90 90
	$pconfig['members'] = $a_bridges[$id]['members'];
91 91
	$pconfig['maxaddr'] = $a_bridges[$id]['maxaddr'];
92 92
	$pconfig['timeout'] = $a_bridges[$id]['timeout'];
93
	if ($a_bridges[$id]['static']) {
94
		$pconfig['static'] = $a_bridges[$id]['static'];
95
	}
96
	if ($a_bridges[$id]['private']) {
97
		$pconfig['private'] = $a_bridges[$id]['private'];
98
	}
99
	if (isset($a_bridges[$id]['stp'])) {
100
		$pconfig['stp'] = $a_bridges[$id]['stp'];
101
	}
102 93
	$pconfig['maxage'] = $a_bridges[$id]['maxage'];
103 94
	$pconfig['fwdelay'] = $a_bridges[$id]['fwdelay'];
104 95
	$pconfig['hellotime'] = $a_bridges[$id]['hellotime'];
......
132 123
		$pconfig['ifpathcost'] = $ifpathcost;
133 124
	}
134 125

  
135
	$pconfig['span'] = $a_bridges[$id]['span'];
126
	if (isset($a_bridges[$id]['static'])) {
127
		$pconfig['static'] = $a_bridges[$id]['static'];
128
	}
129
	if (isset($a_bridges[$id]['private'])) {
130
		$pconfig['private'] = $a_bridges[$id]['private'];
131
	}
132
	if (isset($a_bridges[$id]['stp'])) {
133
		$pconfig['stp'] = $a_bridges[$id]['stp'];
134
	}
135
	if (isset($a_bridges[$id]['span'])) {
136
		$pconfig['span'] = $a_bridges[$id]['span'];
137
	}
136 138
	if (isset($a_bridges[$id]['edge'])) {
137 139
		$pconfig['edge'] = $a_bridges[$id]['edge'];
138 140
	}
......
197 199
		$input_errors[] = gettext("You must select at least one member interface for a bridge.");
198 200
	}
199 201

  
202
	if (is_array($_POST['static'])) {
203
		foreach ($_POST['static'] as $ifstatic) {
204
			if (is_array($_POST['members']) && !in_array($ifstatic, $_POST['members'])) {
205
				$input_errors[] = gettext("Sticky interface ($ifstatic) is not part of the bridge. Remove the sticky interface to continue.");
206
			}
207
		}
208
		$pconfig['static'] = implode(',', $_POST['static']);
209
	}
210
	if (is_array($_POST['private'])) {
211
		foreach ($_POST['private'] as $ifprivate) {
212
			if (is_array($_POST['members']) && !in_array($ifprivate, $_POST['members'])) {
213
				$input_errors[] = gettext("Private interface ($ifprivate) is not part of the bridge. Remove the private interface to continue.");
214
			}
215
		}
216
		$pconfig['private'] = implode(',', $_POST['private']);
217
	}
218
	if (is_array($_POST['stp'])) {
219
		foreach ($_POST['stp'] as $ifstp) {
220
			if (is_array($_POST['members']) && !in_array($ifstp, $_POST['members'])) {
221
				$input_errors[] = gettext("STP interface ($ifstp) is not part of the bridge. Remove the STP interface to continue.");
222
			}
223
		}
224
		$pconfig['stp'] = implode(',', $_POST['stp']);
225
	}
226
	if (is_array($_POST['span'])) {
227
		$pconfig['span'] = implode(',', $_POST['span']);
228
	}
229
	if (is_array($_POST['edge'])) {
230
		foreach ($_POST['edge'] as $ifedge) {
231
			if (is_array($_POST['members']) && !in_array($ifedge, $_POST['members'])) {
232
				$input_errors[] = gettext("Edge interface ($ifedge) is not part of the bridge. Remove the edge interface to continue.");
233
			}
234
		}
235
		$pconfig['edge'] = implode(',', $_POST['edge']);
236
	}
237
	if (is_array($_POST['autoedge'])) {
238
		foreach ($_POST['autoedge'] as $ifautoedge) {
239
			if (is_array($_POST['members']) && !in_array($ifautoedge, $_POST['members'])) {
240
				$input_errors[] = gettext("Auto Edge interface ($ifautoedge) is not part of the bridge. Remove the auto edge interface to continue.");
241
			}
242
		}
243
		$pconfig['autoedge'] = implode(',', $_POST['autoedge']);
244
	}
245
	if (is_array($_POST['ptp'])) {
246
		foreach ($_POST['ptp'] as $ifptp) {
247
			if (is_array($_POST['members']) && !in_array($ifptp, $_POST['members'])) {
248
				$input_errors[] = gettext("PTP interface ($ifptp) is not part of the bridge. Remove the PTP interface to continue.");
249
			}
250
		}
251
		$pconfig['ptp'] = implode(',', $_POST['ptp']);
252
	}
253
	if (is_array($_POST['autoptp'])) {
254
		foreach ($_POST['autoptp'] as $ifautoptp) {
255
			if (is_array($_POST['members']) && !in_array($ifautoptp, $_POST['members'])) {
256
				$input_errors[] = gettext("Auto PTP interface ($ifautoptp) is not part of the bridge. Remove the auto PTP interface to continue.");
257
			}
258
		}
259
		$pconfig['autoptp'] = implode(',', $_POST['autoptp']);
260
	}
200 261
	if (is_array($_POST['members'])) {
201 262
		foreach ($_POST['members'] as $ifmembers) {
202 263
			if (empty($config['interfaces'][$ifmembers])) {
......
206 267
			    $config['interfaces'][$ifmembers]['wireless']['mode'] != "hostap") {
207 268
				$input_errors[] = gettext("Bridging a wireless interface is only possible in hostap mode.");
208 269
			}
209
			if ($_POST['span'] != "none" && $_POST['span'] == $ifmembers) {
210
				$input_errors[] = gettext("Span interface cannot be part of the bridge. Remove the span interface from bridge members to continue.");
270
			if (is_array($_POST['span']) && in_array($ifmembers, $_POST['span'])) {
271
				$input_errors[] = gettext("Span interface ($ifmembers) cannot be part of the bridge. Remove the span interface from bridge members to continue.");
211 272
			}
212 273
			foreach ($a_bridges as $a_bridge) {
213 274
				if ($_POST['bridgeif'] === $a_bridge['bridgeif']) {
......
231 292
		$bridge['descr'] = $_POST['descr'];
232 293
		$bridge['maxaddr'] = $_POST['maxaddr'];
233 294
		$bridge['timeout'] = $_POST['timeout'];
234
		if ($_POST['static']) {
235
			$bridge['static'] = implode(',', $_POST['static']);
236
		}
237
		if ($_POST['private']) {
238
			$bridge['private'] = implode(',', $_POST['private']);
239
		}
240
		if (isset($_POST['stp'])) {
241
			$bridge['stp'] = implode(',', $_POST['stp']);
242
		}
243 295
		$bridge['maxage'] = $_POST['maxage'];
244 296
		$bridge['fwdelay'] = $_POST['fwdelay'];
245 297
		$bridge['hellotime'] = $_POST['hellotime'];
......
269 321
		$bridge['ifpriority'] = $ifpriority;
270 322
		$bridge['ifpathcost'] = $ifpathcost;
271 323

  
272
		if ($_POST['span'] != "none") {
273
			$bridge['span'] = $_POST['span'];
274
		} else {
275
			unset($bridge['span']);
324
		if (isset($_POST['static'])) {
325
			$bridge['static'] = implode(',', $_POST['static']);
326
		}
327
		if (isset($_POST['private'])) {
328
			$bridge['private'] = implode(',', $_POST['private']);
329
		}
330
		if (isset($_POST['stp'])) {
331
			$bridge['stp'] = implode(',', $_POST['stp']);
332
		}
333
		if (isset($_POST['span'])) {
334
			$bridge['span'] = implode(',', $_POST['span']);
276 335
		}
277 336
		if (isset($_POST['edge'])) {
278 337
			$bridge['edge'] = implode(',', $_POST['edge']);
......
287 346
			$bridge['autoptp'] = implode(',', $_POST['autoptp']);
288 347
		}
289 348

  
290

  
291 349
		$bridge['bridgeif'] = $_POST['bridgeif'];
292 350
		interface_bridge_configure($bridge);
293 351
		if ($bridge['bridgeif'] == "" || !stristr($bridge['bridgeif'], "bridge")) {
......
312 370
	}
313 371
}
314 372

  
315
function build_spanport_list() {
316
	global $ifacelist;
317

  
318
	$splist = array('none' => gettext('None'));
319

  
320
	foreach ($ifacelist as $ifn => $ifdescr) {
321
		$splist[$ifn] = $ifdescr;
322
	}
323

  
324
	return($splist);
325
}
326

  
327
function build_member_list() {
328
	global $pconfig, $ifacelist;
329

  
330
	$memberlist = array('list' => array(), 'selected' => array());
331

  
332
	$members_array = explode(',', $pconfig['members']);
333
	foreach ($ifacelist as $ifn => $ifinfo) {
334
		$memberlist['list'][$ifn] = $ifinfo;
335

  
336
		if (in_array($ifn, $members_array)) {
337
			array_push($memberlist['selected'], $ifn);
338
		}
339
	}
340
	unset($members_array);
341
	return($memberlist);
342
}
343

  
344 373
function build_port_list($selecton) {
345 374
	global $ifacelist;
346 375

  
......
369 398

  
370 399
$section = new Form_Section('Bridge Configuration');
371 400

  
372
$memberslist = build_member_list();
401
$memberslist = build_port_list($pconfig['members']);
373 402

  
374 403
$section->addInput(new Form_Select(
375 404
	'members',
......
418 447
	$pconfig['timeout']
419 448
))->setHelp('Set the timeout of address cache entries to this number of seconds. If seconds is zero, then address cache entries will not be expired. The default is 240 seconds');
420 449

  
450
$spanlist = build_port_list($pconfig['span']);
451

  
421 452
$section->addInput(new Form_Select(
422 453
	'span',
423 454
	'Span Port',
424
	$pconfig['span'],
425
	build_spanport_list()
455
	$spanlist['selected'],
456
	$spanlist['list'],
457
	true
426 458
))->setHelp('Add the interface named by interface as a span port on the bridge. Span ports transmit a copy of every frame received by the bridge.' .
427 459
			'This is most useful for snooping a bridged network passively on another host connected to one of the span ports of the bridge. <br />' .
428 460
			'%sThe span interface cannot be part of the bridge member interfaces.%s', ['<strong>', '</strong>']);

Also available in: Unified diff