-
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prevent avahi from serving support_tunnel addresses
- Loading branch information
Showing
5 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[device] | ||
post-up-script=/usr/local/bin/support_tunnel_post_up.sh {iface} | ||
post-down-script=/usr/local/bin/support_tunnel_post_down.sh {iface} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/bin/bash | ||
# This script runs after a support tunnel comes down. Right now, | ||
# it only prevents Avahi from advertising using the wireguard interface | ||
# $1 is the wireguard interface to remove | ||
|
||
# The avahi-daemon.conf follows an ini-style convention; Python's | ||
# configparser makes it easy to safely add & remove contents in a particular | ||
# section, and "shelling out" gives us an opportunity to use `sudo`. | ||
echo "import configparser | ||
import sys | ||
config = configparser.ConfigParser() | ||
config.read('/etc/avahi/avahi-daemon.conf') | ||
if not config.has_section('server'): | ||
config.add_section('server') | ||
deny = set(config['server'].get('deny-interfaces').split(',')) | ||
try: | ||
deny.remove('${1}') | ||
except KeyError as e: | ||
print(f'${1} not in config; exiting early.') | ||
sys.exit(1) | ||
deny_str = '' | ||
for i, d in enumerate(deny): | ||
deny_str += f'{d}' | ||
deny_str += ',' if i != (len(deny) - 1) else '' | ||
config['server']['deny-interfaces'] = deny_str | ||
with open('/etc/avahi/avahi-daemon.conf', 'w') as f: | ||
config.write(f, space_around_delimiters=False) | ||
" | sudo python3 - | ||
|
||
sudo systemctl restart avahi-daemon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/bin/bash | ||
# This script runs after a support tunnel comes up. Right now, | ||
# it only prevents Avahi from advertising using the wireguard interface | ||
# $1 is the wireguard interface name | ||
|
||
# The avahi-daemon.conf follows an ini-style convention; Python's | ||
# configparser makes it easy to add & remove contents in a particular | ||
# section, and "shelling out" gives us an opportunity to use `sudo` | ||
echo "import configparser | ||
config = configparser.ConfigParser() | ||
config.read('/etc/avahi/avahi-daemon.conf') | ||
if not config.has_section('server'): | ||
config.add_section('server') | ||
deny = config['server'].get('deny-interfaces', '').split(',') | ||
deny = [d for d in deny if d] # removes falsy '' | ||
deny.append('${1}') | ||
deny = set(deny) # remove duplicates | ||
deny_str = '' | ||
for i, d in enumerate(deny): | ||
deny_str += f'{d}' | ||
deny_str += ',' if i != (len(deny) - 1) else '' | ||
config['server']['deny-interfaces'] = deny_str | ||
with open('/etc/avahi/avahi-daemon.conf', 'w') as f: | ||
config.write(f, space_around_delimiters=False) | ||
" | sudo python3 - | ||
sudo systemctl restart avahi-daemon |