From aeb966b798dd305c75947a060e3a91091bba33eb Mon Sep 17 00:00:00 2001 From: Suvendhu Hansa Date: Thu, 30 May 2024 09:47:42 +0000 Subject: [PATCH] obuspa: Fix dhcp opt125 for controller discovery --- obuspa/Makefile | 2 +- .../etc/uci-defaults/02-obuspa-dhcp-option | 59 ------------- .../etc/uci-defaults/obuspa-set-dhcp-option | 88 +++++++++++++++++++ 3 files changed, 89 insertions(+), 60 deletions(-) delete mode 100644 obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option create mode 100644 obuspa/files/etc/uci-defaults/obuspa-set-dhcp-option diff --git a/obuspa/Makefile b/obuspa/Makefile index 86eebe577..224bf1039 100644 --- a/obuspa/Makefile +++ b/obuspa/Makefile @@ -108,8 +108,8 @@ define Package/obuspa/install echo "$(CONFIG_BBF_VENDOR_PREFIX)" > $(1)/etc/obuspa/vendor_prefix $(INSTALL_DATA) ./files/etc/obuspa/dmcaching_exclude.json $(1)/etc/obuspa/dmcaching_exclude.json $(INSTALL_BIN) ./files/etc/uci-defaults/01-fix-upgrade-uci $(1)/etc/uci-defaults/ - $(INSTALL_BIN) ./files/etc/uci-defaults/02-obuspa-dhcp-option $(1)/etc/uci-defaults/ $(INSTALL_BIN) ./files/etc/uci-defaults/60-generate-ctrust-defaults $(1)/etc/uci-defaults/ + $(INSTALL_BIN) ./files/etc/uci-defaults/obuspa-set-dhcp-option $(1)/etc/uci-defaults/ $(INSTALL_BIN) ./files/etc/udhcpc.user.d/udhcpc_obuspa_opt125.user $(1)/etc/udhcpc.user.d/udhcpc_obuspa_opt125.user $(BBFDM_INSTALL_CORE_PLUGIN) ./files/etc/bbfdm/json/USPAgent.json $(1) ifeq ($(CONFIG_OBUSPA_ENABLE_TEST_CONTROLLER),y) diff --git a/obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option b/obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option deleted file mode 100644 index b2fa041de..000000000 --- a/obuspa/files/etc/uci-defaults/02-obuspa-dhcp-option +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/sh - -. /lib/functions.sh - -configure_dhcp_options() { - local enabled inerface discovery - config_load obuspa - config_get_bool enabled global enabled 1 - config_get interface global interface "wan" - config_get_bool discovery global dhcp_discovery 1 - - if [ "${enabled}" -eq 0 ]; then - return 0 - fi - - if [ "${discovery}" -eq 1 ]; then - network_uci_update=0 - reqopts="$(uci -q get network."${interface}".reqopts)" - proto="$(uci -q get network."${interface}".proto)" - local req125_present=0 - - for ropt in $reqopts; do - case $ropt in - 125) req125_present=1 ;; - *) ;; - esac - done - - sendopts="$(uci -q get network."${interface}".sendopts)" - opt124="124:" - send124_present=0 - for sopt in $sendopts; do - if [[ "$sopt" == "$opt124"* ]]; then - send124_present=1 - break - fi - done - - if [ "${proto}" = "dhcp" ]; then - if [ ${req125_present} -eq 0 ]; then - newreqopts="$reqopts 125" - uci -q set network."${interface}".reqopts="$newreqopts" - network_uci_update=1 - fi - - if [ ${send124_present} -eq 0 ]; then - newsendopts="${sendopts} 124:00:00:0D:E9:04:03:75:73:70" - uci -q set network."${interface}".sendopts="$newsendopts" - network_uci_update=1 - fi - fi - - if [ ${network_uci_update} -eq 1 ]; then - uci commit network - fi - fi -} - -configure_dhcp_options diff --git a/obuspa/files/etc/uci-defaults/obuspa-set-dhcp-option b/obuspa/files/etc/uci-defaults/obuspa-set-dhcp-option new file mode 100644 index 000000000..7c1062a78 --- /dev/null +++ b/obuspa/files/etc/uci-defaults/obuspa-set-dhcp-option @@ -0,0 +1,88 @@ +#!/bin/sh + +. /lib/functions.sh + +get_access_role() +{ + local mode lan_proto + + lan_proto="$(uci -q get network.lan.proto)" + + if [ "${lan_proto}" == "dhcp" ]; then + mode="extender" + else + mode="full_access" + fi + + echo "$mode" +} + +configure_dhcp_options() { + local enabled inerface discovery + config_load obuspa + config_get_bool enabled global enabled 1 + config_get interface global interface + config_get_bool discovery global dhcp_discovery 1 + + if [ "${enabled}" -eq 0 ]; then + return 0 + fi + + if [ "${discovery}" -eq 0 ]; then + return 0 + fi + + if [ -z "${interface}" ]; then + role="$(get_access_role)" + + if [ "${role}" = "extender" ]; then + interface="lan" + uci -q set obuspa.global.interface="lan" + uci commit obuspa + else + interface="wan" + fi + fi + + network_uci_update=0 + reqopts="$(uci -q get network."${interface}".reqopts)" + proto="$(uci -q get network."${interface}".proto)" + local req125_present=0 + + for ropt in $reqopts; do + case $ropt in + 125) req125_present=1 ;; + *) ;; + esac + done + + sendopts="$(uci -q get network."${interface}".sendopts)" + opt124="124:" + send124_present=0 + for sopt in $sendopts; do + if [[ "$sopt" == "$opt124"* ]]; then + send124_present=1 + break + fi + done + + if [ "${proto}" = "dhcp" ]; then + if [ ${req125_present} -eq 0 ]; then + newreqopts="$reqopts 125" + uci -q set network."${interface}".reqopts="$newreqopts" + network_uci_update=1 + fi + + if [ ${send124_present} -eq 0 ]; then + newsendopts="${sendopts} 124:00:00:0D:E9:04:03:75:73:70" + uci -q set network."${interface}".sendopts="$newsendopts" + network_uci_update=1 + fi + fi + + if [ ${network_uci_update} -eq 1 ]; then + uci commit network + fi +} + +configure_dhcp_options