summaryrefslogtreecommitdiffhomepage
path: root/lib
AgeCommit message (Collapse)Author
2024-07-11nl80211: support the MAC80211_HWSIM netlink protocol familyJo-Philipp Wich
The mac80211_hwsim module exposes a custom generic netlink family for managing simulated phys and userspace data frame transmission. Since hwsim functionality is closely related to nl80211 and useful to e.g. manage simulated wireless testbeds, I decided to include support directly into the nl80211 module. Example calls for creating and destroying hwsim wiphys: nl80211.request(nl80211.const.HWSIM_CMD_NEW_RADIO, 0, { perm_addr: "02:11:22:33:44:55", support_p2p_device: true }); nl80211.request(nl80211.const.HWSIM_CMD_DEL_RADIO, 0, { radio_name: "phy2" }); Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-07-11nl80211: drop unused structure members from connection contextJo-Philipp Wich
The `nlctrl` and `nl80211` family pointers were never used, so drop them from the connection context structure. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-07-11nl80211: support conversion from/to struct array attributesJo-Philipp Wich
Some netlink attributes, e.g. `HWSIM_ATTR_TX_INFO` contain arrays of structures. In order to cover this use-case, extend the ucode <-> nla conversion routines to support `DT_NESTED` declaration in conjunction with `DF_ARRAY`. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-07-11nl80211: gracefully handle illegal netlink error codeJo-Philipp Wich
Some generic netlink commands, e.g. `HWSIM_CMD_NEW_RADIO` might reply with a bogus netlink error message containing a positive error code, leading to an infinite loop in `uc_nl_request()`. Gracefully deal with such occurrences by remapping the error code to `NLE_RANGE` with a custom message. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-07-09nl80211: add wiphy multi-radio supportFelix Fietkau
Support new attributes that describe multiple radios belonging to a single wiphy. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-07-07nl80211: add support for multi-attribute arraysFelix Fietkau
For newly added attributes, the kernel prefers to no longer add a nesting container attribute. Instead, an attribute with the element type is simply added multiple times within the outer container. Add support for this array style, which will be used in the pending wiphy multi radio support. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-07-07nl80211: move access to tb array out of uc_nl_convert_attr and belowFelix Fietkau
Only one place needs access to another attribute from the tb array (HE MCS rates). In order to make that access possible, add a flag to indicate a second attribute dependency via auxdata. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-06-18Merge pull request #204 from f00b4r0/zlibJo-Philipp Wich
2024-06-18lib: introduce zlib libraryThibaut VARÈNE
Introduce a new "zlib" library which provides simplified bindings for zlib inflate/deflate operations. Signed-off-by: Thibaut VARÈNE <hacks@slashdirt.org>
2024-06-17fs: add lock() file methodFelix Fietkau
Implements file based locking on a given file handle. Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-06-17fs: add truncate() file methodFelix Fietkau
Trunates the file referenced by a file handle Signed-off-by: Felix Fietkau <nbd@nbd.name>
2024-05-21socket: implement recvmsg(), sendmsg() and cmsg supportJo-Philipp Wich
Implement socket.recvmsg(), socket.sendmsg() and support for encoding and decoding well known control message types. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: add IPv6 socket optionsJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: handle further socket option value typesJo-Philipp Wich
- Handle varying integer sizes for socket option values - Support interfaces name and index option values Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: improve uc_socket_listen() behaviorJo-Philipp Wich
- Treat address string values containing slashes as AF_UNIX addresses - Default to SOCK_DGRAM for non AF_INET, AF_INET6 sockets - Gracefully handle EOPNOTSUPP condition after listen() call Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: improve uc_socket_connect() behaviorJo-Philipp Wich
Treat address strings containing slashes as AF_UNIX paths and do not attempt to resolve them. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: support IPv6 addresses in struct conversion routinesJo-Philipp Wich
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: uv_to_sockaddr(): fix length calculation for AF_UNIX addressesJo-Philipp Wich
Do not attempt to calculate a dynamic length for AF_UNIX socket addresses but return the total size of `struct sockaddr_un`, like we do it for the structures of other address families as well. Fixes incorrect domain socket path truncation. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-17socket: remove wrong documentation fragmentJo-Philipp Wich
Remove an accidentially copy-pasted jsdoc comment block. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-14socket: optimize poll() argument handlingJo-Philipp Wich
Optimize the poll() function implementation to re-use passed in socket/flag tuple arrays as-is in the return value array, which simplifies attaching state to sockets for user code through subsequent fields in the tuple array. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-13socket: fix potential memory leak in connect()Jo-Philipp Wich
If a non-string value which cannot be interpreted as socket address structure is passed to connect(), the function will leak the internal address vector when returning the error. Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-09socket: fix addrinfo() with omitted service argumentJo-Philipp Wich
Actually pass NULL to getaddrinfo() when the service argument is omitted, instead of incorrectly translating it to a string containing "null". Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-08socket: remove leftover debug codeJo-Philipp Wich
Fixes: 0662de6 ("socket: add AF_PACKET socket type support") Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-08socket: add AF_PACKET socket type supportJo-Philipp Wich
Add the required infrastructure to support Linux AF_PACKET sockets: - Add related constants - Add struct definitions for SOL_PACKET socket options - Add AF_PACKET family support to sockaddr routines Signed-off-by: Jo-Philipp Wich <jo@mein.io>
2024-05-02ubus: fix uc_ubus_have_uloop for eloop+uloop combinationFelix Fietkau
When uloop has been integrated with eloop (in hostapd/wpa_supplicant), uloop_cancelling will return false, since uloop_run is not being called. This leads to ubus.defer() calling uloop_run in a context where it can prevent the other event loop from running. Fix this by detecting event loop integration via uloop_fd_set_cb being set Signed-off-by: Felix Fietkau <nbd@nbd.name>
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>