network: drop unnecessary buffers
This commit is contained in:
parent
ad2bf5df89
commit
7934dede41
|
@ -678,8 +678,7 @@ int config_parse_gateway(
|
||||||
|
|
||||||
Network *network = userdata;
|
Network *network = userdata;
|
||||||
_cleanup_(route_freep) Route *n = NULL;
|
_cleanup_(route_freep) Route *n = NULL;
|
||||||
union in_addr_union buffer;
|
int r;
|
||||||
int r, f;
|
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
assert(section);
|
assert(section);
|
||||||
|
@ -697,14 +696,12 @@ int config_parse_gateway(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
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) {
|
if (r < 0) {
|
||||||
log_syntax(unit, LOG_ERR, filename, line, r, "Route is invalid, ignoring assignment: %s", rvalue);
|
log_syntax(unit, LOG_ERR, filename, line, r, "Route is invalid, ignoring assignment: %s", rvalue);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
n->family = f;
|
|
||||||
n->gw = buffer;
|
|
||||||
TAKE_PTR(n);
|
TAKE_PTR(n);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -724,8 +721,7 @@ int config_parse_preferred_src(
|
||||||
|
|
||||||
Network *network = userdata;
|
Network *network = userdata;
|
||||||
_cleanup_(route_freep) Route *n = NULL;
|
_cleanup_(route_freep) Route *n = NULL;
|
||||||
union in_addr_union buffer;
|
int r;
|
||||||
int r, f;
|
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
assert(section);
|
assert(section);
|
||||||
|
@ -737,15 +733,13 @@ int config_parse_preferred_src(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
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) {
|
if (r < 0) {
|
||||||
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
log_syntax(unit, LOG_ERR, filename, line, EINVAL,
|
||||||
"Preferred source is invalid, ignoring assignment: %s", rvalue);
|
"Preferred source is invalid, ignoring assignment: %s", rvalue);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
n->family = f;
|
|
||||||
n->prefsrc = buffer;
|
|
||||||
TAKE_PTR(n);
|
TAKE_PTR(n);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -765,8 +759,8 @@ int config_parse_destination(
|
||||||
|
|
||||||
Network *network = userdata;
|
Network *network = userdata;
|
||||||
_cleanup_(route_freep) Route *n = NULL;
|
_cleanup_(route_freep) Route *n = NULL;
|
||||||
union in_addr_union buffer;
|
union in_addr_union *buffer;
|
||||||
unsigned char prefixlen;
|
unsigned char *prefixlen;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
|
@ -779,9 +773,16 @@ int config_parse_destination(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = in_addr_prefix_from_string(rvalue, AF_INET, &buffer, &prefixlen);
|
if (streq(lvalue, "Destination")) {
|
||||||
if (r < 0) {
|
buffer = &n->dst;
|
||||||
r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen);
|
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) {
|
if (r < 0) {
|
||||||
log_syntax(unit, LOG_ERR, filename, line, r,
|
log_syntax(unit, LOG_ERR, filename, line, r,
|
||||||
"Route %s= prefix is invalid, ignoring assignment: %s",
|
"Route %s= prefix is invalid, ignoring assignment: %s",
|
||||||
|
@ -789,19 +790,6 @@ int config_parse_destination(
|
||||||
return 0;
|
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);
|
TAKE_PTR(n);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -802,8 +802,8 @@ int config_parse_routing_policy_rule_prefix(
|
||||||
|
|
||||||
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *n = NULL;
|
_cleanup_(routing_policy_rule_freep) RoutingPolicyRule *n = NULL;
|
||||||
Network *network = userdata;
|
Network *network = userdata;
|
||||||
union in_addr_union buffer;
|
union in_addr_union *buffer;
|
||||||
uint8_t prefixlen;
|
uint8_t *prefixlen;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
assert(filename);
|
assert(filename);
|
||||||
|
@ -816,26 +816,20 @@ int config_parse_routing_policy_rule_prefix(
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
r = in_addr_prefix_from_string(rvalue, AF_INET, &buffer, &prefixlen);
|
if (streq(lvalue, "To")) {
|
||||||
if (r < 0) {
|
buffer = &n->to;
|
||||||
r = in_addr_prefix_from_string(rvalue, AF_INET6, &buffer, &prefixlen);
|
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) {
|
if (r < 0) {
|
||||||
log_syntax(unit, LOG_ERR, filename, line, r, "RPDB rule prefix is invalid, ignoring assignment: %s", rvalue);
|
log_syntax(unit, LOG_ERR, filename, line, r, "RPDB rule prefix is invalid, ignoring assignment: %s", rvalue);
|
||||||
return 0;
|
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;
|
n = NULL;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1118,8 +1112,6 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
_cleanup_free_ char *word = NULL, *a = NULL, *b = NULL;
|
_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);
|
r = extract_first_word(&p, &word, NULL, 0);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
|
@ -1132,26 +1124,23 @@ int routing_policy_load_rules(const char *state_file, Set **rules) {
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (STR_IN_SET(a, "from", "to")) {
|
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 (streq(a, "to")) {
|
||||||
if (r < 0) {
|
buffer = &rule->to;
|
||||||
r = in_addr_prefix_from_string(b, AF_INET6, &buffer, &prefixlen);
|
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) {
|
if (r < 0) {
|
||||||
log_error_errno(r, "RPDB rule prefix is invalid, ignoring assignment: %s", b);
|
log_error_errno(r, "RPDB rule prefix is invalid, ignoring assignment: %s", b);
|
||||||
continue;
|
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")) {
|
} else if (streq(a, "tos")) {
|
||||||
r = safe_atou8(b, &rule->tos);
|
r = safe_atou8(b, &rule->tos);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
|
|
Loading…
Reference in a new issue