mirror of
https://github.com/systemd/systemd.git
synced 2024-11-01 17:51:22 +03:00
Merge pull request #10652 from yuwata/lldp-ndisc-string-table
lldp,ndisc: update debug logs
This commit is contained in:
commit
ce9d553d2e
@ -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_;
|
||||
|
@ -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_;
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user