@@ -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+
50114tc_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+
56132tc_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
61137tc_auto_ip_unavailable_status () {
@@ -65,27 +141,27 @@ tc_auto_ip_unavailable_status() {
65141tc_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
73149tc_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
115191tc_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