Add VLAN layer

Mar 12, 2014 at 9:55 PM
I have Pcap file that i try to add VLAN layer so i am using PcapDotNet DLLs like this example:
private Packet AddVlan(Packet packet)
{
    try
    {
        ILayer ethernet = packet.Ethernet.ExtractLayer();
        IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.VLanTaggedFrame.IpV4.ExtractLayer();
        ILayer payload = packet.Ethernet.IpV4.Payload.ExtractLayer();
        DateTime packetTimestamp = packet.Timestamp;
        ipV4Layer.HeaderChecksum = null;
        VLanTaggedFrameLayer vLanTaggedFrameLayer =
            new VLanTaggedFrameLayer
            {
                PriorityCodePoint = ClassOfService.Background,
                CanonicalFormatIndicator = false,
                VLanIdentifier = 50,
                EtherType = EthernetType.IpV4,
            };

        return PacketBuilder.Build(packetTimestamp, ethernet, vLanTaggedFrameLayer, ipV4Layer, payload);
    }
    catch (Exception)
    {
        return null;
    }
}
Image

Any idea how solve it ?
Coordinator
Mar 14, 2014 at 10:04 AM
Hi gshhar,

Is the original packet IPv4 over VLAN over Ethernet?
You say you want to add VLAN layer but you also assume in the code that the original packet already has VLAN layer.

Boaz.
Mar 14, 2014 at 11:04 AM
Edited Mar 14, 2014 at 11:04 AM
Hi,

the original packet is without Vlan (TCP, UDP) layer, any option to take Pcap file and add Vlan layer to all the packets ? (all the packet without Vlan layer of course..)
Coordinator
Mar 14, 2014 at 11:32 AM
If the original packet is without VLAN, then this line is wrong:

IpV4Layer ipV4Layer = (IpV4Layer)packet.Ethernet.VLanTaggedFrame.IpV4.ExtractLayer();

Also, you will need to reset the Ethernet layer's EtherType to VLAN, or to None (which will automatically choose VLAN) so it would work correctly.

I hope this helps,

Boaz.
Mar 14, 2014 at 11:41 AM
Edited Mar 14, 2014 at 11:42 AM
First extract Ethernet layer:
ILayer ethernet = packet.Ethernet.ExtractLayer();
What next ?
Coordinator
Mar 14, 2014 at 12:02 PM
Cast it to EthernetLayer and set EtherType to None.
Mar 14, 2014 at 12:14 PM
Edited Mar 14, 2014 at 12:30 PM
Ok it works fone now.
BTW, can i choose different VLAN ?
Coordinator
Mar 14, 2014 at 3:39 PM
What do you mean by a different VLAN?
Mar 14, 2014 at 4:19 PM
What does ClassOfService and VLanIdentifier mean ?
Coordinator
Mar 15, 2014 at 8:29 AM
From the documentation on these fields:

VLanIdentifier:
A VLAN-aware Bridge may not support the full range of VID values but shall support the use of all VID values in the range 0 through a maximum N,
less than or equal to 4094 and specified for that implementation.
PriorityCodePoint (of ClassOfService):
Indicates the frame priority level.
Values are from 0 (best effort) to 7 (highest); 1 represents the lowest priority.
These values can be used to prioritize different classes of traffic (voice, video, data, etc.).
Mar 16, 2014 at 3:26 PM
I think VLanIdentifier can be also 4095 (0 to 4095)
Coordinator
Mar 16, 2014 at 7:55 PM
From wikipedia:
"
VLAN identifier (VID): a 12-bit field specifying the VLAN to which the frame belongs. The hexadecimal values of 0x000 and 0xFFF are reserved. All other values may be used as VLAN identifiers, allowing up to 4,094 VLANs. The reserved value 0x000 indicates that the frame does not belong to any VLAN; in this case, the 802.1Q tag specifies only a priority and is referred to as a priority tag. On bridges, VLAN 1 (the default VLAN ID) is often reserved for a management VLAN; this is vendor-specific.
"
http://en.wikipedia.org/wiki/IEEE_802.1Q
Mar 17, 2014 at 11:32 AM
Edited Mar 17, 2014 at 11:32 AM
Thanks !

BTW, if i want to implement (in myself) add PPPOE layer, this Encapsulation ontains also several fields (like VLanIdentifier, PriorityCodePoint ) or not ?
Coordinator
Mar 18, 2014 at 3:08 PM
I'm not that familiar with the details of PPPoE.