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