lokikiller / gopacket

Automatically exported from code.google.com/p/gopacket
BSD 3-Clause "New" or "Revised" License
0 stars 1 forks source link

vlan priority was not correctly decoded/encoded #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. The code
package main

import (
        "code.google.com/p/gopacket"
        "code.google.com/p/gopacket/layers"
        "encoding/hex"
        "fmt"
)

func main() {
        if data,err := hex.DecodeString("222222222222121111111111810060640800"); err!=nil {
                panic(err)
        } else {
                buf := gopacket.NewSerializeBuffer()
                packet := gopacket.NewPacket(data, layers.LayerTypeEthernet, gopacket.Default)
                pl := packet.Layers()
                ps := make([]gopacket.SerializableLayer, len(pl))
                for i,p := range pl {
                        ps[i] = p.(gopacket.SerializableLayer)
                }
                if err:= gopacket.SerializeLayers(buf, gopacket.SerializeOptions{}, ps...); err!=nil {
                        panic(err)
                } else {
                        fmt.Println(hex.EncodeToString(buf.Bytes()))
                }
        }
}

2.
3.

What is the expected output? What do you see instead?

Actual:   222222222222121111111111810000640800...
Expected: 222222222222121111111111810060640800...

What version of the product are you using? On what operating system?

Please provide any additional information below.

diff --git a/layers/dot1q.go b/layers/dot1q.go
index f1cccff..1abdc01 100644
--- a/layers/dot1q.go
+++ b/layers/dot1q.go
@@ -27,7 +27,7 @@ func (d *Dot1Q) LayerType() gopacket.LayerType { return 
LayerTypeDot1Q }

 // DecodeFromBytes decodes the given bytes into this layer.
 func (d *Dot1Q) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
-       d.Priority = (data[0] & 0xE0) >> 13
+       d.Priority = (data[0] & 0xE0) >> 5
        d.DropEligible = data[0]&0x10 != 0
        d.VLANIdentifier = binary.BigEndian.Uint16(data[:2]) & 0x0FFF
        d.Type = EthernetType(binary.BigEndian.Uint16(data[2:4]))
@@ -61,7 +61,7 @@ func (d *Dot1Q) SerializeTo(b gopacket.SerializeBuffer, opts 
gopacket.SerializeO
        if d.VLANIdentifier > 0xFFF {
                return fmt.Errorf("vlan identifier %v is too high", d.VLANIdentifier)
        }
-       firstBytes := uint16(d.Priority<<13) | d.VLANIdentifier
+       firstBytes := uint16(d.Priority)<<13 | d.VLANIdentifier
        if d.DropEligible {
                firstBytes |= 0x10
        }

Original issue reported on code.google.com by Hiroaki.Kawai@gmail.com on 7 Jul 2014 at 2:29

GoogleCodeExporter commented 9 years ago
Fixed in 
https://code.google.com/p/gopacket/source/detail?r=58ac84a7e3189dcaeb438999083e1
532db05f723

Original comment by gconnell@google.com on 7 Jul 2014 at 5:26