bbfdm: Add bbfdmd deamon

This commit is contained in:
Amin Ben Romdhane 2023-04-14 12:21:46 +02:00
parent 2870af12ed
commit 7006566087
11 changed files with 119 additions and 5 deletions

View file

@ -4,16 +4,17 @@
include $(TOPDIR)/rules.mk
PKG_NAME:=libbbf_dm
PKG_VERSION:=7.0.1
PKG_NAME:=bbfdm
PKG_VERSION:=1.0.0
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://dev.iopsys.eu/iopsys/bbf.git
PKG_SOURCE_VERSION:=4515b6319870aaa4b415bb66a4c60a91a1fa6592
PKG_SOURCE_URL:=https://dev.iopsys.eu/bbf/bbfdm.git
PKG_SOURCE_VERSION:=0a4105c931f2cba8fec2ffdc813f170903ea3e90
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION)-$(PKG_SOURCE_VERSION).tar.gz
PKG_MIRROR_HASH:=skip
PKG_RELEASE=$(PKG_SOURCE_VERSION)
PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)-$(PKG_VERSION)
PKG_LICENSE:=LGPL-2.1
PKG_LICENSE_FILES:=LICENSE
@ -69,6 +70,15 @@ define Package/libbbf_dm-wolfssl
VARIANT:=wolfssl
endef
define Package/bbfdmd
SECTION:=utils
CATEGORY:=Utilities
SUBMENU:=TRx69
TITLE:=Datamodel ubus backend
DEPENDS:=+libuci +libubox +libubus +libblobmsg-json +libbbf_api +PACKAGE_libbbf_dm-mbedtls:libbbf_dm-mbedtls \
+PACKAGE_libbbf_dm-openssl:libbbf_dm-openssl +PACKAGE_libbbf_dm-wolfssl:libbbf_dm-wolfssl
endef
define Package/userinterface
SECTION:=utils
CATEGORY:=Utilities
@ -150,6 +160,12 @@ ifeq ($(BUILD_VARIANT),mbedtls)
CMAKE_OPTIONS += -DWITH_MBEDTLS=ON
endif
ifeq ($(CONFIG_PACKAGE_bbfdmd),y)
CMAKE_OPTIONS += -DBBFDMD_ENABLED=ON
CMAKE_OPTIONS += \
-DBBFDMD_MAX_MSG_LEN:Integer=10485760
endif
define Package/libbbf_api/install
$(INSTALL_DIR) $(1)/lib
$(CP) $(PKG_BUILD_DIR)/libbbf_api/libbbf_api.so $(1)/lib/
@ -182,6 +198,15 @@ define Package/libbbf_dm/default/prerm
exit 0
endef
define Package/bbfdmd/install
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_BIN) ./files/etc/init.d/bbfdmd $(1)/etc/init.d/bbfdmd
$(INSTALL_CONF) ./files/etc/config/bbfdmd $(1)/etc/config/bbfdmd
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bbfdmd/src/bbfdmd $(1)/usr/sbin/
endef
define Package/userinterface/install
$(INSTALL_DIR) $(1)/etc/config
$(INSTALL_DIR) $(1)/etc/uci-defaults
@ -222,4 +247,5 @@ $(eval $(call BuildPackage,libbbf_dm-openssl))
$(eval $(call BuildPackage,libbbf_dm-wolfssl))
$(eval $(call BuildPackage,libbbf_dm-mbedtls))
$(eval $(call BuildPackage,bbfdmd))
$(eval $(call BuildPackage,userinterface))

View file

@ -0,0 +1,6 @@
config globals 'globals'
option loglevel '1'
option refresh_time '10'
option transaction_timeout '10'

View file

@ -0,0 +1,82 @@
#!/bin/sh /etc/rc.common
START=96
STOP=10
USE_PROCD=1
PROG=/usr/sbin/bbfdmd
log() {
echo "${@}"|logger -t bbfdmd.init -p info
}
validate_bbfdmd_globals_section()
{
uci_validate_section bbfdmd globals "globals" \
'enabled:bool:true' \
'debug:bool:false' \
'loglevel:uinteger' \
'sock:string' \
'transaction_timeout:string'
}
configure_bbfdmd()
{
local enabled debug sock transaction_timeout
config_load bbfdmd
validate_bbfdmd_globals_section || {
log "Validation of bbf section failed"
return 1;
}
[ "${enabled}" -eq 0 ] && return 0
procd_set_param command ${PROG}
if [ "${debug}" -eq 1 ]; then
procd_set_param stdout 1
procd_set_param stderr 1
fi
if [ -f "${sock}" ]; then
procd_append_param command -s "${sock}"
fi
if [ -n "${transaction_timeout}" ]; then
procd_append_param command -t "${transaction_timeout}"
fi
}
apply_sysctl_configuration() {
local sysctl_conf
sysctl_conf="/etc/bbfdm/sysctl.conf"
[ -f "${sysctl_conf}" ] || touch "${sysctl_conf}"
sysctl -e -p "${sysctl_conf}" >&-
}
start_service() {
local sysctl_reload
ubus -t 5 wait_for network.device
[ "$?" -eq 0 ] && sysctl_reload=1
procd_open_instance bbf
configure_bbfdmd
procd_set_param respawn
procd_close_instance
[ "${sysctl_reload}" -eq 1 ] && apply_sysctl_configuration
}
reload_service() {
apply_sysctl_configuration
}
service_triggers()
{
procd_add_reload_trigger "bbfdmd"
}

View file

@ -22,7 +22,7 @@ start_service() {
fi
# Inject firewall rules
procd_open_instance usp
procd_open_instance userinterface
/etc/firewall.userinterface
procd_close_instance
}