[OpenWrt-Devel] [PATCH 2/7] ubus: increase message size limit and make it configurable at build-time
Alexandru Ardelean
ardeleanalex at gmail.com
Fri Jun 27 12:11:40 EDT 2014
---
CMakeLists.txt | 2 ++
libubus-io.c | 10 ++++++++++
libubus.c | 3 ++-
libubus.h | 1 +
ubusmsg.h | 2 +-
5 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index e3b150b..cb2f420 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -9,8 +9,10 @@ OPTION(ENABLE_SYSTEMD "systemd support" ON)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
+SET(UBUS_MAX_MSGLEN 1048576)
ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}")
+ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN})
IF(APPLE)
INCLUDE_DIRECTORIES(/opt/local/include)
diff --git a/libubus-io.c b/libubus-io.c
index c63a920..48bb72d 100644
--- a/libubus-io.c
+++ b/libubus-io.c
@@ -233,6 +233,7 @@ static bool get_next_msg(struct ubus_context *ctx, int *recv_fd)
struct blob_attr data;
} hdrbuf;
struct iovec iov = STATIC_IOV(hdrbuf);
+ int len;
int r;
/* receive header + start attribute */
@@ -247,6 +248,15 @@ static bool get_next_msg(struct ubus_context *ctx, int *recv_fd)
if (!ubus_validate_hdr(&hdrbuf.hdr))
return false;
+ len = blob_raw_len(&hdrbuf.data);
+ if (len > ctx->msgbuf_data_len) {
+ ctx->msgbuf.data = realloc(ctx->msgbuf.data, len * sizeof(char));
+ if (ctx->msgbuf.data)
+ ctx->msgbuf_data_len = len;
+ }
+ if (!ctx->msgbuf.data)
+ return false;
+
memcpy(&ctx->msgbuf.hdr, &hdrbuf.hdr, sizeof(hdrbuf.hdr));
memcpy(ctx->msgbuf.data, &hdrbuf.data, sizeof(hdrbuf.data));
diff --git a/libubus.c b/libubus.c
index 83a2c43..be4e6ac 100644
--- a/libubus.c
+++ b/libubus.c
@@ -280,9 +280,10 @@ static int _ubus_connect(struct ubus_context *ctx, const char *path)
ctx->connection_lost = ubus_default_connection_lost;
ctx->pending_timer.cb = ubus_process_pending_msg;
- ctx->msgbuf.data = calloc(UBUS_MAX_MSGLEN, sizeof(char));
+ ctx->msgbuf.data = calloc(UBUS_MSG_CHUNK_SIZE, sizeof(char));
if (!ctx->msgbuf.data)
return -1;
+ ctx->msgbuf_data_len = UBUS_MSG_CHUNK_SIZE;
INIT_LIST_HEAD(&ctx->requests);
INIT_LIST_HEAD(&ctx->pending);
diff --git a/libubus.h b/libubus.h
index 33a99aa..78ffa38 100644
--- a/libubus.h
+++ b/libubus.h
@@ -155,6 +155,7 @@ struct ubus_context {
void (*connection_lost)(struct ubus_context *ctx);
struct ubus_msghdr_buf msgbuf;
+ uint32_t msgbuf_data_len;
};
struct ubus_object_data {
diff --git a/ubusmsg.h b/ubusmsg.h
index c9b92e7..0a27b42 100644
--- a/ubusmsg.h
+++ b/ubusmsg.h
@@ -19,7 +19,7 @@
#define __packetdata __attribute__((packed)) __attribute__((__aligned__(4)))
-#define UBUS_MAX_MSGLEN 65536
+#define UBUS_MSG_CHUNK_SIZE 65536
#define UBUS_SYSTEM_OBJECT_EVENT 1
#define UBUS_SYSTEM_OBJECT_MAX 1024
--
1.8.4.5
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list