diff options
| author | Sebastien Bacher <seb128@ubuntu.com> | 2021-02-25 11:35:01 +0100 |
|---|---|---|
| committer | Sebastien Bacher <seb128@ubuntu.com> | 2021-02-25 11:49:48 +0100 |
| commit | 77dea84aa6e816f66dc622cec8ae2668eba3c068 (patch) | |
| tree | 755536a0ed1fb36c2899e9bff9e092c4008a25c4 /src/core/dhcp/nm-dhcp-client-logging.h | |
| parent | 47f08826b44eed651b44dc8bacb5b46bc4c52067 (diff) | |
| parent | fd80297a396cc4dd7da4da20208fb360aa369aa7 (diff) | |
Merge branch 'debian/master' into ubuntu/master
Diffstat (limited to 'src/core/dhcp/nm-dhcp-client-logging.h')
| -rw-r--r-- | src/core/dhcp/nm-dhcp-client-logging.h | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/src/core/dhcp/nm-dhcp-client-logging.h b/src/core/dhcp/nm-dhcp-client-logging.h new file mode 100644 index 00000000..d69b3ebd --- /dev/null +++ b/src/core/dhcp/nm-dhcp-client-logging.h @@ -0,0 +1,87 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2016 Red Hat, Inc. + */ + +#ifndef __NETWORKMANAGER_DHCP_CLIENT_LOGGING_H__ +#define __NETWORKMANAGER_DHCP_CLIENT_LOGGING_H__ + +#include "nm-dhcp-client.h" + +static inline NMLogDomain +_nm_dhcp_client_get_domain(NMDhcpClient *self) +{ + if (self) { + switch (nm_dhcp_client_get_addr_family(self)) { + case AF_INET: + return LOGD_DHCP4; + case AF_INET6: + return LOGD_DHCP6; + default: + nm_assert_not_reached(); + break; + } + } + return LOGD_DHCP; +} + +#define _NMLOG_PREFIX_NAME "dhcp" +#define _NMLOG_DOMAIN LOGD_DHCP +#define _NMLOG(level, ...) \ + G_STMT_START \ + { \ + const NMLogLevel _level = (level); \ + \ + /* we check first for LOGD_DHCP instead of the correct domain. + * In the worst case, we guess wrong and enter the block. + * + * Same for the _NMLOG_ENABLED() macro. Probably it would be more + * expensive to determine the correct value then what we could + * safe. */ \ + if (nm_logging_enabled(_level, _NMLOG_DOMAIN)) { \ + NMDhcpClient * _self = (NMDhcpClient *) (self); \ + const char * __ifname = _self ? nm_dhcp_client_get_iface(_self) : NULL; \ + const NMLogDomain _domain = _nm_dhcp_client_get_domain(_self); \ + \ + nm_log(_level, \ + _domain, \ + __ifname, \ + NULL, \ + "%s%s%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME, \ + (_domain == LOGD_DHCP4 ? "4" : (_domain == LOGD_DHCP6 ? "6" : "")), \ + NM_PRINT_FMT_QUOTED(__ifname, " (", __ifname, ")", "") \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ + } \ + G_STMT_END + +#define _NMLOG2(level, domain, ifname, ...) \ + G_STMT_START \ + { \ + const NMLogLevel _level = (level); \ + const NMLogDomain _domain = (domain); \ + \ + /* we check first for LOGD_DHCP instead of the correct domain. + * In the worst case, we guess wrong and enter the block. + * + * Same for the _NMLOG_ENABLED() macro. Probably it would be more + * expensive to determine the correct value then what we could + * safe. */ \ + if (nm_logging_enabled(_level, _domain)) { \ + const char *__ifname = (ifname); \ + \ + nm_log(_level, \ + _domain, \ + __ifname, \ + NULL, \ + "%s%s%s%s%s: " _NM_UTILS_MACRO_FIRST(__VA_ARGS__), \ + _NMLOG_PREFIX_NAME, \ + (_domain == LOGD_DHCP4 ? "4" : (_domain == LOGD_DHCP6 ? "6" : "")), \ + NM_PRINT_FMT_QUOTED(__ifname, " (", __ifname, ")", "") \ + _NM_UTILS_MACRO_REST(__VA_ARGS__)); \ + } \ + } \ + G_STMT_END + +#endif /* __NETWORKMANAGER_DHCP_CLIENT_LOGGING_H__ */ |