1 #ifndef __UDEBUG_RINGBUF_H
2 #define __UDEBUG_RINGBUF_H
8 #include <libubox/list.h>
9 #include <libubox/uloop.h>
10 #include <libubox/avl.h>
12 #define UDEBUG_SOCK_NAME "/var/run/udebug.sock"
17 UDEBUG_FORMAT_BLOBMSG
,
21 UDEBUG_DLT_ETHERNET
= 1,
23 UDEBUG_DLT_RAW_IP
= 101,
24 UDEBUG_DLT_IEEE_802_11
= 105,
25 UDEBUG_DLT_IEEE_802_11_RADIOTAP
= 127,
26 UDEBUG_DLT_NETLINK
= 253,
29 enum udebug_meta_type
{
30 UDEBUG_META_IFACE_NAME
,
31 UDEBUG_META_IFACE_DESC
,
35 #define UDEBUG_TS_MSEC 1000ULL
36 #define UDEBUG_TS_SEC (1000ULL * UDEBUG_TS_MSEC)
41 struct udebug_buf_flag
{
46 struct udebug_buf_meta
{
48 enum udebug_format format
;
49 uint32_t sub_format
; /* linktype for UDEBUG_FORMAT_PACKET */
50 const struct udebug_buf_flag
*flags
;
56 const struct udebug_buf_meta
*meta
;
59 struct list_head list
;
61 struct udebug_hdr
*hdr
;
69 struct udebug_packet_info
{
70 const char *attr
[__UDEBUG_META_MAX
];
73 struct udebug_remote_buf
{
75 struct udebug_buf buf
;
79 /* provided by user */
82 const struct udebug_packet_info
*meta
;
86 struct list_head local_rings
;
87 struct avl_tree remote_rings
;
92 struct uloop_timeout reconnect
;
95 void (*notify_cb
)(struct udebug
*ctx
, struct udebug_remote_buf
*rb
);
104 struct udebug_snapshot
{
105 struct udebug_ptr
*entries
;
106 unsigned int n_entries
;
107 unsigned int dropped
;
113 enum udebug_format format
;
120 struct udebug_snapshot
**list
;
123 struct udebug_snapshot
*s
;
131 uint64_t udebug_timestamp(void);
133 void udebug_entry_init_ts(struct udebug_buf
*buf
, uint64_t timestamp
);
134 static inline void udebug_entry_init(struct udebug_buf
*buf
)
136 udebug_entry_init_ts(buf
, udebug_timestamp());
138 void *udebug_entry_append(struct udebug_buf
*buf
, const void *data
, uint32_t len
);
139 int udebug_entry_printf(struct udebug_buf
*buf
, const char *fmt
, ...);
140 int udebug_entry_vprintf(struct udebug_buf
*buf
, const char *fmt
, va_list ap
);
141 void udebug_entry_add(struct udebug_buf
*buf
);
143 int udebug_buf_init(struct udebug_buf
*buf
, size_t entries
, size_t size
);
144 int udebug_buf_add(struct udebug
*ctx
, struct udebug_buf
*buf
,
145 const struct udebug_buf_meta
*meta
);
146 uint64_t udebug_buf_flags(struct udebug_buf
*buf
);
147 void udebug_buf_free(struct udebug_buf
*buf
);
149 struct udebug_remote_buf
*udebug_remote_buf_get(struct udebug
*ctx
, uint32_t id
);
150 int udebug_remote_buf_map(struct udebug
*ctx
, struct udebug_remote_buf
*rb
, uint32_t id
);
151 void udebug_remote_buf_unmap(struct udebug
*ctx
, struct udebug_remote_buf
*rb
);
152 int udebug_remote_buf_set_poll(struct udebug
*ctx
, struct udebug_remote_buf
*rb
, bool val
);
153 void udebug_remote_buf_set_flags(struct udebug_remote_buf
*rb
, uint64_t mask
, uint64_t set
);
154 struct udebug_snapshot
*udebug_remote_buf_snapshot(struct udebug_remote_buf
*rb
);
155 bool udebug_snapshot_get_entry(struct udebug_snapshot
*s
, struct udebug_iter
*it
, unsigned int entry
);
157 void udebug_remote_buf_set_start_time(struct udebug_remote_buf
*rb
, uint64_t ts
);
158 void udebug_remote_buf_set_start_offset(struct udebug_remote_buf
*rb
, uint32_t idx
);
160 void udebug_iter_start(struct udebug_iter
*it
, struct udebug_snapshot
**s
, size_t n
);
161 bool udebug_iter_next(struct udebug_iter
*it
);
163 void udebug_init(struct udebug
*ctx
);
164 int udebug_connect(struct udebug
*ctx
, const char *path
);
165 void udebug_auto_connect(struct udebug
*ctx
, const char *path
);
166 void udebug_add_uloop(struct udebug
*ctx
);
167 void udebug_poll(struct udebug
*ctx
);
168 void udebug_free(struct udebug
*ctx
);
170 static inline bool udebug_is_connected(struct udebug
*ctx
)
172 return ctx
->fd
.fd
>= 0;