fix vlan calculation

This commit is contained in:
Ted Kruijff 2026-03-26 11:42:55 +01:00
parent b0fa1f8d1b
commit fbb769b05a
No known key found for this signature in database
GPG Key ID: F53594BF1A41A8CE
2 changed files with 5 additions and 8 deletions

View File

@ -74,17 +74,14 @@ class ParseEthernetFrame extends Operation {
const ethType = Utils.byteArrayToChars(input.slice(offset, offset+2)); const ethType = Utils.byteArrayToChars(input.slice(offset, offset+2));
offset += 2; offset += 2;
if (ethType === "\x81\x00" || ethType === "\x88\xA8") {
if (ethType === "\x08\x00") {
break;
} else if (ethType === "\x81\x00" || ethType === "\x88\xA8") {
// Parse the VLAN tag: // Parse the VLAN tag:
// [0000] 0000 0000 0000 // [0000] 0000 0000 0000
// ^^^ PRIO - Ignored // ^^^ PRIO - Ignored
// ^ DEI - Ignored // ^ DEI - Ignored
// ^^^^ ^^^^ ^^^^ VLAN ID // ^^^^ ^^^^ ^^^^ VLAN ID
const vlanTag = input.slice(offset+2, offset+4); const vlanTag = input.slice(offset, offset+2);
vlans.push((vlanTag[0] & 0b00001111) << 4 | vlanTag[1]); vlans.push(((vlanTag[0] & 0b00001111) << 8) | vlanTag[1]);
offset += 2; offset += 2;
} else { } else {

View File

@ -23,7 +23,7 @@ TestRegister.addTests([
{ {
name: "Parse Ethernet frame with one VLAN tag (802.1q)", name: "Parse Ethernet frame with one VLAN tag (802.1q)",
input: "01000ccdcdd00013c3dfae188100a0760165aaaa", input: "01000ccdcdd00013c3dfae188100a0760165aaaa",
expectedOutput: "Source MAC: 00:13:c3:df:ae:18\nDestination MAC: 01:00:0c:cd:cd:d0\nVLAN: 117\nData:\naa aa", expectedOutput: "Source MAC: 00:13:c3:df:ae:18\nDestination MAC: 01:00:0c:cd:cd:d0\nVLAN: 118\nData:\naa aa",
recipeConfig: [ recipeConfig: [
{ {
"op": "Parse Ethernet frame", "op": "Parse Ethernet frame",
@ -34,7 +34,7 @@ TestRegister.addTests([
{ {
name: "Parse Ethernet frame with two VLAN tags (802.1ad)", name: "Parse Ethernet frame with two VLAN tags (802.1ad)",
input: "0019aa7de688002155c8f13c810000d18100001408004500", input: "0019aa7de688002155c8f13c810000d18100001408004500",
expectedOutput: "Source MAC: 00:21:55:c8:f1:3c\nDestination MAC: 00:19:aa:7d:e6:88\nVLAN: 16, 128\nData:\n45 00", expectedOutput: "Source MAC: 00:21:55:c8:f1:3c\nDestination MAC: 00:19:aa:7d:e6:88\nVLAN: 209, 20\nData:\n45 00",
recipeConfig: [ recipeConfig: [
{ {
"op": "Parse Ethernet frame", "op": "Parse Ethernet frame",