summaryrefslogtreecommitdiffhomepage
AgeCommit message (Collapse)Author
2024-03-13vm: rework `in` operator semanticsJo-Philipp Wich
- Ensure that testing for array membership does strict equality tests - Ensure that `(NaN in [ NaN ]) == true` - Do not perform implicit value conversion when testing for object keys, to avoid nonsensical results such as `([] in { "[ ]": true }) == true` - Add test cases for the `in` operator Fixes: #193 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-21lib: fix documentation typo for `pop()` functionJo-Philipp Wich
The function pops the last, not the first element from the array. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-21Merge pull request #190 from jow-/uci-changes-load-packageJo-Philipp Wich
uci: refactor uci.changes() to match documentation
2024-02-21Merge pull request #189 from jow-/safe-iteratorsJo-Philipp Wich
vm: rework object iteration
2024-02-21uci: refactor uci.changes() to match documentationJo-Philipp Wich
When invoked with an explicit package name argument, retain the autoloaded configuration within the context state. Fixes: #188 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-21vm: rework object iterationJo-Philipp Wich
Ensure that deleting object keys during iteration is safe by keeping a global chain of per-object iterators which are advanced to the next key when the entry that is about to be iterated is deleted. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-13compiler: close upvalues on loop control statementsFelix Fietkau
When removing locals from all scopes, upvalues need to be considered like in uc_compiler_leave_scope(). Closing them is required to avoid leaving lingering references to stack values that went out of scope, which would lead to invalid memory accesses in subsequent code when such upvalues are used by closures. Fixes: #187 Signed-off-by: Felix Fietkau <nbd@nbd.name> [add testcase, reword commit message] Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-01-11Merge pull request #185 from jow-/rtnl-enobufs-handlingJo-Philipp Wich
rtnl: improve event reception in order to avoid ENOBUFS
2024-01-10rtnl: increase event socket rx buffer size limit to 1 MiBJo-Philipp Wich
Use the same RX buffer size which iproute2 uses as default, in order to avoid (or rather, delay as much as possible) ENOBUFS conditions when receiving a large burst of netlink notifications. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-01-10rtnl: optimize reception of rtnl eventsJo-Philipp Wich
Once we're notified about pending data on the netlink event socket, try to receive as much messages as possible in order to empty the socket buffer. In contrast to the previous implementation which received one message per epoll read notification, this avoids some premature ENOBUFS situations when a huge burst of messages arrives, e.g. due to kernel side GC runs on the neighbor table. Since libnl's nl_recvmsgs*() functions do not expose the underlying -1 error returned by the recvmsg() calls, we need to indirectly check for errors through errno variable, so clear it out both before the recvmsgs() call and after successfully completing a message reception callback invocation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-01-10rtnl: store callback in listener registry only on successJo-Philipp Wich
Only store the callback reference in the registry once the listener context was successfully initialized, to avoid keeping a lingering entry when invalid parameters are passed. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-12-14nl80211: fix decoding of NL80211_BAND_IFTYPE_ATTR_HE_CAP_MCS_SET attributeJo-Philipp Wich
- The expected length was incorrect - An incorrect MCS MAP index was accessed - The maximum MCS index number were wrong Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-12-14nl80211: fix parsing of NL80211_BAND_ATTR_VHT_MCS_SET attributeJo-Philipp Wich
The length constraint of 16 byte was incorrect, the attribute is 8 bytes long; two bytes for the RX MCS set, two bytes for the highest RX rate, two bytes for the TX MCS set and two bytes for the highest TX rate. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-12-11nl80211: fix datatype of NL80211_BAND_IFTYPE_ATTR_HE_CAP_{MAC,PHY} attrsJo-Philipp Wich
The attributes are arrays of 6 and 11 u8 values respectively. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-30Merge pull request #183 from nbd168/ubus-reworkJo-Philipp Wich
2023-11-30ubus: make ubus_context first in uc_ubus_connection_tFelix Fietkau
Allows other C code to gain access to the ubus context without having to know the layout of the other fields. Also reduce the amount of unnecessary pointer indirection Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-11-07Merge pull request #180 from jow-/uloop-interval-signal-supportJo-Philipp Wich
uloop: support new interval and signal APIs
2023-11-07Merge pull request #181 from jow-/syntax-as-from-not-reservedJo-Philipp Wich
syntax: don't treat `as` and `from` as reserved keywords
2023-11-06syntax: don't treat `as` and `from` as reserved keywordsJo-Philipp Wich
ECMAScript allows using `as` and `from` as identifiers so follow suit and don't treat them specially while parsing. Extend the compiler logic instead to check for TK_LABEL tokens with the expected value to properly parse import and export statements. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-03uloop: support new interval and signal APIsJo-Philipp Wich
Add bindings for the new uloop interval and signal handling APIs and extend the CMake logic to properly detect the presence of these facilities. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-02build: avoid redefining _FORTIFY_SOURCEJo-Philipp Wich
Check if `-D_FORTIFY_SOURCE` was already passed via the CFLAGS environment variable and only add the flag if not already present. Fixes: ea046bd ("build: enable source fortification by default") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-01lib: enforce consistent `index()` behavior with empty needle argumentJo-Philipp Wich
On macOS, the `memmem()` function returns `NULL` instead of the expected start of the haystack string when given a zero-length needle argument. Add special case handling for a zero-length needle argument to ensure that the expected offset `0` is returned on all systems. Ref: #176 Suggested-by: Erwan MAS <erwan@mas.nom.fr> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-01nl80211: fix maybe uninitialized variableJo-Philipp Wich
When compiling with optimizations, gcc reports: .../nl80211.c: In function ‘uc_nl_convert_rta_vht_mcs’: .../nl80211.c:1310:31: error: ‘max_idx’ may be used uninitialized [-Werror=maybe-uninitialized] 1310 | for (j = 0; j <= max_idx; j++) | ~~^~~~~~~~~~ Slightly refactor the code to avoid this issue. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-01vm: fix unused result warningJo-Philipp Wich
When building against glibc with enabled source fortification, gcc reports the following issue: .../vm.c: In function ‘uc_vm_signal_raise’: .../vm.c:3161:9: error: ignoring return value of ‘write’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result] 3161 | write(vm->signal.sigpipe[1], &signum, sizeof(signum)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Since we cannot do any meaningful handling of a potential write error in the affected signal handler context, simply solve this issue by wrapping the `write()` call into an empty `if ()` statement. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-11-01build: enable source fortification by defaultJo-Philipp Wich
Also switch debug builds to -Og instead of -O0 in order to make -D_FORTIFY_SOURCE=2 effective for debug builds. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-19jsdoc: switch to own custom themeJo-Philipp Wich
Switch to a custom fork of the clean jsdoc theme to address a number of quirks and to directly incorporate CSS and markup changes. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-17jsdoc: properly handle indented documentation blocksJo-Philipp Wich
Fix the jsdoc C transpiler plugin to properly detect the start of indented multi line comment blocks. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-12lib: add/improve documentation for require(), loadfile(), loadstring()Jo-Philipp Wich
Add missing documentation for the `require()` function and factor our the description of the compile options dictionary into a separate typedef. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-11uci: fix potential memory leaks in `configs()`Jo-Philipp Wich
In case `uci.cursor.configs()` is invoked with a completely empty configuration directory, the empty configuration list is not free before returning the `UCI_ERR_NOTFOUND` status. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-11Merge pull request #175 from jow-/docs-improvementsJo-Philipp Wich
Various documentation improvements
2023-10-11ci: re-trigger workflows on pull request pushesJo-Philipp Wich
Re-trigger workflow runs for pull requests if the source branch is amended or force pushed. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-11lib: various documentation fixesJo-Philipp Wich
- Consistently use nullable instead of `type|null` expressions - Use @borrows to reduce some duplicated documentation blocks - Add typedef for timelocal()/timegm() TimeSpec value Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-11uci: add module documentationJo-Philipp Wich
Add complete JSDoc documentation coverage for the uci module. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-11docs: use CSS and local JavaScript fixups to improve formattingJo-Philipp Wich
- Reduced margins - Better visual separation of method descriptions - Improved display of argument and return value attributes - Improved display of object and array type descriptions - Shortened absolute module name paths The local JavaScript fixups are a stop-gap measure for now, in the long it likely makes more sense to fork the used JSDoc theme to apply the desired changes directly to the markup. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-10Merge pull request #174 from jow-/log-libJo-Philipp Wich
lib: introduce log library
2023-10-10lib: introduce log libraryJo-Philipp Wich
Introduce a new `log` library which provides bindings for syslog and, if available, the OpenWrt libubox ulog functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-10build: auto-enable module depending on present librariesJo-Philipp Wich
Decide based upon the found libraries whether to enable certain, OpenWrt specific modules by default. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-10build: convert CMakeLists.txt into lowercaseJo-Philipp Wich
Convert cmake directives into lowercase notation for better readability. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-09Merge pull request #173 from nbd168/misc-fixesJo-Philipp Wich
Misc fixes
2023-10-09ci: don't skip pull request workflows for `master` branchJo-Philipp Wich
We want pull request workflows to run, even if the source branch happens to be `master` from a forked repository. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-10-09include: fix execvpe compat function on macOSFelix Fietkau
Accept char * const *, cast internally. Fixes a compile error Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-10-09uloop: rename environ variable to avoid clashing with system macro on macOSFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-10-09types: ensure double serializatiion with decimal placesJo-Philipp Wich
The `%g` printf format used for serializing double values into strings will not include any decimal place if the value happens to be integral, leading to an unwanted double to integer conversion when serializing and subsequently deserializing an integral double value as JSON. Solve this issue by checking the serialized string result for a decimal point or exponential notation and appending `.0` if neither is found. Ref: #173 Suggested-by: Felix Fietkau <nbd@nbd.name> Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-09-25Merge pull request #171 from pktpls/rtnl-netnsidJo-Philipp Wich
rtnl: add IFLA_IF_NETNSID for operating in other namespaces
2023-09-22rtnl: update the link attr TODOsPacket Please
Signed-off-by: Packet Please <pktpls@systemli.org>
2023-09-22rtnl: add IFLA_TARGET_NETNSID for operating in other namespacesPacket Please
Signed-off-by: Packet Please <pktpls@systemli.org>
2023-09-11lib: fix documented return value for `splice()`Jo-Philipp Wich
Make the `splice()` documentation match the actual implementation. Fixes: #170 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-23Merge pull request #169 from jow-/docs-improvementsJo-Philipp Wich
Documentation improvements
2023-08-23docs: add struct module documentationJo-Philipp Wich
Add full documentation coverage for the struct module by utilizing large parts of the Python struct module documentation for the format string description. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-23docs: add missing headline to debug module documentationJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>