@@ -514,6 +514,43 @@ conf_append_bind()
514514 done
515515}
516516
517+ conf_append_bind_interface ()
518+ {
519+ local bind_type=" $1 "
520+ local port=" $2 "
521+ local interfaces=" $3 "
522+ local ipv6_server=" $4 "
523+ local ARGS=" $5 "
524+ local intf=" "
525+
526+ . /lib/functions/network.sh
527+
528+ for intf in ${interfaces} ; do
529+ local __device
530+ local __addrs
531+ network_get_device __device $intf
532+ [ -z " $__device " ] && continue
533+
534+ if [ " $ipv6_server " = " 1" ]; then
535+ local __addr
536+ __addr=$( ifconfig " $__device " | grep ' Scope:Link' \
537+ | sed ' s:.*\(fe[8ab].*\)/.*:\1:' )
538+
539+ conf_append " $bind_type " " [${__addr} ]:${port} @${__device} $ARGS "
540+
541+ network_get_ipaddrs6 __addrs " $intf "
542+ for __addr in ${__addrs} ; do
543+ conf_append " $bind_type " " [${__addr} ]:${port} @${__device} $ARGS "
544+ done
545+ fi
546+
547+ network_get_ipaddrs __addrs " $intf "
548+ for __addr in ${__addrs} ; do
549+ conf_append " $bind_type " " [${__addr} ]:${port} @${__device} $ARGS "
550+ done
551+ done
552+ }
553+
517554load_second_server ()
518555{
519556 local section=" $1 "
@@ -739,6 +776,7 @@ load_service()
739776
740777 config_get_bool bind_device " $section " " bind_device" " 0"
741778 config_get bind_device_name " $section " " bind_device_name" " ${lan_device} "
779+ config_get bind_interfaces " $section " " bind_interface" " "
742780 [ ! -z " $bind_device_name " ] && [ " $bind_device " = " 1" ] && device=" ${bind_device_name} "
743781
744782 config_get cache_file " $section " " cache_file" " $SMARTDNS_CONF_DIR /smartdns.cache"
@@ -829,10 +867,18 @@ load_service()
829867 [ " $auto_set_dnsmasq " = " 0" ] && [ " $old_auto_set_dnsmasq " = " 1" ] && stop_forward_dnsmasq " $old_port " " 0"
830868 }
831869
832- conf_append_bind " bind" " $port " " $device " " $ipv6_server " " $server_flags "
833- [ " $tcp_server " = " 1" ] && conf_append_bind " bind-tcp" " $port " " $device " " $ipv6_server " " $server_flags "
834- [ " $tls_server " = " 1" ] && conf_append_bind " bind-tls" " $tls_server_port " " $device " " $ipv6_server " " $server_flags "
835- [ " $doh_server " = " 1" ] && conf_append_bind " bind-https" " $doh_server_port " " $device " " $ipv6_server " " $server_flags "
870+ local __conf_bin_func
871+ if [ ! -z $bind_interfaces ]; then
872+ __conf_bin_func=" conf_append_bind_interface"
873+ device=${bind_interfaces}
874+ else
875+ __conf_bin_func=" conf_append_bind"
876+ fi
877+
878+ $__conf_bin_func " bind" " $port " " $device " " $ipv6_server " " $server_flags "
879+ [ " $tcp_server " = " 1" ] && $__conf_bin_func " bind-tcp" " $port " " $device " " $ipv6_server " " $server_flags "
880+ [ " $tls_server " = " 1" ] && $__conf_bin_func " bind-tls" " $tls_server_port " " $device " " $ipv6_server " " $server_flags "
881+ [ " $doh_server " = " 1" ] && $__conf_bin_func " bind-https" " $doh_server_port " " $device " " $ipv6_server " " $server_flags "
836882
837883 [ ! -z " $bind_cert " ] && conf_append " bind-cert-file" " $bind_cert "
838884 [ ! -z " $bind_cert_key " ] && conf_append " bind-cert-key-file" " $bind_cert_key "
0 commit comments