Home | History | Annotate | Download | only in contrib
      1 ## RSVP layer
      2 
      3 # This file is part of Scapy
      4 # Scapy is free software: you can redistribute it and/or modify
      5 # it under the terms of the GNU General Public License as published by
      6 # the Free Software Foundation, either version 2 of the License, or
      7 # any later version.
      8 #
      9 # Scapy is distributed in the hope that it will be useful,
     10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
     11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
     12 # GNU General Public License for more details.
     13 #
     14 # You should have received a copy of the GNU General Public License
     15 # along with Scapy. If not, see <http://www.gnu.org/licenses/>.
     16 
     17 # scapy.contrib.description = RSVP
     18 # scapy.contrib.status = loads
     19 
     20 from scapy.packet import *
     21 from scapy.fields import *
     22 from scapy.layers.inet import IP
     23 
     24 rsvpmsgtypes = { 0x01 : "Path",
     25                  0x02 : "Reservation request",
     26                  0x03 : "Path error",
     27                  0x04 : "Reservation request error",
     28                  0x05 : "Path teardown",
     29                  0x06 : "Reservation teardown",
     30                  0x07 : "Reservation request acknowledgment"
     31 }
     32         
     33 class RSVP(Packet):
     34     name = "RSVP"
     35     fields_desc = [ BitField("Version",1,4),
     36                     BitField("Flags",1,4),
     37                     ByteEnumField("Class",0x01, rsvpmsgtypes),
     38                     XShortField("chksum", None),
     39                     ByteField("TTL",1),
     40                     XByteField("dataofs", 0),
     41                     ShortField("Length",None)]
     42     def post_build(self, p, pay):
     43         p += pay
     44         if self.Length is None:
     45             l = len(p)
     46             p = p[:6]+chr((l>>8)&0xff)+chr(l&0xff)+p[8:]
     47         if self.chksum is None:
     48             ck = checksum(p)
     49             p = p[:2]+chr(ck>>8)+chr(ck&0xff)+p[4:]
     50         return p
     51                     
     52 rsvptypes = { 0x01 : "Session",
     53               0x03 : "HOP",
     54               0x04 : "INTEGRITY",
     55               0x05 : "TIME_VALUES",
     56               0x06 : "ERROR_SPEC",
     57               0x07 : "SCOPE",
     58               0x08 :  "STYLE",
     59               0x09 :  "FLOWSPEC",
     60               0x0A :  "FILTER_SPEC",
     61               0x0B :  "SENDER_TEMPLATE",
     62               0x0C  : "SENDER_TSPEC",
     63               0x0D   : "ADSPEC",
     64               0x0E   : "POLICY_DATA",
     65               0x0F   : "RESV_CONFIRM",
     66               0x10   : "RSVP_LABEL",
     67               0x11   : "HOP_COUNT",        
     68               0x12   : "STRICT_SOURCE_ROUTE",
     69               0x13   : "LABEL_REQUEST",
     70               0x14   : "EXPLICIT_ROUTE",
     71               0x15   : "ROUTE_RECORD",
     72               0x16   : "HELLO",
     73               0x17   : "MESSAGE_ID",
     74               0x18   : "MESSAGE_ID_ACK",
     75               0x19   : "MESSAGE_ID_LIST",
     76               0x1E   : "DIAGNOSTIC",
     77               0x1F   : "ROUTE",
     78               0x20   : "DIAG_RESPONSE",
     79               0x21   : "DIAG_SELECT",
     80               0x22   : "RECOVERY_LABEL",
     81               0x23   : "UPSTREAM_LABEL",
     82               0x24   : "LABEL_SET",
     83               0x25   : "PROTECTION",
     84               0x26   : "PRIMARY PATH ROUTE",
     85               0x2A   : "DSBM IP ADDRESS",
     86               0x2B   : "SBM_PRIORITY",
     87               0x2C   : "DSBM TIMER INTERVALS",
     88               0x2D   : "SBM_INFO",
     89               0x32   : "S2L_SUB_LSP",
     90               0x3F   : "DETOUR",
     91               0x40   : "CHALLENGE",
     92               0x41   : "DIFF-SERV",
     93               0x42   : "CLASSTYPE",
     94               0x43   : "LSP_REQUIRED_ATTRIBUTES",
     95               0x80  : "NODE_CHAR",
     96               0x81  : "SUGGESTED_LABEL",
     97               0x82  : "ACCEPTABLE_LABEL_SET",
     98               0x83  : "RESTART_CA",
     99               0x84  : "SESSION-OF-INTEREST",
    100               0x85  : "LINK_CAPABILITY",
    101               0x86  : "Capability Object", 
    102               0xA1  : "RSVP_HOP_L2",
    103               0xA2  : "LAN_NHOP_L2",    
    104               0xA3  : "LAN_NHOP_L3",    
    105               0xA4  : "LAN_LOOPBACK",    
    106               0xA5  : "TCLASS",
    107               0xC0  : "TUNNEL", 
    108               0xC1  : "LSP_TUNNEL_INTERFACE_ID",
    109               0xC2  : "USER_ERROR_SPEC",
    110               0xC3  : "NOTIFY_REQUEST",
    111               0xC4  : "ADMIN-STATUS",
    112               0xC5  : "LSP_ATTRIBUTES",
    113               0xC6  : "ALARM_SPEC",
    114               0xC7  : "ASSOCIATION",
    115               0xC8  : "SECONDARY_EXPLICIT_ROUTE",
    116               0xC9  : "SECONDARY_RECORD_ROUTE",                
    117               0xCD  : "FAST_REROUTE",
    118               0xCF  : "SESSION_ATTRIBUTE",
    119               0xE1  : "DCLASS",
    120               0xE2  : "PACKETCABLE EXTENSIONS",
    121               0xE3  : "ATM_SERVICECLASS",
    122               0xE4  : "CALL_OPS (ASON)",
    123               0xE5  : "GENERALIZED_UNI",
    124               0xE6  : "CALL_ID",
    125               0xE7  : "3GPP2_Object",
    126               0xE8  : "EXCLUDE_ROUTE"
    127 }      
    128 
    129 class RSVP_Object(Packet):
    130     name = "RSVP_Object"
    131     fields_desc = [ ShortField("Length",4),
    132                   ByteEnumField("Class",0x01, rsvptypes),
    133                   ByteField("C-Type",1)]
    134     def guess_payload_class(self, payload):
    135         if self.Class == 0x03:
    136             return RSVP_HOP
    137         elif self.Class == 0x05:
    138             return RSVP_Time
    139         elif self.Class == 0x0c:
    140             return RSVP_SenderTSPEC
    141         elif self.Class == 0x13:
    142             return RSVP_LabelReq
    143         elif self.Class == 0xCF:
    144             return RSVP_SessionAttrb
    145         else:
    146             return RSVP_Data
    147     
    148     
    149 
    150 class RSVP_Data(Packet):
    151     name = "Data"
    152     fields_desc = [StrLenField("Data","",length_from= lambda pkt:pkt.underlayer.Length - 4)]
    153     def default_payload_class(self, payload):
    154       return RSVP_Object
    155 
    156 class RSVP_HOP(Packet):
    157     name = "HOP"
    158     fields_desc = [ IPField("neighbor","0.0.0.0"),
    159                   BitField("inface",1,32)]
    160     def default_payload_class(self, payload):
    161       return RSVP_Object
    162 
    163 class RSVP_Time(Packet):
    164     name = "Time Val"
    165     fields_desc = [ BitField("refresh",1,32)]
    166     def default_payload_class(self, payload):
    167       return RSVP_Object
    168 
    169 class RSVP_SenderTSPEC(Packet):
    170     name = "Sender_TSPEC"
    171     fields_desc = [ ByteField("Msg_Format",0),
    172                     ByteField("reserve",0),
    173                     ShortField("Data_Length",4),
    174                     ByteField("Srv_hdr",1),
    175                     ByteField("reserve2",0),
    176                     ShortField("Srv_Length",4),
    177                     StrLenField("Tokens","",length_from= lambda pkt:pkt.underlayer.Length - 12) ]
    178     def default_payload_class(self, payload):
    179       return RSVP_Object
    180 
    181 class RSVP_LabelReq(Packet):
    182     name = "Lable Req"
    183     fields_desc = [  ShortField("reserve",1),
    184                      ShortField("L3PID",1)]
    185     def default_payload_class(self, payload):
    186       return RSVP_Object
    187 
    188 class RSVP_SessionAttrb(Packet):
    189     name = "Session_Attribute"
    190     fields_desc = [  ByteField("Setup_priority",1),
    191                      ByteField("Hold_priority",1),
    192                      ByteField("flags",1),
    193                      ByteField("Name_length",1),
    194                      StrLenField("Name","",length_from= lambda pkt:pkt.underlayer.Length - 8),
    195                      ]  
    196     def default_payload_class(self, payload):
    197       return RSVP_Object
    198 
    199 bind_layers( IP,     RSVP,     { "proto" : 46} )
    200 bind_layers( RSVP, RSVP_Object, {})
    201