[icmp6] add dedicated multicast address listener
This commit is contained in:
parent
6f83eeddb2
commit
fbadfddee8
1 changed files with 20 additions and 11 deletions
|
@ -9,6 +9,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
|
||||||
|
from scapy.all import ICMPv6ND_NS, ICMPv6
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import re
|
import re
|
||||||
|
@ -17,7 +18,6 @@ import logging
|
||||||
import argparse
|
import argparse
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
# Broken in python2
|
|
||||||
import ipaddress
|
import ipaddress
|
||||||
|
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
|
@ -84,6 +84,10 @@ class L2Controller(object):
|
||||||
log.debug("host: {}".format(host))
|
log.debug("host: {}".format(host))
|
||||||
return "{}1/{}".format(net, mask)
|
return "{}1/{}".format(net, mask)
|
||||||
|
|
||||||
|
def gen_ndp_multicast_addr(self, addr):
|
||||||
|
""" append the 24 bit of the address to the multicast address"""
|
||||||
|
return ipaddress.ip_address(int(self.info['ndp_multicast']) + (int(addr) & 0xffffff))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def add_host_ips(host, net, ipaddr, dev):
|
def add_host_ips(host, net, ipaddr, dev):
|
||||||
subprocess.call(["mx", host, "ip", "addr", "flush", "dev", dev])
|
subprocess.call(["mx", host, "ip", "addr", "flush", "dev", dev])
|
||||||
|
@ -142,6 +146,11 @@ class L2Controller(object):
|
||||||
self.fill_tables()
|
self.fill_tables()
|
||||||
self.config_hosts()
|
self.config_hosts()
|
||||||
|
|
||||||
|
def listen_to_icmp6_multicast(self):
|
||||||
|
"""Only needed for debugging"""
|
||||||
|
|
||||||
|
net = str(self.info['ndp_multicast'])
|
||||||
|
self.controller.table_add("v6_networks", "controller_debug", [net])
|
||||||
|
|
||||||
def fill_tables(self):
|
def fill_tables(self):
|
||||||
self.controller.table_clear("v6_networks")
|
self.controller.table_clear("v6_networks")
|
||||||
|
@ -149,9 +158,8 @@ class L2Controller(object):
|
||||||
net = self.prefix_to_net(v6route['net'], self.v6_mask)
|
net = self.prefix_to_net(v6route['net'], self.v6_mask)
|
||||||
self.controller.table_add("v6_networks", "set_egress_port", [net], [v6route['port']])
|
self.controller.table_add("v6_networks", "set_egress_port", [net], [v6route['port']])
|
||||||
|
|
||||||
net = str(self.info['ndp_multicast'])
|
if
|
||||||
self.controller.table_add("v6_networks", "controller_reply", [net])
|
self.listen_to_icmp6_multicast()
|
||||||
|
|
||||||
|
|
||||||
self.controller.table_clear("v4_routing")
|
self.controller.table_clear("v4_routing")
|
||||||
for v4route in self.v4_routes[self.mode]:
|
for v4route in self.v4_routes[self.mode]:
|
||||||
|
@ -160,13 +168,12 @@ class L2Controller(object):
|
||||||
|
|
||||||
self.controller.table_clear("v6_addresses")
|
self.controller.table_clear("v6_addresses")
|
||||||
for v6addr in self.v6_addresses[self.mode]:
|
for v6addr in self.v6_addresses[self.mode]:
|
||||||
|
icmp6_addr = str(self.gen_ndp_multicast_addr(v6addr))
|
||||||
|
|
||||||
self.controller.table_add("v6_addresses", "controller_reply", [v6addr['addr']])
|
self.controller.table_add("v6_addresses", "controller_reply", [v6addr['addr']])
|
||||||
|
self.controller.table_add("v6_addresses", "controller_reply", [icmp6_addr])
|
||||||
|
|
||||||
|
|
||||||
def gen_ndp_multicast_addr(self, addr):
|
|
||||||
""" append the 24 bit of the address to the multicast address"""
|
|
||||||
return ipaddress.ip_address(int(self.info['ndp_multicast']) + (int(addr) & 0xffffff))
|
|
||||||
|
|
||||||
def config_hosts(self):
|
def config_hosts(self):
|
||||||
""" Assumptions:
|
""" Assumptions:
|
||||||
- all routes are networks (no /128 v6 or /32 v4
|
- all routes are networks (no /128 v6 or /32 v4
|
||||||
|
@ -234,8 +241,10 @@ class L2Controller(object):
|
||||||
print("Special handling needed")
|
print("Special handling needed")
|
||||||
pass
|
pass
|
||||||
elif packet.type == 0x2323:
|
elif packet.type == 0x2323:
|
||||||
print("Debug pkg")
|
# Set back (incorrectly maybe) to IPv6
|
||||||
pass
|
packet.type = 0x86dd
|
||||||
|
print("Debug pkg: ".format(packet))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
print("Broken pkg: {}".format(pkg.__repr__()))
|
print("Broken pkg: {}".format(pkg.__repr__()))
|
||||||
return
|
return
|
||||||
|
@ -250,7 +259,7 @@ class L2Controller(object):
|
||||||
|
|
||||||
self.args = parser.parse_args()
|
self.args = parser.parse_args()
|
||||||
self.mode = self.args.mode
|
self.mode = self.args.mode
|
||||||
|
self.debug = args.debug
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import sys
|
import sys
|
||||||
|
|
Loading…
Reference in a new issue