Project

General

Profile

Feature #4133 » pf_pcp_git.diff

PHP interface patch (pfSense GIT) - Clement Barnier, 12/20/2014 08:34 AM

View differences:

/pfsense/gitrepo/pfSenseGITREPO/etc/inc/config.inc 2014-12-20 13:20:39.000000000 +0100
205 205
	$timezone = "Etc/UTC";
206 206
date_default_timezone_set("$timezone");
207 207

  
208
/* compatibility with older configs using vlan "tags" */	
209
if (($config['version'] < 11) && (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
210
	foreach ($config['vlans']['vlan'] as &$vlan) {
211
		if (empty($vlan['vid']) && !empty($vlan['tag'])) {
212
			$vlan['vid']  =  $vlan['tag'];
213
			unset($vlan['tag']);
214
		}
215
	}
216

  
208 217
if($config_parsed == true) {
209 218
	/* process packager manager custom rules */
210 219
	if(is_dir("/usr/local/pkg/parse_config")) {
/pfsense/gitrepo/pfSenseGITREPO/etc/inc/interfaces.inc 2014-12-13 15:11:56.000000000 +0100
198 198
	if (is_array($config['vlans']['vlan']) && count($config['vlans']['vlan'])) {
199 199
		foreach ($config['vlans']['vlan'] as $vlan) {
200 200
			if (empty($vlan['vlanif']))
201
				$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['tag']}";
201
				$vlan['vlanif'] = "{$vlan['if']}_vlan{$vlan['vid']}";
202 202
			if (!empty($realif) && $realif != $vlan['vlanif'])
203 203
				continue;
204 204

  
......
218 218
		return;
219 219
	}
220 220
	$if = $vlan['if'];
221
	$vlanif  = empty($vlan['vlanif']) ? "{$if}_vlan{$vlan['tag']}" : $vlan['vlanif'];
222
	$tag = $vlan['tag'];
223

  
224 221
	if (empty($if)) {
225 222
		log_error(gettext("interface_vlan_configure called with if undefined."));
226 223
		return;
227
	}
224
	}	
225
	
226
	$vlanif  = empty($vlan['vlanif']) ? "{$if}_vlan{$vlan['vid']}" : $vlan['vlanif'];
227
	$vid  = $vlan['vid'];
228
	$pcp  = empty($vlan['pcp']) ? 0 : $vlan['pcp'];	/* Apply "Best Effort" if not set */
228 229

  
229 230
	/* make sure the parent interface is up */
230 231
	interfaces_bring_up($if);
......
239 240
		pfSense_ngctl_name("{$tmpvlanif}:", $vlanif);
240 241
	}
241 242

  
242
	pfSense_vlan_create($vlanif, $if, $tag);
243
	pfSense_vlan_create($vlanif, $if, $vid, $pcp);
243 244

  
244 245
	interfaces_bring_up($vlanif);
245 246

  
......
261 262
	}
262 263

  
263 264
	$qinqif = $vlan['if'];
264
	$tag = $vlan['tag'];
265
	$tag = $vlan['vid'];
265 266
	if(empty($qinqif)) {
266 267
		log_error(sprintf(gettext("interface_qinq_configure called with if undefined.%s"), "\n"));
267 268
		return;
......
4582 4583
				if ($action == "update") {
4583 4584
					interfaces_bring_up($int);
4584 4585
				} else
4585
					$ifaces[$vlan['tag']] = $vlan;
4586
					$ifaces[$vlan['vid']] = $vlan;
4586 4587
			}
4587 4588
		}
4588 4589
		if (!empty($ifaces))
/pfsense/gitrepo/pfSenseGITREPO/usr/local/www/interfaces_assign.php 2014-12-13 15:06:55.000000000 +0100
56 56
function interface_assign_description($portinfo, $portname) {
57 57
	global $ovpn_descrs;
58 58
	if ($portinfo['isvlan']) {
59
		$descr = sprintf(gettext('VLAN %1$s on %2$s'),$portinfo['tag'],$portinfo['if']);
59
		$descr = sprintf(gettext('VLAN %1$s on %2$s'),$portinfo['vid'],$portinfo['if']);
60 60
		if ($portinfo['descr'])
61 61
			$descr .= " (" . $portinfo['descr'] . ")";
62 62
	} elseif ($portinfo['iswlclone']) {
......
298 298
	if (is_array($config['vlans']['vlan'])) {
299 299
		foreach ($config['vlans']['vlan'] as $vlan) {
300 300
			if (does_interface_exist($vlan['if']) == false)
301
				$input_errors[] = "Vlan parent interface {$vlan['if']} does not exist anymore so vlan id {$vlan['tag']} cannot be created please fix the issue before continuing.";
301
				$input_errors[] = "Vlan parent interface {$vlan['if']} does not exist anymore so vlan id {$vlan['vid']} cannot be created please fix the issue before continuing.";
302 302
		}
303 303
	}
304 304

  
/pfsense/gitrepo/pfSenseGITREPO/usr/local/www/interfaces_vlan.php 2014-12-13 15:06:55.000000000 +0100
112 112
	<div id="mainarea">
113 113
	<table class="tabcont" width="100%" border="0" cellpadding="0" cellspacing="0" summary="main area">
114 114
                <tr>
115
                  <td width="20%" class="listhdrr"><?=gettext("Interface");?></td>
116
                  <td width="20%" class="listhdrr"><?=gettext("VLAN tag");?></td>
115
                  <td width="16%" class="listhdrr"><?=gettext("Interface");?></td>
116
                  <td width="12%" class="listhdrr"><?=gettext("VLAN");?></td>
117
                  <td width="12%" class="listhdrr"><?=gettext("Priority");?></td>				  
117 118
                  <td width="50%" class="listhdr"><?=gettext("Description");?></td>
118 119
                  <td width="10%" class="list"></td>
119 120
				</tr>
......
123 124
					<?=htmlspecialchars($vlan['if']);?>
124 125
                  </td>
125 126
                  <td class="listr">
126
					<?=htmlspecialchars($vlan['tag']);?>
127
					<?=htmlspecialchars($vlan['vid']);?>
127 128
                  </td>
129
                  <td class="listr">
130
					<?=htmlspecialchars($vlan['pcp']);?>
131
                  </td>				  
128 132
                  <td class="listbg">
129 133
                    <?=htmlspecialchars($vlan['descr']);?>&nbsp;
130 134
                  </td>
/pfsense/gitrepo/pfSenseGITREPO/usr/local/www/interfaces_vlan_edit.php 2014-12-13 15:06:55.000000000 +0100
65 65
if (isset($id) && $a_vlans[$id]) {
66 66
	$pconfig['if'] = $a_vlans[$id]['if'];
67 67
	$pconfig['vlanif'] = $a_vlans[$id]['vlanif'];
68
	$pconfig['tag'] = $a_vlans[$id]['tag'];
68
	$pconfig['vid'] = $a_vlans[$id]['vid'];
69
	$pconfig['pcp'] = $a_vlans[$id]['pcp'];	
69 70
	$pconfig['descr'] = $a_vlans[$id]['descr'];
70 71
}
71 72

  
......
75 76
	$pconfig = $_POST;
76 77

  
77 78
	/* input validation */
78
	$reqdfields = explode(" ", "if tag");
79
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN tag"));
79
	$reqdfields = explode(" ", "if vid");
80
	$reqdfieldsn = array(gettext("Parent interface"),gettext("VLAN"));
80 81

  
81 82
	do_input_validation($_POST, $reqdfields, $reqdfieldsn, $input_errors);
82 83

  
83
	if ($_POST['tag'] && (!is_numericint($_POST['tag']) || ($_POST['tag'] < '1') || ($_POST['tag'] > '4094'))) {
84
		$input_errors[] = gettext("The VLAN tag must be an integer between 1 and 4094.");
84
	if ($_POST['vid'] && (!is_numericint($_POST['vid']) || ($_POST['vid'] < '1') || ($_POST['vid'] > '4094'))) {
85
		$input_errors[] = gettext("The VLAN ID must be an integer between 1 and 4094.");
86
	}
87
	if ($_POST['pcp'] && (!is_numericint($_POST['pcp']) || ($_POST['pcp'] < '0') || ($_POST['pcp'] > '7'))) {
88
		$input_errors[] = gettext("The VLAN Priority must be an integer between 0 and 7.");
85 89
	}
86 90

  
87 91
	if (!does_interface_exist($_POST['if']))
88 92
		$input_errors[] = gettext("Interface supplied as parent is invalid");
89 93

  
90 94
	if (isset($id)) {
91
		if ($_POST['tag'] && $_POST['tag'] != $a_vlans[$id]['tag']) {
92
			if (!empty($a_vlans[$id]['vlanif']) && convert_real_interface_to_friendly_interface_name($a_vlans[$id]['vlanif']) != NULL)
93
				$input_errors[] = gettext("Interface is assigned and you cannot change the VLAN tag while assigned.");
94
		}
95
		if ($_POST['vid'] && $_POST['vid'] != $a_vlans[$id]['vid']) {
96
 			if (!empty($a_vlans[$id]['vlanif']) && convert_real_interface_to_friendly_interface_name($a_vlans[$id]['vlanif']) != NULL)
97
				$input_errors[] = gettext("Interface is assigned and you cannot change the VLAN id while assigned.");
98
		}	
95 99
	}
96 100
	foreach ($a_vlans as $vlan) {
97 101
		if (isset($id) && ($a_vlans[$id]) && ($a_vlans[$id] === $vlan))
98 102
			continue;
99 103

  
100
		if (($vlan['if'] == $_POST['if']) && ($vlan['tag'] == $_POST['tag'])) {
101
			$input_errors[] = sprintf(gettext("A VLAN with the tag %s is already defined on this interface."),$vlan['tag']);
104
		if (($vlan['if'] == $_POST['if']) && ($vlan['vid'] == $_POST['vid'])) {
105
			$input_errors[] = sprintf(gettext("A VLAN with id %s is already defined on this interface."),$vlan['vid']);
102 106
			break;
103 107
		}
104 108
	}
105 109
	if (is_array($config['qinqs']['qinqentry'])) {
106 110
		foreach ($config['qinqs']['qinqentry'] as $qinq)
107
			if ($qinq['tag'] == $_POST['tag'] && $qinq['if'] == $_POST['if'])
108
				$input_errors[] = gettext("A QinQ VLAN exists with this tag please remove it to use this tag with.");
111
			if ($qinq['tag'] == $_POST['vid'] && $qinq['if'] == $_POST['if'])
112
				$input_errors[] = gettext("A QinQ VLAN exists with this id please remove it to use this id with.");
109 113
	}
110 114

  
111 115
	if (!$input_errors) {
112 116
		if (isset($id) && $a_vlans[$id]) {
113
			if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['tag'] != $_POST['tag'])) {
117
			if (($a_vlans[$id]['if'] != $_POST['if']) || ($a_vlans[$id]['vid'] != $_POST['vid'])) {
114 118
				if (!empty($a_vlans[$id]['vlanif'])) {
115 119
					$confif = convert_real_interface_to_friendly_interface_name($vlan['vlanif']);
116 120
					// Destroy previous vlan
117 121
					pfSense_interface_destroy($a_vlans[$id]['vlanif']);
118 122
				} else {
119
					pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
120
					$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['tag']}");
123
					pfSense_interface_destroy("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['vid']}");
124
					$confif = convert_real_interface_to_friendly_interface_name("{$a_vlans[$id]['if']}_vlan{$a_vlans[$id]['vid']}");
121 125
				}
122 126
				if ($confif <> "")
123
					$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['tag']}";
127
					$config['interfaces'][$confif]['if'] = "{$_POST['if']}_vlan{$_POST['vid']}";
124 128
			}
125 129
		}
126 130
		$vlan = array();
127 131
		$vlan['if'] = $_POST['if'];
128
		$vlan['tag'] = $_POST['tag'];
129
		$vlan['descr'] = $_POST['descr'];
130
		$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['tag']}";
132
		$vlan['vid'] = $_POST['vid'];
133
		if ($_POST['pcp'] != '')
134
			$vlan['pcp'] = $_POST['pcp']; /* Leave PCP unset if not required */
135
 		$vlan['descr'] = $_POST['descr'];
136
		$vlan['vlanif'] = "{$_POST['if']}_vlan{$_POST['vid']}";
131 137

  
132 138
		$vlan['vlanif'] = interface_vlan_configure($vlan);
133 139
                if ($vlan['vlanif'] == "" || !stristr($vlan['vlanif'], "vlan"))
......
183 189
			<span class="vexpl"><?=gettext("Only VLAN capable interfaces will be shown.");?></span></td>
184 190
                </tr>
185 191
				<tr>
186
                  <td valign="top" class="vncellreq"><?=gettext("VLAN tag ");?></td>
192
                  <td valign="top" class="vncellreq"><?=gettext("VLAN id ");?></td>
187 193
                  <td class="vtable">
188
                    <input name="tag" type="text" class="formfld unknown" id="tag" size="6" value="<?=htmlspecialchars($pconfig['tag']);?>" />
194
                    <input name="vid" type="text" class="formfld unknown" id="vid" size="6" value="<?=htmlspecialchars($pconfig['vid']);?>" />
189 195
                    <br />
190
                    <span class="vexpl"><?=gettext("802.1Q VLAN tag (between 1 and 4094) ");?></span></td>
196
                    <span class="vexpl"><?=gettext("802.1Q VLAN vid (between 1 and 4094) ");?></span></td>
191 197
			    </tr>
192 198
				<tr>
199
                  <td valign="top" class="vncell"><?=gettext("VLAN Priority ");?></td>
200
                  <td class="vtable">
201
                    <input name="pcp" type="text" class="formfld unknown" id="pcp" size="4" value="<?=htmlspecialchars($pconfig['pcp']);?>" />
202
                    <br/>
203
                    <span class="vexpl"><?=gettext("802.1Q VLAN pcp (between 0 and 7, default 0) ");?></span></td>
204
			    </tr>				
205
				<tr>
193 206
                  <td width="22%" valign="top" class="vncell"><?=gettext("Description");?></td>
194 207
                  <td width="78%" class="vtable">
195 208
                    <input name="descr" type="text" class="formfld unknown" id="descr" size="40" value="<?=htmlspecialchars($pconfig['descr']);?>" />
(1-1/4)