Initial icmp6_na support in controller

This commit is contained in:
Nico Schottelius 2019-03-05 16:59:27 +01:00
parent 356f664019
commit a139ad6e83

View file

@ -10,7 +10,7 @@ from scapy.all import sniff, get_if_list, Ether, get_if_hwaddr, sendp
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
from scapy.all import ICMPv6ND_NS, ICMPv6ND_RS, ICMPv6NDOptSrcLLAddr, ICMPv6ND_NS, ICMPv6ND_NA
from scapy.data import ETHER_TYPES
import sys
@ -52,6 +52,7 @@ class L2Controller(object):
self.info={}
self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104")
self.info['mac_address'] = "00:00:0a:00:00:42"
self.info['v6_mask'] = 64
self.info['v6_base'] = ipaddress.ip_network("2001:db8::/32")
@ -229,6 +230,29 @@ class L2Controller(object):
# tcp.ack,
# raw)
def handle_icmp6_ns(self, pkg):
""" Solicitated NA"""
# Both ways should work
dst_mac = pkg[Ether].src
dst_mac = pkg[ICMPv6NDOptSrcLLAddr].src
src_mac = self.info['mac_address']
dst_addr = pkg[IPv6].src
src_addr = pkg[ICMPv6ND_NS].tgt
e = Ether(src=src_mac, dst=dst_mac)
i = IPv6(src=src_addr, dst=dst_addr)
# S=1 -> solicitated
i2 = ICMPv6ND_NA(S=1, tgt=src_addr)
i3 = ICMPv6NDOptSrcLLAddr(lladdr=src_mac)
answer = e / i / i2 / i3
sendp(answer, iface=self.intf, verbose=False)
def recv_msg_cpu(self, pkg):
packet = Ether(str(pkg))
@ -245,12 +269,13 @@ class L2Controller(object):
ether_orig = Ether(src=packet.src, dst=packet.dst, type=cpu_header.type)
orig_packet = ether_orig / IPv6(cpu_header.load)
log.debug("o={}".format(orig_packet.__repr__()))
log.debug("reassambled={}".format(orig_packet.__repr__()))
if cpu_header.task == self.task['DEBUG']:
log.debug("Debug purpose only")
elif cpu_header.task == self.task['ICMP6_NS']:
log.debug("Doing neighbor solicitation")
self.handle_icmp6_ns(orig_packet)
elif cpu_header.task == self.task['ICMP6_GENERAL']:
log.debug("Replying to ICMP packet")