mirror of
https://github.com/openwrt/openwrt.git
synced 2025-03-12 07:24:22 +00:00
dropbear: ensure the interface has an ip-address
Use network_get_ipaddrs_all to get all ip-addresses of an interface. If the function fails, the interface does not exists or has not any suiteable ip addresses assigned. Use the returned ip-address(es) to construct the dropbear listen address. Signed-off-by: Mathias Kresin <openwrt@kresin.me> SVN-Revision: 42857
This commit is contained in:
parent
14e6559eee
commit
b2d099c11c
@ -14,20 +14,15 @@ EXTRA_HELP=" killclients Kill ${NAME} processes except servers and yourself"
|
|||||||
|
|
||||||
append_ports()
|
append_ports()
|
||||||
{
|
{
|
||||||
local ifname="$1"
|
local ipaddrs="$1"
|
||||||
local port="$2"
|
local port="$2"
|
||||||
|
|
||||||
grep -qs "^ *$ifname:" /proc/net/dev || {
|
[ -z "$ipaddrs" ] && {
|
||||||
procd_append_param command -p "$port"
|
procd_append_param command -p "$port"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
for addr in $(
|
for addr in $ipaddrs; do
|
||||||
ifconfig "$ifname" | sed -ne '
|
|
||||||
/addr: *fe[89ab][0-9a-f]:/d
|
|
||||||
s/.* addr: *\([0-9a-f:\.]*\).*/\1/p
|
|
||||||
'
|
|
||||||
); do
|
|
||||||
procd_append_param command -p "$addr:$port"
|
procd_append_param command -p "$addr:$port"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -55,13 +50,20 @@ dropbear_instance()
|
|||||||
local PasswordAuth enable Interface GatewayPorts \
|
local PasswordAuth enable Interface GatewayPorts \
|
||||||
RootPasswordAuth RootLogin rsakeyfile \
|
RootPasswordAuth RootLogin rsakeyfile \
|
||||||
dsskeyfile BannerFile Port SSHKeepAlive IdleTimeout \
|
dsskeyfile BannerFile Port SSHKeepAlive IdleTimeout \
|
||||||
mdns
|
mdns ipaddrs
|
||||||
|
|
||||||
validate_section_dropbear "${1}" || {
|
validate_section_dropbear "${1}" || {
|
||||||
echo "validation failed"
|
echo "validation failed"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[ -n "${Interface}" ] && {
|
||||||
|
network_get_ipaddrs_all ipaddrs "${Interface}" || {
|
||||||
|
echo "interface ${Interface} has no physdev or physdev has no suitable ip"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
[ "${enable}" = "0" ] && return 1
|
[ "${enable}" = "0" ] && return 1
|
||||||
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
|
PIDCOUNT="$(( ${PIDCOUNT} + 1))"
|
||||||
local pid_file="/var/run/${NAME}.${PIDCOUNT}.pid"
|
local pid_file="/var/run/${NAME}.${PIDCOUNT}.pid"
|
||||||
@ -75,8 +77,7 @@ dropbear_instance()
|
|||||||
[ -n "${rsakeyfile}" ] && procd_append_param command -r "${rsakeyfile}"
|
[ -n "${rsakeyfile}" ] && procd_append_param command -r "${rsakeyfile}"
|
||||||
[ -n "${dsskeyfile}" ] && procd_append_param command -d "${dsskeyfile}"
|
[ -n "${dsskeyfile}" ] && procd_append_param command -d "${dsskeyfile}"
|
||||||
[ -n "${BannerFile}" ] && procd_append_param command -b "${BannerFile}"
|
[ -n "${BannerFile}" ] && procd_append_param command -b "${BannerFile}"
|
||||||
[ -n "${Interface}" ] && network_get_device Interface "${Interface}"
|
append_ports "${ipaddrs}" "${Port}"
|
||||||
append_ports "${Interface}" "${Port}"
|
|
||||||
[ "${IdleTimeout}" -ne 0 ] && procd_append_param command -I "${IdleTimeout}"
|
[ "${IdleTimeout}" -ne 0 ] && procd_append_param command -I "${IdleTimeout}"
|
||||||
[ "${SSHKeepAlive}" -ne 0 ] && procd_append_param command -K "${SSHKeepAlive}"
|
[ "${SSHKeepAlive}" -ne 0 ] && procd_append_param command -K "${SSHKeepAlive}"
|
||||||
[ "${mdns}" -ne 0 ] && procd_add_mdns "ssh" "tcp" "$Port" "daemon=dropbear"
|
[ "${mdns}" -ne 0 ] && procd_add_mdns "ssh" "tcp" "$Port" "daemon=dropbear"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user