Exemplo n.º 1
0
func decodeInGRELayer(data []byte, p gopacket.PacketBuilder) error {
	switch (data[0] >> 4) & 0xf {
	case 4:
		ip4 := &layers.IPv4{}
		err := ip4.DecodeFromBytes(data, p)
		p.AddLayer(ip4)
		p.SetNetworkLayer(ip4)
		if err != nil {
			return err
		}
		return p.NextDecoder(ip4.NextLayerType())
	case 6:
		ip6 := &layers.IPv6{}
		err := ip6.DecodeFromBytes(data, p)
		p.AddLayer(ip6)
		p.SetNetworkLayer(ip6)
		if err != nil {
			return err
		}
		return p.NextDecoder(ip6.NextLayerType())
	}
	packet := gopacket.NewPacket(data, layers.LayerTypeARP, gopacket.Lazy)
	layer := packet.Layer(layers.LayerTypeARP)

	p.AddLayer(layer)

	return nil
}
Exemplo n.º 2
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)
}
Exemplo n.º 3
0
func decodeSCTPChunkTypeUnknown(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPUnknownChunkType{SCTPChunk: decodeSCTPChunk(data)}
	sc.bytes = data[:sc.ActualLength]
	p.AddLayer(sc)
	p.SetErrorLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
Exemplo n.º 4
0
func decodeSCTPEmptyLayer(data []byte, p gopacket.PacketBuilder) error {
	sc := &SCTPEmptyLayer{
		SCTPChunk: decodeSCTPChunk(data),
	}
	p.AddLayer(sc)
	return p.NextDecoder(gopacket.DecodeFunc(decodeWithSCTPChunkTypePrefix))
}
Exemplo n.º 5
0
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))
}
Exemplo n.º 6
0
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))
}
Exemplo n.º 7
0
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())
}
Exemplo n.º 8
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)
}
Exemplo n.º 9
0
Arquivo: tom.go Projeto: 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())
}
Exemplo n.º 10
0
Arquivo: mach.go Projeto: 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())
}
Exemplo n.º 11
0
func decodeLinuxSLL(data []byte, p gopacket.PacketBuilder) error {
	sll := &LinuxSLL{}
	if err := sll.DecodeFromBytes(data, p); err != nil {
		return err
	}
	p.AddLayer(sll)
	p.SetLinkLayer(sll)
	return p.NextDecoder(sll.EthernetType)
}
Exemplo n.º 12
0
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)
}
Exemplo n.º 13
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)
}
Exemplo n.º 14
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)
}
Exemplo n.º 15
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())
}
Exemplo n.º 16
0
func decodeEthernet(data []byte, p gopacket.PacketBuilder) error {
	eth := &Ethernet{}
	err := eth.DecodeFromBytes(data, p)
	if err != nil {
		return err
	}
	p.AddLayer(eth)
	p.SetLinkLayer(eth)
	return p.NextDecoder(eth.EthernetType)
}
Exemplo n.º 17
0
func decodeIPv4(data []byte, p gopacket.PacketBuilder) error {
	ip := &IPv4{}
	err := ip.DecodeFromBytes(data, p)
	p.AddLayer(ip)
	p.SetNetworkLayer(ip)
	if err != nil {
		return err
	}
	return p.NextDecoder(ip.NextLayerType())
}
Exemplo n.º 18
0
func decodeTCP(data []byte, p gopacket.PacketBuilder) error {
	tcp := &TCP{}
	err := tcp.DecodeFromBytes(data, p)
	p.AddLayer(tcp)
	p.SetTransportLayer(tcp)
	if err != nil {
		return err
	}
	return p.NextDecoder(gopacket.LayerTypePayload)
}
Exemplo n.º 19
0
func decodeUDP(data []byte, p gopacket.PacketBuilder) error {
	udp := &UDP{}
	err := udp.DecodeFromBytes(data, p)
	p.AddLayer(udp)
	p.SetTransportLayer(udp)
	if err != nil {
		return err
	}
	return p.NextDecoder(udp.NextLayerType())
}
Exemplo n.º 20
0
func decodeSCTP(data []byte, p gopacket.PacketBuilder) error {
	sctp := &SCTP{}
	err := sctp.DecodeFromBytes(data, p)
	p.AddLayer(sctp)
	p.SetTransportLayer(sctp)
	if err != nil {
		return err
	}
	return p.NextDecoder(sctpChunkTypePrefixDecoder)
}
Exemplo n.º 21
0
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))
}
Exemplo n.º 22
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)
}
Exemplo n.º 23
0
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))
}
Exemplo n.º 24
0
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)
}
Exemplo n.º 25
0
func decodeFDDI(data []byte, p gopacket.PacketBuilder) error {
	f := &FDDI{
		FrameControl: FDDIFrameControl(data[0] & 0xF8),
		Priority:     data[0] & 0x07,
		SrcMAC:       net.HardwareAddr(data[1:7]),
		DstMAC:       net.HardwareAddr(data[7:13]),
		BaseLayer:    BaseLayer{data[:13], data[13:]},
	}
	p.SetLinkLayer(f)
	p.AddLayer(f)
	return p.NextDecoder(f.FrameControl)
}
Exemplo n.º 26
0
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)
}
Exemplo n.º 27
0
// 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)
}
Exemplo n.º 28
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)
}
Exemplo n.º 29
0
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))
}
Exemplo n.º 30
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)
}