mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 00:14:32 +09:00
Merge pull request #30896 from yuwata/network-route-conf-parser
network: minor cleanups for conf parsers
This commit is contained in:
@@ -10,6 +10,133 @@
|
||||
#include "parse-util.h"
|
||||
#include "string-util.h"
|
||||
|
||||
int config_parse_gateway(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
Network *network = userdata;
|
||||
_cleanup_(route_free_or_set_invalidp) Route *route = NULL;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (streq(section, "Network")) {
|
||||
/* we are not in an Route section, so use line number instead */
|
||||
r = route_new_static(network, filename, line, &route);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
r = route_new_static(network, filename, section_line, &route);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
route->gateway_from_dhcp_or_ra = false;
|
||||
route->gw_family = AF_UNSPEC;
|
||||
route->gw = IN_ADDR_NULL;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "_dhcp")) {
|
||||
route->gateway_from_dhcp_or_ra = true;
|
||||
route->gw_family = AF_UNSPEC;
|
||||
route->gw = IN_ADDR_NULL;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "_dhcp4")) {
|
||||
route->gateway_from_dhcp_or_ra = true;
|
||||
route->gw_family = AF_INET;
|
||||
route->gw = IN_ADDR_NULL;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "_ipv6ra")) {
|
||||
route->gateway_from_dhcp_or_ra = true;
|
||||
route->gw_family = AF_INET6;
|
||||
route->gw = IN_ADDR_NULL;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
r = in_addr_from_string_auto(rvalue, &route->gw_family, &route->gw);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid %s='%s', ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
route->gateway_from_dhcp_or_ra = false;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_route_gateway_onlink(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
Network *network = userdata;
|
||||
_cleanup_(route_free_or_set_invalidp) Route *route = NULL;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = route_new_static(network, filename, section_line, &route);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = config_parse_tristate(unit, filename, line, section, section_line, lvalue, ltype, rvalue,
|
||||
&route->gateway_onlink, network);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_route_nexthop(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
||||
@@ -3,5 +3,7 @@
|
||||
|
||||
#include "conf-parser.h"
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_gateway_onlink);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_nexthop);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_multipath_route);
|
||||
|
||||
@@ -1892,89 +1892,6 @@ int network_add_default_route_on_device(Network *network) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_gateway(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
Network *network = userdata;
|
||||
_cleanup_(route_free_or_set_invalidp) Route *route = NULL;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
if (streq(section, "Network")) {
|
||||
/* we are not in an Route section, so use line number instead */
|
||||
r = route_new_static(network, filename, line, &route);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
r = route_new_static(network, filename, section_line, &route);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
route->gateway_from_dhcp_or_ra = false;
|
||||
route->gw_family = AF_UNSPEC;
|
||||
route->gw = IN_ADDR_NULL;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "_dhcp")) {
|
||||
route->gateway_from_dhcp_or_ra = true;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "_dhcp4")) {
|
||||
route->gw_family = AF_INET;
|
||||
route->gateway_from_dhcp_or_ra = true;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (streq(rvalue, "_ipv6ra")) {
|
||||
route->gw_family = AF_INET6;
|
||||
route->gateway_from_dhcp_or_ra = true;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
r = in_addr_from_string_auto(rvalue, &route->gw_family, &route->gw);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Invalid %s='%s', ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
route->gateway_from_dhcp_or_ra = false;
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_preferred_src(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
@@ -2207,50 +2124,6 @@ int config_parse_route_table(
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_route_gateway_onlink(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
unsigned line,
|
||||
const char *section,
|
||||
unsigned section_line,
|
||||
const char *lvalue,
|
||||
int ltype,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
|
||||
Network *network = userdata;
|
||||
_cleanup_(route_free_or_set_invalidp) Route *route = NULL;
|
||||
int r;
|
||||
|
||||
assert(filename);
|
||||
assert(section);
|
||||
assert(lvalue);
|
||||
assert(rvalue);
|
||||
assert(data);
|
||||
|
||||
r = route_new_static(network, filename, section_line, &route);
|
||||
if (r == -ENOMEM)
|
||||
return log_oom();
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Failed to allocate route, ignoring assignment: %m");
|
||||
return 0;
|
||||
}
|
||||
|
||||
r = parse_boolean(rvalue);
|
||||
if (r < 0) {
|
||||
log_syntax(unit, LOG_WARNING, filename, line, r,
|
||||
"Could not parse %s=\"%s\", ignoring assignment: %m", lvalue, rvalue);
|
||||
return 0;
|
||||
}
|
||||
|
||||
route->gateway_onlink = r;
|
||||
|
||||
TAKE_PTR(route);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int config_parse_ipv6_route_preference(
|
||||
const char *unit,
|
||||
const char *filename,
|
||||
|
||||
@@ -110,13 +110,11 @@ void network_drop_invalid_routes(Network *network);
|
||||
DEFINE_NETWORK_CONFIG_STATE_FUNCTIONS(Route, route);
|
||||
void link_mark_routes(Link *link, NetworkConfigSource source);
|
||||
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_gateway);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_preferred_src);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_destination);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_priority);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_scope);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_table);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_gateway_onlink);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_ipv6_route_preference);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_protocol);
|
||||
CONFIG_PARSER_PROTOTYPE(config_parse_route_type);
|
||||
|
||||
@@ -1064,7 +1064,7 @@ int config_parse_tristate(
|
||||
|
||||
if (isempty(rvalue)) {
|
||||
*t = -1;
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
r = parse_tristate(rvalue, t);
|
||||
@@ -1074,7 +1074,7 @@ int config_parse_tristate(
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int config_parse_string(
|
||||
|
||||
Reference in New Issue
Block a user