ubus: increase message size limit and make it configurable at build-time

This commit is contained in:
Alexandru Ardelean 2014-06-27 19:11:40 +03:00 committed by Felix Fietkau
parent 7e746e5a85
commit 6d24ad71f6
5 changed files with 16 additions and 2 deletions

View file

@ -9,8 +9,10 @@ OPTION(ENABLE_SYSTEMD "systemd support" ON)
SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "") SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS "")
SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock") SET(UBUS_UNIX_SOCKET "/var/run/ubus.sock")
SET(UBUS_MAX_MSGLEN 1048576)
ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}") ADD_DEFINITIONS( -DUBUS_UNIX_SOCKET="${UBUS_UNIX_SOCKET}")
ADD_DEFINITIONS( -DUBUS_MAX_MSGLEN=${UBUS_MAX_MSGLEN})
IF(APPLE) IF(APPLE)
INCLUDE_DIRECTORIES(/opt/local/include) INCLUDE_DIRECTORIES(/opt/local/include)

View file

@ -233,6 +233,7 @@ static bool get_next_msg(struct ubus_context *ctx, int *recv_fd)
struct blob_attr data; struct blob_attr data;
} hdrbuf; } hdrbuf;
struct iovec iov = STATIC_IOV(hdrbuf); struct iovec iov = STATIC_IOV(hdrbuf);
int len;
int r; int r;
/* receive header + start attribute */ /* 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)) if (!ubus_validate_hdr(&hdrbuf.hdr))
return false; 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.hdr, &hdrbuf.hdr, sizeof(hdrbuf.hdr));
memcpy(ctx->msgbuf.data, &hdrbuf.data, sizeof(hdrbuf.data)); memcpy(ctx->msgbuf.data, &hdrbuf.data, sizeof(hdrbuf.data));

View file

@ -280,9 +280,10 @@ static int _ubus_connect(struct ubus_context *ctx, const char *path)
ctx->connection_lost = ubus_default_connection_lost; ctx->connection_lost = ubus_default_connection_lost;
ctx->pending_timer.cb = ubus_process_pending_msg; 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) if (!ctx->msgbuf.data)
return -1; return -1;
ctx->msgbuf_data_len = UBUS_MSG_CHUNK_SIZE;
INIT_LIST_HEAD(&ctx->requests); INIT_LIST_HEAD(&ctx->requests);
INIT_LIST_HEAD(&ctx->pending); INIT_LIST_HEAD(&ctx->pending);

View file

@ -155,6 +155,7 @@ struct ubus_context {
void (*connection_lost)(struct ubus_context *ctx); void (*connection_lost)(struct ubus_context *ctx);
struct ubus_msghdr_buf msgbuf; struct ubus_msghdr_buf msgbuf;
uint32_t msgbuf_data_len;
}; };
struct ubus_object_data { struct ubus_object_data {

View file

@ -19,7 +19,7 @@
#define __packetdata __attribute__((packed)) __attribute__((__aligned__(4))) #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_EVENT 1
#define UBUS_SYSTEM_OBJECT_MAX 1024 #define UBUS_SYSTEM_OBJECT_MAX 1024