Vendor update gopacket and unix package

This commit is contained in:
Manjunath A Kumatagi committed 2019-02-01 21:28:56 -06:00
1 parent 54d24e65ef
commit 43d3339b39
319 files changed
+91339 -13246

No files matched your search

+55
View File
@@ -37,6 +37,10 @@ type LinkLayerDiscoveryValue struct {
Value []byte
}
func (c *LinkLayerDiscoveryValue) len() int {
return 0
}
// LLDPChassisIDSubType specifies the value type for a single LLDPChassisID.ID
type LLDPChassisIDSubType byte
@@ -57,6 +61,20 @@ type LLDPChassisID struct {
ID []byte
}
func (c *LLDPChassisID) serialize() []byte {
var buf = make([]byte, c.serializedLen())
idLen := uint16(LLDPTLVChassisID)<<9 | uint16(len(c.ID)+1) //id should take 7 bits, length should take 9 bits, +1 for subtype
binary.BigEndian.PutUint16(buf[0:2], idLen)
buf[2] = byte(c.Subtype)
copy(buf[3:], c.ID)
return buf
}
func (c *LLDPChassisID) serializedLen() int {
return len(c.ID) + 3 // +2 for id and length, +1 for subtype
}
// LLDPPortIDSubType specifies the value type for a single LLDPPortID.ID
type LLDPPortIDSubType byte
@@ -77,6 +95,20 @@ type LLDPPortID struct {
ID []byte
}
func (c *LLDPPortID) serialize() []byte {
var buf = make([]byte, c.serializedLen())
idLen := uint16(LLDPTLVPortID)<<9 | uint16(len(c.ID)+1) //id should take 7 bits, length should take 9 bits, +1 for subtype
binary.BigEndian.PutUint16(buf[0:2], idLen)
buf[2] = byte(c.Subtype)
copy(buf[3:], c.ID)
return buf
}
func (c *LLDPPortID) serializedLen() int {
return len(c.ID) + 3 // +2 for id and length, +1 for subtype
}
// LinkLayerDiscovery is a packet layer containing the LinkLayer Discovery Protocol.
// See http:http://standards.ieee.org/getieee802/download/802.1AB-2009.pdf
// ChassisID, PortID and TTL are mandatory TLV's. Other values can be decoded
@@ -733,6 +765,29 @@ func (c *LinkLayerDiscovery) LayerType() gopacket.LayerType {
return LayerTypeLinkLayerDiscovery
}
// SerializeTo serializes LLDP packet to bytes and writes on SerializeBuffer.
func (c *LinkLayerDiscovery) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error {
chassIDLen := c.ChassisID.serializedLen()
portIDLen := c.PortID.serializedLen()
vb, err := b.AppendBytes(chassIDLen + portIDLen + 4) // +4 for TTL
if err != nil {
return err
}
copy(vb[:chassIDLen], c.ChassisID.serialize())
copy(vb[chassIDLen:], c.PortID.serialize())
ttlIDLen := uint16(LLDPTLVTTL)<<9 | uint16(2)
binary.BigEndian.PutUint16(vb[chassIDLen+portIDLen:], ttlIDLen)
binary.BigEndian.PutUint16(vb[chassIDLen+portIDLen+2:], c.TTL)
vb, err = b.AppendBytes(2) // End Tlv, 2 bytes
if err != nil {
return err
}
binary.BigEndian.PutUint16(vb[len(vb)-2:], uint16(0)) //End tlv, 2 bytes, all zero
return nil
}
func decodeLinkLayerDiscovery(data []byte, p gopacket.PacketBuilder) error {
var vals []LinkLayerDiscoveryValue
vData := data[0:]