Begin to introduce arp support

This commit is contained in:
Nico Schottelius 2019-03-31 15:48:00 +02:00
commit 07f0867175
4 changed files with 100 additions and 7 deletions

View file

@ -35,7 +35,8 @@ table_id_fields = {
2: 'TABLE_ICMP6',
3: 'TABLE_V6_NETWORKS',
4: 'TABLE_NAT46',
5: 'TABLE_V4_NETWORKS'
5: 'TABLE_V4_NETWORKS',
6: 'TABLE_ARP'
}
table_proto = {
@ -47,6 +48,10 @@ table_proto = {
'ICMP_ECHO_REQUEST' : 8
}
table_arp = {
'ARP_REQUEST': 1,
'ARP_REPLY': 2
}
class CpuHeader(Packet):
@ -72,6 +77,7 @@ class L2Controller(object):
# https://en.wikipedia.org/wiki/Solicited-node_multicast_address
self.info['ndp_multicast'] = ipaddress.ip_network("ff02::1:ff00:0/104")
self.info['mac_addr'] = "00:00:0a:00:00:42"
self.info['mac_broadcast'] = "ff:ff:ff:ff:ff:ff:ff"
self.info['ipv6_link_local'] = ipaddress.ip_address("fe80::200:aff:fe00:42")
self.info['v6_mask'] = 64
@ -234,6 +240,9 @@ class L2Controller(object):
[str(icmp6_net), str(icmp6_type)], [])
def ipv4_router(self, net):
return net[self.info['switch_suffix']]
def fill_tables(self):
self.controller.table_clear("v6_networks")
for v6route in self.v6_routes[self.mode]:
@ -243,6 +252,14 @@ class L2Controller(object):
for v4route in self.v4_routes[self.mode]:
self.controller.table_add("v4_networks", "set_egress_port", [str(v4route['net'])], [str(v4route['port'])])
# ARP support
router = "{}/32".format(self.ipv4_router(v4route['net']))
self.controller.table_add("v4_arp", "arp_reply",
[str(self.info['mac_broadcast']),
str(table_arp['ARP_REQUEST']),
router],
[str(self.info['mac_addr'])]
if self.args.multicast_to_controller:
self.listen_to_icmp6_multicast()
@ -304,7 +321,7 @@ class L2Controller(object):
dev = "{}-eth0".format(host)
net = v4route['net']
ipaddr = "{}/{}".format(net[1],net.prefixlen)
router = str(net[self.info['switch_suffix']])
router = self.ipv4_router(net)
self.config_v4_host(host, str(net), str(ipaddr), dev, router)