map-topology: validate config options

This commit is contained in:
Filip Matusiak 2022-02-16 13:51:48 +01:00 committed by Jakob Olsson
parent c54e44a820
commit b07664f7d5

View file

@ -5,7 +5,72 @@ STOP=21
USE_PROCD=1
IS_CFG_VALID=1
validate_topology_config() {
uci_validate_section topology topology "topology" \
'enabled:bool:true' \
'depth:range(0,16)' \
'interval:range(0,65535)' \
'maxlog:range(0,128)' \
[ "$?" -ne 0 ] && {
logger -s -t "topology" "Validation of topology UCI file failed"
return 1
}
return 0
}
validate_global_section() {
uci_validate_section hosts global "global" \
'ageing_timer:uinteger' \
'reboot_persistent:bool'
[ "$?" -ne 0 ] && {
logger -s -t "hosts" "Validation of global section failed"
IS_CFG_VALID=0
return 1
}
return 0
}
validate_host_section() {
local section="$1"
uci_validate_section hosts $section "${1}" \
'macaddr:macaddr' \
'interface_type:or("wifi","eth")' \
'active:bool' \
'active_last_change:string'
[ "$?" -ne 0 ] && {
logger -s -t "hosts" "Validation of host section $section failed"
IS_CFG_VALID=0
return 1
}
return 0
}
validate_hosts_config() {
IS_CFG_VALID=1
validate_global_section &&
config_foreach validate_host_section host
[ "$IS_CFG_VALID" -ne 1 ] && {
logger -s -t "topology" "Validation of hosts UCI file failed"
return 1
}
return 0
}
start_service() {
config_load "topology"
validate_topology_config || return 1;
config_load "hosts"
validate_hosts_config || return 1;
procd_open_instance
procd_set_param command "/usr/sbin/topologyd"
procd_set_param respawn