-
Notifications
You must be signed in to change notification settings - Fork 124
Refactor MagicDNS support to properly handle appconnectors #667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
lmagyar
wants to merge
19
commits into
hassio-addons:main
Choose a base branch
from
lmagyar:pr-fix-proxies
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
d7a5c9e
Move MagicDNS egress proxy to non-default port
lmagyar 9f40826
Move egress proxy setup script into separate file like ingress proxy
lmagyar e304660
Move MagicDNS ingress proxy to non-default port
lmagyar 9dcf4f3
replace bind-dynamic with bind-interfaces for egress proxy
lmagyar 66f54fb
use different ports for the proxies
lmagyar 989caa9
tailscaled waits for the egress proxy
lmagyar 155244f
comment on bind-dynamic vs bind-interfaces
lmagyar 367b9a9
Fix magicdns for appconnectors
lmagyar f79be40
fix shellcheck errors
lmagyar 96d786e
minor fixes, thanks bunny
lmagyar 6936b26
halp app on dns reconfig failure
lmagyar 81871d4
use plain exit.nok
lmagyar d15f1bc
test file content also, thanks bunny
lmagyar 6118310
don't poll for dns config changes, use ipn bus events
lmagyar c240649
add log line
lmagyar afb8cf3
Advance previous_ipn_dns_config only after a successful probe.
lmagyar 1d26902
use both login and both log server domains
lmagyar 3efddfd
fix jq errors on non-DNS netmaps
lmagyar 85cefa0
Graceful shutdown on SIGTERM caused by manual app stop
lmagyar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,72 @@ | ||
| #!/usr/bin/env bashio | ||
| # shellcheck shell=bash | ||
| export LOG_FD | ||
| # ============================================================================== | ||
| # Setup DNAT for outgoing MagicDNS queries toward egress dnsmasq proxy | ||
| # ============================================================================== | ||
|
|
||
| readonly DNSMASQ_EGRESS_ADDRESS_IPV4="127.100.100.100" | ||
|
|
||
| function setup_forwarding() { | ||
| local cmd="${1}" | ||
| local proto="${2}" | ||
| local ip_version="${3}" | ||
| local address_bits="${4}" | ||
| local from_address="${5}" | ||
| local to_address="${6}" | ||
| local to_port="${7}" | ||
|
|
||
| bashio::log.info "Setting up forwarding for MagicDNS egress proxy (${proto}, ${ip_version})" | ||
| if ${cmd} -t nat -S OUTPUT \ | ||
| | grep -Eq "^-A OUTPUT -d ${from_address//[\[\]]/}/${address_bits} -p ${proto} -m ${proto} --dport 53 -j DNAT --to-destination $(sed -r 's/(\[|\])/\\\1/g' <<< "${to_address}"):${to_port}$" | ||
| then | ||
| bashio::log.notice "Forwarding is already set for MagicDNS egress proxy (${proto}, ${ip_version})" | ||
| else | ||
| if ! ${cmd} -t nat -A OUTPUT -d "${from_address//[\[\]]/}" -p "${proto}" --dport 53 -j DNAT --to-destination "${to_address}:${to_port}"; then | ||
| bashio::exit.nok "Setting up forwarding for MagicDNS egress proxy is unsuccessful (${proto}, ${ip_version})" | ||
| fi | ||
| fi | ||
| } | ||
|
|
||
| function remove_forwarding() { | ||
| local cmd="${1}" | ||
| local ip_version="${2}" | ||
| local address_bits="${3}" | ||
| local from_address="${4}" | ||
| local to_address="${5}" | ||
|
|
||
| local variables | ||
| local proto | ||
| local to_port | ||
|
|
||
| for variables in $( \ | ||
| ${cmd} -t nat -S OUTPUT \ | ||
| | { grep -E "^-A OUTPUT -d ${from_address//[\[\]]/}/${address_bits} -p \S+ -m \S+ --dport 53 -j DNAT --to-destination $(sed -r 's/(\[|\])/\\\1/g' <<< "${to_address}"):\d+$" || true ;} \ | ||
| | sed -nr 's/^.*?-p\s(\S+).*?:(\d+)$/\1|\2/p') | ||
| do | ||
| IFS='|' read -r proto to_port <<< "${variables}" | ||
|
lmagyar marked this conversation as resolved.
|
||
| bashio::log.info "Removing forwarding for MagicDNS egress proxy (${proto}, ${ip_version})" | ||
| if ! ${cmd} -t nat -D OUTPUT -d "${from_address//[\[\]]/}" -p "${proto}" --dport 53 -j DNAT --to-destination "${to_address}:${to_port}"; then | ||
| bashio::log.warning "Removing forwarding for MagicDNS egress proxy is unsuccessful (${proto}, ${ip_version})" | ||
| fi | ||
| done | ||
| } | ||
|
|
||
| case "${1-}-${2-}" in | ||
| setup-forwarding) | ||
| if ! bashio::var.has_value "${3-}"; then | ||
| echo "Port is missing" 1>&2 | ||
| echo "Usage: $(basename "$0") setup forwarding port" 1>&2 | ||
| exit 1 | ||
| fi | ||
| setup_forwarding "iptables" "udp" "IPv4" "32" "${DNSMASQ_EGRESS_ADDRESS_IPV4}" "${DNSMASQ_EGRESS_ADDRESS_IPV4}" "${3}" | ||
| setup_forwarding "iptables" "tcp" "IPv4" "32" "${DNSMASQ_EGRESS_ADDRESS_IPV4}" "${DNSMASQ_EGRESS_ADDRESS_IPV4}" "${3}" | ||
| ;; | ||
| remove-forwarding) | ||
| remove_forwarding "iptables" "IPv4" "32" "${DNSMASQ_EGRESS_ADDRESS_IPV4}" "${DNSMASQ_EGRESS_ADDRESS_IPV4}" | ||
| ;; | ||
| *) | ||
| echo "Usage: $(basename "$0") setup|remove forwarding [port in case of setup forwarding]" 1>&2 | ||
| exit 1 | ||
| ;; | ||
| esac | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.