Commit graph

191 commits

Author SHA1 Message Date
Alexandru Ardelean
af63ab64af ubus: add count test to validate large message sizes
Client creates a string "1 2 3 ... 10000 ...", sends it to the server
along with the maximum number in the string.

Server creates another string like the client sent.

It validates it and, returns strcmp()'s result.

This is loop-ed every 2 seconds.
2014-07-03 12:47:11 +02:00
Alexandru Ardelean
f47005a44c libubus: fix ubus_invoke() to return err in case ubus_start_request() fails
Seems the UBUS_MAX_MSGLEN is ignored by ubus_invoke(),
and then segfault happens.

This issue is present before this set of patches.
2014-07-03 12:46:44 +02:00
Alexandru Ardelean
996e16b2cb ubusd: replace ubusd_msg_unshare() with ubus_msg_new() to prevent invalid free-ing
The realloc is problematic mostly with large packets, as the pointer changes
so what eventually gets free'd is invalid.
Note that ub ptr param in the  call will be passed on to a ubus_msg_free(),
right after ubus_msg_ref() finishes.

This bug stayed hidden the same way as the bug in libubus writev_retry().
Since the write/sendmsg function can send about ~200k the ubus_msg_enqueue()
call does not get triggered.
2014-07-03 12:45:49 +02:00
Alexandru Ardelean
5db90dbc94 libubus: fix writev_retry() function when writing large packets
Seems this bug stayed hidden for a while, because the write/sendmsg function
can send up to ~200k in one send, so it looked at first why there was
some data mismatch.
2014-07-03 12:45:30 +02:00
Alexandru Ardelean
82da9db3a9 libubus: add logic to reduce msgbuf data size after 16 small messages 2014-07-03 12:45:13 +02:00
Alexandru Ardelean
6d24ad71f6 ubus: increase message size limit and make it configurable at build-time 2014-07-03 12:44:19 +02:00
Alexandru Ardelean
7e746e5a85 libubus: refactor ubus_context msgbuf data to be dynamically allocated 2014-07-03 12:42:42 +02:00
Felix Fietkau
3869e0ca07 libubus: fix deferring invoke processing for non-uloop usage
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-06-25 10:24:27 +02:00
Felix Fietkau
bbd3fbc9cc libubus: always defer processing incoming invoke/unsubscribe/notify if there is a request pending
This fixes recursion problems on config reload in netifd and simplifies
application handling of requests

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-06-24 22:34:53 +02:00
Felix Fietkau
9fda19140e cli: implement wait_for
Allows waiting for one or more objects to appear
Returns instantly if objects are already present

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-05-06 16:58:11 +02:00
Steven Barth
6dffecb36b lua: forward return codes from lua to ubus
Signed-off-by: Steven Barth <cyrus@openwrt.org>
Tested-by: Luka Perkov <luka@openwrt.org>
2014-05-05 19:56:31 +02:00
Felix Fietkau
2c71017cfb libubus: add support for defining a policy mask
This allows sharing a policy array across methods, but masking out
unused entries for individual methods.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-04-27 00:40:25 +02:00
Felix Fietkau
7c9e76ed08 ubusd: fix processing object method signatures
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-04-01 13:45:29 +02:00
Felix Fietkau
1d5ac421a5 libubus: do not use uloop_run() inside ubus_complete_request
Avoid unrelated uloop callbacks by using poll() on the ubus fd instead.

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-18 22:36:38 +01:00
Felix Fietkau
4d7b2ab639 libubus-internal: use the __hidden definition from libubox
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-03-18 22:12:21 +01:00
Felix Fietkau
8f3c5a7b50 libubus: close file descriptor after passing it in the status msg
Simplifies handling of non-deferred requests

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-27 16:48:55 +01:00
Karl Vogel
334c389180 ubus: Fix imbalance in lua stack push/pop of values.
The lua getglobal and rawgeti both push a value onto the lua stack,
but they weren't being removed by the ubus_method_handler function,
thus corrupting the lua stack.

In case the specified method wasn't a function, the stack was also
corrupted as the method name remained on the stack.

Signed-off-by: Karl Vogel <karl.vogel@gmail.com>
2014-02-23 18:20:29 +01:00
Felix Fietkau
54926994e2 examples/client: receive data from the passed file descriptor
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Felix Fietkau
85dff762f9 examples/server: send a file descriptor as part of the request to the "hello" method
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Felix Fietkau
47a9ab0c64 libubus: implement file descriptor passing support
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Felix Fietkau
37cc5d2f25 ubusd: implement protocol support for passing file descriptors as part of request completion msgs from objects to clients
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2014-02-18 15:03:53 +01:00
Luka Perkov
4e82a1fabb lua: allow methods with no arguments
In C it is possible to have methods without arguments (UBUS_METHOD_NOARG).
Enable support for the same calls in Lua too.

This commit also fixes segfault which can be caused by passing non-table type
where table is expected. The lua_gettablelen() function is called after we have
made sure we are dealing with a table in the first place.

Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-28 22:20:30 +00:00
Luka Perkov
b356773921 lua: fix whitespaces and typo
Signed-off-by: Luka Perkov <luka@openwrt.org>
2014-01-28 22:20:26 +00:00
John Crispin
29d7092252 add auto (re)connect logic to libubus
Signed-off-by: John Crispin <blogic@openwrt.org>
2014-01-22 13:53:11 +00:00
John Crispin
8ea9667036 add Lua bindings for ubus events
It mostly mimick the style of the existing code.

With it and the ubox Lua bindings, you can now send ubus events
through Lua or listen for events (you can register for multiple events
at the same time).

Signed-off-by: Jeff Remy <jeff.remy@gmail.com>
2013-11-07 16:23:30 +01:00
Felix Fietkau
a9ee3ef0cf libubus: pull the variable length data array out of struct ubus_msghdr to fix builds with clang
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-10-29 17:28:37 +01:00
Jo-Philipp Wich
6ae17d0298 ubusd: use umask of 0177 for now to prevent a world- and group-writable unix socket 2013-09-28 17:23:29 +02:00
Lukasz Baj
d486006ab9 libubus: Check if remove callback exists before call it
When process unsubscribes then remove callback is called. But it
can be NULL if not defined, so we should check it before we call it.

Signed-off-by: Lukasz Baj <l.baj@radytek.com>
2013-08-29 20:35:38 +02:00
Felix Fietkau
b20a8a01c7 libubus: detect read/write errors and set the eof flag, even if uloop is not used as main event loop
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-08-08 22:42:50 +02:00
Felix Fietkau
62bfc16a09 libubus: fix publishing objects after reconnect
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-08-08 22:20:39 +02:00
Yousong Zhou
2b4fc4c916 Add a return value to make compiler silent.
Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2013-08-04 10:53:36 +02:00
Yousong Zhou
cca7fb2ab1 Fix the condition for stopping the writev_retry.
All iov's were sent only after the last were sent (iov_len == 0). We
could have 'cur_len == 0' if the sent iov's were sent wholly but not all
iov's were sent (how about all but the last).

Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com>
2013-08-04 10:53:24 +02:00
Felix Fietkau
f72dca720b libubus: fix logic inversion for cancelling requests
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-05-30 12:39:51 +02:00
Felix Fietkau
9f52d1769b cli: use the new json-c library name
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-05-29 12:53:22 +02:00
Felix Fietkau
dd3afa517d libubus: fix deadlock in recursive synchronous ubus requests
When synchronous request completion loops are running, the innermost
loop can receive events that can unblock the outer loops, however the
loop clears uloop_cancelled (which is set by the request completion).

This causes the event loop to continue running even while a completion
loop has already been unblocked.

Fix this by not clearing uloop_cancelled for inner loops

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-05-11 20:39:54 +02:00
Felix Fietkau
90037b772c libubus: fix crash on reconnect with objects that have no type
Signed-off-by: John Crispin <blogic@openwrt.org>
2013-04-04 22:03:24 +02:00
Felix Fietkau
47b38c98ae libubus: fix passing the return code of the subscriber callback to the notifier
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-03-17 18:29:38 +01:00
Felix Fietkau
460301e62d libubus: fix synchronous ubus_notify without waiting for a timeout
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-03-17 17:55:11 +01:00
Felix Fietkau
3b66d054cc libubus: add ubus_unregister_subscriber wrapper
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-03-17 03:11:35 +01:00
Felix Fietkau
495f460818 libubus: add UBUS_METHOD_NOARG
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-03-06 16:56:33 +01:00
Thomas Gstädtner
62cdfc3d16 add systemd support
This adds basic systemd support, incl. socket activation.
If systemd build is disabled, there won't be any sign of it neither
during build nor after.
If systemd build is enabled (default), but systemd is not available,
no systemd stuff is installed, so there is no impact whatsoever.
2013-03-04 19:11:21 +01:00
Thomas Gstädtner
29a2ed2f17 make UBUS_UNIX_SOCKET configurable via cmake
this is mainly useful to have a single location to read the setting
from, when it is used multiple times at build time (which it will in a
following patch) :)
2013-03-04 19:11:15 +01:00
Thomas Gstädtner
a15a09aed4 add INCLUDE_DIRECTORIES to subdirectories 2013-03-03 03:43:22 +01:00
Thomas Gstädtner
80d64827e9 make building examples an option 2013-03-03 03:43:06 +01:00
Felix Fietkau
82713b9d49 build: remove install prefix override
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2013-01-23 15:22:46 +01:00
Jo-Philipp Wich
bf566871bd lua: pass u64 blob type as double to Lua 2013-01-13 20:37:19 +01:00
Felix Fietkau
7c140855d9 libubus: free internal blob_buf memory when freeing an ubus context
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-30 14:14:22 +01:00
Felix Fietkau
bb856ad8a9 examples: disable the message on the server example, measure the notify latency on the client example
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-15 16:52:03 +01:00
Felix Fietkau
3642af8097 libubus: fix data type of request sequence counter. fixes hang after ~64K requests
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-15 16:51:28 +01:00
Felix Fietkau
4b9ed896cf libubus: fix uninitialized variable warning
Signed-off-by: Felix Fietkau <nbd@openwrt.org>
2012-12-15 14:11:15 +01:00