diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-06 14:07:19 +0900 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-06 20:15:09 +0900 |
commit | a2dcda328a43693b73449ce6be0545dd60846cd9 (patch) | |
tree | bcc4b467b40e786689f9b9528b7a5f9eb54ab451 | |
parent | 4f0e4d29b0fa232d077653cea57061770c3a529e (diff) | |
download | systemd-a2dcda328a43693b73449ce6be0545dd60846cd9.tar.gz systemd-a2dcda328a43693b73449ce6be0545dd60846cd9.tar.bz2 systemd-a2dcda328a43693b73449ce6be0545dd60846cd9.zip |
ndisc: improve debug log message
-rw-r--r-- | src/libsystemd-network/ndisc-internal.h | 3 | ||||
-rw-r--r-- | src/libsystemd-network/sd-ndisc.c | 15 | ||||
-rw-r--r-- | src/systemd/sd-ndisc.h | 6 |
3 files changed, 20 insertions, 4 deletions
diff --git a/src/libsystemd-network/ndisc-internal.h b/src/libsystemd-network/ndisc-internal.h index fdabbc1b0e..0c04fea8e5 100644 --- a/src/libsystemd-network/ndisc-internal.h +++ b/src/libsystemd-network/ndisc-internal.h @@ -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_; diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c index d679fc8222..b2fd087987 100644 --- a/src/libsystemd-network/sd-ndisc.c +++ b/src/libsystemd-network/sd-ndisc.c @@ -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); } diff --git a/src/systemd/sd-ndisc.h b/src/systemd/sd-ndisc.h index 6b6249ca03..d1bee343a2 100644 --- a/src/systemd/sd-ndisc.h +++ b/src/systemd/sd-ndisc.h @@ -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); |