#include <libubox/list.h>
#include <libubox/uloop.h>
#include <libubox/blobmsg.h>
#include "ubus_common.h"
#include "ubusd_id.h"
#include "ubusd_obj.h"
#include "ubusmsg.h"
#include "ubusd_acl.h"
Go to the source code of this file.
|
struct ubus_msg_buf * | ubus_msg_new (void *data, int len, bool shared) |
|
void | ubus_msg_send (struct ubus_client *cl, struct ubus_msg_buf *ub) |
|
ssize_t | ubus_msg_writev (int fd, struct ubus_msg_buf *ub, size_t offset) |
|
void | ubus_msg_free (struct ubus_msg_buf *ub) |
|
void | ubus_msg_list_free (struct ubus_msg_buf_list *ubl) |
|
struct blob_attr ** | ubus_parse_msg (struct blob_attr *msg, size_t len) |
|
struct ubus_client * | ubusd_proto_new_client (int fd, uloop_fd_handler cb) |
|
void | ubusd_proto_receive_message (struct ubus_client *cl, struct ubus_msg_buf *ub) |
|
void | ubusd_proto_free_client (struct ubus_client *cl) |
|
void | ubus_proto_send_msg_from_blob (struct ubus_client *cl, struct ubus_msg_buf *ub, uint8_t type) |
|
int | ubusd_cmd_lookup (struct ubus_client *cl, struct ubus_client_cmd *cmd) |
|
void | ubusd_event_init (void) |
|
void | ubusd_event_cleanup_object (struct ubus_object *obj) |
|
void | ubusd_send_obj_event (struct ubus_object *obj, bool add) |
|
int | ubusd_send_event (struct ubus_client *cl, const char *id, event_fill_cb fill_cb, void *cb_priv) |
|
void | ubusd_acl_init (void) |
|
void | ubusd_monitor_init (void) |
|
void | ubusd_monitor_message (struct ubus_client *cl, struct ubus_msg_buf *ub, bool send) |
|
void | ubusd_monitor_disconnect (struct ubus_client *cl) |
|
◆ UBUS_CLIENT_MAX_TXQ_LEN
#define UBUS_CLIENT_MAX_TXQ_LEN UBUS_MAX_MSGLEN |
◆ UBUS_OBJ_HASH_BITS
#define UBUS_OBJ_HASH_BITS 4 |
◆ event_fill_cb
typedef struct ubus_msg_buf*(* event_fill_cb) (void *priv, const char *id) |
◆ ubus_msg_free()
Definition at line 67 of file ubusd.c.
#define USES_EXTERNAL_BUFFER
◆ ubus_msg_list_free()
Definition at line 136 of file ubusd.c.
138 list_del_init(&ubl->
list);
struct ubus_msg_buf * msg
void ubus_msg_free(struct ubus_msg_buf *ub)
◆ ubus_msg_new()
struct ubus_msg_buf* ubus_msg_new |
( |
void * |
data, |
|
|
int |
len, |
|
|
bool |
shared |
|
) |
| |
Definition at line 39 of file ubusd.c.
42 int buflen =
sizeof(*ub);
47 ub = calloc(1, buflen);
58 ub->
data = (
void *) (ub + 1);
◆ ubus_msg_send()
Definition at line 162 of file ubusd.c.
175 if (written >= (ssize_t) (ub->
len +
sizeof(ub->
hdr)))
182 uloop_fd_add(&cl->
sock, ULOOP_READ | ULOOP_WRITE | ULOOP_EDGE_TRIGGER);
struct list_head tx_queue
static void ubus_msg_enqueue(struct ubus_client *cl, struct ubus_msg_buf *ub)
ssize_t ubus_msg_writev(int fd, struct ubus_msg_buf *ub, size_t offset)
void ubusd_monitor_message(struct ubus_client *cl, struct ubus_msg_buf *ub, bool send)
◆ ubus_msg_writev()
ssize_t ubus_msg_writev |
( |
int |
fd, |
|
|
struct ubus_msg_buf * |
ub, |
|
|
size_t |
offset |
|
) |
| |
Definition at line 83 of file ubusd.c.
85 uint8_t fd_buf[CMSG_SPACE(
sizeof(
int))] = { 0 };
86 static struct iovec iov[2];
87 struct msghdr msghdr = { 0 };
94 msghdr.msg_iovlen = ARRAY_SIZE(iov);
95 msghdr.msg_control = fd_buf;
96 msghdr.msg_controllen =
sizeof(fd_buf);
98 cmsg = CMSG_FIRSTHDR(&msghdr);
99 cmsg->cmsg_type = SCM_RIGHTS;
100 cmsg->cmsg_level = SOL_SOCKET;
101 cmsg->cmsg_len = CMSG_LEN(
sizeof(
int));
103 pfd = (
int *) CMSG_DATA(cmsg);
104 msghdr.msg_controllen = cmsg->cmsg_len;
107 if (ub->
fd < 0 || offset) {
108 msghdr.msg_control = NULL;
109 msghdr.msg_controllen = 0;
112 if (offset <
sizeof(ub->
hdr)) {
115 hdr.seq = cpu_to_be16(ub->
hdr.
seq);
116 hdr.peer = cpu_to_be32(ub->
hdr.
peer);
118 iov[0].iov_base = ((
char *) &hdr) + offset;
119 iov[0].iov_len =
sizeof(hdr) - offset;
120 iov[1].iov_base = (
char *) ub->
data;
121 iov[1].iov_len = ub->
len;
123 offset -=
sizeof(ub->
hdr);
124 iov[0].iov_base = ((
char *) ub->
data) + offset;
125 iov[0].iov_len = ub->
len - offset;
126 msghdr.msg_iovlen = 1;
130 ret = sendmsg(fd, &msghdr, 0);
131 }
while (ret < 0 && errno == EINTR);
◆ ubus_parse_msg()
struct blob_attr** ubus_parse_msg |
( |
struct blob_attr * |
msg, |
|
|
size_t |
len |
|
) |
| |
Definition at line 46 of file libubus-io.c.
static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX]
static struct blob_attr * attrbuf[UBUS_ATTR_MAX]
◆ ubus_proto_send_msg_from_blob()
Definition at line 78 of file ubusd_proto.c.
void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
static struct ubus_msg_buf * ubus_reply_from_blob(struct ubus_msg_buf *ub, bool shared)
◆ ubusd_acl_init()
void ubusd_acl_init |
( |
void |
| ) |
|
Definition at line 568 of file ubusd_acl.c.
int(* recv_msg)(struct ubus_client *client, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
static struct avl_tree ubusd_acls
static struct ubus_object * acl_obj
static int ubusd_acl_recv(struct ubus_client *cl, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
void ubus_init_string_tree(struct avl_tree *tree, bool dup)
struct ubus_object * ubusd_create_object_internal(struct ubus_object_type *type, uint32_t id)
#define UBUS_SYSTEM_OBJECT_ACL
◆ ubusd_cmd_lookup()
Definition at line 285 of file ubusd_proto.c.
288 struct blob_attr **attr;
296 int *retmsg_data = blob_data(blob_data(retmsg->
data));
301 *retmsg_data = htonl(ret);
struct ubus_msg_buf * msg
struct ubus_msg_buf * retmsg
struct blob_attr ** ubus_parse_msg(struct blob_attr *msg, size_t len)
static int __ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr, struct ubus_client_cmd *cmd)
◆ ubusd_event_cleanup_object()
void ubusd_event_cleanup_object |
( |
struct ubus_object * |
obj | ) |
|
Definition at line 36 of file ubusd_event.c.
static void ubusd_delete_event_source(struct event_source *evs)
◆ ubusd_event_init()
void ubusd_event_init |
( |
void |
| ) |
|
Definition at line 266 of file ubusd_event.c.
static struct ubus_object * event_obj
static int ubusd_event_recv(struct ubus_client *cl, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
static struct avl_tree patterns
#define UBUS_SYSTEM_OBJECT_EVENT
◆ ubusd_monitor_disconnect()
void ubusd_monitor_disconnect |
( |
struct ubus_client * |
cl | ) |
|
Definition at line 65 of file ubusd_monitor.c.
static struct ubus_monitor * ubusd_monitor_find(struct ubus_client *cl)
static void ubusd_monitor_free(struct ubus_monitor *m)
◆ ubusd_monitor_init()
void ubusd_monitor_init |
( |
void |
| ) |
|
Definition at line 128 of file ubusd_monitor.c.
static int ubusd_monitor_recv(struct ubus_client *cl, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
static struct ubus_object * monitor_obj
#define UBUS_SYSTEM_OBJECT_MONITOR
◆ ubusd_monitor_message()
Definition at line 77 of file ubusd_monitor.c.
79 static struct blob_buf mb;
82 if (list_empty(&monitors))
85 blob_buf_init(&mb, 0);
96 list_for_each_entry(m, &monitors,
list) {
struct ubus_msg_buf * ubus_msg_new(void *data, int len, bool shared)
◆ ubusd_proto_free_client()
void ubusd_proto_free_client |
( |
struct ubus_client * |
cl | ) |
|
Definition at line 600 of file ubusd_proto.c.
604 list_for_each_entry_safe(obj, tmp, &cl->
objects,
list) {
609 blob_buf_free(&cl->
b);
void ubusd_acl_free_client(struct ubus_client *cl)
static void ubus_free_id(struct avl_tree *tree, struct ubus_id *id)
void ubusd_free_object(struct ubus_object *obj)
static struct avl_tree clients
◆ ubusd_proto_new_client()
struct ubus_client* ubusd_proto_new_client |
( |
int |
fd, |
|
|
uloop_fd_handler |
cb |
|
) |
| |
Definition at line 564 of file ubusd_proto.c.
568 cl = calloc(1,
sizeof(*cl));
int(* cb)(struct ubus_context *ctx, int argc, char **argv)
struct list_head cmd_queue
int ubusd_acl_init_client(struct ubus_client *cl, int fd)
bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id, uint32_t val)
static int ubusd_proto_init_retmsg(struct ubus_client *cl)
static bool ubusd_send_hello(struct ubus_client *cl)
◆ ubusd_proto_receive_message()
Definition at line 512 of file ubusd_proto.c.
517 int *retmsg_data = blob_data(blob_data(retmsg->
data));
544 *retmsg_data = htonl(ret);
static const ubus_cmd_cb handlers[__UBUS_MSG_LAST]
static void ubus_msg_close_fd(struct ubus_msg_buf *ub)
int(* ubus_cmd_cb)(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
@ UBUS_STATUS_INVALID_COMMAND
◆ ubusd_send_event()
Definition at line 140 of file ubusd_event.c.
158 const char *key = ev->
avl.key;
163 if (cur_match_len < match_len)
166 match_len = cur_match_len;
172 if (match_len != (
int) strlen(key))
static bool ubus_strmatch_len(const char *s1, const char *s2, int *len)
int ubusd_acl_check(struct ubus_client *cl, const char *obj, const char *method, enum ubusd_acl_type type)
static void ubusd_send_event_msg(struct ubus_msg_buf **ub, struct ubus_client *cl, struct ubus_object *obj, const char *id, event_fill_cb fill_cb, void *cb_priv)
@ UBUS_STATUS_PERMISSION_DENIED
◆ ubusd_send_obj_event()
void ubusd_send_obj_event |
( |
struct ubus_object * |
obj, |
|
|
bool |
add |
|
) |
| |
Definition at line 259 of file ubusd_event.c.
261 const char *
id = add ?
"ubus.object.add" :
"ubus.object.remove";
int ubusd_send_event(struct ubus_client *cl, const char *id, event_fill_cb fill_cb, void *cb_priv)
static struct ubus_msg_buf * ubusd_create_object_event_msg(void *priv, const char *id)
◆ ubusd_acl_dir
const char* ubusd_acl_dir |
|
extern |