Ubus
OpenWrt system message/RPC bus.
ubusd_monitor.c File Reference
#include "ubusd.h"

Go to the source code of this file.

Data Structures

struct  ubus_monitor
 

Functions

static LIST_HEAD (monitors)
 
static void ubusd_monitor_free (struct ubus_monitor *m)
 
static bool ubusd_monitor_connect (struct ubus_client *cl, struct ubus_msg_buf *ub)
 
static struct ubus_monitorubusd_monitor_find (struct ubus_client *cl)
 
void ubusd_monitor_disconnect (struct ubus_client *cl)
 
void ubusd_monitor_message (struct ubus_client *cl, struct ubus_msg_buf *ub, bool send)
 
static int ubusd_monitor_recv (struct ubus_client *cl, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
 
void ubusd_monitor_init (void)
 

Variables

static struct ubus_objectmonitor_obj
 

Function Documentation

◆ LIST_HEAD()

static LIST_HEAD ( monitors  )
static

◆ ubusd_monitor_connect()

static bool ubusd_monitor_connect ( struct ubus_client cl,
struct ubus_msg_buf ub 
)
static

Definition at line 33 of file ubusd_monitor.c.

34 {
35  struct ubus_monitor *m;
36 
38 
39  m = calloc(1, sizeof(*m));
40  if (!m)
41  return false;
42 
43  m->cl = cl;
44  list_add_tail(&m->list, &monitors);
45 
46  return true;
47 }
struct list_head list
Definition: ubusd_monitor.c:20
struct ubus_client * cl
Definition: ubusd_monitor.c:21
void ubusd_monitor_disconnect(struct ubus_client *cl)
Definition: ubusd_monitor.c:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ubusd_monitor_disconnect()

void ubusd_monitor_disconnect ( struct ubus_client cl)

Definition at line 65 of file ubusd_monitor.c.

66 {
67  struct ubus_monitor *m;
68 
70  if (!m)
71  return;
72 
74 }
static struct ubus_monitor * ubusd_monitor_find(struct ubus_client *cl)
Definition: ubusd_monitor.c:50
static void ubusd_monitor_free(struct ubus_monitor *m)
Definition: ubusd_monitor.c:26
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ubusd_monitor_find()

static struct ubus_monitor* ubusd_monitor_find ( struct ubus_client cl)
static

Definition at line 50 of file ubusd_monitor.c.

51 {
52  struct ubus_monitor *m, *tmp;
53 
54  list_for_each_entry_safe(m, tmp, &monitors, list) {
55  if (m->cl != cl)
56  continue;
57 
58  return m;
59  }
60 
61  return NULL;
62 }
Here is the caller graph for this function:

◆ ubusd_monitor_free()

static void ubusd_monitor_free ( struct ubus_monitor m)
static

Definition at line 26 of file ubusd_monitor.c.

27 {
28  list_del(&m->list);
29  free(m);
30 }
Here is the caller graph for this function:

◆ ubusd_monitor_init()

void ubusd_monitor_init ( void  )

Definition at line 128 of file ubusd_monitor.c.

129 {
131  if (monitor_obj != NULL)
133 }
int(* recv_msg)(struct ubus_client *client, struct ubus_msg_buf *ub, const char *method, struct blob_attr *msg)
Definition: ubusd_obj.h:55
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
Definition: ubusd_monitor.c:16
struct ubus_object * ubusd_create_object_internal(struct ubus_object_type *type, uint32_t id)
Definition: ubusd_obj.c:103
#define UBUS_SYSTEM_OBJECT_MONITOR
Definition: ubusmsg.h:26
Here is the caller graph for this function:

◆ ubusd_monitor_message()

void ubusd_monitor_message ( struct ubus_client cl,
struct ubus_msg_buf ub,
bool  send 
)

Definition at line 77 of file ubusd_monitor.c.

78 {
79  static struct blob_buf mb;
80  struct ubus_monitor *m;
81 
82  if (list_empty(&monitors))
83  return;
84 
85  blob_buf_init(&mb, 0);
86  blob_put_int32(&mb, UBUS_MONITOR_CLIENT, cl->id.id);
87  blob_put_int32(&mb, UBUS_MONITOR_PEER, ub->hdr.peer);
88  blob_put_int32(&mb, UBUS_MONITOR_SEQ, ub->hdr.seq);
89  blob_put_int32(&mb, UBUS_MONITOR_TYPE, ub->hdr.type);
90  blob_put_int8(&mb, UBUS_MONITOR_SEND, send);
91  blob_put(&mb, UBUS_MONITOR_DATA, blob_data(ub->data), blob_len(ub->data));
92 
93  ub = ubus_msg_new(mb.head, blob_raw_len(mb.head), true);
95 
96  list_for_each_entry(m, &monitors, list) {
97  ub->hdr.seq = ++m->seq;
98  ubus_msg_send(m->cl, ub);
99  }
100 
101  ubus_msg_free(ub);
102 }
struct ubus_id id
Definition: ubusd.h:51
uint32_t id
Definition: ubusd_id.h:22
uint32_t seq
Definition: ubusd_monitor.c:22
struct blob_attr * data
Definition: ubusd.h:34
struct ubus_msghdr hdr
Definition: ubusd.h:33
uint32_t peer
Definition: ubusmsg.h:33
uint8_t type
Definition: ubusmsg.h:31
uint16_t seq
Definition: ubusmsg.h:32
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
@ UBUS_MSG_MONITOR
Definition: ubusmsg.h:73
@ UBUS_MONITOR_DATA
Definition: ubusmsg.h:112
@ UBUS_MONITOR_CLIENT
Definition: ubusmsg.h:107
@ UBUS_MONITOR_SEND
Definition: ubusmsg.h:109
@ UBUS_MONITOR_PEER
Definition: ubusmsg.h:108
@ UBUS_MONITOR_SEQ
Definition: ubusmsg.h:110
@ UBUS_MONITOR_TYPE
Definition: ubusmsg.h:111
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ubusd_monitor_recv()

static int ubusd_monitor_recv ( struct ubus_client cl,
struct ubus_msg_buf ub,
const char *  method,
struct blob_attr *  msg 
)
static

Definition at line 105 of file ubusd_monitor.c.

107 {
108  /* Only root is allowed for now */
109  if (cl->uid != 0 || cl->gid != 0)
111 
112  if (!strcmp(method, "add")) {
113  if (!ubusd_monitor_connect(cl, ub))
115 
116  return UBUS_STATUS_OK;
117  }
118 
119  if (!strcmp(method, "remove")) {
121  return UBUS_STATUS_OK;
122  }
123 
125 }
gid_t gid
Definition: ubusd.h:56
uid_t uid
Definition: ubusd.h:55
static bool ubusd_monitor_connect(struct ubus_client *cl, struct ubus_msg_buf *ub)
Definition: ubusd_monitor.c:33
@ UBUS_STATUS_METHOD_NOT_FOUND
Definition: ubusmsg.h:122
@ UBUS_STATUS_PERMISSION_DENIED
Definition: ubusmsg.h:125
@ UBUS_STATUS_OK
Definition: ubusmsg.h:119
@ UBUS_STATUS_UNKNOWN_ERROR
Definition: ubusmsg.h:128
Here is the call graph for this function:

Variable Documentation

◆ monitor_obj

struct ubus_object* monitor_obj
static

Definition at line 16 of file ubusd_monitor.c.