Skip to content

Commit 9e63cd4

Browse files
authored
Add dual-stack mDNS and Samba link handling
* Add dual-stack mDNS and Samba link handling Inventory IPv4 and IPv6 links for Samba and mDNS, keeping Samba bind tokens explicit while preserving IPv4 link-local support. Add UDP6 mDNS participation with per-link ff02::fb joins, scoped IPv6 sends, and link-valid A/AAAA advertising. Update watchdog, doctor probes, tests, manifests, and rebuilt NetBSD mdns/nbns artifacts. * Fix NetBSD interface inventory parsing Parse SIOCGIFCONF entries through a checked raw sockaddr view so NetBSD 4 IPv6 addresses are not truncated or overread. Use explicit IPv6 netmask ioctls, keep unknown prefixes out of Samba/AAAA output, normalize IPv4 link-local masks, and share fstat socket checks. Rebuild mdns/nbns artifacts and extend tests for raw ifconf entries, invalid masks, and socket scanning. * Harden mdns runtime link handling Fix Ubuntu CI portability by marking BSD-only ifreq parameters as intentionally unused on platforms that do not expose sockaddr lengths. Improve mdns-advertiser's runtime socket update path with rollback for partial multicast joins, IPv4 fallback when IPv6 transport setup fails, capacity truncation reporting, bounded stack-only log truncation, and known-answer suppression that does not hide other link-valid A/AAAA records. Rebuild mdns and nbns NetBSD artifacts and refresh the artifact manifest. * Refactor mDNS response planning and harden link handling Plan mDNS responses from the active link inventory before applying known-answer suppression and packet writing. Keep broken per-link socket failures scoped to that link/family, preserve IPv4-only watchdog checks, and rebuild the affected NetBSD artifacts. * Improve mDNS query response behavior Handle service type enumeration, ANY-class questions, legacy unicast question sections, multicast response delays, and unicast hop limits in the planned RRset response path. Rebuild the NetBSD 6 and NetBSD 4 mDNS artifacts and expand tests for mDNS query routing, service enumeration, startup spacing, socket options, and NBSTAT response shape. * Prefer IPv4 mDNS health checks while accepting IPv6-only listeners
1 parent 5ef7cac commit 9e63cd4

23 files changed

Lines changed: 6775 additions & 1154 deletions

bin/mdns-netbsd4be/mdns-advertiser

20.4 KB
Binary file not shown.

bin/mdns-netbsd4le/mdns-advertiser

20.6 KB
Binary file not shown.

bin/mdns/mdns-advertiser

19.9 KB
Binary file not shown.

bin/nbns-netbsd4be/nbns-advertiser

136 Bytes
Binary file not shown.

bin/nbns-netbsd4le/nbns-advertiser

188 Bytes
Binary file not shown.

bin/nbns/nbns-advertiser

280 Bytes
Binary file not shown.

build/auto-ip-common.inc

Lines changed: 848 additions & 37 deletions
Large diffs are not rendered by default.

build/mdns-advertiser.c

Lines changed: 3283 additions & 790 deletions
Large diffs are not rendered by default.

src/timecapsulesmb/assets/artifact-manifest.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@
22
"artifacts": {
33
"mdns-advertiser": {
44
"path": "bin/mdns/mdns-advertiser",
5-
"sha256": "82245f3a581d196c9cad98d076d29769c0cf0dc4052681ddd8b4a050be0b0722"
5+
"sha256": "1a072c376e56e43ec03c8a9158926dfd6c7a6486c4ebf23e30978e293f0629fb"
66
},
77
"mdns-advertiser-netbsd4le": {
88
"path": "bin/mdns-netbsd4le/mdns-advertiser",
9-
"sha256": "9e63f0a4c2c483fd4c3b6727cd2005f363abe734c74ab14f1185c32d01823016"
9+
"sha256": "8dfb9461c57f8a45a531bd4b822e602e49b7d017adb2877cd04915d81a08d3f1"
1010
},
1111
"mdns-advertiser-netbsd4be": {
1212
"path": "bin/mdns-netbsd4be/mdns-advertiser",
13-
"sha256": "bdd638d4cca35d95307e4d93feba4ced1300fde4d96406e38d99f9747f00723d"
13+
"sha256": "390a00fdc40b49e4c5698f942aa7e83a66bfd0821bd47e982a40945c1fed51cf"
1414
},
1515
"nbns-advertiser": {
1616
"path": "bin/nbns/nbns-advertiser",
17-
"sha256": "5dd1b7df3dedcbc5dd6e6d2575a3c141cad9757d09d3e94e836cee72d3c08e66"
17+
"sha256": "717c588d32f74f1d2b4ce9e3201fd2a46bc4fed3aa79810a81b3f1ed456c2f08"
1818
},
1919
"nbns-advertiser-netbsd4le": {
2020
"path": "bin/nbns-netbsd4le/nbns-advertiser",
21-
"sha256": "ffd0908e2803dd254e16ef9379000221037668be5735c86656c258ff44810d02"
21+
"sha256": "f261078b379b898468b56988047a92f7181444582c0aa99c91a8fb8970046194"
2222
},
2323
"nbns-advertiser-netbsd4be": {
2424
"path": "bin/nbns-netbsd4be/nbns-advertiser",
25-
"sha256": "1c58af90353388535d9497573fa5151226ed0ed094a0f4b36788607b2c4b3078"
25+
"sha256": "366169b448badfea93f150d4fa707e97e0fb7afee4eec8d341785a606406e29a"
2626
},
2727
"smbd": {
2828
"path": "bin/samba4/smbd",

src/timecapsulesmb/assets/boot/samba4/common.d/45-network-bind.sh

Lines changed: 90 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,37 @@ tc_smb_bind_token_is_ipv4_cidr() {
2828
return 0
2929
}
3030

31-
tc_normalize_smb_bind_cidrs() {
32-
cidrs=$1
31+
tc_smb_bind_token_is_ipv6_cidr() {
32+
token=$1
33+
34+
case "$token" in
35+
""|/*|*/|*/*/*|*[!0123456789abcdefABCDEF:./]*) return 1 ;;
36+
*:*) ;;
37+
*) return 1 ;;
38+
esac
39+
40+
prefix_part=${token#*/}
41+
case "$prefix_part" in
42+
""|*[!0123456789]*) return 1 ;;
43+
esac
44+
[ "$prefix_part" -le 128 ] 2>/dev/null || return 1
45+
46+
return 0
47+
}
48+
49+
tc_smb_bind_token_is_cidr() {
50+
tc_smb_bind_token_is_ipv4_cidr "$1" || tc_smb_bind_token_is_ipv6_cidr "$1"
51+
}
52+
53+
tc_normalize_smb_bind_tokens() {
54+
bind_tokens=$1
3355
normalized=
3456

35-
set -- $cidrs
57+
set -- $bind_tokens
3658
[ "$#" -gt 0 ] || return 1
3759

3860
for cidr_token in "$@"; do
39-
tc_smb_bind_token_is_ipv4_cidr "$cidr_token" || return 1
61+
tc_smb_bind_token_is_cidr "$cidr_token" || return 1
4062
if [ -n "$normalized" ]; then
4163
normalized="$normalized $cidr_token"
4264
else
@@ -47,15 +69,69 @@ tc_normalize_smb_bind_cidrs() {
4769
printf '%s\n' "$normalized"
4870
}
4971

72+
tc_normalize_smb_bind_cidrs() {
73+
tc_normalize_smb_bind_tokens "$1"
74+
}
75+
76+
tc_normalize_mdns_socket_families() {
77+
families=$1
78+
saw_ipv4=0
79+
saw_ipv6=0
80+
normalized=
81+
82+
set -- $families
83+
[ "$#" -gt 0 ] || return 1
84+
85+
for family_token in "$@"; do
86+
case "$family_token" in
87+
ipv4)
88+
[ "$saw_ipv4" = "0" ] || return 1
89+
saw_ipv4=1
90+
;;
91+
ipv6)
92+
[ "$saw_ipv6" = "0" ] || return 1
93+
saw_ipv6=1
94+
;;
95+
*) return 1 ;;
96+
esac
97+
done
98+
99+
if [ "$saw_ipv4" = "1" ]; then
100+
normalized=ipv4
101+
fi
102+
if [ "$saw_ipv6" = "1" ]; then
103+
if [ -n "$normalized" ]; then
104+
normalized="$normalized ipv6"
105+
else
106+
normalized=ipv6
107+
fi
108+
fi
109+
110+
[ -n "$normalized" ] || return 1
111+
printf '%s\n' "$normalized"
112+
}
113+
50114
tc_probe_auto_ip_cidrs() {
51115
[ -x "$TC_MDNS_BIN" ] || return 1
52116
cidrs=$("$TC_MDNS_BIN" --print-auto-ip-cidrs 2>/dev/null) || return $?
53117
tc_normalize_smb_bind_cidrs "$cidrs" || return 1
54118
}
55119

120+
tc_probe_smb_bind_tokens() {
121+
[ -x "$TC_MDNS_BIN" ] || return 1
122+
bind_tokens=$("$TC_MDNS_BIN" --print-smb-bind-interfaces 2>/dev/null) || return $?
123+
tc_normalize_smb_bind_tokens "$bind_tokens" || return 1
124+
}
125+
126+
tc_probe_mdns_socket_families() {
127+
[ -x "$TC_MDNS_BIN" ] || return 1
128+
families=$("$TC_MDNS_BIN" --print-mdns-socket-families 2>/dev/null) || return $?
129+
tc_normalize_mdns_socket_families "$families" || return 1
130+
}
131+
56132
tc_probe_smb_bind_interfaces() {
57-
cidrs=$(tc_probe_auto_ip_cidrs) || return $?
58-
printf '127.0.0.1/8 %s\n' "$cidrs"
133+
bind_tokens=$(tc_probe_smb_bind_tokens) || return $?
134+
printf '127.0.0.1/8 ::1/128 %s\n' "$bind_tokens"
59135
}
60136

61137
tc_auto_ip_unavailable_status() {
@@ -65,27 +141,27 @@ tc_auto_ip_unavailable_status() {
65141
tc_mark_smb_deferred_no_ip() {
66142
TC_WATCHDOG_SMB_DEFERRED_NO_IP=1
67143
if [ "${TC_SMB_IPV4_WAIT_LOGGED:-0}" != "1" ]; then
68-
tc_log "Samba IPv4 bind discovery deferred; no usable IPv4 has appeared yet"
144+
tc_log "Samba bind discovery deferred; no usable address has appeared yet"
69145
TC_SMB_IPV4_WAIT_LOGGED=1
70146
fi
71147
}
72148

73149
tc_wait_for_smb_ipv4() {
74150
if [ ! -x "$TC_MDNS_BIN" ]; then
75-
tc_log "Samba IPv4 bind discovery failed; missing $TC_MDNS_BIN"
151+
tc_log "Samba bind discovery failed; missing $TC_MDNS_BIN"
76152
return 1
77153
fi
78154

79155
while :; do
80-
if cidrs=$(tc_probe_auto_ip_cidrs); then
81-
tc_log "Samba IPv4 bind discovery: first usable IPv4 observed: $cidrs"
156+
if bind_tokens=$(tc_probe_smb_bind_tokens); then
157+
tc_log "Samba bind discovery: first usable address observed: $bind_tokens"
82158
return 0
83159
else
84160
probe_status=$?
85161
fi
86162

87163
if ! tc_auto_ip_unavailable_status "$probe_status"; then
88-
tc_log "Samba IPv4 bind discovery failed with exit code $probe_status"
164+
tc_log "Samba bind discovery failed with exit code $probe_status"
89165
return 1
90166
fi
91167

@@ -98,7 +174,7 @@ tc_refresh_smb_bind_interfaces() {
98174
if bind_interfaces=$(tc_probe_smb_bind_interfaces); then
99175
TC_SMB_BIND_INTERFACES=$bind_interfaces
100176
TC_WATCHDOG_SMB_DEFERRED_NO_IP=0
101-
tc_log "Samba IPv4 bind interfaces: $TC_SMB_BIND_INTERFACES"
177+
tc_log "Samba bind interfaces: $TC_SMB_BIND_INTERFACES"
102178
return 0
103179
else
104180
probe_status=$?
@@ -107,14 +183,14 @@ tc_refresh_smb_bind_interfaces() {
107183
if tc_auto_ip_unavailable_status "$probe_status"; then
108184
tc_mark_smb_deferred_no_ip
109185
else
110-
tc_log "Samba IPv4 bind interface probe failed with exit code $probe_status"
186+
tc_log "Samba bind interface probe failed with exit code $probe_status"
111187
fi
112188
return 1
113189
}
114190

115191
tc_prepare_smb_bind_context() {
116192
tc_wait_for_smb_ipv4 || return 1
117-
tc_log "Samba IPv4 bind discovery: waiting ${TC_SMB_IPV4_SETTLE_SECONDS}s for network stabilization"
193+
tc_log "Samba bind discovery: waiting ${TC_SMB_IPV4_SETTLE_SECONDS}s for network stabilization"
118194
sleep "$TC_SMB_IPV4_SETTLE_SECONDS"
119195
tc_refresh_smb_bind_interfaces
120196
}

0 commit comments

Comments
 (0)