1 // Copyright 2012 Google, Inc. All rights reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the LICENSE file in the root of the source
15 "github.com/google/gopacket"
18 type LinuxSLLPacketType uint16
21 LinuxSLLPacketTypeHost LinuxSLLPacketType = 0 // To us
22 LinuxSLLPacketTypeBroadcast LinuxSLLPacketType = 1 // To all
23 LinuxSLLPacketTypeMulticast LinuxSLLPacketType = 2 // To group
24 LinuxSLLPacketTypeOtherhost LinuxSLLPacketType = 3 // To someone else
25 LinuxSLLPacketTypeOutgoing LinuxSLLPacketType = 4 // Outgoing of any type
26 // These ones are invisible by user level
27 LinuxSLLPacketTypeLoopback LinuxSLLPacketType = 5 // MC/BRD frame looped back
28 LinuxSLLPacketTypeFastroute LinuxSLLPacketType = 6 // Fastrouted frame
31 func (l LinuxSLLPacketType) String() string {
33 case LinuxSLLPacketTypeHost:
35 case LinuxSLLPacketTypeBroadcast:
37 case LinuxSLLPacketTypeMulticast:
39 case LinuxSLLPacketTypeOtherhost:
41 case LinuxSLLPacketTypeOutgoing:
43 case LinuxSLLPacketTypeLoopback:
45 case LinuxSLLPacketTypeFastroute:
48 return fmt.Sprintf("Unknown(%d)", int(l))
51 type LinuxSLL struct {
53 PacketType LinuxSLLPacketType
56 EthernetType EthernetType
59 // LayerType returns LayerTypeLinuxSLL.
60 func (sll *LinuxSLL) LayerType() gopacket.LayerType { return LayerTypeLinuxSLL }
62 func (sll *LinuxSLL) CanDecode() gopacket.LayerClass {
63 return LayerTypeLinuxSLL
66 func (sll *LinuxSLL) LinkFlow() gopacket.Flow {
67 return gopacket.NewFlow(EndpointMAC, sll.Addr, nil)
70 func (sll *LinuxSLL) NextLayerType() gopacket.LayerType {
71 return sll.EthernetType.LayerType()
74 func (sll *LinuxSLL) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error {
76 return errors.New("Linux SLL packet too small")
78 sll.PacketType = LinuxSLLPacketType(binary.BigEndian.Uint16(data[0:2]))
79 sll.AddrLen = binary.BigEndian.Uint16(data[4:6])
81 sll.Addr = net.HardwareAddr(data[6 : sll.AddrLen+6])
82 sll.EthernetType = EthernetType(binary.BigEndian.Uint16(data[14:16]))
83 sll.BaseLayer = BaseLayer{data[:16], data[16:]}
88 func decodeLinuxSLL(data []byte, p gopacket.PacketBuilder) error {
90 if err := sll.DecodeFromBytes(data, p); err != nil {
95 return p.NextDecoder(sll.EthernetType)