1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-01 17:51:22 +03:00

ndisc: improve debug log message

This commit is contained in:
Yu Watanabe 2018-11-06 14:07:19 +09:00
parent 4f0e4d29b0
commit a2dcda328a
3 changed files with 20 additions and 4 deletions

View File

@ -38,3 +38,6 @@ struct sd_ndisc {
#define log_ndisc_errno(error, fmt, ...) log_internal(LOG_DEBUG, error, __FILE__, __LINE__, __func__, "NDISC: " fmt, ##__VA_ARGS__)
#define log_ndisc(fmt, ...) log_ndisc_errno(0, fmt, ##__VA_ARGS__)
const char* ndisc_event_to_string(sd_ndisc_event e) _const_;
sd_ndisc_event ndisc_event_from_string(const char *s) _pure_;

View File

@ -16,19 +16,30 @@
#include "ndisc-router.h"
#include "random-util.h"
#include "socket-util.h"
#include "string-table.h"
#include "string-util.h"
#include "util.h"
#define NDISC_TIMEOUT_NO_RA_USEC (NDISC_ROUTER_SOLICITATION_INTERVAL * NDISC_MAX_ROUTER_SOLICITATIONS)
static const char * const ndisc_event_table[_SD_NDISC_EVENT_MAX] = {
[SD_NDISC_EVENT_TIMEOUT] = "timeout",
[SD_NDISC_EVENT_ROUTER] = "router",
};
DEFINE_STRING_TABLE_LOOKUP(ndisc_event, sd_ndisc_event);
static void ndisc_callback(sd_ndisc *ndisc, sd_ndisc_event event, sd_ndisc_router *rt) {
assert(ndisc);
assert(event >= 0 && event < _SD_NDISC_EVENT_MAX);
log_ndisc("Invoking callback for '%c'.", event);
if (!ndisc->callback)
if (!ndisc->callback) {
log_ndisc("Received '%s' event.", ndisc_event_to_string(event));
return;
}
log_ndisc("Invoking callback for '%s' event.", ndisc_event_to_string(event));
ndisc->callback(ndisc, event, rt, ndisc->userdata);
}

View File

@ -55,8 +55,10 @@ typedef struct sd_ndisc sd_ndisc;
typedef struct sd_ndisc_router sd_ndisc_router;
typedef enum sd_ndisc_event {
SD_NDISC_EVENT_TIMEOUT = 't',
SD_NDISC_EVENT_ROUTER = 'r',
SD_NDISC_EVENT_TIMEOUT,
SD_NDISC_EVENT_ROUTER,
_SD_NDISC_EVENT_MAX,
_SD_NDISC_EVENT_INVALID = -1,
} sd_ndisc_event;
typedef void (*sd_ndisc_callback_t)(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *rt, void *userdata);