From c9f88318655ac3242c0bf400bc6cca613dbabfeb Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Tue, 5 Mar 2019 22:04:04 +0100 Subject: [PATCH] icmp6 echo reply --- p4app/controller.py | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/p4app/controller.py b/p4app/controller.py index 3ea4d9b..382f95c 100644 --- a/p4app/controller.py +++ b/p4app/controller.py @@ -11,6 +11,7 @@ from scapy.all import IP, Raw, IPv6, TCP, TCP_client, Ether from scapy.all import sniff from scapy.all import Packet, BitField, IntEnumField, ShortField, XShortEnumField, ShortEnumField from scapy.all import ICMPv6ND_NS, ICMPv6ND_RS, ICMPv6NDOptSrcLLAddr, ICMPv6ND_NS, ICMPv6ND_NA, ICMPv6NDOptDstLLAddr +from scapy.all import ICMPv6EchoRequest, ICMPv6EchoReply from scapy.data import ETHER_TYPES import sys @@ -230,6 +231,29 @@ class L2Controller(object): # tcp.ack, # raw) + def handle_icmp6_echo_request(self, pkg): + """ + Sample from the wire: + + DEBUG:main:reassambled=>> + """ + + log.info("Replying to ICMP packet") + dst_mac = pkg[Ether].src + src_mac = pkg[Ether].dst + + dst_addr = pkg[IPv6].src + src_addr = pkg[IPv6].dst + + e = Ether(src=src_mac, dst=dst_mac) + i = IPv6(src=src_addr, dst=dst_addr) + i2 = ICMPv6EchoReply(id=pkg[ICMPv6EchoRequest].id, + seq=pkg[ICMPv6EchoRequest].seq, + data=pkg[ICMPv6EchoRequest].data) + i2.cksum = None + self.send_pkg(answer) + + def handle_icmp6_ns(self, pkg): """ Solicitated NA""" @@ -263,9 +287,6 @@ class L2Controller(object): # Let scapy recalc checksum (try3) # answer = answer.__class__(str(answer)) - - - self.send_pkg(answer) def send_pkg(self, pkg): @@ -295,7 +316,8 @@ class L2Controller(object): log.info("Doing neighbor solicitation") self.handle_icmp6_ns(orig_packet) elif cpu_header.task == self.task['ICMP6_GENERAL']: - log.info("Replying to ICMP packet") + if ICMPv6EchoRequest in orig_packet: + handle_icmp6_echo_request(orig_packet) else: print("Broken pkg: {}".format(pkg.__repr__()))