Skip to content

Commit

Permalink
with -vv, print each route being added/replaced
Browse files Browse the repository at this point in the history
  • Loading branch information
dlenski committed May 26, 2020
1 parent aa8a1e7 commit 9b1393e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions vpn_slice/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import os, subprocess as sp
import argparse
from enum import Enum
from itertools import chain
from itertools import chain, zip_longest
from ipaddress import ip_network, ip_address, IPv4Address, IPv4Network, IPv6Address, IPv6Network, IPv6Interface
from time import sleep
from random import randint, choice, shuffle
Expand All @@ -16,6 +16,9 @@
def setproctitle(title):
pass

def tagged(iter, tag):
return zip_longest(iter, (), fillvalue=tag)

from .version import __version__
from .util import slurpy

Expand Down Expand Up @@ -129,6 +132,8 @@ def do_connect(env, args):
# set explicit route to gateway
gwr = providers.route.get_route(env.gateway)
providers.route.replace_route(env.gateway, **gwr)
if args.verbose > 1:
print("Set explicit route to VPN gateway %s (%s)" % (env.gateway, ', '.join('%s %s' % kv for kv in gwr.items())), file=stderr)

# drop incoming traffic from VPN
if not args.incoming:
Expand Down Expand Up @@ -172,7 +177,9 @@ def do_connect(env, args):

# set up routes to the DNS and Windows name servers, subnets, and local aliases
ns = env.dns + env.dns6 + (env.nbns if args.nbns else [])
for dest in chain(ns, args.subnets, args.aliases):
for dest, tag in chain(tagged(ns, "nameserver"), tagged(args.subnets, "subnet"), tagged(args.aliases, "alias")):
if args.verbose > 1:
print("Adding route to %s %s through %s." % (tag, dest, env.tundev), file=stderr)
providers.route.replace_route(dest, dev=env.tundev)
else:
providers.route.flush_cache()
Expand All @@ -182,6 +189,8 @@ def do_connect(env, args):
# restore routes to excluded subnets
for dest, exc_route in exc_subnets:
providers.route.replace_route(dest, **exc_route)
if args.verbose > 1:
print("Restoring split-exclude route to %s (%s)" % (dest, ', '.join('%s %s' % kv for kv in exc_route.items())), file=stderr)
else:
providers.route.flush_cache()
if args.verbose:
Expand Down Expand Up @@ -233,6 +242,8 @@ def do_post_connect(env, args):

# add routes to hosts
for ip in ip_routes:
if args.verbose > 1:
print("Adding route to %s (for named hosts) through %s." % (ip, env.tundev), file=stderr)
providers.route.replace_route(ip, dev=env.tundev)
else:
providers.route.flush_cache()
Expand Down

0 comments on commit 9b1393e

Please sign in to comment.