1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-23 21:35:11 +03:00

Merge pull request #34111 from yuwata/log_section_full_errno

network: introduce log_section_full_errno() and friends, and use them
This commit is contained in:
Yu Watanabe 2024-08-24 08:31:02 +09:00 committed by GitHub
commit 4e03518b16
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 55 additions and 15 deletions

View File

@ -2005,16 +2005,25 @@ int config_parse_routing_policy_rule_type(
return 0;
}
#define log_rule_section(rule, fmt, ...) \
({ \
const RoutingPolicyRule *_rule = (rule); \
log_section_warning_errno( \
_rule ? _rule->section : NULL, \
SYNTHETIC_ERRNO(EINVAL), \
fmt " Ignoring [RoutingPolicyRule] section.", \
##__VA_ARGS__); \
})
static int routing_policy_rule_section_verify(RoutingPolicyRule *rule) {
assert(rule);
if (section_is_invalid(rule->section))
return -EINVAL;
if ((rule->family == AF_INET && FLAGS_SET(rule->address_family, ADDRESS_FAMILY_IPV6)) ||
(rule->family == AF_INET6 && FLAGS_SET(rule->address_family, ADDRESS_FAMILY_IPV4)))
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: address family specified by Family= conflicts with the address "
"specified by To= or From=. Ignoring [RoutingPolicyRule] section from line %u.",
rule->section->filename, rule->section->line);
return log_rule_section(rule, "Address family specified by Family= conflicts with To= and/or From=.");
if (rule->family == AF_UNSPEC) {
if (IN_SET(rule->address_family, ADDRESS_FAMILY_IPV4, ADDRESS_FAMILY_NO))
@ -2024,24 +2033,18 @@ static int routing_policy_rule_section_verify(RoutingPolicyRule *rule) {
/* rule->family can be AF_UNSPEC only when Family=both. */
}
assert(IN_SET(rule->family, AF_INET, AF_INET6) || rule->address_family == ADDRESS_FAMILY_YES);
if (rule->l3mdev)
rule->table = RT_TABLE_UNSPEC;
if (rule->type == FR_ACT_GOTO) {
if (rule->priority_goto <= 0)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: Type=goto is specified but the target priority GoTo= is unspecified. "
"Ignoring [RoutingPolicyRule] section from line %u.",
rule->section->filename,
rule->section->line);
return log_rule_section(rule, "Type=goto is specified but the target priority GoTo= is unspecified.");
if (rule->priority_set && rule->priority >= rule->priority_goto)
return log_error_errno(SYNTHETIC_ERRNO(EINVAL),
"%s: goto target priority %"PRIu32" must be larger than the priority of this rule %"PRIu32". "
"Ignoring [RoutingPolicyRule] section from line %u.",
rule->section->filename,
rule->priority_goto, rule->priority,
rule->section->line);
return log_rule_section(rule, "Goto target priority %"PRIu32" must be larger than the priority of this rule %"PRIu32".",
rule->priority_goto, rule->priority);
}
return 0;

View File

@ -203,6 +203,43 @@ static inline bool section_is_invalid(ConfigSection *section) {
DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func); \
DEFINE_TRIVIAL_CLEANUP_FUNC(type*, free_func##_or_set_invalid);
#define log_section_full_errno_zerook(section, level, error, ...) \
({ \
const ConfigSection *_s = (section); \
log_syntax(/* unit = */ NULL, \
level, \
_s ? _s->filename : NULL, \
_s ? _s->line : 0, \
error, \
__VA_ARGS__); \
})
#define log_section_full_errno(section, level, error, ...) \
({ \
int _error = (error); \
ASSERT_NON_ZERO(_error); \
log_section_full_errno_zerook(section, level, _error, __VA_ARGS__); \
})
#define log_section_full(section, level, fmt, ...) \
({ \
if (BUILD_MODE_DEVELOPER) \
assert(!strstr(fmt, "%m")); \
(void) log_section_full_errno_zerook(section, level, 0, fmt, ##__VA_ARGS__); \
})
#define log_section_debug(section, ...) log_section_full(section, LOG_DEBUG, __VA_ARGS__)
#define log_section_info(section, ...) log_section_full(section, LOG_INFO, __VA_ARGS__)
#define log_section_notice(section, ...) log_section_full(section, LOG_NOTICE, __VA_ARGS__)
#define log_section_warning(section, ...) log_section_full(section, LOG_WARNING, __VA_ARGS__)
#define log_section_error(section, ...) log_section_full(section, LOG_ERR, __VA_ARGS__)
#define log_section_debug_errno(section, error, ...) log_section_full_errno(section, LOG_DEBUG, error, __VA_ARGS__)
#define log_section_info_errno(section, error, ...) log_section_full_errno(section, LOG_INFO, error, __VA_ARGS__)
#define log_section_notice_errno(section, error, ...) log_section_full_errno(section, LOG_NOTICE, error, __VA_ARGS__)
#define log_section_warning_errno(section, error, ...) log_section_full_errno(section, LOG_WARNING, error, __VA_ARGS__)
#define log_section_error_errno(section, error, ...) log_section_full_errno(section, LOG_ERR, error, __VA_ARGS__)
CONFIG_PARSER_PROTOTYPE(config_parse_int);
CONFIG_PARSER_PROTOTYPE(config_parse_unsigned);
CONFIG_PARSER_PROTOTYPE(config_parse_long);