1 |
b991e3b5
|
Ermal Lu?i
|
<?php
|
2 |
|
|
/*
|
3 |
ce77a9c4
|
Phil Davis
|
interfaces_qinq_edit.php
|
4 |
|
|
|
5 |
|
|
Copyright (C) 2013-2015 Electric Sheep Fencing, LP
|
6 |
1d7ba683
|
ayvis
|
Copyright (C) 2009 Ermal Luçi
|
7 |
b991e3b5
|
Ermal Lu?i
|
All rights reserved.
|
8 |
|
|
|
9 |
|
|
Redistribution and use in source and binary forms, with or without
|
10 |
|
|
modification, are permitted provided that the following conditions are met:
|
11 |
|
|
|
12 |
|
|
1. Redistributions of source code must retain the above copyright notice,
|
13 |
|
|
this list of conditions and the following disclaimer.
|
14 |
|
|
|
15 |
|
|
2. Redistributions in binary form must reproduce the above copyright
|
16 |
|
|
notice, this list of conditions and the following disclaimer in the
|
17 |
|
|
documentation and/or other materials provided with the distribution.
|
18 |
|
|
|
19 |
|
|
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
20 |
|
|
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
21 |
|
|
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
22 |
|
|
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
|
23 |
|
|
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
24 |
|
|
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
25 |
|
|
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
26 |
|
|
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
27 |
|
|
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
28 |
|
|
POSSIBILITY OF SUCH DAMAGE.
|
29 |
|
|
*/
|
30 |
7ac5a4cb
|
Scott Ullrich
|
/*
|
31 |
3bbf56d7
|
Stephen Beaver
|
pfSense_BUILDER_BINARIES: /usr/sbin/ngctl
|
32 |
|
|
pfSense_MODULE: interfaces
|
33 |
7ac5a4cb
|
Scott Ullrich
|
*/
|
34 |
b991e3b5
|
Ermal Lu?i
|
|
35 |
|
|
##|+PRIV
|
36 |
7997ed44
|
Renato Botelho
|
##|*IDENT=page-interfaces-qinq-edit
|
37 |
b991e3b5
|
Ermal Lu?i
|
##|*NAME=Interfaces: QinQ: Edit page
|
38 |
7997ed44
|
Renato Botelho
|
##|*DESCR=Allow access to 'Interfaces: QinQ: Edit' page
|
39 |
b991e3b5
|
Ermal Lu?i
|
##|*MATCH=interfaces_qinq_edit.php*
|
40 |
|
|
##|-PRIV
|
41 |
|
|
|
42 |
93bcbb6a
|
Renato Botelho
|
$pgtitle = array(gettext("Interfaces"),gettext("QinQ"), gettext("Edit"));
|
43 |
b32dd0a6
|
jim-p
|
$shortcut_section = "interfaces";
|
44 |
b991e3b5
|
Ermal Lu?i
|
|
45 |
|
|
require("guiconfig.inc");
|
46 |
|
|
|
47 |
|
|
if (!is_array($config['qinqs']['qinqentry']))
|
48 |
|
|
$config['qinqs']['qinqentry'] = array();
|
49 |
|
|
|
50 |
|
|
$a_qinqs = &$config['qinqs']['qinqentry'];
|
51 |
|
|
|
52 |
|
|
$portlist = get_interface_list();
|
53 |
|
|
|
54 |
|
|
/* add LAGG interfaces */
|
55 |
|
|
if (is_array($config['laggs']['lagg']) && count($config['laggs']['lagg'])) {
|
56 |
3bbf56d7
|
Stephen Beaver
|
foreach ($config['laggs']['lagg'] as $lagg)
|
57 |
|
|
$portlist[$lagg['laggif']] = $lagg;
|
58 |
b991e3b5
|
Ermal Lu?i
|
}
|
59 |
|
|
|
60 |
|
|
if (count($portlist) < 1) {
|
61 |
|
|
header("Location: interfaces_qinq.php");
|
62 |
|
|
exit;
|
63 |
|
|
}
|
64 |
|
|
|
65 |
e41ec584
|
Renato Botelho
|
if (is_numericint($_GET['id']))
|
66 |
|
|
$id = $_GET['id'];
|
67 |
3bbf56d7
|
Stephen Beaver
|
|
68 |
e41ec584
|
Renato Botelho
|
if (isset($_POST['id']) && is_numericint($_POST['id']))
|
69 |
b991e3b5
|
Ermal Lu?i
|
$id = $_POST['id'];
|
70 |
|
|
|
71 |
|
|
if (isset($id) && $a_qinqs[$id]) {
|
72 |
|
|
$pconfig['if'] = $a_qinqs[$id]['if'];
|
73 |
|
|
$pconfig['tag'] = $a_qinqs[$id]['tag'];
|
74 |
|
|
$pconfig['members'] = $a_qinqs[$id]['members'];
|
75 |
|
|
$pconfig['descr'] = html_entity_decode($a_qinqs[$id]['descr']);
|
76 |
|
|
$pconfig['autogroup'] = isset($a_qinqs[$id]['autogroup']);
|
77 |
|
|
$pconfig['autoadjustmtu'] = isset($a_qinqs[$id]['autoadjustmtu']);
|
78 |
|
|
}
|
79 |
|
|
|
80 |
|
|
if ($_POST) {
|
81 |
|
|
unset($input_errors);
|
82 |
|
|
$pconfig = $_POST;
|
83 |
|
|
|
84 |
|
|
if (empty($_POST['tag']))
|
85 |
93bcbb6a
|
Renato Botelho
|
$input_errors[] = gettext("First level tag cannot be empty.");
|
86 |
b991e3b5
|
Ermal Lu?i
|
if (isset($id) && $a_qinqs[$id]['tag'] != $_POST['tag'])
|
87 |
93bcbb6a
|
Renato Botelho
|
$input_errors[] = gettext("You are editing an existing entry and modifying the first level tag is not allowed.");
|
88 |
b991e3b5
|
Ermal Lu?i
|
if (isset($id) && $a_qinqs[$id]['if'] != $_POST['if'])
|
89 |
93bcbb6a
|
Renato Botelho
|
$input_errors[] = gettext("You are editing an existing entry and modifying the interface is not allowed.");
|
90 |
b991e3b5
|
Ermal Lu?i
|
if (!isset($id)) {
|
91 |
3bbf56d7
|
Stephen Beaver
|
foreach ($a_qinqs as $qinqentry) {
|
92 |
b991e3b5
|
Ermal Lu?i
|
if ($qinqentry['tag'] == $_POST['tag'] && $qinqentry['if'] == $_POST['if'])
|
93 |
93bcbb6a
|
Renato Botelho
|
$input_errors[] = gettext("QinQ level already exists for this interface, edit it!");
|
94 |
3bbf56d7
|
Stephen Beaver
|
}
|
95 |
|
|
|
96 |
b991e3b5
|
Ermal Lu?i
|
if (is_array($config['vlans']['vlan'])) {
|
97 |
|
|
foreach ($config['vlans']['vlan'] as $vlan)
|
98 |
|
|
if ($vlan['tag'] == $_POST['tag'] && $vlan['if'] == $_POST['if'])
|
99 |
93bcbb6a
|
Renato Botelho
|
$input_errors[] = gettext("A normal VLAN exists with this tag please remove it to use this tag for QinQ first level.");
|
100 |
b991e3b5
|
Ermal Lu?i
|
}
|
101 |
|
|
}
|
102 |
|
|
|
103 |
|
|
$qinqentry = array();
|
104 |
|
|
$qinqentry['if'] = $_POST['if'];
|
105 |
|
|
$qinqentry['tag'] = $_POST['tag'];
|
106 |
3bbf56d7
|
Stephen Beaver
|
|
107 |
b991e3b5
|
Ermal Lu?i
|
if ($_POST['autogroup'] == "yes")
|
108 |
|
|
$qinqentry['autogroup'] = true;
|
109 |
|
|
|
110 |
|
|
$members = "";
|
111 |
|
|
$isfirst = 0;
|
112 |
|
|
|
113 |
3bbf56d7
|
Stephen Beaver
|
// Read the POSTed member array into a space separated list translating any ranges
|
114 |
|
|
// into their included values
|
115 |
|
|
foreach ($_POST['members'] as $memb) {
|
116 |
|
|
// Might be a range
|
117 |
|
|
$member = explode("-", $memb);
|
118 |
|
|
|
119 |
|
|
if (count($member) > 1) {
|
120 |
|
|
if (preg_match("/([^0-9])+/", $member[0], $match) || preg_match("/([^0-9])+/", $member[1], $match))
|
121 |
|
|
$input_errors[] = gettext("Tags can contain only numbers or a range in format #-#.");
|
122 |
|
|
|
123 |
|
|
for ($i = $member[0]; $i <= $member[1]; $i++) {
|
124 |
|
|
$members .= ($isfirst == 0 ? '':' ') . $i;
|
125 |
|
|
$isfirst++;
|
126 |
|
|
}
|
127 |
|
|
}
|
128 |
|
|
else { // Just a single number
|
129 |
|
|
if (preg_match("/([^0-9])+/", $memb, $match))
|
130 |
|
|
$input_errors[] = gettext("Tags can contain only numbers or a range in format #-#.");
|
131 |
|
|
else {
|
132 |
|
|
$members .= ($isfirst == 0 ? '':' ') . $memb;
|
133 |
b991e3b5
|
Ermal Lu?i
|
$isfirst++;
|
134 |
|
|
}
|
135 |
|
|
}
|
136 |
|
|
}
|
137 |
|
|
|
138 |
|
|
if (!$input_errors) {
|
139 |
|
|
$qinqentry['members'] = $members;
|
140 |
d865241e
|
jim-p
|
$qinqentry['descr'] = $_POST['descr'];
|
141 |
4400ad66
|
Ermal Lu?i
|
$qinqentry['vlanif'] = "{$_POST['if']}_{$_POST['tag']}";
|
142 |
b991e3b5
|
Ermal Lu?i
|
$nmembers = explode(" ", $members);
|
143 |
|
|
|
144 |
|
|
if (isset($id) && $a_qinqs[$id]) {
|
145 |
|
|
$omembers = explode(" ", $a_qinqs[$id]['members']);
|
146 |
|
|
$delmembers = array_diff($omembers, $nmembers);
|
147 |
908e5985
|
Renato Botelho
|
$addmembers = array_diff($nmembers, $omembers);
|
148 |
|
|
|
149 |
|
|
if ((count($delmembers) > 0) || (count($addmembers) > 0)) {
|
150 |
|
|
$fd = fopen("{$g['tmp_path']}/netgraphcmd", "w");
|
151 |
b991e3b5
|
Ermal Lu?i
|
foreach ($delmembers as $tag) {
|
152 |
908e5985
|
Renato Botelho
|
fwrite($fd, "shutdown {$qinqentry['vlanif']}h{$tag}:\n");
|
153 |
|
|
fwrite($fd, "msg {$qinqentry['vlanif']}qinq: delfilter \\\"{$qinqentry['vlanif']}{$tag}\\\"\n");
|
154 |
b991e3b5
|
Ermal Lu?i
|
}
|
155 |
908e5985
|
Renato Botelho
|
|
156 |
b991e3b5
|
Ermal Lu?i
|
foreach ($addmembers as $member) {
|
157 |
908e5985
|
Renato Botelho
|
$qinq = array();
|
158 |
|
|
$qinq['if'] = $qinqentry['vlanif'];
|
159 |
|
|
$qinq['tag'] = $member;
|
160 |
4400ad66
|
Ermal Lu?i
|
$macaddr = get_interface_mac($qinqentry['vlanif']);
|
161 |
908e5985
|
Renato Botelho
|
interface_qinq2_configure($qinq, $fd, $macaddr);
|
162 |
b991e3b5
|
Ermal Lu?i
|
}
|
163 |
908e5985
|
Renato Botelho
|
|
164 |
|
|
fclose($fd);
|
165 |
|
|
mwexec("/usr/sbin/ngctl -f {$g['tmp_path']}/netgraphcmd");
|
166 |
b991e3b5
|
Ermal Lu?i
|
}
|
167 |
|
|
$a_qinqs[$id] = $qinqentry;
|
168 |
|
|
} else {
|
169 |
b554b869
|
Renato Botelho
|
interface_qinq_configure($qinqentry);
|
170 |
b991e3b5
|
Ermal Lu?i
|
$a_qinqs[] = $qinqentry;
|
171 |
|
|
}
|
172 |
|
|
if ($_POST['autogroup'] == "yes") {
|
173 |
|
|
if (!is_array($config['ifgroups']['ifgroupentry']))
|
174 |
|
|
$config['ifgroups']['ifgroupentry'] = array();
|
175 |
|
|
foreach ($config['ifgroups']['ifgroupentry'] as $gid => $group) {
|
176 |
|
|
if ($group['ifname'] == "QinQ") {
|
177 |
|
|
$found = true;
|
178 |
|
|
break;
|
179 |
|
|
}
|
180 |
|
|
}
|
181 |
|
|
$additions = "";
|
182 |
|
|
foreach($nmembers as $qtag)
|
183 |
4400ad66
|
Ermal Lu?i
|
$additions .= "{$qinqentry['vlanif']}_{$qtag} ";
|
184 |
|
|
$additions .= "{$qinqentry['vlanif']}";
|
185 |
b991e3b5
|
Ermal Lu?i
|
if ($found == true)
|
186 |
|
|
$config['ifgroups']['ifgroupentry'][$gid]['members'] .= " {$additions}";
|
187 |
|
|
else {
|
188 |
|
|
$gentry = array();
|
189 |
|
|
$gentry['ifname'] = "QinQ";
|
190 |
|
|
$gentry['members'] = "{$additions}";
|
191 |
93bcbb6a
|
Renato Botelho
|
$gentry['descr'] = gettext("QinQ VLANs group");
|
192 |
ceae2616
|
Ermal Lu?i
|
$config['ifgroups']['ifgroupentry'][] = $gentry;
|
193 |
b991e3b5
|
Ermal Lu?i
|
}
|
194 |
|
|
}
|
195 |
|
|
|
196 |
|
|
write_config();
|
197 |
|
|
|
198 |
|
|
header("Location: interfaces_qinq.php");
|
199 |
|
|
exit;
|
200 |
|
|
} else {
|
201 |
d865241e
|
jim-p
|
$pconfig['descr'] = $_POST['descr'];
|
202 |
b991e3b5
|
Ermal Lu?i
|
$pconfig['tag'] = $_POST['tag'];
|
203 |
|
|
$pconfig['members'] = $members;
|
204 |
|
|
}
|
205 |
|
|
}
|
206 |
|
|
|
207 |
4b94f9ec
|
Stephen Beaver
|
function build_parent_list() {
|
208 |
|
|
global $portlist;
|
209 |
3bbf56d7
|
Stephen Beaver
|
|
210 |
4b94f9ec
|
Stephen Beaver
|
$list = array();
|
211 |
3bbf56d7
|
Stephen Beaver
|
|
212 |
4b94f9ec
|
Stephen Beaver
|
foreach ($portlist as $ifn => $ifinfo) {
|
213 |
|
|
if (is_jumbo_capable($ifn))
|
214 |
|
|
$list[$ifn] = $ifn . ' (' . $ifinfo['mac'] . ')';
|
215 |
|
|
}
|
216 |
3bbf56d7
|
Stephen Beaver
|
|
217 |
|
|
return($list);
|
218 |
4b94f9ec
|
Stephen Beaver
|
}
|
219 |
b991e3b5
|
Ermal Lu?i
|
|
220 |
4b94f9ec
|
Stephen Beaver
|
include("head.inc");
|
221 |
b991e3b5
|
Ermal Lu?i
|
|
222 |
3bbf56d7
|
Stephen Beaver
|
if ($input_errors)
|
223 |
|
|
print_input_errors($input_errors);
|
224 |
b991e3b5
|
Ermal Lu?i
|
|
225 |
4b94f9ec
|
Stephen Beaver
|
require('classes/Form.class.php');
|
226 |
|
|
|
227 |
|
|
$form = new Form(new Form_Button(
|
228 |
|
|
'Submit',
|
229 |
|
|
gettext("Save")
|
230 |
|
|
));
|
231 |
|
|
|
232 |
|
|
$section = new Form_Section('Interface QinQ Edit');
|
233 |
|
|
|
234 |
|
|
$section->addInput(new Form_Select(
|
235 |
3bbf56d7
|
Stephen Beaver
|
'if',
|
236 |
4b94f9ec
|
Stephen Beaver
|
'Parent interface',
|
237 |
|
|
$pconfig['if'],
|
238 |
|
|
build_parent_list()
|
239 |
|
|
))->setHelp('Only QinQ capable interfaces will be shown.');
|
240 |
3bbf56d7
|
Stephen Beaver
|
|
241 |
4b94f9ec
|
Stephen Beaver
|
$section->addInput(new Form_Input(
|
242 |
|
|
'tag',
|
243 |
|
|
'First level tag',
|
244 |
|
|
'number',
|
245 |
|
|
$pconfig['tag'],
|
246 |
|
|
['max' => '4094', 'min' => '1']
|
247 |
|
|
))->setHelp('This is the first level VLAN tag. On top of this are stacked the member VLANs defined below.');
|
248 |
3bbf56d7
|
Stephen Beaver
|
|
249 |
4b94f9ec
|
Stephen Beaver
|
$section->addInput(new Form_Checkbox(
|
250 |
|
|
'autogroup',
|
251 |
|
|
'Option(s)',
|
252 |
|
|
'Adds interface to QinQ interface groups',
|
253 |
|
|
$pconfig['autogroup']
|
254 |
|
|
))->setHelp('Allows rules to be written more easily');
|
255 |
|
|
|
256 |
|
|
$section->addInput(new Form_Input(
|
257 |
|
|
'descr',
|
258 |
|
|
'Description',
|
259 |
|
|
'text',
|
260 |
|
|
$pconfig['descr']
|
261 |
|
|
))->setHelp('You may enter a description here for your reference (not parsed).');
|
262 |
|
|
|
263 |
|
|
$section->addInput(new Form_StaticText(
|
264 |
|
|
'Member(s)',
|
265 |
|
|
'You can specify ranges in the inputs below. Enter a range (2-3) or individual numbers.' . '<br />' .
|
266 |
|
|
'Click "Duplicate" as many times as needed to add new inputs'
|
267 |
|
|
));
|
268 |
|
|
|
269 |
3bbf56d7
|
Stephen Beaver
|
if (isset($id) && $a_qinqs[$id]) {
|
270 |
|
|
$section->addInput(new Form_Input(
|
271 |
|
|
'id',
|
272 |
|
|
null,
|
273 |
|
|
'hidden',
|
274 |
|
|
$id
|
275 |
|
|
));
|
276 |
|
|
}
|
277 |
|
|
|
278 |
4b94f9ec
|
Stephen Beaver
|
$counter = 0;
|
279 |
|
|
$members = $pconfig['members'];
|
280 |
|
|
|
281 |
3bbf56d7
|
Stephen Beaver
|
// List each of the member tags from the space-separated list
|
282 |
|
|
if ($members != "")
|
283 |
4b94f9ec
|
Stephen Beaver
|
$item = explode(" ", $members);
|
284 |
|
|
else
|
285 |
|
|
$item = array('');
|
286 |
3bbf56d7
|
Stephen Beaver
|
|
287 |
4b94f9ec
|
Stephen Beaver
|
foreach($item as $ww) {
|
288 |
|
|
$member = $item[$counter];
|
289 |
|
|
|
290 |
|
|
$group = new Form_Group($counter == 0 ? 'Tag(s)':'');
|
291 |
3bbf56d7
|
Stephen Beaver
|
|
292 |
4b94f9ec
|
Stephen Beaver
|
$group->add(new Form_Input(
|
293 |
|
|
'members',
|
294 |
|
|
null,
|
295 |
|
|
'text',
|
296 |
|
|
$ww
|
297 |
3bbf56d7
|
Stephen Beaver
|
))->setWidth(6); // Width must be <= 8 to make room for the duplication buttons
|
298 |
|
|
|
299 |
4b94f9ec
|
Stephen Beaver
|
$counter++;
|
300 |
|
|
|
301 |
3bbf56d7
|
Stephen Beaver
|
$group->enableDuplication(null, true); // Buttons are in-line with the input
|
302 |
4b94f9ec
|
Stephen Beaver
|
$section->add($group);
|
303 |
b991e3b5
|
Ermal Lu?i
|
}
|
304 |
|
|
|
305 |
4b94f9ec
|
Stephen Beaver
|
$form->add($section);
|
306 |
b991e3b5
|
Ermal Lu?i
|
|
307 |
4b94f9ec
|
Stephen Beaver
|
print($form);
|
308 |
|
|
|
309 |
|
|
include("foot.inc");
|