diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-11-06 16:41:48 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-11-06 16:41:48 +0300 |
commit | ce9d553d2ec31b23b8d1a569c5a13b88496fd3cd (patch) | |
tree | 3bc4eb600411854574371006b09c265e65e899ff | |
parent | 875622c39e925f866587629b997e47fe4c7ff1cd (diff) | |
parent | 90208b8217e4b6bb309ca6767056c816cc0d1a4f (diff) | |
download | systemd-ce9d553d2ec31b23b8d1a569c5a13b88496fd3cd.tar.gz systemd-ce9d553d2ec31b23b8d1a569c5a13b88496fd3cd.tar.bz2 systemd-ce9d553d2ec31b23b8d1a569c5a13b88496fd3cd.zip |
Merge pull request #10652 from yuwata/lldp-ndisc-string-table
lldp,ndisc: update debug logs
-rw-r--r-- | src/libsystemd-network/lldp-internal.h | 3 | ||||
-rw-r--r-- | src/libsystemd-network/ndisc-internal.h | 3 | ||||
-rw-r--r-- | src/libsystemd-network/sd-lldp.c | 20 | ||||
-rw-r--r-- | src/libsystemd-network/sd-ndisc.c | 15 | ||||
-rw-r--r-- | src/network/test-network-tables.c | 4 | ||||
-rw-r--r-- | src/systemd/sd-lldp.h | 10 | ||||
-rw-r--r-- | src/systemd/sd-ndisc.h | 6 |
7 files changed, 49 insertions, 12 deletions
diff --git a/src/libsystemd-network/lldp-internal.h b/src/libsystemd-network/lldp-internal.h index 328d51f8ea..88b54933c3 100644 --- a/src/libsystemd-network/lldp-internal.h +++ b/src/libsystemd-network/lldp-internal.h @@ -34,3 +34,6 @@ struct sd_lldp { #define log_lldp_errno(error, fmt, ...) log_internal(LOG_DEBUG, error, __FILE__, __LINE__, __func__, "LLDP: " fmt, ##__VA_ARGS__) #define log_lldp(fmt, ...) log_lldp_errno(0, fmt, ##__VA_ARGS__) + +const char* lldp_event_to_string(sd_lldp_event e) _const_; +sd_lldp_event lldp_event_from_string(const char *s) _pure_; 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-lldp.c b/src/libsystemd-network/sd-lldp.c index f72ef204b9..993ca13727 100644 --- a/src/libsystemd-network/sd-lldp.c +++ b/src/libsystemd-network/sd-lldp.c @@ -6,15 +6,25 @@ #include "sd-lldp.h" #include "alloc-util.h" +#include "ether-addr-util.h" #include "fd-util.h" #include "lldp-internal.h" #include "lldp-neighbor.h" #include "lldp-network.h" #include "socket-util.h" -#include "ether-addr-util.h" +#include "string-table.h" #define LLDP_DEFAULT_NEIGHBORS_MAX 128U +static const char * const lldp_event_table[_SD_LLDP_EVENT_MAX] = { + [SD_LLDP_EVENT_ADDED] = "added", + [SD_LLDP_EVENT_REMOVED] = "removed", + [SD_LLDP_EVENT_UPDATED] = "updated", + [SD_LLDP_EVENT_REFRESHED] = "refreshed", +}; + +DEFINE_STRING_TABLE_LOOKUP(lldp_event, sd_lldp_event); + static void lldp_flush_neighbors(sd_lldp *lldp) { sd_lldp_neighbor *n; @@ -26,12 +36,14 @@ static void lldp_flush_neighbors(sd_lldp *lldp) { static void lldp_callback(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n) { assert(lldp); + assert(event >= 0 && event < _SD_LLDP_EVENT_MAX); - log_lldp("Invoking callback for '%c'.", event); - - if (!lldp->callback) + if (!lldp->callback) { + log_lldp("Received '%s' event.", lldp_event_to_string(event)); return; + } + log_lldp("Invoking callback for '%s' event.", lldp_event_to_string(event)); lldp->callback(lldp, event, n, lldp->userdata); } 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/network/test-network-tables.c b/src/network/test-network-tables.c index cfcfbeebf2..6b110b7110 100644 --- a/src/network/test-network-tables.c +++ b/src/network/test-network-tables.c @@ -1,6 +1,8 @@ #include "dhcp6-internal.h" #include "dhcp6-protocol.h" #include "ethtool-util.h" +#include "lldp-internal.h" +#include "ndisc-internal.h" #include "netdev/bond.h" #include "netdev/ipvlan.h" #include "netdev/macvlan.h" @@ -35,6 +37,8 @@ int main(int argc, char **argv) { test_table(nl_union_link_info_data, NL_UNION_LINK_INFO_DATA); test_table(radv_prefix_delegation, RADV_PREFIX_DELEGATION); test_table(wol, WOL); + test_table(lldp_event, SD_LLDP_EVENT); + test_table(ndisc_event, SD_NDISC_EVENT); test_table_sparse(ipvlan_mode, NETDEV_IPVLAN_MODE); test_table_sparse(macvlan_mode, NETDEV_MACVLAN_MODE); diff --git a/src/systemd/sd-lldp.h b/src/systemd/sd-lldp.h index d650794cc0..a3e5cd6be6 100644 --- a/src/systemd/sd-lldp.h +++ b/src/systemd/sd-lldp.h @@ -109,10 +109,12 @@ typedef struct sd_lldp sd_lldp; typedef struct sd_lldp_neighbor sd_lldp_neighbor; typedef enum sd_lldp_event { - SD_LLDP_EVENT_ADDED = 'a', - SD_LLDP_EVENT_REMOVED = 'r', - SD_LLDP_EVENT_UPDATED = 'u', - SD_LLDP_EVENT_REFRESHED = 'f', + SD_LLDP_EVENT_ADDED, + SD_LLDP_EVENT_REMOVED, + SD_LLDP_EVENT_UPDATED, + SD_LLDP_EVENT_REFRESHED, + _SD_LLDP_EVENT_MAX, + _SD_LLDP_EVENT_INVALID = -1, } sd_lldp_event; typedef void (*sd_lldp_callback_t)(sd_lldp *lldp, sd_lldp_event event, sd_lldp_neighbor *n, void *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); |