#include <stdarg.h>
#include <syslog.h>
-#include <udebug.h>
-
#include "netifd.h"
#include "ubus.h"
#include "config.h"
static struct list_head process_list = LIST_HEAD_INIT(process_list);
static struct udebug ud;
-static struct udebug_buf udb;
-static bool udebug_enabled;
+static struct udebug_buf udb_log;
+struct udebug_buf udb_nl;
+static const struct udebug_buf_meta meta_log = {
+ .name = "netifd_log",
+ .format = UDEBUG_FORMAT_STRING,
+};
+static const struct udebug_buf_meta meta_nl = {
+ .name = "netifd_nl",
+ .format = UDEBUG_FORMAT_PACKET,
+ .sub_format = UDEBUG_DLT_NETLINK,
+};
+static struct udebug_ubus_ring rings[] = {
+ {
+ .buf = &udb_log,
+ .meta = &meta_log,
+ .default_entries = 1024,
+ .default_size = 64 * 1024,
+ },
+ {
+ .buf = &udb_nl,
+ .meta = &meta_nl,
+ .default_entries = 1024,
+ .default_size = 64 * 1024,
+ },
+};
#define DEFAULT_LOG_LEVEL L_NOTICE
static void
netifd_udebug_vprintf(const char *format, va_list ap)
{
- if (!udebug_enabled)
+ if (!udebug_buf_valid(&udb_log))
return;
- udebug_entry_init(&udb);
- udebug_entry_vprintf(&udb, format, ap);
- udebug_entry_add(&udb);
+ udebug_entry_init(&udb_log);
+ udebug_entry_vprintf(&udb_log, format, ap);
+ udebug_entry_add(&udb_log);
}
void netifd_udebug_printf(const char *format, ...)
va_end(ap);
}
-void netifd_udebug_set_enabled(bool val)
+void netifd_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data,
+ bool enabled)
{
- static const struct udebug_buf_meta meta = {
- .name = "netifd_log",
- .format = UDEBUG_FORMAT_STRING,
- };
-
- if (udebug_enabled == val)
- return;
-
- udebug_enabled = val;
- if (!val) {
- udebug_buf_free(&udb);
- udebug_free(&ud);
- return;
- }
-
- udebug_init(&ud);
- udebug_auto_connect(&ud, NULL);
- udebug_buf_init(&udb, 1024, 64 * 1024);
- udebug_buf_add(&ud, &udb, &meta);
+ udebug_ubus_apply_config(&ud, rings, ARRAY_SIZE(rings), data, enabled);
}
void
openlog("netifd", 0, LOG_DAEMON);
netifd_setup_signals();
+ uloop_init();
+ udebug_init(&ud);
+ udebug_auto_connect(&ud, NULL);
+ for (size_t i = 0; i < ARRAY_SIZE(rings); i++)
+ udebug_ubus_ring_init(&ud, &rings[i]);
+
if (netifd_ubus_init(socket) < 0) {
fprintf(stderr, "Failed to connect to ubus\n");
return 1;
#include <libubox/utils.h>
#include <libubus.h>
+#include <udebug.h>
#ifdef linux
#include <netinet/ether.h>
extern const char *resolv_conf;
extern char *hotplug_cmd_path;
extern unsigned int debug_mask;
+extern struct udebug_buf udb_nl;
enum {
L_CRIT,
};
void netifd_udebug_printf(const char *format, ...);
-void netifd_udebug_set_enabled(bool val);
+void netifd_udebug_config(struct udebug_ubus *ctx, struct blob_attr *data,
+ bool enabled);
void netifd_log_message(int priority, const char *format, ...);
int netifd_start_process(const char **argv, char **env, struct netifd_process *proc);
return;
}
+static void
+nl_udebug_cb(void *priv, struct nl_msg *msg)
+{
+ struct nlmsghdr *nlh = nlmsg_hdr(msg);
+
+ udebug_netlink_msg(priv, nlmsg_get_proto(msg), nlh, nlh->nlmsg_len);
+}
+
static struct nl_sock *
create_socket(int protocol, int groups)
{
return NULL;
}
+ nl_socket_set_tx_debug_cb(sock, nl_udebug_cb, &udb_nl);
+ nl_socket_set_rx_debug_cb(sock, nl_udebug_cb, &udb_nl);
+
return sock;
}
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
-#include <udebug.h>
#include "netifd.h"
#include "interface.h"
return ubus_invoke(ubus_ctx, id, method, msg, data_cb, data, 3000);
}
-static void
-netifd_udebug_cb(struct udebug_ubus *ctx, struct blob_attr *data, bool enabled)
-{
- netifd_udebug_set_enabled(enabled);
-}
-
int
netifd_ubus_init(const char *path)
{
- uloop_init();
ubus_path = path;
ubus_ctx = ubus_connect(path);
netifd_add_object(&wireless_object);
netifd_add_iface_object();
- udebug_ubus_init(&udebug, ubus_ctx, "netifd", netifd_udebug_cb);
+ udebug_ubus_init(&udebug, ubus_ctx, "netifd", netifd_udebug_config);
return 0;
}