Skip to content
Snippets Groups Projects
Commit 44b58a91 authored by Guillaume Valadon's avatar Guillaume Valadon
Browse files

Merged in MarcelPatzlaff/scapy (pull request #124)

IS-IS / CLNS improvements
parents 8df02af2 fa1e669e
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
% IS-IS Tests
* Tests for the IS-IS layer
+ Basic Layer Tests
= Layer Binding
p = Dot3()/LLC()/ISIS_CommonHdr()/ISIS_P2P_Hello()
assert(p[LLC].dsap == 0xfe)
assert(p[LLC].ssap == 0xfe)
assert(p[LLC].ctrl == 0x03)
assert(p[ISIS_CommonHdr].nlpid == 0x83)
assert(p[ISIS_CommonHdr].pdutype == 17)
assert(p[ISIS_CommonHdr].hdrlen == 20)
+ Package Tests
= LSP
p = Dot3(dst="09:00:2b:00:00:05",src="00:00:00:aa:00:8c")/LLC()/ISIS_CommonHdr()/ISIS_L2_LSP(
lifetime=863, lspid="1720.1600.8016.00-00", seqnum=0x1f0, typeblock="L1+L2",
tlvs=[
ISIS_AreaTlv(
areas=[ISIS_AreaEntry(areaid="49.1000")]
),
ISIS_ProtocolsSupportedTlv(
nlpids=["IPv4", "IPv6"]
),
ISIS_DynamicHostnameTlv(
hostname="BR-HH"
),
ISIS_IpInterfaceAddressTlv(
addresses=["172.16.8.16"]
),
ISIS_GenericTlv(
type=134,
val="\xac\x10\x08\x10"
),
ISIS_ExtendedIpReachabilityTlv(
pfxs=[
ISIS_ExtendedIpPrefix(metric=0, pfx="172.16.8.16/32"),
ISIS_ExtendedIpPrefix(metric=10, pfx="10.1.0.109/30"),
ISIS_ExtendedIpPrefix(metric=10, pfx="10.1.0.181/30")
]
),
ISIS_Ipv6ReachabilityTlv(
pfxs=[
ISIS_Ipv6Prefix(metric=0, pfx="fe10:1::10/128"),
ISIS_Ipv6Prefix(metric=10, pfx="fd1f:1::/64"),
ISIS_Ipv6Prefix(metric=10, pfx="fd1f:1:12::/64")
]
),
ISIS_ExtendedIsReachabilityTlv(
neighbours=[ISIS_ExtendedIsNeighbourEntry(neighbourid="1720.1600.8004.00", metric=10)]
)
]
)
p = p.__class__(str(p))
assert(p[ISIS_L2_LSP].pdulength == 150)
assert(p[ISIS_L2_LSP].checksum == 0x8701)
\ No newline at end of file
......@@ -2,7 +2,7 @@
CLNS Extension
~~~~~~~~~~~~~~~~~~~~~
:copyright: 2014 BENOCS GmbH, Berlin (Germany)
:copyright: 2014, 2015 BENOCS GmbH, Berlin (Germany)
:author: Marcel Patzlaff, mpatzlaff@benocs.com
:license: GPLv2
......@@ -18,69 +18,67 @@
:description:
This module provides a layer and registration function for
OSI Connectionless-mode Network Services (such as IS-IS).
:TODO:
- rework this if a better way is found/implemented to bind
protocols such as IS-IS (or if IS-IS remains the sole CLN
protocol)
This module provides a registration function and a generic PDU
for OSI Connectionless-mode Network Services (such as IS-IS).
"""
import struct
from scapy.config import conf
from scapy.fields import ByteEnumField, PacketField
from scapy.layers.l2 import LLC
from scapy.packet import Packet, bind_layers
network_layer_protocol_ids= {
0x00 : "Null",
0x08 : "Q.933",
0x80 : "IEEE SNAP",
0x81 : "ISO 8438 CLNP",
0x82 : "ISO 9542 ES-IS",
0x83 : "ISO 10589 IS-IS",
0x8E : "IPv6",
0xB0 : "FRF.9",
0xB1 : "FRF.12",
0xC0 : "TRILL",
0xC1 : "IEEE 802.aq",
0xCC : "IPv4",
0xCF : "PPP"
from scapy.packet import Packet, bind_top_down, bind_bottom_up
network_layer_protocol_ids = {
0x00: "Null",
0x08: "Q.933",
0x80: "IEEE SNAP",
0x81: "ISO 8438 CLNP",
0x82: "ISO 9542 ES-IS",
0x83: "ISO 10589 IS-IS",
0x8E: "IPv6",
0xB0: "FRF.9",
0xB1: "FRF.12",
0xC0: "TRILL",
0xC1: "IEEE 802.aq",
0xCC: "IPv4",
0xCF: "PPP"
}
_cln_protocols= {}
_cln_protocols = {}
class _GenericClnsPdu(Packet):
name= "Generic CLNS PDU"
fields_desc= [
name = "Generic CLNS PDU"
fields_desc = [
ByteEnumField("nlpid", 0x00, network_layer_protocol_ids),
PacketField("rawdata", None, conf.raw_layer)
]
class ConnectionlessNetworkService(Packet):
name= "Connectionless-mode Network Service"
def guess_payload_class(self, p):
cls= conf.raw_layer
if len(p) >= 1:
nlpid = struct.unpack("!B", p[0])[0]
cls= _cln_protocols.get(nlpid, _GenericClnsPdu)
return cls
def _create_cln_pdu(s, **kwargs):
pdu_cls = conf.raw_layer
if len(s) >= 1:
nlpid = struct.unpack("!B", s[0])[0]
pdu_cls = _cln_protocols.get(nlpid, _GenericClnsPdu)
return pdu_cls(s, **kwargs)
@conf.commands.register
def register_cln_protocol(nlpid, cln_protocol_class):
if nlpid is None or cln_protocol_class is None:
return
_cln_protocols[nlpid]= cln_protocol_class
chk = _cln_protocols.get(nlpid, None)
if chk is not None and chk != cln_protocol_class:
raise ValueError("different protocol already registered!")
_cln_protocols[nlpid] = cln_protocol_class
bind_top_down(LLC, cln_protocol_class, dsap=0xfe, ssap=0xfe, ctrl=3)
bind_layers(LLC, ConnectionlessNetworkService, dsap=0xfe, ssap=0xfe, ctrl=3)
\ No newline at end of file
bind_top_down(LLC, _GenericClnsPdu, dsap=0xfe, ssap=0xfe, ctrl=3)
bind_bottom_up(LLC, _create_cln_pdu, dsap=0xfe, ssap=0xfe, ctrl=3)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment