From f5b9baff78332914a2ad34cd89d6844bb589aa06 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Sat, 23 Feb 2019 15:13:47 +0100 Subject: [PATCH] [controller] setup IPv6 hosts --- p4app/controller.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/p4app/controller.py b/p4app/controller.py index 9139e74..863d2bf 100644 --- a/p4app/controller.py +++ b/p4app/controller.py @@ -14,6 +14,8 @@ import re import logging import argparse import ipaddress +import subprocess + logging.basicConfig() log = logging.getLogger("main") @@ -66,11 +68,21 @@ class L2Controller(object): - all routes are networks (no /128 v6 or /32 v4 - hosts get the first ip address in the network """ - for v6route in self.v6_routes[self.mode]: - self.controller.table_add("v6_routing", "set_egress_port", [v6route['net']], [v6route['port']]) - for v4route in self.v4_routes[self.mode]: - self.controller.table_add("v4_routing", "set_egress_port", [v4route['net']], [v4route['port']]) + for v6route in self.v6_routes[self.mode]: + host = "h{}".format(v6route['port']) + dev = "{}-eth0".format(host) + net = ipaddress.ip_network(v6route['net']) + ipaddr = "{}/{}".format(net[1],net.prefix_length) + + subprocess.run(["mx", host, "ip", "addr", "flush", "dev", dev]) + subprocess.run(["mx", host, "sysctl", "net.ipv6.conf.lo.disable_ipv6=0"]) + subprocess.run(["mx", host, "sysctl", "net.ipv6.conf.{}.disable_ipv6=0".format(dev)]) + subprocess.run(["mx", host, "ip", "addr", "add", ipaddr, "dev", dev]) + + # mx h$i "ip -6 route add default via 2001:db8:6::42" + + #for v4route in self.v4_routes[self.mode]: def debug_print_pkg(self, pkg, msg="INCOMING"):