Skip to content
Snippets Groups Projects
Commit 3bc49afb authored by Marcel Patzlaff's avatar Marcel Patzlaff
Browse files

CHANGE: removed dedicated CLNS layer and replaced it with a better usable solution

CHANGE: made IS-IS more PEP-8 compliant
parent 5a64a524
No related branches found
No related tags found
No related merge requests found
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
CLNS Extension CLNS Extension
~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~
:copyright: 2014 BENOCS GmbH, Berlin (Germany) :copyright: 2014, 2015 BENOCS GmbH, Berlin (Germany)
:author: Marcel Patzlaff, mpatzlaff@benocs.com :author: Marcel Patzlaff, mpatzlaff@benocs.com
:license: GPLv2 :license: GPLv2
...@@ -18,69 +18,67 @@ ...@@ -18,69 +18,67 @@
:description: :description:
This module provides a layer and registration function for This module provides a registration function and a generic PDU
OSI Connectionless-mode Network Services (such as IS-IS). 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)
""" """
import struct import struct
from scapy.config import conf from scapy.config import conf
from scapy.fields import ByteEnumField, PacketField from scapy.fields import ByteEnumField, PacketField
from scapy.layers.l2 import LLC from scapy.layers.l2 import LLC
from scapy.packet import Packet, bind_layers from scapy.packet import Packet, bind_top_down, bind_bottom_up
network_layer_protocol_ids= { network_layer_protocol_ids = {
0x00 : "Null", 0x00: "Null",
0x08 : "Q.933", 0x08: "Q.933",
0x80 : "IEEE SNAP", 0x80: "IEEE SNAP",
0x81 : "ISO 8438 CLNP", 0x81: "ISO 8438 CLNP",
0x82 : "ISO 9542 ES-IS", 0x82: "ISO 9542 ES-IS",
0x83 : "ISO 10589 IS-IS", 0x83: "ISO 10589 IS-IS",
0x8E : "IPv6", 0x8E: "IPv6",
0xB0 : "FRF.9", 0xB0: "FRF.9",
0xB1 : "FRF.12", 0xB1: "FRF.12",
0xC0 : "TRILL", 0xC0: "TRILL",
0xC1 : "IEEE 802.aq", 0xC1: "IEEE 802.aq",
0xCC : "IPv4", 0xCC: "IPv4",
0xCF : "PPP" 0xCF: "PPP"
} }
_cln_protocols= {} _cln_protocols = {}
class _GenericClnsPdu(Packet): class _GenericClnsPdu(Packet):
name= "Generic CLNS PDU" name = "Generic CLNS PDU"
fields_desc= [ fields_desc = [
ByteEnumField("nlpid", 0x00, network_layer_protocol_ids), ByteEnumField("nlpid", 0x00, network_layer_protocol_ids),
PacketField("rawdata", None, conf.raw_layer) PacketField("rawdata", None, conf.raw_layer)
] ]
class ConnectionlessNetworkService(Packet): def _create_cln_pdu(s, **kwargs):
name= "Connectionless-mode Network Service" pdu_cls = conf.raw_layer
def guess_payload_class(self, p): if len(s) >= 1:
cls= conf.raw_layer nlpid = struct.unpack("!B", s[0])[0]
pdu_cls = _cln_protocols.get(nlpid, _GenericClnsPdu)
if len(p) >= 1:
nlpid = struct.unpack("!B", p[0])[0] return pdu_cls(s, **kwargs)
cls= _cln_protocols.get(nlpid, _GenericClnsPdu)
return cls
@conf.commands.register @conf.commands.register
def register_cln_protocol(nlpid, cln_protocol_class): def register_cln_protocol(nlpid, cln_protocol_class):
if nlpid is None or cln_protocol_class is None: if nlpid is None or cln_protocol_class is None:
return 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) bind_top_down(LLC, _GenericClnsPdu, dsap=0xfe, ssap=0xfe, ctrl=3)
\ No newline at end of file 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