summaryrefslogtreecommitdiffhomepage
path: root/lib
AgeCommit message (Collapse)Author
2024-04-25Merge pull request #197 from jow-/docs-add-uloopJo-Philipp Wich
uloop: add documentation
2024-04-25socket: make socket.send() accept non-string dataJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-04-25uloop: add documentationJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-04-24socket: rework error handlingJo-Philipp Wich
- fix `error()` function documentation - change error message format order to `msg: strerror` - change `xxx() failed` messages to just `xxx()` Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-04-24lib: introduce socket libraryJo-Philipp Wich
Introduce a new socket module which provides bindings for the BSD sockets API to ucode scripts. Example usage: import * as socket from 'socket'; let sk = socket.create(socket.AF_INET, socket.SOCK_STREAM); sk.connect("192.168.1.1", 80); sk.send("GET / HTTP/1.0\r\n\r\n"); print(sk.recv(4096)); sk.close(); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-04-15uci: remove incorrectly documentated reorder() parameterJo-Philipp Wich
The reorder() function takes no `name` parameter, this was a copy-paste error in the documentation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-04-07ubus: add explicit support for deferring incoming requestsFelix Fietkau
This is needed when asynchronously processing requests via uloop, e.g. using uclient. Example script: let libubus = require("ubus"); let uloop = require("uloop"); uloop.init(); let ubus = libubus.connect(); ubus.publish("test", { test: { call: function(req) { req.defer(); uloop.timer(1000, () => { req.reply({ msg: "Hello, world!" }, 0); }); }, args: {} }, }); uloop.run(); uloop.done(); Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-02-21uloop: automatically clear error informationJo-Philipp Wich
Make all functions clear the last error information on success in order to ensure that `error()` never reports stale information. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-21uci: automatically clear error informationJo-Philipp Wich
Make all functions clear the last error information on success in order to ensure that `error()` never reports stale information. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-02-21ubus: automatically clear error informationJo-Philipp Wich
Make all functions clear the last error information on success in order to ensure that `error()` never reports stale information. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
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-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-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-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-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-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-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-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-09uloop: rename environ variable to avoid clashing with system macro on macOSFelix Fietkau
Signed-off-by: Felix Fietkau <nbd@nbd.name>
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-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>
2023-08-09lib: introduce debug libraryJo-Philipp Wich
Introduce a new debug library which provides introspection facilities for debugging ucode scripts. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-08-09treewide: consolidate platform specific code in platform.cJo-Philipp Wich
Get rid of most __APPLE__ guards by introducing a central platform.c unit providing drop-in replacements for missing APIs. Also move system signal definitions into the new platform file to be able to share them with the upcoming debug library. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-27uloop: interrupt on VM signalsJo-Philipp Wich
When the VM instance loading the uloop module has signal dispatching enabled, implicitly register the signal pipe as file descriptor in the global uloop and dispatch received signals to the VM instance. This ensures that the respective managed ucode signal handlers are invoked immediately and not just after `uloop_run()` returns. Also end the uloop in case any invoked signal handler threw an exception, to match the expected behaviour with other kinds of callbacks. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-25fs: explicitly compare isatty() resultJo-Philipp Wich
Reportedly, automatic conversion of the `isatty()` int result value to a bool does not work correctly on PPC. Explicitly compare the result value with `1` to infer the boolean result value. Fixes: #165 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-13Merge pull request #164 from jow-/docs-improvementsJo-Philipp Wich
docs: various improvements
2023-07-13docs: various improvementsJo-Philipp Wich
- Switch JSDoc theme to "clean-jsdoc-theme" - Add some custom CSS and JS tweaks to the theme - Use a condensed README.md for the toplevel directory - Include a longer README.md in the documentation portal - Tweak JSDoc annotations for better output results - Register `ucode.mein.io` CNAME Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-12Merge pull request #163 from jow-/docs-improvementsJo-Philipp Wich
fs: complete function documentation coverage
2023-07-12fs: use `fseeko()` and `ftello()`Jo-Philipp Wich
Use `fseeko()` and `ftello()` instead of `fseek()` and `ftell()` respectively in order to be able to deal with large file offsets. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-12fs: complete function documentation coverageJo-Philipp Wich
Add missing function documentation and return value annotations. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-12fs: add JSDoc documentationJo-Philipp Wich
Add JSDoc documentation blocks to all exported filesystem functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-07-12math: add JSDoc documentationJo-Philipp Wich
Add JSDoc documentation blocks to all exported math functions. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-06-05nl80211: add constants for iftypesFelix Fietkau
Useful for adding/removing interfaces Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-05-27ubus: add support for strings containing null bytesFelix Fietkau
When converting ucode strings to blobmsg, use blobmsg_add_field in order to explicltly pass the length of the data. In the other direction, use ucv_string_new_length based on the attribute length. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-05-27struct: remove state->lenFelix Fietkau
It is unused and I couldn't find any purpose for it Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-04-03uci: fix ctx.commit() without argumentsJo-Philipp Wich
A uci commit operation may invalidate the package pointer, leading to an infinite loop while iterating the packages to commit. Refactor the code to first build a string list of configurations, then iterating it in order to avoid the iterator invalidation. While we're at it, also allow restricting save and revert operations to single configs, which was rejected as invalid before. Fixes: #146 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-03-17ubus: support multiple call return valuesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2023-02-13rtnl: add missing uc_vm_registry_set callFelix Fietkau
Fixes maintaining the listener array Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-02-13rtnl: add missing ucv_get() callsFelix Fietkau
Arguments stored in the registry need an extra reference Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-02-13nl80211: add missing ucv_get() callsFelix Fietkau
Arguments stored in the registry need an extra reference Signed-off-by: Felix Fietkau <nbd@nbd.name>
2023-02-12nl80211: fix NL80211_ATTR_SURVEY_INFOAndre Heider
This is the last attribute, adapt .nattr to include it so it gets parsed. Signed-off-by: Andre Heider <a.heider@gmail.com>