Ubus
OpenWrt system message/RPC bus.
ubusd_proto.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2011-2014 Felix Fietkau <nbd@openwrt.org>
3  *
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
7  *
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.
12  */
13 
14 #include <arpa/inet.h>
15 #include <unistd.h>
16 
17 #include "ubusd.h"
18 
19 struct blob_buf b;
20 static struct avl_tree clients;
21 
22 static struct blob_attr *attrbuf[UBUS_ATTR_MAX];
23 
24 typedef int (*ubus_cmd_cb)(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr);
25 
26 static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX] = {
27  [UBUS_ATTR_SIGNATURE] = { .type = BLOB_ATTR_NESTED },
28  [UBUS_ATTR_OBJTYPE] = { .type = BLOB_ATTR_INT32 },
29  [UBUS_ATTR_OBJPATH] = { .type = BLOB_ATTR_STRING },
30  [UBUS_ATTR_OBJID] = { .type = BLOB_ATTR_INT32 },
31  [UBUS_ATTR_STATUS] = { .type = BLOB_ATTR_INT32 },
32  [UBUS_ATTR_METHOD] = { .type = BLOB_ATTR_STRING },
33  [UBUS_ATTR_USER] = { .type = BLOB_ATTR_STRING },
34  [UBUS_ATTR_GROUP] = { .type = BLOB_ATTR_STRING },
35 };
36 
37 struct blob_attr **ubus_parse_msg(struct blob_attr *msg, size_t len)
38 {
39  blob_parse_untrusted(msg, len, attrbuf, ubus_policy, UBUS_ATTR_MAX);
40  return attrbuf;
41 }
42 
43 static void ubus_msg_close_fd(struct ubus_msg_buf *ub)
44 {
45  if (ub->fd < 0)
46  return;
47 
48  close(ub->fd);
49  ub->fd = -1;
50 }
51 
52 static void ubus_msg_init(struct ubus_msg_buf *ub, uint8_t type, uint16_t seq, uint32_t peer)
53 {
54  ub->hdr.version = 0;
55  ub->hdr.type = type;
56  ub->hdr.seq = seq;
57  ub->hdr.peer = peer;
58 }
59 
60 static struct ubus_msg_buf *ubus_msg_from_blob(bool shared)
61 {
62  return ubus_msg_new(b.head, blob_raw_len(b.head), shared);
63 }
64 
65 static struct ubus_msg_buf *ubus_reply_from_blob(struct ubus_msg_buf *ub, bool shared)
66 {
67  struct ubus_msg_buf *new;
68 
69  new = ubus_msg_from_blob(shared);
70  if (!new)
71  return NULL;
72 
73  ubus_msg_init(new, UBUS_MSG_DATA, ub->hdr.seq, ub->hdr.peer);
74  return new;
75 }
76 
77 void
79  uint8_t type)
80 {
81  /* keep the fd to be passed if it is UBUS_MSG_INVOKE */
82  int fd = ub->fd;
83  ub = ubus_reply_from_blob(ub, true);
84  if (!ub)
85  return;
86 
87  ub->hdr.type = type;
88  ub->fd = fd;
89 
90  ubus_msg_send(cl, ub);
91  ubus_msg_free(ub);
92 }
93 
94 static bool ubusd_send_hello(struct ubus_client *cl)
95 {
96  struct ubus_msg_buf *ub;
97 
98  blob_buf_init(&b, 0);
99  ub = ubus_msg_from_blob(true);
100  if (!ub)
101  return false;
102 
103  ubus_msg_init(ub, UBUS_MSG_HELLO, 0, cl->id.id);
104  ubus_msg_send(cl, ub);
105  ubus_msg_free(ub);
106  return true;
107 }
108 
109 static int ubusd_send_pong(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
110 {
111  ub->hdr.type = UBUS_MSG_DATA;
112  ubus_msg_send(cl, ub);
113  return 0;
114 }
115 
116 static int ubusd_handle_remove_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
117 {
118  struct ubus_object *obj;
119 
120  if (!attr[UBUS_ATTR_OBJID])
122 
123  obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID]));
124  if (!obj)
125  return UBUS_STATUS_NOT_FOUND;
126 
127  if (obj->client != cl)
129 
130  blob_buf_init(&b, 0);
131  blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
132 
133  /* check if we're removing the object type as well */
134  if (obj->type && obj->type->refcount == 1)
135  blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id);
136 
138  ubusd_free_object(obj);
139 
140  return 0;
141 }
142 
143 static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
144 {
145  struct ubus_object *obj;
146 
147  obj = ubusd_create_object(cl, attr);
148  if (!obj)
150 
151  blob_buf_init(&b, 0);
152  blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
153  if (attr[UBUS_ATTR_SIGNATURE] && obj->type)
154  blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id);
155 
157  return 0;
158 }
159 
160 static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj)
161 {
162  struct ubus_method *m;
163  int all_cnt = 0, cnt = 0;
164  void *s;
165 
166  if (!obj->type)
167  return;
168 
169  blob_buf_init(&b, 0);
170 
171  blob_put_string(&b, UBUS_ATTR_OBJPATH, obj->path.key);
172  blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
173  blob_put_int32(&b, UBUS_ATTR_OBJTYPE, obj->type->id.id);
174 
175  s = blob_nest_start(&b, UBUS_ATTR_SIGNATURE);
176  list_for_each_entry(m, &obj->type->methods, list) {
177  all_cnt++;
178  if (!ubusd_acl_check(cl, obj->path.key, blobmsg_name(m->data), UBUS_ACL_ACCESS)) {
179  blobmsg_add_blob(&b, m->data);
180  cnt++;
181  }
182  }
183  blob_nest_end(&b, s);
184 
185  if (cnt || !all_cnt)
187 }
188 
190  struct ubus_msg_buf *msg,
191  struct ubus_object *obj)
192 {
193  struct ubus_client_cmd *cmd = malloc(sizeof(*cmd));
194 
195  if (cmd) {
196  cmd->msg = msg;
197  cmd->obj = obj;
198  list_add_tail(&cmd->list, &cl->cmd_queue);
199  return -2;
200  }
202 }
203 
204 static int __ubusd_handle_lookup(struct ubus_client *cl,
205  struct ubus_msg_buf *ub,
206  struct blob_attr **attr,
207  struct ubus_client_cmd *cmd)
208 {
209  struct ubus_object *obj = NULL;
210  char *objpath;
211  bool found = false;
212  int len;
213 
214  if (!attr[UBUS_ATTR_OBJPATH]) {
215  if (cmd)
216  obj = cmd->obj;
217 
218  /* Start from beginning or continue from the last object */
219  if (obj == NULL)
220  obj = avl_first_element(&path, obj, path);
221 
222  avl_for_element_range(obj, avl_last_element(&path, obj, path), obj, path) {
223  /* Keep sending objects until buffering starts */
224  if (list_empty(&cl->tx_queue)) {
225  ubusd_send_obj(cl, ub, obj);
226  } else {
227  /* Queue command and continue on the next call */
228  int ret;
229 
230  if (cmd == NULL) {
231  ret = ubus_client_cmd_queue_add(cl, ub, obj);
232  } else {
233  cmd->obj = obj;
234  ret = -2;
235  }
236  return ret;
237  }
238  }
239  return 0;
240  }
241 
242  objpath = blob_data(attr[UBUS_ATTR_OBJPATH]);
243  len = strlen(objpath);
244  if (objpath[len - 1] != '*') {
245  obj = avl_find_element(&path, objpath, obj, path);
246  if (!obj)
247  return UBUS_STATUS_NOT_FOUND;
248 
249  ubusd_send_obj(cl, ub, obj);
250  return 0;
251  }
252 
253  objpath[--len] = 0;
254 
255  obj = avl_find_ge_element(&path, objpath, obj, path);
256  if (!obj)
257  return UBUS_STATUS_NOT_FOUND;
258 
259  while (!strncmp(objpath, obj->path.key, len)) {
260  found = true;
261  ubusd_send_obj(cl, ub, obj);
262  if (obj == avl_last_element(&path, obj, path))
263  break;
264  obj = avl_next_element(obj, path);
265  }
266 
267  if (!found)
268  return UBUS_STATUS_NOT_FOUND;
269 
270  return 0;
271 }
272 
273 static int ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
274 {
275  int rc;
276 
277  if (list_empty(&cl->tx_queue))
278  rc = __ubusd_handle_lookup(cl, ub, attr, NULL);
279  else
280  rc = ubus_client_cmd_queue_add(cl, ub, NULL);
281 
282  return rc;
283 }
284 
285 int ubusd_cmd_lookup(struct ubus_client *cl, struct ubus_client_cmd *cmd)
286 {
287  struct ubus_msg_buf *ub = cmd->msg;
288  struct blob_attr **attr;
289  int ret;
290 
291  attr = ubus_parse_msg(ub->data, blob_raw_len(ub->data));
292  ret = __ubusd_handle_lookup(cl, ub, attr, cmd);
293 
294  if (ret != -2) {
295  struct ubus_msg_buf *retmsg = cl->retmsg;
296  int *retmsg_data = blob_data(blob_data(retmsg->data));
297 
298  retmsg->hdr.seq = ub->hdr.seq;
299  retmsg->hdr.peer = ub->hdr.peer;
300 
301  *retmsg_data = htonl(ret);
302  ubus_msg_send(cl, retmsg);
303  }
304  return ret;
305 }
306 
307 static void
309  const char *method, struct ubus_msg_buf *ub,
310  struct blob_attr *data)
311 {
312  blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
313  blob_put_string(&b, UBUS_ATTR_METHOD, method);
314  if (cl->user)
315  blob_put_string(&b, UBUS_ATTR_USER, cl->user);
316  if (cl->group)
317  blob_put_string(&b, UBUS_ATTR_GROUP, cl->group);
318  if (data)
319  blob_put(&b, UBUS_ATTR_DATA, blob_data(data), blob_len(data));
320 
322 }
323 
324 static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
325 {
326  struct ubus_object *obj = NULL;
327  struct ubus_id *id;
328  const char *method;
329 
330  if (!attr[UBUS_ATTR_METHOD] || !attr[UBUS_ATTR_OBJID])
332 
333  id = ubus_find_id(&objects, blob_get_u32(attr[UBUS_ATTR_OBJID]));
334  if (!id)
335  return UBUS_STATUS_NOT_FOUND;
336 
337  obj = container_of(id, struct ubus_object, id);
338 
339  method = blob_data(attr[UBUS_ATTR_METHOD]);
340 
341  if (ubusd_acl_check(cl, obj->path.key, method, UBUS_ACL_ACCESS))
343 
344  if (!obj->client)
345  return obj->recv_msg(cl, ub, method, attr[UBUS_ATTR_DATA]);
346 
347  ub->hdr.peer = cl->id.id;
348  blob_buf_init(&b, 0);
349 
350  ubusd_forward_invoke(cl, obj, method, ub, attr[UBUS_ATTR_DATA]);
351 
352  return -1;
353 }
354 
355 static int ubusd_handle_notify(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
356 {
357  struct ubus_object *obj = NULL;
358  struct ubus_subscription *s;
359  struct ubus_id *id;
360  const char *method;
361  bool no_reply = false;
362  void *c;
363 
364  if (!attr[UBUS_ATTR_METHOD] || !attr[UBUS_ATTR_OBJID])
366 
367  if (attr[UBUS_ATTR_NO_REPLY])
368  no_reply = blob_get_int8(attr[UBUS_ATTR_NO_REPLY]);
369 
370  id = ubus_find_id(&objects, blob_get_u32(attr[UBUS_ATTR_OBJID]));
371  if (!id)
372  return UBUS_STATUS_NOT_FOUND;
373 
374  obj = container_of(id, struct ubus_object, id);
375  if (obj->client != cl)
377 
378  if (!no_reply) {
379  blob_buf_init(&b, 0);
380  blob_put_int32(&b, UBUS_ATTR_OBJID, id->id);
381  c = blob_nest_start(&b, UBUS_ATTR_SUBSCRIBERS);
382  list_for_each_entry(s, &obj->subscribers, list) {
383  blob_put_int32(&b, 0, s->subscriber->id.id);
384  }
385  blob_nest_end(&b, c);
386  blob_put_int32(&b, UBUS_ATTR_STATUS, 0);
388  }
389 
390  ub->hdr.peer = cl->id.id;
391  method = blob_data(attr[UBUS_ATTR_METHOD]);
392  list_for_each_entry(s, &obj->subscribers, list) {
393  blob_buf_init(&b, 0);
394  if (no_reply)
395  blob_put_int8(&b, UBUS_ATTR_NO_REPLY, 1);
396  ubusd_forward_invoke(cl, s->subscriber, method, ub, attr[UBUS_ATTR_DATA]);
397  }
398 
399  return -1;
400 }
401 
402 static struct ubus_client *ubusd_get_client_by_id(uint32_t id)
403 {
404  struct ubus_id *clid;
405 
406  clid = ubus_find_id(&clients, id);
407  if (!clid)
408  return NULL;
409 
410  return container_of(clid, struct ubus_client, id);
411 }
412 
413 static int ubusd_handle_response(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
414 {
415  struct ubus_object *obj;
416 
417  if (!attr[UBUS_ATTR_OBJID] ||
418  (ub->hdr.type == UBUS_MSG_STATUS && !attr[UBUS_ATTR_STATUS]) ||
419  (ub->hdr.type == UBUS_MSG_DATA && !attr[UBUS_ATTR_DATA]))
420  goto out;
421 
422  obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID]));
423  if (!obj)
424  goto out;
425 
426  if (cl != obj->client)
427  goto out;
428 
429  cl = ubusd_get_client_by_id(ub->hdr.peer);
430  if (!cl)
431  goto out;
432 
433  ub->hdr.peer = blob_get_u32(attr[UBUS_ATTR_OBJID]);
434  ubus_msg_send(cl, ub);
435 out:
436  return -1;
437 }
438 
439 static int ubusd_handle_add_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
440 {
441  struct ubus_object *obj, *target;
442 
443  if (!attr[UBUS_ATTR_OBJID] || !attr[UBUS_ATTR_TARGET])
445 
446  obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID]));
447  if (!obj)
448  return UBUS_STATUS_NOT_FOUND;
449 
450  if (cl != obj->client)
452 
453  target = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_TARGET]));
454  if (!target || !target->client)
455  return UBUS_STATUS_NOT_FOUND;
456 
457  if (cl == target->client)
459 
460  if (!target->path.key) {
461  if (strcmp(target->client->user, cl->user) && strcmp(target->client->group, cl->group))
462  return UBUS_STATUS_NOT_FOUND;
463  } else if (ubusd_acl_check(cl, target->path.key, NULL, UBUS_ACL_SUBSCRIBE)) {
464  return UBUS_STATUS_NOT_FOUND;
465  }
466 
467  ubus_subscribe(obj, target);
468  return 0;
469 }
470 
471 static int ubusd_handle_remove_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
472 {
473  struct ubus_object *obj;
474  struct ubus_subscription *s;
475  uint32_t id;
476 
477  if (!attr[UBUS_ATTR_OBJID] || !attr[UBUS_ATTR_TARGET])
479 
480  obj = ubusd_find_object(blob_get_u32(attr[UBUS_ATTR_OBJID]));
481  if (!obj)
482  return UBUS_STATUS_NOT_FOUND;
483 
484  if (cl != obj->client)
486 
487  id = blob_get_u32(attr[UBUS_ATTR_TARGET]);
488  list_for_each_entry(s, &obj->target_list, target_list) {
489  if (s->target->id.id != id)
490  continue;
491 
492  ubus_unsubscribe(s);
493  return 0;
494  }
495 
496  return UBUS_STATUS_NOT_FOUND;
497 }
498 
510 };
511 
513 {
514  ubus_cmd_cb cb = NULL;
515  int ret;
516  struct ubus_msg_buf *retmsg = cl->retmsg;
517  int *retmsg_data = blob_data(blob_data(retmsg->data));
518 
519  retmsg->hdr.seq = ub->hdr.seq;
520  retmsg->hdr.peer = ub->hdr.peer;
521 
522  if (ub->hdr.type < __UBUS_MSG_LAST)
523  cb = handlers[ub->hdr.type];
524 
525  if (ub->hdr.type != UBUS_MSG_STATUS && ub->hdr.type != UBUS_MSG_INVOKE)
526  ubus_msg_close_fd(ub);
527 
528  /* Note: no callback should free the `ub` buffer
529  that's always done right after the callback finishes */
530  if (cb)
531  ret = cb(cl, ub, ubus_parse_msg(ub->data, blob_raw_len(ub->data)));
532  else
534 
535  /* Command has not been completed yet and got queued */
536  if (ret == -2)
537  return;
538 
539  ubus_msg_free(ub);
540 
541  if (ret == -1)
542  return;
543 
544  *retmsg_data = htonl(ret);
545  ubus_msg_send(cl, retmsg);
546 }
547 
548 static int ubusd_proto_init_retmsg(struct ubus_client *cl)
549 {
550  struct blob_buf *b = &cl->b;
551 
552  blob_buf_init(&cl->b, 0);
553  blob_put_int32(&cl->b, UBUS_ATTR_STATUS, 0);
554 
555  /* we make the 'retmsg' buffer shared with the blob_buf b, to reduce mem duplication */
556  cl->retmsg = ubus_msg_new(b->head, blob_raw_len(b->head), true);
557  if (!cl->retmsg)
558  return -1;
559 
561  return 0;
562 }
563 
564 struct ubus_client *ubusd_proto_new_client(int fd, uloop_fd_handler cb)
565 {
566  struct ubus_client *cl;
567 
568  cl = calloc(1, sizeof(*cl));
569  if (!cl)
570  return NULL;
571 
572  if (ubusd_acl_init_client(cl, fd))
573  goto free;
574 
575  INIT_LIST_HEAD(&cl->objects);
576  INIT_LIST_HEAD(&cl->cmd_queue);
577  INIT_LIST_HEAD(&cl->tx_queue);
578  cl->sock.fd = fd;
579  cl->sock.cb = cb;
580  cl->pending_msg_fd = -1;
581 
582  if (!ubus_alloc_id(&clients, &cl->id, 0))
583  goto free;
584 
585  if (ubusd_proto_init_retmsg(cl))
586  goto free;
587 
588  if (!ubusd_send_hello(cl))
589  goto delete;
590 
591  return cl;
592 
593 delete:
594  ubus_free_id(&clients, &cl->id);
595 free:
596  free(cl);
597  return NULL;
598 }
599 
601 {
602  struct ubus_object *obj, *tmp;
603 
604  list_for_each_entry_safe(obj, tmp, &cl->objects, list) {
605  ubusd_free_object(obj);
606  }
607 
608  ubus_msg_free(cl->retmsg);
609  blob_buf_free(&cl->b);
610 
612  ubus_free_id(&clients, &cl->id);
613 }
614 
616 {
617  bool active = !list_empty(&obj->subscribers);
618  struct ubus_msg_buf *ub;
619 
620  blob_buf_init(&b, 0);
621  blob_put_int32(&b, UBUS_ATTR_OBJID, obj->id.id);
622  blob_put_int8(&b, UBUS_ATTR_ACTIVE, active);
623 
624  ub = ubus_msg_from_blob(false);
625  if (!ub)
626  return;
627 
628  ubus_msg_init(ub, UBUS_MSG_NOTIFY, ++obj->invoke_seq, 0);
629  ubus_msg_send(obj->client, ub);
630  ubus_msg_free(ub);
631 }
632 
634 {
635  struct ubus_msg_buf *ub;
636 
637  blob_buf_init(&b, 0);
638  blob_put_int32(&b, UBUS_ATTR_OBJID, s->subscriber->id.id);
639  blob_put_int32(&b, UBUS_ATTR_TARGET, s->target->id.id);
640 
641  ub = ubus_msg_from_blob(false);
642  if (ub != NULL) {
645  ubus_msg_free(ub);
646  }
647 
648  ubus_unsubscribe(s);
649 }
650 
651 static void __constructor ubusd_proto_init(void)
652 {
654 }
int(* cb)(struct ubus_context *ctx, int argc, char **argv)
Definition: cli.c:581
int ubus_subscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id)
Definition: libubus-sub.c:118
int ubus_unsubscribe(struct ubus_context *ctx, struct ubus_subscriber *obj, uint32_t id)
Definition: libubus-sub.c:123
struct ubus_object * obj
Definition: ubusd.h:47
struct ubus_msg_buf * msg
Definition: ubusd.h:46
struct list_head list
Definition: ubusd.h:45
struct ubus_msg_buf * retmsg
Definition: ubusd.h:68
char * user
Definition: ubusd.h:57
struct blob_buf b
Definition: ubusd.h:53
struct ubus_id id
Definition: ubusd.h:51
int pending_msg_fd
Definition: ubusd.h:70
struct list_head cmd_queue
Definition: ubusd.h:62
struct list_head tx_queue
Definition: ubusd.h:63
char * group
Definition: ubusd.h:58
struct list_head objects
Definition: ubusd.h:60
struct uloop_fd sock
Definition: ubusd.h:52
uint32_t id
Definition: ubusd_id.h:22
struct blob_attr data[]
Definition: ubusd_obj.h:35
struct list_head list
Definition: ubusd_obj.h:33
struct blob_attr * data
Definition: ubusd.h:34
struct ubus_msghdr hdr
Definition: ubusd.h:33
int fd
Definition: ubusd.h:35
uint32_t peer
Definition: ubusmsg.h:33
uint8_t version
Definition: ubusmsg.h:30
uint8_t type
Definition: ubusmsg.h:31
uint16_t seq
Definition: ubusmsg.h:32
const struct ubus_method * methods
Definition: libubus.h:122
uint32_t id
Definition: libubus.h:120
uint32_t id
Definition: libubus.h:130
struct ubus_object_type * type
Definition: libubus.h:133
struct list_head subscribers target_list
Definition: ubusd_obj.h:49
struct ubus_client * client
Definition: ubusd_obj.h:54
const char * path
Definition: libubus.h:132
unsigned int invoke_seq
Definition: ubusd_obj.h:59
struct list_head list
Definition: ubusd_obj.h:45
int(* recv_msg)(struct ubus_client *client, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
Definition: ubusd_obj.h:55
struct ubus_object * target
Definition: ubusd_obj.h:40
struct list_head list target_list
Definition: ubusd_obj.h:39
struct ubus_object * subscriber
Definition: ubusd_obj.h:40
void ubus_msg_free(struct ubus_msg_buf *ub)
Definition: ubusd.c:67
struct ubus_msg_buf * ubus_msg_new(void *data, int len, bool shared)
Definition: ubusd.c:39
void ubus_msg_send(struct ubus_client *cl, struct ubus_msg_buf *ub)
Definition: ubusd.c:162
int ubusd_acl_init_client(struct ubus_client *cl, int fd)
Definition: ubusd_acl.c:170
int ubusd_acl_check(struct ubus_client *cl, const char *obj, const char *method, enum ubusd_acl_type type)
Definition: ubusd_acl.c:90
void ubusd_acl_free_client(struct ubus_client *cl)
Definition: ubusd_acl.c:209
@ UBUS_ACL_ACCESS
Definition: ubusd_acl.h:20
@ UBUS_ACL_SUBSCRIBE
Definition: ubusd_acl.h:19
void ubus_init_id_tree(struct avl_tree *tree)
Definition: ubusd_id.c:40
bool ubus_alloc_id(struct avl_tree *tree, struct ubus_id *id, uint32_t val)
Definition: ubusd_id.c:53
static void ubus_free_id(struct avl_tree *tree, struct ubus_id *id)
Definition: ubusd_id.h:29
static struct ubus_id * ubus_find_id(struct avl_tree *tree, uint32_t id)
Definition: ubusd_id.h:34
struct ubus_object * ubusd_create_object(struct ubus_client *cl, struct blob_attr **attr)
Definition: ubusd_obj.c:129
struct avl_tree objects
Definition: ubusd_obj.c:18
struct avl_tree path
Definition: ubusd_obj.c:19
void ubusd_free_object(struct ubus_object *obj)
Definition: ubusd_obj.c:202
static struct ubus_object * ubusd_find_object(uint32_t objid)
Definition: ubusd_obj.h:66
static void __constructor ubusd_proto_init(void)
Definition: ubusd_proto.c:651
static struct ubus_msg_buf * ubus_msg_from_blob(bool shared)
Definition: ubusd_proto.c:60
static const struct blob_attr_info ubus_policy[UBUS_ATTR_MAX]
Definition: ubusd_proto.c:26
static void ubusd_forward_invoke(struct ubus_client *cl, struct ubus_object *obj, const char *method, struct ubus_msg_buf *ub, struct blob_attr *data)
Definition: ubusd_proto.c:308
struct ubus_client * ubusd_proto_new_client(int fd, uloop_fd_handler cb)
Definition: ubusd_proto.c:564
static struct blob_attr * attrbuf[UBUS_ATTR_MAX]
Definition: ubusd_proto.c:22
static int ubusd_handle_notify(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:355
static struct avl_tree clients
Definition: ubusd_proto.c:20
static int ubus_client_cmd_queue_add(struct ubus_client *cl, struct ubus_msg_buf *msg, struct ubus_object *obj)
Definition: ubusd_proto.c:189
static int ubusd_proto_init_retmsg(struct ubus_client *cl)
Definition: ubusd_proto.c:548
void ubus_notify_unsubscribe(struct ubus_subscription *s)
Definition: ubusd_proto.c:633
static int ubusd_send_pong(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:109
static const ubus_cmd_cb handlers[__UBUS_MSG_LAST]
Definition: ubusd_proto.c:499
int ubusd_cmd_lookup(struct ubus_client *cl, struct ubus_client_cmd *cmd)
Definition: ubusd_proto.c:285
static int ubusd_handle_add_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:439
static bool ubusd_send_hello(struct ubus_client *cl)
Definition: ubusd_proto.c:94
static void ubusd_send_obj(struct ubus_client *cl, struct ubus_msg_buf *ub, struct ubus_object *obj)
Definition: ubusd_proto.c:160
static int ubusd_handle_response(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:413
struct blob_buf b
Definition: ubusd_proto.c:19
static int ubusd_handle_remove_watch(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:471
static int ubusd_handle_remove_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:116
static void ubus_msg_close_fd(struct ubus_msg_buf *ub)
Definition: ubusd_proto.c:43
static int ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:273
static int ubusd_handle_invoke(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:324
static int ubusd_handle_add_object(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:143
void ubus_notify_subscription(struct ubus_object *obj)
Definition: ubusd_proto.c:615
void ubusd_proto_free_client(struct ubus_client *cl)
Definition: ubusd_proto.c:600
static struct ubus_msg_buf * ubus_reply_from_blob(struct ubus_msg_buf *ub, bool shared)
Definition: ubusd_proto.c:65
static void ubus_msg_init(struct ubus_msg_buf *ub, uint8_t type, uint16_t seq, uint32_t peer)
Definition: ubusd_proto.c:52
int(* ubus_cmd_cb)(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr)
Definition: ubusd_proto.c:24
struct blob_attr ** ubus_parse_msg(struct blob_attr *msg, size_t len)
Definition: ubusd_proto.c:37
void ubus_proto_send_msg_from_blob(struct ubus_client *cl, struct ubus_msg_buf *ub, uint8_t type)
Definition: ubusd_proto.c:78
void ubusd_proto_receive_message(struct ubus_client *cl, struct ubus_msg_buf *ub)
Definition: ubusd_proto.c:512
static int __ubusd_handle_lookup(struct ubus_client *cl, struct ubus_msg_buf *ub, struct blob_attr **attr, struct ubus_client_cmd *cmd)
Definition: ubusd_proto.c:204
static struct ubus_client * ubusd_get_client_by_id(uint32_t id)
Definition: ubusd_proto.c:402
uint16_t seq
Definition: ubusmsg.h:2
uint8_t type
Definition: ubusmsg.h:1
uint32_t peer
Definition: ubusmsg.h:3
@ UBUS_MSG_INVOKE
Definition: ubusmsg.h:53
@ UBUS_MSG_DATA
Definition: ubusmsg.h:44
@ UBUS_MSG_REMOVE_OBJECT
Definition: ubusmsg.h:56
@ UBUS_MSG_STATUS
Definition: ubusmsg.h:41
@ UBUS_MSG_PING
Definition: ubusmsg.h:47
@ UBUS_MSG_ADD_OBJECT
Definition: ubusmsg.h:55
@ UBUS_MSG_LOOKUP
Definition: ubusmsg.h:50
@ UBUS_MSG_NOTIFY
Definition: ubusmsg.h:71
@ __UBUS_MSG_LAST
Definition: ubusmsg.h:76
@ UBUS_MSG_HELLO
Definition: ubusmsg.h:38
@ UBUS_MSG_SUBSCRIBE
Definition: ubusmsg.h:63
@ UBUS_MSG_UNSUBSCRIBE
Definition: ubusmsg.h:64
@ UBUS_STATUS_INVALID_ARGUMENT
Definition: ubusmsg.h:121
@ UBUS_STATUS_NOT_FOUND
Definition: ubusmsg.h:123
@ UBUS_STATUS_INVALID_COMMAND
Definition: ubusmsg.h:120
@ UBUS_STATUS_PERMISSION_DENIED
Definition: ubusmsg.h:125
@ UBUS_STATUS_UNKNOWN_ERROR
Definition: ubusmsg.h:128
@ UBUS_ATTR_OBJTYPE
Definition: ubusmsg.h:88
@ UBUS_ATTR_TARGET
Definition: ubusmsg.h:92
@ UBUS_ATTR_ACTIVE
Definition: ubusmsg.h:94
@ UBUS_ATTR_OBJPATH
Definition: ubusmsg.h:84
@ UBUS_ATTR_METHOD
Definition: ubusmsg.h:86
@ UBUS_ATTR_SUBSCRIBERS
Definition: ubusmsg.h:97
@ UBUS_ATTR_STATUS
Definition: ubusmsg.h:82
@ UBUS_ATTR_NO_REPLY
Definition: ubusmsg.h:95
@ UBUS_ATTR_OBJID
Definition: ubusmsg.h:85
@ UBUS_ATTR_SIGNATURE
Definition: ubusmsg.h:89
@ UBUS_ATTR_GROUP
Definition: ubusmsg.h:100
@ UBUS_ATTR_DATA
Definition: ubusmsg.h:91
@ UBUS_ATTR_USER
Definition: ubusmsg.h:99
@ UBUS_ATTR_MAX
Definition: ubusmsg.h:103