Commit 5cd57a3e authored by Omar Kallel's avatar Omar Kallel
Browse files

Ticket refs #5876: icwmp: Init scripts enhancements and cleanup

parent 56a6cbf0
#
# Copyright (C) 2020 iopsys Software Solutions AB
# Copyright (C) 2021 Iopsys Software Solutions AB
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
......@@ -8,11 +8,11 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=icwmp
PKG_VERSION:=8.2.3-2021-10-13
PKG_VERSION:=8.2.4-2021-10-13
PKG_FIXUP:=autoreconf
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/icwmp.git
PKG_SOURCE_PROTO:=git
PKG_SOURCE_VERSION:=ecb82332ce36b54ce5376bb9ffda16c04c30a8e3
PKG_SOURCE_VERSION:=45c842f7aa2ef3719b8700e8d4bd3b973b80117c
PKG_RELEASE=$(PKG_SOURCE_VERSION)
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
......
......@@ -10,6 +10,7 @@ STOP=10
USE_PROCD=1
PROG="/usr/sbin/icwmpd"
KEEP_PATH="/lib/upgrade/keep.d/icwmp"
EXTRA_HELP=" start [GetRPCMethods] Start icwmpd service and send GetRPCMethods"
......@@ -59,43 +60,29 @@ get_acs_url() {
enable_dhcp_option43() {
local wan=$1
local discovery=0
case $2 in
enable|1) discovery=1 ;;
esac
### Ask for DHCP Option 43 only if CWMP is enabled ###
local enabled
local newreqopts=
local baseopts=
local reqopts="$(uci -q get network.$wan.reqopts)"
local proto="$(uci -q get network.$wan.proto)"
local tropts="43"
local oldreqopts="$reqopts"
local ropt iopt
for ropt in $reqopts; do
case $ropt in
43) ;;
*) baseopts="$baseopts $ropt" ;;
esac
done
ropt=""
reqopts="$baseopts $tropts"
local newreqopts=""
local option43_present=0
for ropt in $reqopts; do
case $ropt in
43) [ $discovery -eq 1 ] && newreqopts="$newreqopts $ropt" ;;
*) newreqopts="$newreqopts $ropt" ;;
43) option43_present=1 ;;
*) ;;
esac
done
if [ ${option43_present} -eq 1 ]; then
return;
fi
newreqopts="$reqopts 43"
if [ $proto == "dhcp" ]; then
newreqopts="$(echo $newreqopts | tr ' ' '\n' | sort -n | tr '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')"
oldreqopts="$(echo $oldreqopts | tr ' ' '\n' | sort -n | tr '\n' ' ' | sed 's/^[ \t]*//;s/[ \t]*$//')"
[ "$newreqopts" == "$oldreqopts" ] && return
uci -q set network.$wan.reqopts="$newreqopts"
uci commit network
ubus call network reload
ubus call uci commit '{"config":"network"}'
fi
########################################################
}
wait_for_option43() {
......@@ -143,9 +130,7 @@ wait_for_resolvfile() {
set_wan_interface() {
local l3_device=""
local default_wan_interface=""
config_get default_wan_interface cpe default_wan_interface "wan"
json_load "$(ifstatus $default_wan_interface)"
json_get_var l3_device l3_device
if [ "$l3_device" != "" ];then
......@@ -154,42 +139,135 @@ set_wan_interface() {
fi
}
service_running() {
ubus wait_for usp.raw
validate_acs_section()
{
uci_validate_section cwmp acs "acs" \
'passwd:string' \
'periodic_inform_enable:bool' \
'periodic_inform_interval:uinteger' \
'periodic_inform_time:string' \
'url:string' \
'dhcp_discovery:or("enable","disable")' \
'compression:or("GZIP","Deflate","Disabled")' \
'retry_min_wait_interval:range(1, 65535)' \
'retry_interval_multiplier:range(1000, 65535)' \
'https_ssl_capath:file' \
'ipv6_enable:bool'
}
start_service() {
if [ ! -f /tmp/.icwmpd_boot ]; then
touch /etc/icwmpd/.icwmpd_boot
touch /tmp/.icwmpd_boot
else
[ -f /sbin/netifd ] && log "Waiting for Network to be started ..." && ubus -t 5 wait_for network.interface
[ -f /etc/config/wireless ] && log "Waiting for WiFi to be started ..." && ubus -t 5 wait_for network.wireless
[ -f /usr/sbin/dnsmasq ] && log "Waiting for DNS Proxy to be started ..." && ubus -t 5 wait_for dnsmasq
[ -f /etc/config/dhcp ] && log "Waiting for DNS Server(s) ..." && wait_for_resolvfile 20
[ -f /usr/sbin/asterisk ] && log "Waiting for Voice to be started ..." && ubus -t 5 wait_for asterisk
log "Waiting for usp.raw to be started"
ubus wait_for usp.raw
config_load cwmp
set_wan_interface
wait_for_option43 20
get_acs_url
procd_open_instance icwmp
procd_set_param command "$PROG"
if [ "$1" = "GetRPCMethods" ];then
procd_append_param command -g
elif [ -f /etc/icwmpd/.icwmpd_boot ]; then
procd_append_param command -b
validate_cpe_section()
{
uci_validate_section cwmp cpe "cpe" \
'interface:string' \
'default_wan_interface:string:wan' \
'log_to_console:or("enable","disable")' \
'log_to_file:or("enable","disable")' \
'log_severity:or("EMERG", "ALERT", "CRITIC" ,"ERROR", "WARNING", "NOTICE", "INFO", "DEBUG")' \
'log_max_size:uinteger' \
'userid:string' \
'passwd:string' \
'port:uinteger' \
'provisioning_code:string:""' \
'amd_version:range(1, 6)' \
'instance_mode:or("InstanceNumber","InstanceAlias")' \
'session_timeout:uinteger' \
'notification:bool' \
'exec_download:bool' \
'periodic_notify_enable:bool' \
'periodic_notify_interval:uinteger'
}
regenerate_ssl_link(){
local cert_dir="/etc/ssl/certs"
for cfile in `ls -1 ${cert_dir}/*.pem 2>/dev/null`
do
local hash=$(openssl x509 -hash -noout -in $cfile)
if [ ! -f "${hash}.0" ]; then
ln -s $cfile $cert_dir/${hash}.0
fi
procd_set_param respawn \
${respawn_threshold:-5} \
${respawn_timeout:-10} ${respawn_retry:-3}
done
}
validate_defaults() {
config_load cwmp
validate_acs_section || {
log "Validation of acs section failed"
return 1;
}
procd_close_instance
validate_cpe_section || {
log "Validation of cpe section failed"
return 1;
}
dhcp_url=`uci -c /var/state get cwmp.acs.url`
[ -z "${url}" -a -z "${dhcp_url}"] && {
log "ACS url is empty"
return 1;
}
[ -z "${default_wan_interface}" ] && {
log "Wan interface is empty"
return 1;
}
return 0;
}
update_keeps() {
local keep=${1}
# Add entry to keep if not present already
[ ! -f "${KEEP_PATH}" ] && {
echo ${keep} > ${KEEP_PATH}
return 0;
}
grep -q "${keep}" ${KEEP_PATH} || {
echo ${keep} >> ${KEEP_PATH}
}
}
boot()
{
regenerate_ssl_link
#update_keeps "/etc/icwmpd/.icwmpd_backup_session.xml"
start
}
start_service() {
config_load cwmp
set_wan_interface
wait_for_option43 20
get_acs_url
validate_defaults || {
log "Validation of defaults failed"
return 1;
}
# Set wan interface if not configured
set_wan_interface
# Set dhcp option 43 if dhcp discovery enabled
if [ "${dhcp_discovery}" == "enable" -o "${dhcp_discovery}" == "1" ]; then
enable_dhcp_option43 $default_wan_interface
fi
procd_open_instance icwmp
procd_set_param command "$PROG"
procd_append_param command -b
procd_set_param respawn \
${respawn_threshold:-5} \
${respawn_timeout:-10} ${respawn_retry:-3}
procd_close_instance
}
reload_service() {
......@@ -198,6 +276,6 @@ reload_service() {
}
service_triggers() {
procd_add_config_trigger "config.change" "cwmp" /etc/init.d/icwmpd reload
procd_add_reload_trigger "cwmp"
}
......@@ -41,14 +41,4 @@ set_cwmp_reqopts() {
fi
}
regenerate_ssl_link(){
local cert_dir="/etc/ssl/certs"
local all_file=$(ls $cert_dir/*.pem)
for cfile in $all_file
do
ln -s $cfile $cert_dir/$(openssl x509 -hash -noout -in $cfile).0
done
}
set_cwmp_reqopts
regenerate_ssl_link
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment