示例#1
0
func decodeVXLAN(data []byte, p gopacket.PacketBuilder) error {
	vx := &VXLAN{}

	// VNI is a 24bit number, Uint32 requires 32 bits
	var buf [4]byte
	copy(buf[1:], data[4:7])

	// RFC 7348 https://tools.ietf.org/html/rfc7348
	vx.ValidIDFlag = data[0]&0x08 > 0        // 'I' bit per RFC7348
	vx.VNI = binary.BigEndian.Uint32(buf[:]) // VXLAN Network Identifier per RFC7348

	// Group Based Policy https://tools.ietf.org/html/draft-smith-vxlan-group-policy-00
	vx.GBPExtension = data[0]&0x80 > 0                       // 'G' bit per the group policy draft
	vx.GBPDontLearn = data[1]&0x40 > 0                       // 'D' bit - the egress VTEP MUST NOT learn the source address of the encapsulated frame.
	vx.GBPApplied = data[1]&0x80 > 0                         // 'A' bit - indicates that the group policy has already been applied to this packet.
	vx.GBPGroupPolicyID = binary.BigEndian.Uint16(data[2:4]) // Policy ID as per the group policy draft

	// Layer information
	const vxlanLength = 8
	vx.Contents = data[:vxlanLength]
	vx.Payload = data[vxlanLength:]

	p.AddLayer(vx)
	return p.NextDecoder(LinkTypeEthernet)
}
示例#2
0
文件: sctp.go 项目: CNDonny/scope
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPEmptyLayer{
		SCTPChunk: decodeSCTPChunk(data),
	}
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例#3
0
文件: mach.go 项目: ikravets/ev
func decodeMach(data []byte, p gopacket.PacketBuilder) (err error) {
	panic("FIXME")
	defer errs.PassE(&err)
	m := &Mach{}
	errs.CheckE(m.DecodeFromBytes(data, p))
	p.AddLayer(m)
	return p.NextDecoder(m.NextLayerType())
}
示例#4
0
文件: moldudp64.go 项目: ikravets/ev
func decodeMoldUDP64(data []byte, p gopacket.PacketBuilder) error {
	m := &MoldUDP64{}
	if err := m.DecodeFromBytes(data, p); err != nil {
		return err
	}
	p.AddLayer(m)
	return p.NextDecoder(m.NextLayerType())
}
示例#5
0
文件: sctp.go 项目: CNDonny/scope
func decodeSCTPShutdown(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPShutdown{
		SCTPChunk:        decodeSCTPChunk(data),
		CumulativeTSNAck: binary.BigEndian.Uint32(data[4:8]),
	}
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例#6
0
文件: tom.go 项目: ikravets/ev
func (a TomMessageType) Decode(data []byte, p gopacket.PacketBuilder) error {
	layer := TomMessageTypeMetadata[a].CreateLayer()
	if err := layer.DecodeFromBytes(data, p); err != nil {
		return err
	}
	p.AddLayer(layer)
	return p.NextDecoder(layer.NextLayerType())
}
示例#7
0
func decodeLoopback(data []byte, p gopacket.PacketBuilder) error {
	l := Loopback{}
	if err := l.DecodeFromBytes(data, gopacket.NilDecodeFeedback); err != nil {
		return err
	}
	p.AddLayer(&l)
	return p.NextDecoder(l.Family)
}
示例#8
0
文件: sctp.go 项目: CNDonny/scope
func decodeSCTPCookieEcho(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPCookieEcho{
		SCTPChunk: decodeSCTPChunk(data),
	}
	sc.Cookie = data[4:sc.Length]
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例#9
0
文件: icmp4.go 项目: CNDonny/scope
func decodeICMPv4(data []byte, p gopacket.PacketBuilder) error {
	i := &ICMPv4{}
	err := i.DecodeFromBytes(data, p)
	if err != nil {
		return err
	}
	p.AddLayer(i)
	return p.NextDecoder(gopacket.LayerTypePayload)
}
示例#10
0
func decodeDHCPv4(data []byte, p gopacket.PacketBuilder) error {
	dhcp := &DHCPv4{}
	err := dhcp.DecodeFromBytes(data, p)
	if err != nil {
		return err
	}
	p.AddLayer(dhcp)
	return p.NextDecoder(gopacket.LayerTypePayload)
}
示例#11
0
func decodeVxlan(data []byte, p gopacket.PacketBuilder) error {
	v := &VXLAN{BaseLayer: BaseLayer{Contents: data}}
	err := v.DecodeFromBytes(data, p)
	p.AddLayer(v)
	if err != nil {
		return err
	}
	return p.NextDecoder(v.NextLayerType())
}
示例#12
0
func decodeIPv6HopByHop(data []byte, p gopacket.PacketBuilder) error {
	i := &IPv6HopByHop{}
	err := i.DecodeFromBytes(data, p)
	p.AddLayer(i)
	if err != nil {
		return err
	}
	return p.NextDecoder(i.NextHeader)
}
示例#13
0
文件: ipsec.go 项目: CNDonny/scope
func decodeIPSecESP(data []byte, p gopacket.PacketBuilder) error {
	i := &IPSecESP{
		BaseLayer: BaseLayer{data, nil},
		SPI:       binary.BigEndian.Uint32(data[:4]),
		Seq:       binary.BigEndian.Uint32(data[4:8]),
		Encrypted: data[8:],
	}
	p.AddLayer(i)
	return nil
}
示例#14
0
文件: dns.go 项目: nhooyr/gopacket
// decodeDNS decodes the byte slice into a DNS type. It also
// setups the application Layer in PacketBuilder.
func decodeDNS(data []byte, p gopacket.PacketBuilder) error {
	d := &DNS{}
	err := d.DecodeFromBytes(data, p)
	if err != nil {
		return err
	}
	p.AddLayer(d)
	p.SetApplicationLayer(d)
	return nil
}
示例#15
0
文件: sctp.go 项目: cdshann/minimega
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
	chunk, err := decodeSCTPChunk(data)
	if err != nil {
		return err
	}
	sc := &SCTPEmptyLayer{
		SCTPChunk: chunk,
	}
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例#16
0
func decodeCapwapDataKeepAlive(data []byte, p gopacket.PacketBuilder) error {
	length := binary.BigEndian.Uint16(data)
	p.AddLayer(&CapwapDataKeepAlive{
		BaseLayer: layers.BaseLayer{
			Contents: data[:2],
			Payload:  data[2:length],
		},
		MessageElementLength: length,
	})
	return p.NextDecoder(gopacket.LayerTypePayload)
}
示例#17
0
文件: ctp.go 项目: nplanel/gopacket
func decodeEthernetCTP(data []byte, p gopacket.PacketBuilder) error {
	c := &EthernetCTP{
		SkipCount: binary.LittleEndian.Uint16(data[:2]),
		BaseLayer: BaseLayer{data[:2], data[2:]},
	}
	if c.SkipCount%2 != 0 {
		return fmt.Errorf("EthernetCTP skip count is odd: %d", c.SkipCount)
	}
	p.AddLayer(c)
	return p.NextDecoder(gopacket.DecodeFunc(decodeEthernetCTPFromFunctionType))
}
示例#18
0
文件: base.go 项目: CNDonny/scope
func decodingLayerDecoder(d layerDecodingLayer, data []byte, p gopacket.PacketBuilder) error {
	err := d.DecodeFromBytes(data, p)
	if err != nil {
		return err
	}
	p.AddLayer(d)
	next := d.NextLayerType()
	if next == gopacket.LayerTypeZero {
		return nil
	}
	return p.NextDecoder(next)
}
示例#19
0
文件: pppoe.go 项目: hgGeorg/mongo
// decodePPPoE decodes the PPPoE header (see http://tools.ietf.org/html/rfc2516).
func decodePPPoE(data []byte, p gopacket.PacketBuilder) error {
	pppoe := &PPPoE{
		Version:   data[0] >> 4,
		Type:      data[0] & 0x0F,
		Code:      PPPoECode(data[1]),
		SessionId: binary.BigEndian.Uint16(data[2:4]),
		Length:    binary.BigEndian.Uint16(data[4:6]),
	}
	pppoe.BaseLayer = BaseLayer{data[:6], data[6 : 6+pppoe.Length]}
	p.AddLayer(pppoe)
	return p.NextDecoder(pppoe.Code)
}
示例#20
0
func decodeDot11NoFCS(data []byte, p gopacket.PacketBuilder) error {
	payload := append(data, 0, 0, 0, 0)
	h := crc32.NewIEEE()
	h.Write(data)
	binary.LittleEndian.PutUint32(payload[len(data):], h.Sum32())
	p.AddLayer(&Dot11NoFCS{
		BaseLayer: layers.BaseLayer{
			Payload: payload,
		},
	})
	return p.NextDecoder(layers.LayerTypeDot11)
}
示例#21
0
文件: llc.go 项目: jesseward/gopacket
func decodeSNAP(data []byte, p gopacket.PacketBuilder) error {
	s := &SNAP{
		OrganizationalCode: data[:3],
		Type:               EthernetType(binary.BigEndian.Uint16(data[3:5])),
		BaseLayer:          BaseLayer{data[:5], data[5:]},
	}
	p.AddLayer(s)
	// BUG(gconnell):  When decoding SNAP, we treat the SNAP type as an Ethernet
	// type.  This may not actually be an ethernet type in all cases,
	// depending on the organizational code.  Right now, we don't check.
	return p.NextDecoder(s.Type)
}
示例#22
0
func decodeCapwapControlHeader(data []byte, p gopacket.PacketBuilder) error {
	msgElementLength := binary.BigEndian.Uint16(data[5:])
	p.AddLayer(&CapwapControlHeader{
		BaseLayer: layers.BaseLayer{
			Contents: data[:8],
			Payload:  data[8 : 5+int(msgElementLength)],
		},
		MessageType:      binary.BigEndian.Uint32(data),
		SeqNum:           data[4],
		MsgElementLength: msgElementLength,
	})
	return p.NextDecoder(gopacket.LayerTypePayload)
}
示例#23
0
文件: sctp.go 项目: CNDonny/scope
func decodeSCTPHeartbeat(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPHeartbeat{
		SCTPChunk: decodeSCTPChunk(data),
	}
	paramData := data[4:sc.Length]
	for len(paramData) > 0 {
		p := SCTPHeartbeatParameter(decodeSCTPParameter(paramData))
		paramData = paramData[p.ActualLength:]
		sc.Parameters = append(sc.Parameters, p)
	}
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
示例#24
0
func decodeLwappControl(data []byte, p gopacket.PacketBuilder) error {
	p.AddLayer(&LwappControl{
		BaseLayer: layers.BaseLayer{
			Contents: data[:8],
			Payload:  data[8:],
		},
		MessageType:      data[0],
		SeqNum:           data[1],
		MsgElementLength: binary.BigEndian.Uint16(data[2:]),
		SessionID:        binary.BigEndian.Uint32(data[4:]),
	})
	return p.NextDecoder(gopacket.LayerTypePayload)
}
示例#25
0
func decodeIPv6Fragment(data []byte, p gopacket.PacketBuilder) error {
	i := &IPv6Fragment{
		BaseLayer:      BaseLayer{data[:8], data[8:]},
		NextHeader:     IPProtocol(data[0]),
		Reserved1:      data[1],
		FragmentOffset: binary.BigEndian.Uint16(data[2:4]) >> 3,
		Reserved2:      data[3] & 0x6 >> 1,
		MoreFragments:  data[3]&0x1 != 0,
		Identification: binary.BigEndian.Uint32(data[4:8]),
	}
	p.AddLayer(i)
	return p.NextDecoder(gopacket.DecodeFragment)
}
示例#26
0
文件: ndp.go 项目: CNDonny/scope
func decodeNortelDiscovery(data []byte, p gopacket.PacketBuilder) error {
	c := &NortelDiscovery{}
	if len(data) < 11 {
		return fmt.Errorf("Invalid NortelDiscovery packet length %d", len(data))
	}
	c.IPAddress = data[0:4]
	c.SegmentID = data[4:7]
	c.Chassis = NDPChassisType(data[7])
	c.Backplane = NDPBackplaneType(data[8])
	c.State = NDPState(data[9])
	c.NumLinks = uint8(data[10])
	p.AddLayer(c)
	return nil
}
示例#27
0
func decodeLwapp(data []byte, p gopacket.PacketBuilder) error {
	lwapp := &Lwapp{
		BaseLayer: layers.BaseLayer{
			Contents: data[:6],
			Payload:  data[6:],
		},
		Flags:       LwappFlags(data[0]),
		FragID:      data[1],
		Length:      binary.BigEndian.Uint16(data[2:]),
		StatusWLANs: binary.BigEndian.Uint16(data[4:]),
	}
	p.AddLayer(lwapp)
	return p.NextDecoder(lwapp.NextLayerType())
}
示例#28
0
func decodeLLC(data []byte, p gopacket.PacketBuilder) error {
	l := &LLC{
		DSAP:    data[0] & 0xFE,
		IG:      data[0]&0x1 != 0,
		SSAP:    data[1] & 0xFE,
		CR:      data[1]&0x1 != 0,
		Control: data[2],
	}
	/*
		if l.Control&0x1 == 0 || l.Control&0x3 == 0x1 {
			l.Control = l.Control<<8 | uint16(data[3])
			l.Contents = data[:4]
			l.Payload = data[4:]
		} else {
			l.Contents = data[:3]
			l.Payload = data[3:]
		}
	*/
	l.Contents = data[:3]
	l.Payload = data[3:]
	p.AddLayer(l)
	if l.DSAP == 0xAA && l.SSAP == 0xAA {
		return p.NextDecoder(LayerTypeSNAP)
	} else if l.DSAP == 0x42 && l.SSAP == 0x42 && l.Control == 0x03 {
		return p.NextDecoder(LayerTypeBPDU)
	}
	return p.NextDecoder(gopacket.DecodeUnknown)
}
示例#29
0
func decodeIPv6Destination(data []byte, p gopacket.PacketBuilder) error {
	i := &IPv6Destination{
		ipv6ExtensionBase: decodeIPv6ExtensionBase(data),
		// We guess we'll 1-2 options, one regular option at least, then maybe one
		// padding option.
		Options: make([]IPv6DestinationOption, 0, 2),
	}
	var opt *IPv6DestinationOption
	for d := i.Contents[2:]; len(d) > 0; d = d[opt.ActualLength:] {
		i.Options = append(i.Options, IPv6DestinationOption(decodeIPv6HeaderTLVOption(d)))
		opt = &i.Options[len(i.Options)-1]
	}
	p.AddLayer(i)
	return p.NextDecoder(i.NextHeader)
}
示例#30
0
// decodeLAMP decodes the Marker and Marker Responder PDU
func decodeLAMP(data []byte, p gopacket.PacketBuilder) error {
	lamp := &LAMP{BaseLayer: BaseLayer{Contents: data}}
	var vals []LAMPValue
	vData := data[1:]
	lamp.Version = LAMPVersionType(data[0])
	for len(vData) > 0 {
		t := LAMPTLVType(vData[0])
		val := LAMPValue{TlvType: t, Length: vData[1]}
		if val.Length > 0 {
			val.Value = vData[2:val.Length]
		}
		vals = append(vals, val)
		if val.TlvType == LAMPTLVTerminator {
			break
		}
		if len(vData) < int(val.Length) {
			return fmt.Errorf("Malformed LAMP Header")
		}
		vData = vData[val.Length:]
	}
	if len(vals) < 2 {
		return fmt.Errorf("Missing mandatory LAMP TLV", vals)
	}

	pktEnd := false
	for _, v := range vals {
		switch v.TlvType {
		case LAMPTLVTerminator:
			pktEnd = true
		case LAMPTLVMarkerInfo, LAMPTLVMarkerResponder:
			lamp.Marker = LAMPMarkerTlv{TlvType: v.TlvType,
				Length:        v.Length,
				RequesterPort: binary.BigEndian.Uint16(v.Value[0:2]),
				RequesterSystem: [6]uint8{uint8(v.Value[2]), uint8(v.Value[3]), uint8(v.Value[4]),
					uint8(v.Value[5]), uint8(v.Value[6]), uint8(v.Value[7])},
				RequesterTransactionId: binary.BigEndian.Uint32(v.Value[8:12]),
			}
		}
	}

	if lamp.Marker.TlvType == 0 ||
		!pktEnd {
		return fmt.Errorf("Missing mandatory LAMP TLV")
	}
	p.AddLayer(lamp)
	//fmt.Println("decodeLAMP exit")
	return nil
}