ucode: update to latest git HEAD

Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
John Crispin
2022-01-23 15:58:36 +01:00
parent dc35dd1ce5
commit d5fed93ec0
5 changed files with 434 additions and 1136 deletions

View File

@@ -13,8 +13,8 @@ PKG_RELEASE:=1
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL=https://github.com/jow-/ucode.git
PKG_SOURCE_DATE:=2021-07-30
PKG_SOURCE_VERSION:=0f022aae0c6008fe6f2219871d32dca8b9105066
PKG_MIRROR_HASH:=
PKG_SOURCE_VERSION:=03b6a8efc1834a4114f0d11e1a7cecff3242b305
PKG_MIRROR_HASH:=6af37293d6d7023f30728c76a02b4e48d323262a45058410760a30256e0dbe2b
PKG_MAINTAINER:=Jo-Philipp Wich <jo@mein.io>
PKG_LICENSE:=ISC
@@ -110,6 +110,33 @@ define Package/ucode-mod-uci/description
endef
define Package/ucode-mod-nl80211
$(Package/ucode/default)
TITLE+= (nl80211 module)
DEPENDS:=ucode +libnl-tiny +kmod-mac80211
endef
define Package/ucode-mod-nl80211/description
The nl80211 module allows templates to send and receive nl80211 messages..
endef
define Package/ucode-mod-struct
$(Package/ucode/default)
TITLE+= (struct module)
DEPENDS:=ucode
endef
define Package/ucode-mod-struct/description
The struct module allows templates to unpack binary buffers.
endef
define Build/Prepare
$(Build/Prepare/Default)
$(CP) $(STAGING_DIR)/usr/include/mac80211/uapi/linux/nl80211.h $(PKG_BUILD_DIR)/nl80211_copy.h
endef
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/lib $(1)/usr/include/ucode
$(CP) $(PKG_INSTALL_DIR)/usr/include/ucode/*.h $(1)/usr/include/ucode/
@@ -152,6 +179,16 @@ define Package/ucode-mod-uci/install
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/ucode/uci.so $(1)/usr/lib/ucode/
endef
define Package/ucode-mod-nl80211/install
$(INSTALL_DIR) $(1)/usr/lib/ucode
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/ucode/nl80211.so $(1)/usr/lib/ucode/
endef
define Package/ucode-mod-struct/install
$(INSTALL_DIR) $(1)/usr/lib/ucode
$(INSTALL_BIN) $(PKG_INSTALL_DIR)/usr/lib/ucode/struct.so $(1)/usr/lib/ucode/
endef
$(eval $(call BuildPackage,ucode))
$(eval $(call BuildPackage,libucode))
@@ -160,3 +197,5 @@ $(eval $(call BuildPackage,ucode-mod-resolv))
$(eval $(call BuildPackage,ucode-mod-math))
$(eval $(call BuildPackage,ucode-mod-ubus))
$(eval $(call BuildPackage,ucode-mod-uci))
$(eval $(call BuildPackage,ucode-mod-nl80211))
$(eval $(call BuildPackage,ucode-mod-struct))

View File

@@ -0,0 +1,13 @@
Index: ucode-2021-07-30-03b6a8ef/lib/nl80211.c
===================================================================
--- ucode-2021-07-30-03b6a8ef.orig/lib/nl80211.c
+++ ucode-2021-07-30-03b6a8ef/lib/nl80211.c
@@ -38,7 +38,7 @@ limitations under the License.
#include <netlink/genl/family.h>
#include <netlink/genl/ctrl.h>
-#include <linux/nl80211.h>
+#include "../nl80211_copy.h"
#include <linux/ieee80211.h>
#include "ucode/module.h"

View File

@@ -0,0 +1,166 @@
From aaf6b8d2355044843a7f0e765fb295518d5c114b Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Thu, 20 Jan 2022 10:48:35 +0100
Subject: [PATCH] fixes
---
lib/nl80211.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 68 insertions(+), 5 deletions(-)
diff --git a/lib/nl80211.c b/lib/nl80211.c
index fc24fb8..e308ebc 100644
--- a/lib/nl80211.c
+++ b/lib/nl80211.c
@@ -45,6 +45,8 @@ limitations under the License.
#define err_return(code, ...) do { set_error(code, __VA_ARGS__); return NULL; } while(0)
+#define NL80211_ATTR_NOT_IMPLEMENTED 0x10000
+
static struct {
int code;
char *msg;
@@ -257,6 +259,14 @@ static const uc_nl_nested_spec_t nl80211_keys_nla = {
}
};
+#ifndef NL80211_MESHCONF_NOLEARN
+#define NL80211_MESHCONF_NOLEARN NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
+#ifndef NL80211_MESHCONF_CONNECTED_TO_AS
+#define NL80211_MESHCONF_CONNECTED_TO_AS NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
static const uc_nl_nested_spec_t nl80211_mesh_params_nla = {
.headsize = 0,
.nattrs = 29,
@@ -348,6 +358,14 @@ static const uc_nl_nested_spec_t nl80211_nan_func_nla = {
}
};
+#ifndef NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK
+#define NL80211_PMSR_FTM_REQ_ATTR_LMR_FEEDBACK NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
+#ifndef NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR
+#define NL80211_PMSR_FTM_REQ_ATTR_BSS_COLOR NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
static const uc_nl_nested_spec_t nl80211_peer_measurements_peers_req_data_ftm_nla = {
.headsize = 0,
.nattrs = 13,
@@ -497,6 +515,26 @@ static const uc_nl_nested_spec_t nl80211_wiphy_bands_freqs_wmm_nla = {
}
};
+#ifndef NL80211_FREQUENCY_ATTR_1MHZ
+#define NL80211_FREQUENCY_ATTR_1MHZ NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
+#ifndef NL80211_FREQUENCY_ATTR_2MHZ
+#define NL80211_FREQUENCY_ATTR_2MHZ NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
+#ifndef NL80211_FREQUENCY_ATTR_4MHZ
+#define NL80211_FREQUENCY_ATTR_4MHZ NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
+#ifndef NL80211_FREQUENCY_ATTR_8MHZ
+#define NL80211_FREQUENCY_ATTR_8MHZ NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
+#ifndef NL80211_FREQUENCY_ATTR_16MHZ
+#define NL80211_FREQUENCY_ATTR_16MHZ NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
static const uc_nl_nested_spec_t nl80211_wiphy_bands_freqs_nla = {
.headsize = 0,
.nattrs = 25,
@@ -538,6 +576,10 @@ static const uc_nl_nested_spec_t nl80211_wiphy_bands_rates_nla = {
}
};
+#ifndef NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS
+#define NL80211_BAND_IFTYPE_ATTR_VENDOR_ELEMS NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
static const uc_nl_nested_spec_t nl80211_wiphy_bands_iftype_data_nla = {
.headsize = 0,
.nattrs = 7,
@@ -645,13 +687,26 @@ static const uc_nl_nested_spec_t nl80211_bss_nla = {
static const uc_nl_nested_spec_t nl80211_sta_info_bitrate_nla = {
.headsize = 0,
- .nattrs = 5,
+ .nattrs = 18,
.attrs = {
{ NL80211_RATE_INFO_BITRATE, "bitrate", DT_U16, 0, NULL },
{ NL80211_RATE_INFO_BITRATE32, "bitrate32", DT_U32, 0, NULL },
{ NL80211_RATE_INFO_MCS, "mcs", DT_U8, 0, NULL },
{ NL80211_RATE_INFO_40_MHZ_WIDTH, "40_mhz_width", DT_FLAG, 0, NULL },
{ NL80211_RATE_INFO_SHORT_GI, "short_gi", DT_FLAG, 0, NULL },
+ { NL80211_RATE_INFO_VHT_MCS, "vht_mcs", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_VHT_NSS, "vht_nss", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_HE_MCS, "he_mcs", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_HE_NSS, "he_nss", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_HE_GI, "he_gi", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_HE_DCM, "he_dcm", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_HE_RU_ALLOC, "he_ru_alloc", DT_U8, 0, NULL },
+ { NL80211_RATE_INFO_40_MHZ_WIDTH, "width_40", DT_FLAG, 0, NULL },
+ { NL80211_RATE_INFO_80_MHZ_WIDTH, "width_80", DT_FLAG, 0, NULL },
+ { NL80211_RATE_INFO_80P80_MHZ_WIDTH, "width_80p80", DT_FLAG, 0, NULL },
+ { NL80211_RATE_INFO_160_MHZ_WIDTH, "width_160", DT_FLAG, 0, NULL },
+ { NL80211_RATE_INFO_10_MHZ_WIDTH, "width_10", DT_FLAG, 0, NULL },
+ { NL80211_RATE_INFO_5_MHZ_WIDTH, "width_5", DT_FLAG, 0, NULL },
}
};
@@ -695,9 +750,13 @@ static const uc_nl_nested_spec_t nl80211_bss_param_nla = {
}
};
+#ifndef NL80211_STA_INFO_CONNECTED_TO_AS
+#define NL80211_STA_INFO_CONNECTED_TO_AS NL80211_ATTR_NOT_IMPLEMENTED
+#endif
+
static const uc_nl_nested_spec_t nl80211_sta_info_nla = {
.headsize = 0,
- .nattrs = 34,
+ .nattrs = 35,
.attrs = {
{ NL80211_STA_INFO_INACTIVE_TIME, "inactive_time", DT_U32, 0, NULL },
{ NL80211_STA_INFO_RX_BYTES, "rx_bytes", DT_U32, 0, NULL },
@@ -724,15 +783,16 @@ static const uc_nl_nested_spec_t nl80211_sta_info_nla = {
{ NL80211_STA_INFO_NONPEER_PM, "nonpeer_pm", DT_U32, 0, NULL },
{ NL80211_STA_INFO_CHAIN_SIGNAL, "chain_signal", DT_S8, DF_MULTIPLE|DF_AUTOIDX, NULL },
{ NL80211_STA_INFO_CHAIN_SIGNAL_AVG, "chain_signal_avg", DT_S8, DF_MULTIPLE|DF_AUTOIDX, NULL },
- { NL80211_STA_INFO_TID_STATS, "tid_stats", DT_NESTED, 0, &nl80211_tid_stats_nla },
+ { NL80211_STA_INFO_TID_STATS, "tid_stats", DT_NESTED, DF_MULTIPLE|DF_AUTOIDX, &nl80211_tid_stats_nla },
{ NL80211_STA_INFO_BSS_PARAM, "bss_param", DT_NESTED, 0, &nl80211_bss_param_nla },
{ NL80211_STA_INFO_RX_DURATION, "rx_duration", DT_U64, 0, NULL },
{ NL80211_STA_INFO_TX_DURATION, "tx_duration", DT_U64, 0, NULL },
- { NL80211_STA_INFO_ACK_SIGNAL, "ack_signal", DT_U8, 0, NULL },
- { NL80211_STA_INFO_ACK_SIGNAL_AVG, "ack_signal_avg", DT_U8, 0, NULL },
+ { NL80211_STA_INFO_ACK_SIGNAL, "ack_signal", DT_S8, 0, NULL },
+ { NL80211_STA_INFO_ACK_SIGNAL_AVG, "ack_signal_avg", DT_S8, 0, NULL },
{ NL80211_STA_INFO_AIRTIME_LINK_METRIC, "airtime_link_metric", DT_U32, 0, NULL },
{ NL80211_STA_INFO_CONNECTED_TO_AS, "connected_to_as", DT_BOOL, 0, NULL },
{ NL80211_STA_INFO_CONNECTED_TO_GATE, "connected_to_gate", DT_BOOL, 0, NULL },
+ { NL80211_STA_INFO_CONNECTED_TIME, "connected_time", DT_U32, 0, NULL },
}
};
@@ -1044,6 +1104,9 @@ uc_nl_parse_attrs(struct nl_msg *msg, char *base, const uc_nl_attr_spec_t *attrs
bool exists;
for (i = 0; i < nattrs; i++) {
+ if (attrs[i].attr == NL80211_ATTR_NOT_IMPLEMENTED)
+ continue;
+
v = ucv_object_get(obj, attrs[i].key, &exists);
if (!exists)
--
2.25.1

View File

@@ -0,0 +1,213 @@
From 9c77d85f8e121bf0994eb4bc572eea5cf093f0c6 Mon Sep 17 00:00:00 2001
From: John Crispin <john@phrozen.org>
Date: Tue, 25 Jan 2022 16:54:48 +0100
Subject: [PATCH] add os library
Signed-off-by: John Crispin <john@phrozen.org>
---
CMakeLists.txt | 7 +++
lib/os.c | 167 +++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 174 insertions(+)
create mode 100644 lib/os.c
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 7c84fc3..f7d4f83 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -27,6 +27,7 @@ OPTION(RTNL_SUPPORT "Route Netlink plugin support" ON)
OPTION(NL80211_SUPPORT "Wireless Netlink plugin support" ON)
OPTION(RESOLV_SUPPORT "NS resolve plugin support" ON)
OPTION(STRUCT_SUPPORT "Struct plugin support" ON)
+OPTION(OS_SUPPORT "OS plugin support" ON)
SET(LIB_SEARCH_PATH "${CMAKE_INSTALL_PREFIX}/lib/ucode/*.so:${CMAKE_INSTALL_PREFIX}/share/ucode/*.uc:./*.so:./*.uc" CACHE STRING "Default library search path")
STRING(REPLACE ":" "\", \"" LIB_SEARCH_DEFINE "${LIB_SEARCH_PATH}")
@@ -143,6 +144,12 @@ IF(NL80211_SUPPORT)
TARGET_LINK_LIBRARIES(nl80211_lib ${nl})
ENDIF()
+IF(OS_SUPPORT)
+ SET(LIBRARIES ${LIBRARIES} os_lib)
+ ADD_LIBRARY(os_lib MODULE lib/os.c)
+ SET_TARGET_PROPERTIES(os_lib PROPERTIES OUTPUT_NAME os PREFIX "")
+ENDIF()
+
IF(RESOLV_SUPPORT)
SET(LIBRARIES ${LIBRARIES} resolv_lib)
ADD_LIBRARY(resolv_lib MODULE lib/resolv.c)
diff --git a/lib/os.c b/lib/os.c
new file mode 100644
index 0000000..cebad15
--- /dev/null
+++ b/lib/os.c
@@ -0,0 +1,167 @@
+#include <glob.h>
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <ctype.h>
+#include <libgen.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <regex.h>
+
+#include <sys/sysinfo.h>
+
+#include "ucode/module.h"
+
+static regex_t pat_vmdata, pat_vmstk;
+static struct sysinfo info;
+static long systick;
+
+static void __attribute__((constructor))
+measure_init()
+{
+ regcomp(&pat_vmdata, "VmData:[ \t]*([0-9]*) kB", REG_EXTENDED);
+ regcomp(&pat_vmstk, "VmStk:[ \t]*([0-9]*) kB", REG_EXTENDED);
+ sysinfo(&info);
+ systick = sysconf(_SC_CLK_TCK);
+}
+
+static void __attribute__((destructor))
+measure_fini()
+{
+ regfree(&pat_vmdata);
+ regfree(&pat_vmstk);
+}
+
+static char *
+strnchr(char *buf, int c, int i)
+{
+ while (*buf && i) {
+ buf = strchr(buf, c);
+ buf++;
+ i--;
+ }
+ return buf;
+}
+
+static int
+measure_process(uc_value_t *obj, pid_t pid)
+{
+ int fd;
+ char buffer[512] = "";
+ ssize_t rxed;
+ regmatch_t matches[2];
+ glob_t gl;
+ size_t i;
+ char *ch;
+
+ uint32_t fdcount = 0;
+ uint32_t mem = 0;
+
+ snprintf(buffer, sizeof(buffer), "/proc/%i/fd/*", (int)pid);
+
+ if (glob(buffer, GLOB_NOESCAPE | GLOB_MARK, NULL, &gl))
+ return -1;
+
+ for (i = 0; i < gl.gl_pathc; i++)
+ if (isdigit(basename(gl.gl_pathv[i])[0]))
+ fdcount = fdcount + 1;
+ globfree(&gl);
+ ucv_object_add(obj, "fd", ucv_int64_new(fdcount));
+
+ snprintf(buffer, sizeof(buffer), "/proc/%i/stat", (int)pid);
+ fd = open(buffer, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ rxed = read(fd, buffer, sizeof(buffer) - 1);
+ close(fd);
+ if (rxed == -1)
+ return -1;
+
+ buffer[rxed] = 0;
+
+ ch = strnchr(buffer, ' ', 14);
+ if (ch)
+ ucv_object_add(obj, "load", ucv_int64_new(atoll(ch)));
+
+ ch = strnchr(buffer, ' ', 21);
+ if (ch)
+ ucv_object_add(obj, "age", ucv_int64_new(info.uptime - atol(ch) / systick));
+
+ snprintf(buffer, sizeof(buffer), "/proc/%i/status", (int)pid);
+ fd = open(buffer, O_RDONLY);
+ if (fd == -1)
+ return -1;
+
+ rxed = read(fd, buffer, sizeof(buffer) - 1);
+ close(fd);
+ if (rxed == -1)
+ return -1;
+
+ buffer[rxed] = 0;
+
+ if (!regexec(&pat_vmdata, buffer, 2, matches, 0))
+ mem += atoi(buffer + matches[1].rm_so) * 1024;
+
+ if (!regexec(&pat_vmstk, buffer, 2, matches, 0))
+ mem += atoi(buffer + matches[1].rm_so) * 1024;
+
+ ucv_object_add(obj, "memory", ucv_int64_new(mem));
+
+ return 0;
+}
+
+static uc_value_t *
+uc_system_hostname(uc_vm_t *vm, size_t nargs)
+{
+ char buf[255] = {};
+
+ if (gethostname(buf, sizeof(buf)) < 0)
+ return NULL;
+
+ return ucv_string_new(buf);
+}
+
+static uc_value_t *
+uc_system_loadavg(uc_vm_t *vm, size_t nargs)
+{
+ uc_value_t *res_obj = NULL;
+ int i;
+
+ sysinfo(&info);
+
+ res_obj = ucv_array_new(vm);
+ for (i = 0; i < 3; i++)
+ ucv_array_push(res_obj, ucv_double_new(((double) info.loads[i]) / 65535.0f));
+
+ return res_obj;
+}
+
+static uc_value_t *
+uc_system_process(uc_vm_t *vm, size_t nargs)
+{
+ uc_value_t *pid = uc_fn_arg(0);
+ uc_value_t *res_obj = NULL;
+
+ if (ucv_type(pid) != UC_INTEGER)
+ return NULL;
+
+ res_obj = ucv_object_new(vm);
+
+ measure_process(res_obj, ucv_uint64_get(pid));
+
+ return res_obj;
+}
+
+static const uc_function_list_t system_fns[] = {
+ { "hostname", uc_system_hostname },
+ { "loadavg", uc_system_loadavg },
+ { "process", uc_system_process },
+};
+
+void uc_module_init(uc_vm_t *vm, uc_value_t *scope)
+{
+ uc_function_list_register(scope, system_fns);
+}
--
2.25.1

File diff suppressed because it is too large Load Diff