2 * Copyright (C) 2011 Felix Fietkau <nbd@openwrt.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2.1
6 * as published by the Free Software Foundation
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
14 #include <sys/types.h>
16 #include <sys/socket.h>
20 #include <libubox/blob.h>
21 #include <libubox/blobmsg.h>
22 #include <libubox/usock.h>
27 #define STATIC_IOV(_var) { .iov_base = (char *) &(_var), .iov_len = sizeof(_var) }
29 const char *__ubus_strerror
[__UBUS_STATUS_LAST
] = {
30 [UBUS_STATUS_OK
] = "Success",
31 [UBUS_STATUS_INVALID_COMMAND
] = "Invalid command",
32 [UBUS_STATUS_INVALID_ARGUMENT
] = "Invalid argument",
33 [UBUS_STATUS_METHOD_NOT_FOUND
] = "Method not found",
34 [UBUS_STATUS_NOT_FOUND
] = "Not found",
35 [UBUS_STATUS_NO_DATA
] = "No response",
36 [UBUS_STATUS_PERMISSION_DENIED
] = "Permission denied",
37 [UBUS_STATUS_TIMEOUT
] = "Request timed out",
38 [UBUS_STATUS_NOT_SUPPORTED
] = "Operation not supported",
39 [UBUS_STATUS_UNKNOWN_ERROR
] = "Unknown error",
42 static struct blob_buf b
;
44 static const struct blob_attr_info ubus_policy
[UBUS_ATTR_MAX
] = {
45 [UBUS_ATTR_STATUS
] = { .type
= BLOB_ATTR_INT32
},
46 [UBUS_ATTR_OBJID
] = { .type
= BLOB_ATTR_INT32
},
47 [UBUS_ATTR_OBJPATH
] = { .type
= BLOB_ATTR_STRING
},
48 [UBUS_ATTR_METHOD
] = { .type
= BLOB_ATTR_STRING
},
50 static struct blob_attr
*attrbuf
[UBUS_ATTR_MAX
];
52 struct ubus_pending_data
{
53 struct list_head list
;
55 struct blob_attr data
[];
58 static int ubus_cmp_id(const void *k1
, const void *k2
, void *ptr
)
60 const uint32_t *id1
= k1
, *id2
= k2
;
68 static struct blob_attr
**ubus_parse_msg(struct blob_attr
*msg
)
70 blob_parse(msg
, attrbuf
, ubus_policy
, UBUS_ATTR_MAX
);
74 const char *ubus_strerror(int error
)
78 if (error
< 0 || error
>= __UBUS_STATUS_LAST
)
81 if (!__ubus_strerror
[error
])
84 return __ubus_strerror
[error
];
87 sprintf(err
, "Unknown error: %d", error
);
91 static int writev_retry(int fd
, struct iovec
*iov
, int iov_len
)
96 int cur_len
= writev(fd
, iov
, iov_len
);
100 /* turn off non-blocking mode */
101 fcntl(fd
, F_SETFL
, fcntl(fd
, F_GETFL
) &
112 while (cur_len
>= iov
->iov_len
) {
113 cur_len
-= iov
->iov_len
;
116 if (!cur_len
|| !iov_len
)
119 iov
->iov_len
-= cur_len
;
123 static int ubus_send_msg(struct ubus_context
*ctx
, uint32_t seq
,
124 struct blob_attr
*msg
, int cmd
, uint32_t peer
)
126 struct ubus_msghdr hdr
;
127 struct iovec iov
[2] = {
137 blob_buf_init(&b
, 0);
141 iov
[1].iov_base
= (char *) msg
;
142 iov
[1].iov_len
= blob_raw_len(msg
);
144 return writev_retry(ctx
->sock
.fd
, iov
, ARRAY_SIZE(iov
));
147 static int ubus_start_request(struct ubus_context
*ctx
, struct ubus_request
*req
,
148 struct blob_attr
*msg
, int cmd
, uint32_t peer
)
150 memset(req
, 0, sizeof(*req
));
152 if (msg
&& blob_pad_len(msg
) > UBUS_MAX_MSGLEN
)
155 INIT_LIST_HEAD(&req
->list
);
156 INIT_LIST_HEAD(&req
->pending
);
159 req
->seq
= ++ctx
->request_seq
;
160 return ubus_send_msg(ctx
, req
->seq
, msg
, cmd
, peer
);
163 static bool recv_retry(int fd
, struct iovec
*iov
, bool wait
)
167 while (iov
->iov_len
> 0) {
168 bytes
= read(fd
, iov
->iov_base
, iov
->iov_len
);
183 iov
->iov_len
-= bytes
;
184 iov
->iov_base
+= bytes
;
190 static bool ubus_validate_hdr(struct ubus_msghdr
*hdr
)
192 if (hdr
->version
!= 0)
195 if (blob_raw_len(hdr
->data
) < sizeof(*hdr
->data
))
198 if (blob_pad_len(hdr
->data
) > UBUS_MAX_MSGLEN
)
204 static bool get_next_msg(struct ubus_context
*ctx
)
206 struct iovec iov
= STATIC_IOV(ctx
->msgbuf
.hdr
);
208 /* receive header + start attribute */
209 iov
.iov_len
+= sizeof(struct blob_attr
);
210 if (!recv_retry(ctx
->sock
.fd
, &iov
, false))
213 iov
.iov_len
= blob_len(ctx
->msgbuf
.hdr
.data
);
214 if (iov
.iov_len
> 0 && !recv_retry(ctx
->sock
.fd
, &iov
, true))
217 return ubus_validate_hdr(&ctx
->msgbuf
.hdr
);
220 static bool ubus_get_status(struct ubus_msghdr
*hdr
, int *ret
)
222 ubus_parse_msg(hdr
->data
);
224 if (!attrbuf
[UBUS_ATTR_STATUS
])
227 *ret
= blob_get_u32(attrbuf
[UBUS_ATTR_STATUS
]);
231 static void req_data_cb(struct ubus_request
*req
, int type
, struct blob_attr
*data
)
233 struct blob_attr
**attr
;
235 if (req
->raw_data_cb
)
236 req
->raw_data_cb(req
, type
, data
);
241 attr
= ubus_parse_msg(data
);
242 req
->data_cb(req
, type
, attr
[UBUS_ATTR_DATA
]);
245 static void ubus_process_req_data(struct ubus_request
*req
)
247 struct ubus_pending_data
*data
;
249 while (!list_empty(&req
->pending
)) {
250 data
= list_first_entry(&req
->pending
,
251 struct ubus_pending_data
, list
);
252 list_del(&data
->list
);
254 req_data_cb(req
, data
->type
, data
->data
);
259 static void ubus_req_complete_cb(struct ubus_request
*req
)
261 ubus_complete_handler_t cb
= req
->complete_cb
;
266 req
->complete_cb
= NULL
;
267 cb(req
, req
->status_code
);
270 static int ubus_process_req_status(struct ubus_request
*req
, struct ubus_msghdr
*hdr
)
272 int ret
= UBUS_STATUS_INVALID_ARGUMENT
;
274 if (!list_empty(&req
->list
))
275 list_del(&req
->list
);
277 ubus_get_status(hdr
, &ret
);
278 req
->peer
= hdr
->peer
;
279 req
->status_msg
= true;
280 req
->status_code
= ret
;
282 ubus_req_complete_cb(req
);
287 static void ubus_req_data(struct ubus_request
*req
, struct ubus_msghdr
*hdr
)
289 struct ubus_pending_data
*data
;
294 req_data_cb(req
, hdr
->type
, hdr
->data
);
295 ubus_process_req_data(req
);
296 req
->blocked
= false;
299 ubus_req_complete_cb(req
);
304 len
= blob_raw_len(hdr
->data
);
305 data
= calloc(1, sizeof(*data
) + len
);
309 data
->type
= hdr
->type
;
310 memcpy(data
->data
, hdr
->data
, len
);
311 list_add(&data
->list
, &req
->pending
);
314 static struct ubus_request
*ubus_find_request(struct ubus_context
*ctx
, uint32_t seq
, uint32_t peer
)
316 struct ubus_request
*req
;
318 list_for_each_entry(req
, &ctx
->requests
, list
) {
319 if (seq
!= req
->seq
|| peer
!= req
->peer
)
327 static void ubus_process_invoke(struct ubus_context
*ctx
, struct ubus_msghdr
*hdr
)
329 struct ubus_request_data req
;
330 struct ubus_object
*obj
;
335 ubus_parse_msg(hdr
->data
);
337 if (!attrbuf
[UBUS_ATTR_OBJID
])
340 objid
= blob_get_u32(attrbuf
[UBUS_ATTR_OBJID
]);
342 if (!attrbuf
[UBUS_ATTR_METHOD
]) {
343 ret
= UBUS_STATUS_INVALID_ARGUMENT
;
347 obj
= avl_find_element(&ctx
->objects
, &objid
, obj
, avl
);
349 ret
= UBUS_STATUS_NOT_FOUND
;
353 for (method
= 0; method
< obj
->n_methods
; method
++)
354 if (!obj
->methods
[method
].name
||
355 !strcmp(obj
->methods
[method
].name
,
356 blob_data(attrbuf
[UBUS_ATTR_METHOD
])))
360 ret
= UBUS_STATUS_METHOD_NOT_FOUND
;
365 req
.peer
= hdr
->peer
;
367 ret
= obj
->methods
[method
].handler(ctx
, obj
, &req
,
368 blob_data(attrbuf
[UBUS_ATTR_METHOD
]),
369 attrbuf
[UBUS_ATTR_DATA
]);
372 blob_buf_init(&b
, 0);
373 blob_put_int32(&b
, UBUS_ATTR_STATUS
, ret
);
374 blob_put_int32(&b
, UBUS_ATTR_OBJID
, objid
);
375 ubus_send_msg(ctx
, hdr
->seq
, b
.head
, UBUS_MSG_STATUS
, hdr
->peer
);
378 static void ubus_process_msg(struct ubus_context
*ctx
, struct ubus_msghdr
*hdr
)
380 struct ubus_request
*req
;
383 case UBUS_MSG_STATUS
:
384 req
= ubus_find_request(ctx
, hdr
->seq
, hdr
->peer
);
388 ubus_process_req_status(req
, hdr
);
392 req
= ubus_find_request(ctx
, hdr
->seq
, hdr
->peer
);
393 if (req
&& (req
->data_cb
|| req
->raw_data_cb
))
394 ubus_req_data(req
, hdr
);
397 case UBUS_MSG_INVOKE
:
398 ubus_process_invoke(ctx
, hdr
);
403 void ubus_abort_request(struct ubus_context
*ctx
, struct ubus_request
*req
)
405 if (!list_empty(&req
->list
))
408 req
->cancelled
= true;
409 ubus_process_req_data(req
);
410 list_del(&req
->list
);
413 void ubus_complete_request_async(struct ubus_context
*ctx
, struct ubus_request
*req
)
415 if (!list_empty(&req
->list
))
418 list_add(&req
->list
, &ctx
->requests
);
421 static void ubus_handle_data(struct uloop_fd
*u
, unsigned int events
)
423 struct ubus_context
*ctx
= container_of(u
, struct ubus_context
, sock
);
424 struct ubus_msghdr
*hdr
= &ctx
->msgbuf
.hdr
;
426 while (get_next_msg(ctx
)) {
427 ubus_process_msg(ctx
, hdr
);
433 ctx
->connection_lost(ctx
);
436 static void ubus_sync_req_cb(struct ubus_request
*req
, int ret
)
438 req
->status_msg
= true;
439 req
->status_code
= ret
;
443 struct ubus_sync_req_cb
{
444 struct uloop_timeout timeout
;
445 struct ubus_request
*req
;
448 static void ubus_sync_req_timeout_cb(struct uloop_timeout
*timeout
)
450 struct ubus_sync_req_cb
*cb
;
452 cb
= container_of(timeout
, struct ubus_sync_req_cb
, timeout
);
453 ubus_sync_req_cb(cb
->req
, UBUS_STATUS_TIMEOUT
);
456 int ubus_complete_request(struct ubus_context
*ctx
, struct ubus_request
*req
,
459 struct ubus_sync_req_cb cb
;
460 ubus_complete_handler_t complete_cb
= req
->complete_cb
;
461 bool registered
= ctx
->sock
.registered
;
462 bool cancelled
= uloop_cancelled
;
463 int status
= UBUS_STATUS_NO_DATA
;
471 memset(&cb
, 0, sizeof(cb
));
473 cb
.timeout
.cb
= ubus_sync_req_timeout_cb
;
474 uloop_timeout_set(&cb
.timeout
, timeout
);
477 ubus_complete_request_async(ctx
, req
);
478 req
->complete_cb
= ubus_sync_req_cb
;
483 uloop_timeout_cancel(&cb
.timeout
);
486 status
= req
->status_code
;
488 req
->complete_cb
= complete_cb
;
489 if (req
->complete_cb
)
490 req
->complete_cb(req
, status
);
492 uloop_cancelled
= cancelled
;
494 uloop_fd_delete(&ctx
->sock
);
499 struct ubus_lookup_request
{
500 struct ubus_request req
;
501 ubus_lookup_handler_t cb
;
504 static void ubus_lookup_cb(struct ubus_request
*ureq
, int type
, struct blob_attr
*msg
)
506 struct ubus_lookup_request
*req
;
507 struct ubus_object_data obj
;
508 struct blob_attr
**attr
;
510 req
= container_of(ureq
, struct ubus_lookup_request
, req
);
511 attr
= ubus_parse_msg(msg
);
513 if (!attr
[UBUS_ATTR_OBJID
] || !attr
[UBUS_ATTR_OBJPATH
] ||
514 !attr
[UBUS_ATTR_OBJTYPE
])
517 memset(&obj
, 0, sizeof(obj
));
518 obj
.id
= blob_get_u32(attr
[UBUS_ATTR_OBJID
]);
519 obj
.path
= blob_data(attr
[UBUS_ATTR_OBJPATH
]);
520 obj
.type_id
= blob_get_u32(attr
[UBUS_ATTR_OBJTYPE
]);
521 obj
.signature
= attr
[UBUS_ATTR_SIGNATURE
];
522 req
->cb(ureq
->ctx
, &obj
, ureq
->priv
);
525 int ubus_lookup(struct ubus_context
*ctx
, const char *path
,
526 ubus_lookup_handler_t cb
, void *priv
)
528 struct ubus_lookup_request lookup
;
530 blob_buf_init(&b
, 0);
532 blob_put_string(&b
, UBUS_ATTR_OBJPATH
, path
);
534 if (ubus_start_request(ctx
, &lookup
.req
, b
.head
, UBUS_MSG_LOOKUP
, 0) < 0)
535 return UBUS_STATUS_INVALID_ARGUMENT
;
537 lookup
.req
.raw_data_cb
= ubus_lookup_cb
;
538 lookup
.req
.priv
= priv
;
540 return ubus_complete_request(ctx
, &lookup
.req
, 0);
543 static void ubus_lookup_id_cb(struct ubus_request
*req
, int type
, struct blob_attr
*msg
)
545 struct blob_attr
**attr
;
546 uint32_t *id
= req
->priv
;
548 attr
= ubus_parse_msg(msg
);
550 if (!attr
[UBUS_ATTR_OBJID
])
553 *id
= blob_get_u32(attr
[UBUS_ATTR_OBJID
]);
556 int ubus_lookup_id(struct ubus_context
*ctx
, const char *path
, uint32_t *id
)
558 struct ubus_request req
;
560 blob_buf_init(&b
, 0);
562 blob_put_string(&b
, UBUS_ATTR_OBJPATH
, path
);
564 if (ubus_start_request(ctx
, &req
, b
.head
, UBUS_MSG_LOOKUP
, 0) < 0)
565 return UBUS_STATUS_INVALID_ARGUMENT
;
567 req
.raw_data_cb
= ubus_lookup_id_cb
;
570 return ubus_complete_request(ctx
, &req
, 0);
573 int ubus_send_reply(struct ubus_context
*ctx
, struct ubus_request_data
*req
,
574 struct blob_attr
*msg
)
578 blob_buf_init(&b
, 0);
579 blob_put_int32(&b
, UBUS_ATTR_OBJID
, req
->object
);
580 blob_put(&b
, UBUS_ATTR_DATA
, blob_data(msg
), blob_len(msg
));
581 ret
= ubus_send_msg(ctx
, req
->seq
, b
.head
, UBUS_MSG_DATA
, req
->peer
);
583 return UBUS_STATUS_NO_DATA
;
588 int ubus_invoke_async(struct ubus_context
*ctx
, uint32_t obj
, const char *method
,
589 struct blob_attr
*msg
, struct ubus_request
*req
)
591 blob_buf_init(&b
, 0);
592 blob_put_int32(&b
, UBUS_ATTR_OBJID
, obj
);
593 blob_put_string(&b
, UBUS_ATTR_METHOD
, method
);
595 blob_put(&b
, UBUS_ATTR_DATA
, blob_data(msg
), blob_len(msg
));
597 if (ubus_start_request(ctx
, req
, b
.head
, UBUS_MSG_INVOKE
, obj
) < 0)
598 return UBUS_STATUS_INVALID_ARGUMENT
;
603 int ubus_invoke(struct ubus_context
*ctx
, uint32_t obj
, const char *method
,
604 struct blob_attr
*msg
, ubus_data_handler_t cb
, void *priv
,
607 struct ubus_request req
;
609 ubus_invoke_async(ctx
, obj
, method
, msg
, &req
);
612 return ubus_complete_request(ctx
, &req
, timeout
);
615 static void ubus_add_object_cb(struct ubus_request
*req
, int type
, struct blob_attr
*msg
)
617 struct ubus_object
*obj
= req
->priv
;
621 if (!attrbuf
[UBUS_ATTR_OBJID
])
624 obj
->id
= blob_get_u32(attrbuf
[UBUS_ATTR_OBJID
]);
626 if (attrbuf
[UBUS_ATTR_OBJTYPE
])
627 obj
->type
->id
= blob_get_u32(attrbuf
[UBUS_ATTR_OBJTYPE
]);
629 obj
->avl
.key
= &obj
->id
;
630 avl_insert(&req
->ctx
->objects
, &obj
->avl
);
633 static void ubus_push_method_data(const struct ubus_method
*m
)
638 mtbl
= blobmsg_open_table(&b
, m
->name
);
640 for (i
= 0; i
< m
->n_policy
; i
++)
641 blobmsg_add_u32(&b
, m
->policy
[i
].name
, m
->policy
[i
].type
);
643 blobmsg_close_table(&b
, mtbl
);
646 static bool ubus_push_object_type(const struct ubus_object_type
*type
)
651 s
= blob_nest_start(&b
, UBUS_ATTR_SIGNATURE
);
653 for (i
= 0; i
< type
->n_methods
; i
++)
654 ubus_push_method_data(&type
->methods
[i
]);
656 blob_nest_end(&b
, s
);
661 static int __ubus_add_object(struct ubus_context
*ctx
, struct ubus_object
*obj
)
663 struct ubus_request req
;
666 blob_buf_init(&b
, 0);
668 if (obj
->name
&& obj
->type
) {
669 blob_put_string(&b
, UBUS_ATTR_OBJPATH
, obj
->name
);
672 blob_put_int32(&b
, UBUS_ATTR_OBJTYPE
, obj
->type
->id
);
673 else if (!ubus_push_object_type(obj
->type
))
674 return UBUS_STATUS_INVALID_ARGUMENT
;
677 if (ubus_start_request(ctx
, &req
, b
.head
, UBUS_MSG_ADD_OBJECT
, 0) < 0)
678 return UBUS_STATUS_INVALID_ARGUMENT
;
680 req
.raw_data_cb
= ubus_add_object_cb
;
682 ret
= ubus_complete_request(ctx
, &req
, 0);
687 return UBUS_STATUS_NO_DATA
;
692 int ubus_add_object(struct ubus_context
*ctx
, struct ubus_object
*obj
)
694 if (!obj
->name
|| !obj
->type
)
695 return UBUS_STATUS_INVALID_ARGUMENT
;
697 return __ubus_add_object(ctx
, obj
);
700 static void ubus_remove_object_cb(struct ubus_request
*req
, int type
, struct blob_attr
*msg
)
702 struct ubus_object
*obj
= req
->priv
;
706 if (!attrbuf
[UBUS_ATTR_OBJID
])
711 if (attrbuf
[UBUS_ATTR_OBJTYPE
] && obj
->type
)
714 avl_delete(&req
->ctx
->objects
, &obj
->avl
);
717 int ubus_remove_object(struct ubus_context
*ctx
, struct ubus_object
*obj
)
719 struct ubus_request req
;
722 blob_buf_init(&b
, 0);
723 blob_put_int32(&b
, UBUS_ATTR_OBJID
, obj
->id
);
725 if (ubus_start_request(ctx
, &req
, b
.head
, UBUS_MSG_REMOVE_OBJECT
, 0) < 0)
726 return UBUS_STATUS_INVALID_ARGUMENT
;
728 req
.raw_data_cb
= ubus_remove_object_cb
;
730 ret
= ubus_complete_request(ctx
, &req
, 0);
735 return UBUS_STATUS_NO_DATA
;
740 static int ubus_event_cb(struct ubus_context
*ctx
, struct ubus_object
*obj
,
741 struct ubus_request_data
*req
,
742 const char *method
, struct blob_attr
*msg
)
744 struct ubus_event_handler
*ev
;
746 ev
= container_of(obj
, struct ubus_event_handler
, obj
);
747 ev
->cb(ctx
, ev
, method
, msg
);
751 static const struct ubus_method event_method
= {
753 .handler
= ubus_event_cb
,
756 int ubus_register_event_handler(struct ubus_context
*ctx
,
757 struct ubus_event_handler
*ev
,
760 struct ubus_object
*obj
= &ev
->obj
;
765 obj
->methods
= &event_method
;
768 if (!!obj
->name
^ !!obj
->type
)
769 return UBUS_STATUS_INVALID_ARGUMENT
;
771 ret
= __ubus_add_object(ctx
, obj
);
776 /* use a second buffer, ubus_invoke() overwrites the primary one */
777 memset(&b2
, 0, sizeof(b2
));
778 blob_buf_init(&b2
, 0);
779 blobmsg_add_u32(&b2
, "object", obj
->id
);
781 blobmsg_add_string(&b2
, "pattern", pattern
);
783 return ubus_invoke(ctx
, UBUS_SYSTEM_OBJECT_EVENT
, "register", b2
.head
,
787 int ubus_send_event(struct ubus_context
*ctx
, const char *id
,
788 struct blob_attr
*data
)
790 struct ubus_request req
;
793 blob_buf_init(&b
, 0);
794 blob_put_int32(&b
, UBUS_ATTR_OBJID
, UBUS_SYSTEM_OBJECT_EVENT
);
795 blob_put_string(&b
, UBUS_ATTR_METHOD
, "send");
796 s
= blob_nest_start(&b
, UBUS_ATTR_DATA
);
797 blobmsg_add_string(&b
, "id", id
);
798 blobmsg_add_field(&b
, BLOBMSG_TYPE_TABLE
, "data", blob_data(data
), blob_len(data
));
799 blob_nest_end(&b
, s
);
801 if (ubus_start_request(ctx
, &req
, b
.head
, UBUS_MSG_INVOKE
, UBUS_SYSTEM_OBJECT_EVENT
) < 0)
802 return UBUS_STATUS_INVALID_ARGUMENT
;
804 return ubus_complete_request(ctx
, &req
, 0);
807 static void ubus_default_connection_lost(struct ubus_context
*ctx
)
809 if (ctx
->sock
.registered
)
813 struct ubus_context
*ubus_connect(const char *path
)
815 struct ubus_context
*ctx
;
817 struct ubus_msghdr hdr
;
818 struct blob_attr data
;
820 struct blob_attr
*buf
;
823 path
= UBUS_UNIX_SOCKET
;
825 ctx
= calloc(1, sizeof(*ctx
));
829 ctx
->sock
.fd
= usock(USOCK_UNIX
, path
, NULL
);
830 if (ctx
->sock
.fd
< 0)
833 ctx
->sock
.cb
= ubus_handle_data
;
835 if (read(ctx
->sock
.fd
, &hdr
, sizeof(hdr
)) != sizeof(hdr
))
838 if (!ubus_validate_hdr(&hdr
.hdr
))
841 if (hdr
.hdr
.type
!= UBUS_MSG_HELLO
)
844 buf
= calloc(1, blob_raw_len(&hdr
.data
));
848 memcpy(buf
, &hdr
.data
, sizeof(hdr
.data
));
849 if (read(ctx
->sock
.fd
, blob_data(buf
), blob_len(buf
)) != blob_len(buf
))
852 ctx
->local_id
= hdr
.hdr
.peer
;
855 ctx
->connection_lost
= ubus_default_connection_lost
;
857 INIT_LIST_HEAD(&ctx
->requests
);
858 avl_init(&ctx
->objects
, ubus_cmp_id
, false, NULL
);
875 void ubus_free(struct ubus_context
*ctx
)