I am confused
This commit is contained in:
parent
46b0f16f0d
commit
440782c569
1 changed files with 37 additions and 10 deletions
|
@ -8,7 +8,7 @@ from p4utils.utils.sswitch_API import SimpleSwitchAPI
|
||||||
|
|
||||||
from scapy.all import sniff, get_if_list, Ether, get_if_hwaddr, sendp
|
from scapy.all import sniff, get_if_list, Ether, get_if_hwaddr, sendp
|
||||||
from scapy.all import IP, Raw, IPv6, TCP, TCP_client
|
from scapy.all import IP, Raw, IPv6, TCP, TCP_client
|
||||||
from scapy.all import Ether, sniff, Packet, BitField
|
from scapy.all import Ether, sniff, Packet, BitField, IntEnumField, ShortField
|
||||||
from scapy.all import ICMPv6ND_NS
|
from scapy.all import ICMPv6ND_NS
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -24,12 +24,18 @@ logging.basicConfig()
|
||||||
log = logging.getLogger("main")
|
log = logging.getLogger("main")
|
||||||
|
|
||||||
|
|
||||||
|
cpu_fields = {
|
||||||
|
1: 'ICMP6_NS',
|
||||||
|
2: 'ICMP6_GENERAL',
|
||||||
|
3: 'DEBUG'
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class CpuHeader(Packet):
|
class CpuHeader(Packet):
|
||||||
name = 'CpuPacket'
|
name = 'CpuPacket'
|
||||||
fields_desc = [
|
fields_desc = [
|
||||||
BitField('task',0,8),
|
IntEnumField('task', 1, cpu_fields ),
|
||||||
BitField('ingress_port', 0, 16)
|
ShortField('ingress_port', 0)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
@ -38,11 +44,8 @@ class L2Controller(object):
|
||||||
# Command line mapping
|
# Command line mapping
|
||||||
self.modes = ['base', 'router']
|
self.modes = ['base', 'router']
|
||||||
|
|
||||||
self.task = {
|
# Reverse maps the cpu header
|
||||||
'ICMP6_NS': 1,
|
self.task = dict(reversed(item) for item in cpu_fields.items())
|
||||||
'ICMP6_GENERAL': 2,
|
|
||||||
'DEBUG': 3
|
|
||||||
}
|
|
||||||
|
|
||||||
self.info={}
|
self.info={}
|
||||||
self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104")
|
self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104")
|
||||||
|
@ -227,6 +230,7 @@ class L2Controller(object):
|
||||||
packet = Ether(str(pkg))
|
packet = Ether(str(pkg))
|
||||||
|
|
||||||
self.debug_print_pkg(pkg)
|
self.debug_print_pkg(pkg)
|
||||||
|
print("p={}".format(pkg.__repr__()))
|
||||||
|
|
||||||
if packet.type == 0x0800:
|
if packet.type == 0x0800:
|
||||||
pass
|
pass
|
||||||
|
@ -235,8 +239,31 @@ class L2Controller(object):
|
||||||
elif packet.type == 0x4242:
|
elif packet.type == 0x4242:
|
||||||
print("Special handling needed")
|
print("Special handling needed")
|
||||||
cpu_header = CpuHeader(packet.payload)
|
cpu_header = CpuHeader(packet.payload)
|
||||||
print("cpu = {}".format(cpu_header.__repr__()))
|
|
||||||
print("orig = {}".format(pkg))
|
print("cpu = {} {}".format(cpu_header.__repr__(), len(cpu_header)))
|
||||||
|
|
||||||
|
ether_part = pkg[Ether]
|
||||||
|
# read from cpu header
|
||||||
|
ether_part.type = 0x86dd
|
||||||
|
|
||||||
|
ether_orig = Ether(src=packet.src, dst=packet.dst, type=0x86dd)
|
||||||
|
|
||||||
|
# used to find correct offset = 3
|
||||||
|
|
||||||
|
# for i in range(1, 32):
|
||||||
|
# content_orig = packet.load[i:]
|
||||||
|
# try:
|
||||||
|
# orig_packet = ether_orig / IPv6(content_orig)
|
||||||
|
# print("{}: {}".format(i, orig_packet.__repr__()))
|
||||||
|
|
||||||
|
# except Exception as e:
|
||||||
|
# pass
|
||||||
|
|
||||||
|
orig_packet = ether_orig / IPv6(packet.load[3:])
|
||||||
|
self.debug_print_pkg(orig_packet)
|
||||||
|
print("o={}".format(orig_packet.__repr__()))
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Broken pkg: {}".format(pkg.__repr__()))
|
print("Broken pkg: {}".format(pkg.__repr__()))
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue