Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified bin/mdns-netbsd4be/mdns-advertiser
Binary file not shown.
Binary file modified bin/mdns-netbsd4le/mdns-advertiser
Binary file not shown.
Binary file modified bin/mdns/mdns-advertiser
Binary file not shown.
Binary file modified bin/nbns-netbsd4be/nbns-advertiser
Binary file not shown.
Binary file modified bin/nbns-netbsd4le/nbns-advertiser
Binary file not shown.
Binary file modified bin/nbns/nbns-advertiser
Binary file not shown.
885 changes: 848 additions & 37 deletions build/auto-ip-common.inc

Large diffs are not rendered by default.

4,073 changes: 3,283 additions & 790 deletions build/mdns-advertiser.c

Large diffs are not rendered by default.

12 changes: 6 additions & 6 deletions src/timecapsulesmb/assets/artifact-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@
"artifacts": {
"mdns-advertiser": {
"path": "bin/mdns/mdns-advertiser",
"sha256": "82245f3a581d196c9cad98d076d29769c0cf0dc4052681ddd8b4a050be0b0722"
"sha256": "1a072c376e56e43ec03c8a9158926dfd6c7a6486c4ebf23e30978e293f0629fb"
},
"mdns-advertiser-netbsd4le": {
"path": "bin/mdns-netbsd4le/mdns-advertiser",
"sha256": "9e63f0a4c2c483fd4c3b6727cd2005f363abe734c74ab14f1185c32d01823016"
"sha256": "8dfb9461c57f8a45a531bd4b822e602e49b7d017adb2877cd04915d81a08d3f1"
},
"mdns-advertiser-netbsd4be": {
"path": "bin/mdns-netbsd4be/mdns-advertiser",
"sha256": "bdd638d4cca35d95307e4d93feba4ced1300fde4d96406e38d99f9747f00723d"
"sha256": "390a00fdc40b49e4c5698f942aa7e83a66bfd0821bd47e982a40945c1fed51cf"
},
"nbns-advertiser": {
"path": "bin/nbns/nbns-advertiser",
"sha256": "5dd1b7df3dedcbc5dd6e6d2575a3c141cad9757d09d3e94e836cee72d3c08e66"
"sha256": "717c588d32f74f1d2b4ce9e3201fd2a46bc4fed3aa79810a81b3f1ed456c2f08"
},
"nbns-advertiser-netbsd4le": {
"path": "bin/nbns-netbsd4le/nbns-advertiser",
"sha256": "ffd0908e2803dd254e16ef9379000221037668be5735c86656c258ff44810d02"
"sha256": "f261078b379b898468b56988047a92f7181444582c0aa99c91a8fb8970046194"
},
"nbns-advertiser-netbsd4be": {
"path": "bin/nbns-netbsd4be/nbns-advertiser",
"sha256": "1c58af90353388535d9497573fa5151226ed0ed094a0f4b36788607b2c4b3078"
"sha256": "366169b448badfea93f150d4fa707e97e0fb7afee4eec8d341785a606406e29a"
},
"smbd": {
"path": "bin/samba4/smbd",
Expand Down
104 changes: 90 additions & 14 deletions src/timecapsulesmb/assets/boot/samba4/common.d/45-network-bind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,37 @@ tc_smb_bind_token_is_ipv4_cidr() {
return 0
}

tc_normalize_smb_bind_cidrs() {
cidrs=$1
tc_smb_bind_token_is_ipv6_cidr() {
token=$1

case "$token" in
""|/*|*/|*/*/*|*[!0123456789abcdefABCDEF:./]*) return 1 ;;
*:*) ;;
*) return 1 ;;
esac

prefix_part=${token#*/}
case "$prefix_part" in
""|*[!0123456789]*) return 1 ;;
esac
[ "$prefix_part" -le 128 ] 2>/dev/null || return 1

return 0
}

tc_smb_bind_token_is_cidr() {
tc_smb_bind_token_is_ipv4_cidr "$1" || tc_smb_bind_token_is_ipv6_cidr "$1"
}

tc_normalize_smb_bind_tokens() {
bind_tokens=$1
normalized=

set -- $cidrs
set -- $bind_tokens
[ "$#" -gt 0 ] || return 1

for cidr_token in "$@"; do
tc_smb_bind_token_is_ipv4_cidr "$cidr_token" || return 1
tc_smb_bind_token_is_cidr "$cidr_token" || return 1
if [ -n "$normalized" ]; then
normalized="$normalized $cidr_token"
else
Expand All @@ -47,15 +69,69 @@ tc_normalize_smb_bind_cidrs() {
printf '%s\n' "$normalized"
}

tc_normalize_smb_bind_cidrs() {
tc_normalize_smb_bind_tokens "$1"
}

tc_normalize_mdns_socket_families() {
families=$1
saw_ipv4=0
saw_ipv6=0
normalized=

set -- $families
[ "$#" -gt 0 ] || return 1

for family_token in "$@"; do
case "$family_token" in
ipv4)
[ "$saw_ipv4" = "0" ] || return 1
saw_ipv4=1
;;
ipv6)
[ "$saw_ipv6" = "0" ] || return 1
saw_ipv6=1
;;
*) return 1 ;;
esac
done

if [ "$saw_ipv4" = "1" ]; then
normalized=ipv4
fi
if [ "$saw_ipv6" = "1" ]; then
if [ -n "$normalized" ]; then
normalized="$normalized ipv6"
else
normalized=ipv6
fi
fi

[ -n "$normalized" ] || return 1
printf '%s\n' "$normalized"
}

tc_probe_auto_ip_cidrs() {
[ -x "$TC_MDNS_BIN" ] || return 1
cidrs=$("$TC_MDNS_BIN" --print-auto-ip-cidrs 2>/dev/null) || return $?
tc_normalize_smb_bind_cidrs "$cidrs" || return 1
}

tc_probe_smb_bind_tokens() {
[ -x "$TC_MDNS_BIN" ] || return 1
bind_tokens=$("$TC_MDNS_BIN" --print-smb-bind-interfaces 2>/dev/null) || return $?
tc_normalize_smb_bind_tokens "$bind_tokens" || return 1
}

tc_probe_mdns_socket_families() {
[ -x "$TC_MDNS_BIN" ] || return 1
families=$("$TC_MDNS_BIN" --print-mdns-socket-families 2>/dev/null) || return $?
tc_normalize_mdns_socket_families "$families" || return 1
}

tc_probe_smb_bind_interfaces() {
cidrs=$(tc_probe_auto_ip_cidrs) || return $?
printf '127.0.0.1/8 %s\n' "$cidrs"
bind_tokens=$(tc_probe_smb_bind_tokens) || return $?
printf '127.0.0.1/8 ::1/128 %s\n' "$bind_tokens"
}

tc_auto_ip_unavailable_status() {
Expand All @@ -65,27 +141,27 @@ tc_auto_ip_unavailable_status() {
tc_mark_smb_deferred_no_ip() {
TC_WATCHDOG_SMB_DEFERRED_NO_IP=1
if [ "${TC_SMB_IPV4_WAIT_LOGGED:-0}" != "1" ]; then
tc_log "Samba IPv4 bind discovery deferred; no usable IPv4 has appeared yet"
tc_log "Samba bind discovery deferred; no usable address has appeared yet"
TC_SMB_IPV4_WAIT_LOGGED=1
fi
}

tc_wait_for_smb_ipv4() {
if [ ! -x "$TC_MDNS_BIN" ]; then
tc_log "Samba IPv4 bind discovery failed; missing $TC_MDNS_BIN"
tc_log "Samba bind discovery failed; missing $TC_MDNS_BIN"
return 1
fi

while :; do
if cidrs=$(tc_probe_auto_ip_cidrs); then
tc_log "Samba IPv4 bind discovery: first usable IPv4 observed: $cidrs"
if bind_tokens=$(tc_probe_smb_bind_tokens); then
tc_log "Samba bind discovery: first usable address observed: $bind_tokens"
return 0
else
probe_status=$?
fi

if ! tc_auto_ip_unavailable_status "$probe_status"; then
tc_log "Samba IPv4 bind discovery failed with exit code $probe_status"
tc_log "Samba bind discovery failed with exit code $probe_status"
return 1
fi

Expand All @@ -98,7 +174,7 @@ tc_refresh_smb_bind_interfaces() {
if bind_interfaces=$(tc_probe_smb_bind_interfaces); then
TC_SMB_BIND_INTERFACES=$bind_interfaces
TC_WATCHDOG_SMB_DEFERRED_NO_IP=0
tc_log "Samba IPv4 bind interfaces: $TC_SMB_BIND_INTERFACES"
tc_log "Samba bind interfaces: $TC_SMB_BIND_INTERFACES"
return 0
else
probe_status=$?
Expand All @@ -107,14 +183,14 @@ tc_refresh_smb_bind_interfaces() {
if tc_auto_ip_unavailable_status "$probe_status"; then
tc_mark_smb_deferred_no_ip
else
tc_log "Samba IPv4 bind interface probe failed with exit code $probe_status"
tc_log "Samba bind interface probe failed with exit code $probe_status"
fi
return 1
}

tc_prepare_smb_bind_context() {
tc_wait_for_smb_ipv4 || return 1
tc_log "Samba IPv4 bind discovery: waiting ${TC_SMB_IPV4_SETTLE_SECONDS}s for network stabilization"
tc_log "Samba bind discovery: waiting ${TC_SMB_IPV4_SETTLE_SECONDS}s for network stabilization"
sleep "$TC_SMB_IPV4_SETTLE_SECONDS"
tc_refresh_smb_bind_interfaces
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ tc_stage_disk_runtime() {
tc_stage_runtime "$TC_PAYLOAD_DIR" "$SMBD_SRC" "$NBNS_SRC"
if [ -z "$TC_SMB_BIND_INTERFACES" ]; then
tc_refresh_smb_bind_interfaces || {
tc_log "runtime staging failed: no usable IPv4 bind interface is available"
tc_log "runtime staging failed: no usable bind address is available"
return 1
}
fi
Expand Down Expand Up @@ -293,7 +293,7 @@ tc_generate_smb_conf() {
netbios name = $SMB_NETBIOS_NAME
workgroup = WORKGROUP
# Samba's interface enumeration can race boot networking on Time Capsule.
# Bind to the IPv4 CIDRs discovered immediately before rendering config.
# Bind to explicit IPv4/IPv6 CIDRs discovered immediately before rendering config.
interfaces = $TC_SMB_BIND_INTERFACES
bind interfaces only = yes
server string = $SMB_SERVER_STRING
Expand Down
12 changes: 8 additions & 4 deletions src/timecapsulesmb/assets/boot/samba4/common.d/60-advertisers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,17 @@ tc_run_mdns_snapshot_command() {
}

tc_mdns_auto_ip_available() {
tc_probe_mdns_socket_families >/dev/null 2>&1
}

tc_nbns_auto_ip_available() {
tc_probe_auto_ip_cidrs >/dev/null 2>&1
}

tc_mark_mdns_deferred_no_ip() {
TC_WATCHDOG_MDNS_DEFERRED_NO_IP=1
if [ "$TC_MDNS_AUTO_IP_WAIT_LOGGED" != "1" ]; then
tc_log "mDNS startup deferred; no usable IPv4 has appeared yet"
tc_log "mDNS startup deferred; no usable address has appeared yet"
TC_MDNS_AUTO_IP_WAIT_LOGGED=1
fi
}
Expand All @@ -251,18 +255,18 @@ tc_ensure_mdns_auto_ip_seen() {
return 1
fi

tc_log "mDNS auto-ip check: running $TC_MDNS_BIN --print-auto-ip-cidrs"
tc_log "mDNS auto-ip check: running $TC_MDNS_BIN --print-mdns-socket-families"
if tc_mdns_auto_ip_available; then
TC_MDNS_AUTO_IP_SEEN=1
tc_log "mDNS auto-ip check: usable IPv4 is available"
tc_log "mDNS auto-ip check: usable address is available"
tc_log "mDNS auto-ip is available; starting capture and advertiser"
return 0
else
mdns_auto_ip_status=$?
fi

if tc_auto_ip_unavailable_status "$mdns_auto_ip_status"; then
tc_log "mDNS auto-ip check: no usable IPv4 yet"
tc_log "mDNS auto-ip check: no usable address yet"
tc_mark_mdns_deferred_no_ip
else
TC_WATCHDOG_MDNS_UNAVAILABLE=1
Expand Down
Loading
Loading