From a0c2541b6bd38fcfd8282a5f86d6366fbd20d614 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 14 Apr 2021 23:12:50 +0200 Subject: [PATCH] =?UTF-8?q?libsystemd-network:=20use=20macro=20for=20defin?= =?UTF-8?q?itions=20of=20log=5F{lldp,dhcp,=E2=80=A6}=5Ferrno?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit No functional change. --- src/libsystemd-network/dhcp-internal.h | 15 +++++---------- src/libsystemd-network/dhcp-server-internal.h | 15 +++++---------- src/libsystemd-network/dhcp6-internal.h | 17 ++++++----------- src/libsystemd-network/lldp-internal.h | 17 ++++++----------- src/libsystemd-network/ndisc-internal.h | 17 ++++++----------- src/libsystemd-network/radv-internal.h | 17 ++++++----------- src/libsystemd-network/sd-ipv4acd.c | 15 +++++---------- src/libsystemd-network/sd-ipv4ll.c | 15 +++++---------- src/shared/log-link.h | 11 +++++++++++ 9 files changed, 55 insertions(+), 84 deletions(-) diff --git a/src/libsystemd-network/dhcp-internal.h b/src/libsystemd-network/dhcp-internal.h index 8eefc02726..ee2ce2b250 100644 --- a/src/libsystemd-network/dhcp-internal.h +++ b/src/libsystemd-network/dhcp-internal.h @@ -66,15 +66,10 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, ui #define DHCP_CLIENT_DONT_DESTROY(client) \ _cleanup_(sd_dhcp_client_unrefp) _unused_ sd_dhcp_client *_dont_destroy_##client = sd_dhcp_client_ref(client) -#define log_dhcp_client_errno(client, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_dhcp_client_get_ifname(client), \ - LOG_DEBUG, _e, "DHCPv4 client: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) +#define log_dhcp_client_errno(client, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "DHCPv4 client: ", \ + sd_dhcp_client_get_ifname(client), \ + error, fmt, ##__VA_ARGS__) #define log_dhcp_client(client, fmt, ...) \ log_dhcp_client_errno(client, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h index 391f2da9ac..67c1cf4605 100644 --- a/src/libsystemd-network/dhcp-server-internal.h +++ b/src/libsystemd-network/dhcp-server-internal.h @@ -98,15 +98,10 @@ int dhcp_server_send_packet(sd_dhcp_server *server, void client_id_hash_func(const DHCPClientId *p, struct siphash *state); int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b); -#define log_dhcp_server_errno(server, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_dhcp_server_get_ifname(server), \ - LOG_DEBUG, _e, "DHCPv4 server: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) +#define log_dhcp_server_errno(server, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "DHCPv4 server: ", \ + sd_dhcp_server_get_ifname(server), \ + error, fmt, ##__VA_ARGS__) #define log_dhcp_server(server, fmt, ...) \ log_dhcp_server_errno(server, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/dhcp6-internal.h b/src/libsystemd-network/dhcp6-internal.h index 26897404fe..2b61a7bb3b 100644 --- a/src/libsystemd-network/dhcp6-internal.h +++ b/src/libsystemd-network/dhcp6-internal.h @@ -119,15 +119,10 @@ int dhcp6_message_type_from_string(const char *s) _pure_; const char *dhcp6_message_status_to_string(int s) _const_; int dhcp6_message_status_from_string(const char *s) _pure_; -#define log_dhcp6_client_errno(client, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_dhcp6_client_get_ifname(client), \ - LOG_DEBUG, _e, "DHCPv6 client: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) -#define log_dhcp6_client(client, fmt, ...) \ +#define log_dhcp6_client_errno(client, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "DHCPv6 client: ", \ + sd_dhcp6_client_get_ifname(client), \ + error, fmt, ##__VA_ARGS__) +#define log_dhcp6_client(client, fmt, ...) \ log_dhcp6_client_errno(client, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/lldp-internal.h b/src/libsystemd-network/lldp-internal.h index 6babcce066..8846fa5323 100644 --- a/src/libsystemd-network/lldp-internal.h +++ b/src/libsystemd-network/lldp-internal.h @@ -36,15 +36,10 @@ struct sd_lldp { const char* lldp_event_to_string(sd_lldp_event_t e) _const_; sd_lldp_event_t lldp_event_from_string(const char *s) _pure_; -#define log_lldp_errno(lldp, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_lldp_get_ifname(lldp), \ - LOG_DEBUG, _e, "LLDP: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) -#define log_lldp(lldp, fmt, ...) \ +#define log_lldp_errno(lldp, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "LLDP: ", \ + sd_lldp_get_ifname(lldp), \ + error, fmt, ##__VA_ARGS__) +#define log_lldp(lldp, fmt, ...) \ log_lldp_errno(lldp, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/ndisc-internal.h b/src/libsystemd-network/ndisc-internal.h index d7aa69a181..490305c329 100644 --- a/src/libsystemd-network/ndisc-internal.h +++ b/src/libsystemd-network/ndisc-internal.h @@ -41,15 +41,10 @@ struct sd_ndisc { const char* ndisc_event_to_string(sd_ndisc_event_t e) _const_; sd_ndisc_event_t ndisc_event_from_string(const char *s) _pure_; -#define log_ndisc_errno(ndisc, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_ndisc_get_ifname(ndisc), \ - LOG_DEBUG, _e, "NDISC: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) -#define log_ndisc(ndisc, fmt, ...) \ +#define log_ndisc_errno(ndisc, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "NDISC: ", \ + sd_ndisc_get_ifname(ndisc), \ + error, fmt, ##__VA_ARGS__) +#define log_ndisc(ndisc, fmt, ...) \ log_ndisc_errno(ndisc, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/radv-internal.h b/src/libsystemd-network/radv-internal.h index eef6db514a..7586ce6755 100644 --- a/src/libsystemd-network/radv-internal.h +++ b/src/libsystemd-network/radv-internal.h @@ -125,15 +125,10 @@ struct sd_radv_route_prefix { LIST_FIELDS(struct sd_radv_route_prefix, prefix); }; -#define log_radv_errno(radv, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_radv_get_ifname(radv), \ - LOG_DEBUG, _e, "RADV: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) -#define log_radv(radv, fmt, ...) \ +#define log_radv_errno(radv, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "RADV: ", \ + sd_radv_get_ifname(radv), \ + error, fmt, ##__VA_ARGS__) +#define log_radv(radv, fmt, ...) \ log_radv_errno(radv, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 65a8588725..a2f3ab4921 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -75,16 +75,11 @@ struct sd_ipv4acd { void* userdata; }; -#define log_ipv4acd_errno(acd, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_ipv4acd_get_ifname(acd), \ - LOG_DEBUG, _e, "IPv4ACD: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) +#define log_ipv4acd_errno(acd, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "IPv4ACD: ", \ + sd_ipv4acd_get_ifname(acd), \ + error, fmt, ##__VA_ARGS__) #define log_ipv4acd(acd, fmt, ...) \ log_ipv4acd_errno(acd, 0, fmt, ##__VA_ARGS__) diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index cdde412a55..448449059e 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -49,16 +49,11 @@ struct sd_ipv4ll { void* userdata; }; -#define log_ipv4ll_errno(ll, error, fmt, ...) \ - ({ \ - int _e = (error); \ - if (DEBUG_LOGGING) \ - log_interface_full_errno_zerook( \ - sd_ipv4ll_get_ifname(ll), \ - LOG_DEBUG, _e, "IPv4LL: " fmt, \ - ##__VA_ARGS__); \ - -ERRNO_VALUE(_e); \ - }) +#define log_ipv4ll_errno(ll, error, fmt, ...) \ + log_interface_prefix_full_errno_zerook( \ + "IPv4LL: ", \ + sd_ipv4ll_get_ifname(ll), \ + error, fmt, ##__VA_ARGS__) #define log_ipv4ll(ll, fmt, ...) \ log_ipv4ll_errno(ll, 0, fmt, ##__VA_ARGS__) diff --git a/src/shared/log-link.h b/src/shared/log-link.h index 5f2b176353..20eab4cc04 100644 --- a/src/shared/log-link.h +++ b/src/shared/log-link.h @@ -17,6 +17,17 @@ log_interface_full_errno_zerook(ifname, level, _error, __VA_ARGS__); \ }) +#define log_interface_prefix_full_errno_zerook(prefix, ifname_expr, error, fmt, ...) \ + ({ \ + int _e = (error); \ + if (DEBUG_LOGGING) \ + log_interface_full_errno_zerook( \ + ifname_expr, \ + LOG_DEBUG, _e, prefix fmt, \ + ##__VA_ARGS__); \ + -ERRNO_VALUE(_e); \ + }) + /* * The following macros append INTERFACE= to the message. * The macros require a struct named 'Link' which contains 'char *ifname':