mirror of
				https://github.com/Telecominfraproject/wlan-ap.git
				synced 2025-10-30 01:52:51 +00:00 
			
		
		
		
	ucode: update to latest HEAD
Signed-off-by: John Crispin <john@phrozen.org>
This commit is contained in:
		| @@ -12,9 +12,9 @@ PKG_RELEASE:=1 | ||||
|  | ||||
| PKG_SOURCE_PROTO:=git | ||||
| PKG_SOURCE_URL=https://github.com/jow-/ucode.git | ||||
| PKG_MIRROR_HASH:=376b89c35967d3761acb192af9fb6b7b20dbcc50d03c8ed851751d2376bf26b4 | ||||
| PKG_SOURCE_DATE:=2021-07-30 | ||||
| PKG_SOURCE_VERSION:=03b6a8efc1834a4114f0d11e1a7cecff3242b305 | ||||
| PKG_MIRROR_HASH:=6af37293d6d7023f30728c76a02b4e48d323262a45058410760a30256e0dbe2b | ||||
| PKG_SOURCE_VERSION:=8fd4746da31b945a6259ac846f7cf8dcfef0b1ef | ||||
| PKG_MAINTAINER:=Jo-Philipp Wich <jo@mein.io> | ||||
| PKG_LICENSE:=ISC | ||||
|  | ||||
|   | ||||
| @@ -1,15 +1,15 @@ | ||||
| From eac420899717e2d23f6d13304bd67278a7e91730 Mon Sep 17 00:00:00 2001 | ||||
| From 25df1c3e41f274f70e4fbf5fdc10e4290ba019f5 Mon Sep 17 00:00:00 2001 | ||||
| From: John Crispin <john@phrozen.org> | ||||
| Date: Thu, 20 Jan 2022 10:48:35 +0100 | ||||
| Subject: [PATCH 1/2] fixes | ||||
| Subject: [PATCH] fixes | ||||
|  | ||||
| --- | ||||
|  lib/nl80211.c | 76 +++++++++++++++++++++++++++++++++++++++++++++++---- | ||||
|  lib/nl80211.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++---- | ||||
|  lib/rtnl.c    |  1 + | ||||
|  2 files changed, 71 insertions(+), 6 deletions(-) | ||||
|  2 files changed, 87 insertions(+), 6 deletions(-) | ||||
|  | ||||
| diff --git a/lib/nl80211.c b/lib/nl80211.c | ||||
| index fc24fb8..1d0871a 100644 | ||||
| index fc24fb8..3e21141 100644 | ||||
| --- a/lib/nl80211.c | ||||
| +++ b/lib/nl80211.c | ||||
| @@ -45,6 +45,8 @@ limitations under the License. | ||||
| @@ -132,7 +132,7 @@ index fc24fb8..1d0871a 100644 | ||||
|  	.attrs = { | ||||
|  		{ NL80211_STA_INFO_INACTIVE_TIME, "inactive_time", DT_U32, 0, NULL }, | ||||
|  		{ NL80211_STA_INFO_RX_BYTES, "rx_bytes", DT_U32, 0, NULL }, | ||||
| @@ -724,21 +783,22 @@ static const uc_nl_nested_spec_t nl80211_sta_info_nla = { | ||||
| @@ -724,21 +783,37 @@ 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 }, | ||||
| @@ -149,25 +149,41 @@ index fc24fb8..1d0871a 100644 | ||||
|  		{ 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 }, | ||||
| +	} | ||||
| +}; | ||||
| + | ||||
| +static const uc_nl_nested_spec_t nl80211_survey_info_nla = { | ||||
| +	.headsize = 0, | ||||
| +	.nattrs = 8, | ||||
| +	.attrs = { | ||||
| +		{ NL80211_SURVEY_INFO_FREQUENCY, "frequency", DT_U32, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_TIME, "time", DT_U64, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_TIME_TX, "time_tx", DT_U64, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_TIME_RX, "time_rx", DT_U64, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_TIME_BUSY, "busy", DT_U64, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_TIME_EXT_BUSY, "ext_busy", DT_U64, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_TIME_SCAN, "scan", DT_U64, 0, NULL }, | ||||
| +		{ NL80211_SURVEY_INFO_NOISE, "noise", DT_U8, 0, NULL }, | ||||
|  	} | ||||
|  }; | ||||
|   | ||||
|  static const uc_nl_nested_spec_t nl80211_msg = { | ||||
|  	.headsize = 0, | ||||
| -	.nattrs = 124, | ||||
| +	.nattrs = 125, | ||||
| +	.nattrs = 126, | ||||
|  	.attrs = { | ||||
|  		{ NL80211_ATTR_4ADDR, "4addr", DT_U8, 0, NULL }, | ||||
|  		{ NL80211_ATTR_AIRTIME_WEIGHT, "airtime_weight", DT_U16, 0, NULL }, | ||||
| @@ -864,6 +924,7 @@ static const uc_nl_nested_spec_t nl80211_msg = { | ||||
| @@ -864,6 +939,8 @@ static const uc_nl_nested_spec_t nl80211_msg = { | ||||
|  		{ NL80211_ATTR_WPA_VERSIONS, "wpa_versions", DT_U32, 0, NULL }, | ||||
|  		{ NL80211_ATTR_SUPPORTED_IFTYPES, "supported_iftypes", DT_NESTED, 0, &nl80211_ifcomb_limit_types_nla }, | ||||
|  		{ NL80211_ATTR_SOFTWARE_IFTYPES, "software_iftypes", DT_NESTED, 0, &nl80211_ifcomb_limit_types_nla }, | ||||
| +		{ NL80211_ATTR_MAX_AP_ASSOC_STA, "max_ap_assoc", DT_U16, 0, NULL }, | ||||
| +		{ NL80211_ATTR_SURVEY_INFO, "survey_info", DT_NESTED, 0, &nl80211_survey_info_nla }, | ||||
|  	} | ||||
|  }; | ||||
|   | ||||
| @@ -1044,6 +1105,9 @@ uc_nl_parse_attrs(struct nl_msg *msg, char *base, const uc_nl_attr_spec_t *attrs | ||||
| @@ -1044,6 +1121,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++) { | ||||
|   | ||||
| @@ -1,213 +0,0 @@ | ||||
| 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 | ||||
|  | ||||
		Reference in New Issue
	
	Block a user
	 John Crispin
					John Crispin