Commit 2477ff52 authored by Julien Muchembled's avatar Julien Muchembled

Propagate default route

parent a24ecb2e
import math, nemu, os, signal, socket, subprocess, sys, time
import math, nemu, os, signal, socket, subprocess, sys, time, weakref
from collections import defaultdict
IPTABLES = 'iptables'
SCREEN = 'screen'
......@@ -26,6 +26,12 @@ def disable_signal_on_children(sig):
sigint = signal.signal(sig, lambda *x: os.getpid() == pid and sigint(*x))
Node__add_interface = nemu.Node._add_interface
def _add_interface(node, iface):
iface.__dict__['node'] = weakref.proxy(node)
return Node__add_interface(node, iface)
nemu.Node._add_interface = _add_interface
# create nodes
for name in """internet=I registry=R
gateway1=g1 machine1=1 machine2=2
......@@ -95,6 +101,7 @@ in_if_0.add_v4_address(address='', prefix_len=24)
in_if_1.add_v4_address(address='', prefix_len=24)
in_if_2.add_v4_address(address='', prefix_len=24)
in_if_3.add_v4_address(address='', prefix_len=24)
in_if_3.add_v6_address(address='2001:db8::1', prefix_len=48)
g1_if_0.add_v4_address(address='', prefix_len=24)
g1_if_1.add_v4_address(address='', prefix_len=24)
g2_if_0.add_v4_address(address='', prefix_len=24)
......@@ -108,9 +115,17 @@ m6_if_0.add_v4_address(address='', prefix_len=24)
m7_if_0.add_v4_address(address='', prefix_len=24)
m8_if_0.add_v4_address(address='', prefix_len=24)
def add_llrtr(iface, peer, dst='default'):
for a in peer.get_addresses():
a = a['address']
if a.startswith('fe80:'):
return iface.node.Popen(('ip', 'route', 'add', dst, 'via', a,
'proto', 'static', 'dev',
# setup routes
add_llrtr(re_if_0, in_if_0)
add_llrtr(in_if_0, re_if_0, '2001:db8:42::/48')
registry.add_route(prefix='', prefix_len=8, nexthop='')
#internet.add_route(prefix='', prefix_len=16, nexthop='')
internet.add_route(prefix='', prefix_len=16, nexthop='')
gateway1.add_route(prefix='', prefix_len=8, nexthop='')
gateway2.add_route(prefix='', prefix_len=8, nexthop='')
......@@ -52,22 +52,22 @@ def client(iface, server_address, encrypt, *args, **kw):
return openvpn(iface, encrypt, *remote, **kw)
def router(network, subnet, hello_interval, log_path, state_path, pidfile,
def router(subnet, hello_interval, gateway, log_path, state_path, pidfile,
tunnel_interfaces, *args, **kw):
s = utils.ipFromBin(subnet)
n = len(subnet)
cmd = ['babeld',
'-C', 'redistribute local deny',
'-C', 'redistribute ip %s/%u eq %u' % (s, n, n),
'-C', 'redistribute deny',
#'-C', 'in ip %s/%u' % (utils.ipFromBin(network), len(network)),
#'-C', 'in deny',
'-h', str(hello_interval),
'-H', str(hello_interval),
'-L', log_path,
'-S', state_path,
'-I', pidfile,
'-C', 'redistribute local deny',
'-C', 'redistribute ip %s/%u eq %u' % (s, n, n),
'-C', 'redistribute deny']
if gateway:
cmd[-2:-2] = '-C', 'redistribute ip ::/0 eq 0'
for iface in tunnel_interfaces:
cmd += '-C', 'interface %s rxcost 512' % iface
cmd += args
......@@ -181,7 +181,7 @@ def main():
tunnel_manager = write_pipe = None
config.babel_args += config.iface_list
cleanup = [plib.router(network, subnet, config.hello,
cleanup = [plib.router(subnet, config.hello, tunnel_manager is not None,
os.path.join(config.log, 'babeld.log'),
os.path.join(config.state, 'babeld.state'),
config.babel_pidfile, tunnel_interfaces,
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment