From f407219cd1e70a62a7c2596d75bd7edcc4df697c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 14 Apr 2021 22:53:49 +0200 Subject: [PATCH] Check that errno passed log_{interface,link}_*_errno() is non-zero --- src/libsystemd-network/dhcp-internal.h | 2 +- src/libsystemd-network/dhcp-server-internal.h | 2 +- src/libsystemd-network/dhcp6-internal.h | 2 +- src/libsystemd-network/lldp-internal.h | 2 +- src/libsystemd-network/ndisc-internal.h | 2 +- src/libsystemd-network/radv-internal.h | 2 +- src/libsystemd-network/sd-ipv4acd.c | 2 +- src/libsystemd-network/sd-ipv4ll.c | 2 +- src/shared/log-link.h | 22 +++++++++++++++---- 9 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/libsystemd-network/dhcp-internal.h b/src/libsystemd-network/dhcp-internal.h index c5c851c575..8eefc02726 100644 --- a/src/libsystemd-network/dhcp-internal.h +++ b/src/libsystemd-network/dhcp-internal.h @@ -70,7 +70,7 @@ int dhcp_packet_verify_headers(DHCPPacket *packet, size_t len, bool checksum, ui ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_dhcp_client_get_ifname(client), \ LOG_DEBUG, _e, "DHCPv4 client: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/dhcp-server-internal.h b/src/libsystemd-network/dhcp-server-internal.h index d30d91082f..391f2da9ac 100644 --- a/src/libsystemd-network/dhcp-server-internal.h +++ b/src/libsystemd-network/dhcp-server-internal.h @@ -102,7 +102,7 @@ int client_id_compare_func(const DHCPClientId *a, const DHCPClientId *b); ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_dhcp_server_get_ifname(server), \ LOG_DEBUG, _e, "DHCPv4 server: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/dhcp6-internal.h b/src/libsystemd-network/dhcp6-internal.h index 274b14b056..26897404fe 100644 --- a/src/libsystemd-network/dhcp6-internal.h +++ b/src/libsystemd-network/dhcp6-internal.h @@ -123,7 +123,7 @@ int dhcp6_message_status_from_string(const char *s) _pure_; ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_dhcp6_client_get_ifname(client), \ LOG_DEBUG, _e, "DHCPv6 client: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/lldp-internal.h b/src/libsystemd-network/lldp-internal.h index f13555d35c..6babcce066 100644 --- a/src/libsystemd-network/lldp-internal.h +++ b/src/libsystemd-network/lldp-internal.h @@ -40,7 +40,7 @@ sd_lldp_event_t lldp_event_from_string(const char *s) _pure_; ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_lldp_get_ifname(lldp), \ LOG_DEBUG, _e, "LLDP: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/ndisc-internal.h b/src/libsystemd-network/ndisc-internal.h index 44a7e76c21..d7aa69a181 100644 --- a/src/libsystemd-network/ndisc-internal.h +++ b/src/libsystemd-network/ndisc-internal.h @@ -45,7 +45,7 @@ sd_ndisc_event_t ndisc_event_from_string(const char *s) _pure_; ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_ndisc_get_ifname(ndisc), \ LOG_DEBUG, _e, "NDISC: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/radv-internal.h b/src/libsystemd-network/radv-internal.h index fe5d74fda4..eef6db514a 100644 --- a/src/libsystemd-network/radv-internal.h +++ b/src/libsystemd-network/radv-internal.h @@ -129,7 +129,7 @@ struct sd_radv_route_prefix { ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_radv_get_ifname(radv), \ LOG_DEBUG, _e, "RADV: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 643bdc4ba9..65a8588725 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -79,7 +79,7 @@ struct sd_ipv4acd { ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_ipv4acd_get_ifname(acd), \ LOG_DEBUG, _e, "IPv4ACD: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 49e9350fba..cdde412a55 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -53,7 +53,7 @@ struct sd_ipv4ll { ({ \ int _e = (error); \ if (DEBUG_LOGGING) \ - log_interface_full_errno( \ + log_interface_full_errno_zerook( \ sd_ipv4ll_get_ifname(ll), \ LOG_DEBUG, _e, "IPv4LL: " fmt, \ ##__VA_ARGS__); \ diff --git a/src/shared/log-link.h b/src/shared/log-link.h index ecc2609e51..5f2b176353 100644 --- a/src/shared/log-link.h +++ b/src/shared/log-link.h @@ -3,13 +3,20 @@ #include "log.h" -#define log_interface_full_errno(ifname, level, error, ...) \ +#define log_interface_full_errno_zerook(ifname, level, error, ...) \ ({ \ const char *_ifname = (ifname); \ _ifname ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, "INTERFACE=", _ifname, NULL, NULL, ##__VA_ARGS__) : \ log_internal(level, error, PROJECT_FILE, __LINE__, __func__, ##__VA_ARGS__); \ }) +#define log_interface_full_errno(ifname, level, error, ...) \ + ({ \ + int _error = (error); \ + ASSERT_NON_ZERO(_error); \ + log_interface_full_errno_zerook(ifname, level, _error, __VA_ARGS__); \ + }) + /* * The following macros append INTERFACE= to the message. * The macros require a struct named 'Link' which contains 'char *ifname': @@ -21,13 +28,20 @@ * See, network/networkd-link.h for example. */ -#define log_link_full_errno(link, level, error, ...) \ +#define log_link_full_errno_zerook(link, level, error, ...) \ ({ \ const Link *_l = (link); \ - log_interface_full_errno(_l ? _l->ifname : NULL, level, error, ##__VA_ARGS__); \ + log_interface_full_errno_zerook(_l ? _l->ifname : NULL, level, error, __VA_ARGS__); \ }) -#define log_link_full(link, level, ...) (void) log_link_full_errno(link, level, 0, __VA_ARGS__) +#define log_link_full_errno(link, level, error, ...) \ + ({ \ + int _error = (error); \ + ASSERT_NON_ZERO(_error); \ + log_link_full_errno_zerook(link, level, _error, __VA_ARGS__); \ + }) + +#define log_link_full(link, level, ...) (void) log_link_full_errno_zerook(link, level, 0, __VA_ARGS__) #define log_link_debug(link, ...) log_link_full(link, LOG_DEBUG, __VA_ARGS__) #define log_link_info(link, ...) log_link_full(link, LOG_INFO, __VA_ARGS__)