Home | History | Annotate | Download | only in contrib
      1 # This file is part of Scapy
      2 # Scapy is free software: you can redistribute it and/or modify
      3 # it under the terms of the GNU General Public License as published by
      4 # the Free Software Foundation, either version 2 of the License, or
      5 # any later version.
      6 #
      7 # Scapy is distributed in the hope that it will be useful,
      8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
      9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     10 # GNU General Public License for more details.
     11 #
     12 # You should have received a copy of the GNU General Public License
     13 # along with Scapy. If not, see <http://www.gnu.org/licenses/>.
     14 
     15 # scapy.contrib.description = Cisco HDLC and SLARP
     16 # scapy.contrib.status = loads
     17 
     18 # This layer is based on information from http://www.nethelp.no/net/cisco-hdlc.txt
     19 
     20 from scapy.data import DLT_C_HDLC
     21 from scapy.packet import *
     22 from scapy.fields import *
     23 from scapy.layers.l2 import *
     24 from scapy.layers.inet import *
     25 from scapy.layers.inet6 import *
     26 
     27 class CHDLC(Packet):
     28     name = "Cisco HDLC"
     29     fields_desc = [ ByteEnumField("address", 0x0f, {0x0f : "unicast", 0x8f :"multicast"}),
     30                     ByteField("control", 0),
     31                     XShortField("proto", 0x0800)]
     32 
     33 class SLARP(Packet):
     34     name = "SLARP"
     35     fields_desc = [ IntEnumField("type", 2, {0 : "request", 1 : "reply", 2 :"line keepalive"}),
     36                     ConditionalField(IPField("address", "192.168.0.1"),
     37                                         lambda pkt : pkt.type == 0 or pkt.type == 1),
     38                     ConditionalField(IPField("mask", "255.255.255.0"),
     39                                         lambda pkt : pkt.type == 0 or pkt.type == 1),
     40                     ConditionalField(XShortField("unused", 0),
     41                                         lambda pkt : pkt.type == 0 or pkt.type == 1),
     42                     ConditionalField(IntField("mysequence", 0),
     43                                         lambda pkt : pkt.type == 2),
     44                     ConditionalField(IntField("yoursequence", 0),
     45                                         lambda pkt : pkt.type == 2),
     46                     ConditionalField(XShortField("reliability", 0xffff),
     47                                         lambda pkt : pkt.type == 2)]
     48 
     49 bind_layers( CHDLC, Dot3,  proto=0x6558)
     50 bind_layers( CHDLC, IP,    proto=0x800)
     51 bind_layers( CHDLC, IPv6,  proto=0x86dd)
     52 bind_layers( CHDLC, SLARP, proto=0x8035)
     53 bind_layers( CHDLC, STP,   proto=0x4242)
     54 
     55 conf.l2types.register(DLT_C_HDLC, CHDLC)
     56