Skip to content

Commit

Permalink
Explicitly pass address family option to BSD route
Browse files Browse the repository at this point in the history
  • Loading branch information
gmacon committed Mar 16, 2020
1 parent a97c9e7 commit 63e76f6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions vpn_slice/mac.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ def _route(self, *args):
def _ifconfig(self, *args):
return subprocess.check_output([self.ifconfig] + list(map(str, args)), universal_newlines=True)

def _family_option(self, destination):
return '-inet6' if destination.version == 6 else '-inet'

def add_route(self, destination, *, via=None, dev=None, src=None, mtu=None):
args = ['add']
args = ['add', self._family_option(destination)]
if mtu is not None:
args.extend(('-mtu', str(mtu)))
if via is not None:
Expand All @@ -53,10 +56,10 @@ def add_route(self, destination, *, via=None, dev=None, src=None, mtu=None):
replace_route = add_route

def remove_route(self, destination):
self._route('delete', destination)
self._route('delete', self._family_option(destination), destination)

def get_route(self, destination):
info = self._route('get', destination)
info = self._route('get', self._family_option(destination), destination)
lines = iter(info.splitlines())
info_d = {}
for line in lines:
Expand Down

0 comments on commit 63e76f6

Please sign in to comment.