1
0
mirror of https://github.com/systemd/systemd.git synced 2024-12-27 07:22:31 +03:00

network: drop unnecessary buffers

This commit is contained in:
Yu Watanabe 2018-12-03 10:22:05 +01:00 committed by Lennart Poettering
parent ad2bf5df89
commit 7934dede41
2 changed files with 43 additions and 66 deletions

View File

@ -678,8 +678,7 @@ int config_parse_gateway(
Network *network = userdata;
_cleanup_(route_freep) Route *n = NULL;
union in_addr_union buffer;
int r, f;
int r;
assert(filename);
assert(section);
@ -697,14 +696,12 @@ int config_parse_gateway(
if (r < 0)
return r;
r = in_addr_from_string_auto(rvalue, &f, &buffer);
r = in_addr_from_string_auto(rvalue, &n->family, &n->gw);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "Route is invalid, ignoring assignment: %s", rvalue);
return 0;
}
n->family = f;
n->gw = buffer;
TAKE_PTR(n);
return 0;
@ -724,8 +721,7 @@ int config_parse_preferred_src(
Network *network = userdata;
_cleanup_(route_freep) Route *n = NULL;
union in_addr_union buffer;
int r, f;
int r;
assert(filename);
assert(section);
@ -737,15 +733,13 @@ int config_parse_preferred_src(
if (r < 0)
return r;
r = in_addr_from_string_auto(rvalue, &f, &buffer);
r = in_addr_from_string_auto(rvalue, &n->family, &n->prefsrc);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
"Preferred source is invalid, ignoring assignment: %s", rvalue);
return 0;
}
n->family = f;
n->prefsrc = buffer;
TAKE_PTR(n);
return 0;
@ -765,8 +759,8 @@ int config_parse_destination(
Network *network = userdata;
_cleanup_(route_freep) Route *n = NULL;
union in_addr_union buffer;
unsigned char prefixlen;
union in_addr_union *buffer;
unsigned char *prefixlen;
int r;
assert(filename);
@ -779,9 +773,16 @@ int config_parse_destination(
if (r < 0)
return r;
r = in_addr_prefix_from_string(rvalue, AF_INET, &buffer, &prefixlen);
if (r < 0) {
r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen);
if (streq(lvalue, "Destination")) {
buffer = &n->dst;
prefixlen = &n->dst_prefixlen;
} else if (streq(lvalue, "Source")) {
buffer = &n->src;
prefixlen = &n->src_prefixlen;
} else
assert_not_reached(lvalue);
r = in_addr_prefix_from_string_auto(rvalue, &n->family, buffer, prefixlen);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
"Route %s= prefix is invalid, ignoring assignment: %s",
@ -789,19 +790,6 @@ int config_parse_destination(
return 0;
}
n->family = AF_INET6;
} else
n->family = AF_INET;
if (streq(lvalue, "Destination")) {
n->dst = buffer;
n->dst_prefixlen = prefixlen;
} else if (streq(lvalue, "Source")) {
n->src = buffer;
n->src_prefixlen = prefixlen;
} else
assert_not_reached(lvalue);
TAKE_PTR(n);
return 0;
}

View File

@ -802,8 +802,8 @@ int config_parse_routing_policy_rule_prefix(
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *n = NULL;
Network *network = userdata;
union in_addr_union buffer;
uint8_t prefixlen;
union in_addr_union *buffer;
uint8_t *prefixlen;
int r;
assert(filename);
@ -816,26 +816,20 @@ int config_parse_routing_policy_rule_prefix(
if (r < 0)
return r;
r = in_addr_prefix_from_string(rvalue, AF_INET, &buffer, &prefixlen);
if (r < 0) {
r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen);
if (streq(lvalue, "To")) {
buffer = &n->to;
prefixlen = &n->to_prefixlen;
} else {
buffer = &n->from;
prefixlen = &n->from_prefixlen;
}
r = in_addr_prefix_from_string_auto(rvalue, &n->family, buffer, prefixlen);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r, "RPDB rule prefix is invalid, ignoring assignment: %s", rvalue);
return 0;
}
n->family = AF_INET6;
} else
n->family = AF_INET;
if (streq(lvalue, "To")) {
n->to = buffer;
n->to_prefixlen = prefixlen;
} else {
n->from = buffer;
n->from_prefixlen = prefixlen;
}
n = NULL;
return 0;
@ -1118,8 +1112,6 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
for (;;) {
_cleanup_free_ char *word = NULL, *a = NULL, *b = NULL;
union in_addr_union buffer;
uint8_t prefixlen;
r = extract_first_word(&p, &word, NULL, 0);
if (r < 0)
@ -1132,26 +1124,23 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
continue;
if (STR_IN_SET(a, "from", "to")) {
union in_addr_union *buffer;
uint8_t *prefixlen;
r = in_addr_prefix_from_string(b, AF_INET, &buffer, &prefixlen);
if (r < 0) {
r = in_addr_prefix_from_string(b, AF_INET6, &buffer, &prefixlen);
if (streq(a, "to")) {
buffer = &rule->to;
prefixlen = &rule->to_prefixlen;
} else {
buffer = &rule->from;
prefixlen = &rule->from_prefixlen;
}
r = in_addr_prefix_from_string_auto(b, &rule->family, buffer, prefixlen);
if (r < 0) {
log_error_errno(r, "RPDB rule prefix is invalid, ignoring assignment: %s", b);
continue;
}
rule->family = AF_INET6;
} else
rule->family = AF_INET;
if (streq(a, "to")) {
rule->to = buffer;
rule->to_prefixlen = prefixlen;
} else {
rule->from = buffer;
rule->from_prefixlen = prefixlen;
}
} else if (streq(a, "tos")) {
r = safe_atou8(b, &rule->tos);
if (r < 0) {