1
0
mirror of https://github.com/systemd/systemd.git synced 2025-02-04 21:47:31 +03:00

Merge pull request #20443 from yuwata/network-conf-parser-cleanups

network: conf parser cleanups
This commit is contained in:
Yu Watanabe 2021-08-17 02:42:27 +09:00 committed by GitHub
commit 7c58ee5f8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 196 additions and 164 deletions

View File

@ -1053,7 +1053,8 @@ IPv6Token=prefixstable:2002:da8:1::</programlisting></para>
<varlistentry> <varlistentry>
<term><varname>Label=</varname></term> <term><varname>Label=</varname></term>
<listitem> <listitem>
<para>An address label.</para> <para>Specifies the label for the IPv4 address. The label must be a 7-bit ASCII string with
a length of 1…15 characters. Defaults to unset.</para>
</listitem> </listitem>
</varlistentry> </varlistentry>
<varlistentry> <varlistentry>

View File

@ -164,16 +164,18 @@ static int netdev_geneve_create(NetDev *netdev) {
return r; return r;
} }
int config_parse_geneve_vni(const char *unit, int config_parse_geneve_vni(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Geneve *v = userdata; Geneve *v = userdata;
uint32_t f; uint32_t f;
int r; int r;
@ -199,16 +201,18 @@ int config_parse_geneve_vni(const char *unit,
return 0; return 0;
} }
int config_parse_geneve_address(const char *unit, int config_parse_geneve_address(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Geneve *v = userdata; Geneve *v = userdata;
union in_addr_union *addr = data, buffer; union in_addr_union *addr = data, buffer;
int r, f; int r, f;
@ -236,16 +240,18 @@ int config_parse_geneve_address(const char *unit,
return 0; return 0;
} }
int config_parse_geneve_flow_label(const char *unit, int config_parse_geneve_flow_label(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Geneve *v = userdata; Geneve *v = userdata;
uint32_t f; uint32_t f;
int r; int r;
@ -272,16 +278,18 @@ int config_parse_geneve_flow_label(const char *unit,
return 0; return 0;
} }
int config_parse_geneve_ttl(const char *unit, int config_parse_geneve_ttl(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Geneve *v = userdata; Geneve *v = userdata;
unsigned f; unsigned f;
int r; int r;

View File

@ -501,16 +501,18 @@ static int netdev_tunnel_verify(NetDev *netdev, const char *filename) {
return 0; return 0;
} }
int config_parse_tunnel_address(const char *unit, int config_parse_tunnel_address(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Tunnel *t = userdata; Tunnel *t = userdata;
union in_addr_union *addr = data, buffer; union in_addr_union *addr = data, buffer;
int r, f; int r, f;
@ -555,16 +557,18 @@ int config_parse_tunnel_address(const char *unit,
return 0; return 0;
} }
int config_parse_tunnel_key(const char *unit, int config_parse_tunnel_key(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
union in_addr_union buffer; union in_addr_union buffer;
Tunnel *t = userdata; Tunnel *t = userdata;
uint32_t k; uint32_t k;
@ -596,16 +600,18 @@ int config_parse_tunnel_key(const char *unit,
return 0; return 0;
} }
int config_parse_ipv6_flowlabel(const char* unit, int config_parse_ipv6_flowlabel(
const char *filename, const char* unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
IPv6FlowLabel *ipv6_flowlabel = data; IPv6FlowLabel *ipv6_flowlabel = data;
Tunnel *t = userdata; Tunnel *t = userdata;
int k = 0; int k = 0;
@ -635,16 +641,18 @@ int config_parse_ipv6_flowlabel(const char* unit,
return 0; return 0;
} }
int config_parse_encap_limit(const char* unit, int config_parse_encap_limit(
const char *filename, const char* unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Tunnel *t = userdata; Tunnel *t = userdata;
int k = 0; int k = 0;
int r; int r;
@ -673,26 +681,27 @@ int config_parse_encap_limit(const char* unit,
return 0; return 0;
} }
int config_parse_6rd_prefix(const char* unit, int config_parse_6rd_prefix(
const char *filename, const char* unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Tunnel *t = userdata; Tunnel *t = userdata;
union in_addr_union p;
uint8_t l;
int r;
assert(filename); assert(filename);
assert(lvalue); assert(lvalue);
assert(rvalue); assert(rvalue);
union in_addr_union p;
uint8_t l;
int r;
r = in_addr_prefix_from_string(rvalue, AF_INET6, &p, &l); r = in_addr_prefix_from_string(rvalue, AF_INET6, &p, &l);
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 6rd prefix \"%s\", ignoring: %m", rvalue); log_syntax(unit, LOG_WARNING, filename, line, r, "Failed to parse 6rd prefix \"%s\", ignoring: %m", rvalue);

View File

@ -174,16 +174,18 @@ static int netdev_vxlan_fill_message_create(NetDev *netdev, Link *link, sd_netli
return r; return r;
} }
int config_parse_vxlan_address(const char *unit, int config_parse_vxlan_address(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
VxLan *v = userdata; VxLan *v = userdata;
union in_addr_union *addr = data, buffer; union in_addr_union *addr = data, buffer;
int r, f; int r, f;
@ -225,16 +227,18 @@ int config_parse_vxlan_address(const char *unit,
return 0; return 0;
} }
int config_parse_port_range(const char *unit, int config_parse_port_range(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
VxLan *v = userdata; VxLan *v = userdata;
uint16_t low, high; uint16_t low, high;
int r; int r;
@ -257,16 +261,18 @@ int config_parse_port_range(const char *unit,
return 0; return 0;
} }
int config_parse_flow_label(const char *unit, int config_parse_flow_label(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
VxLan *v = userdata; VxLan *v = userdata;
unsigned f; unsigned f;
int r; int r;
@ -293,16 +299,18 @@ int config_parse_flow_label(const char *unit,
return 0; return 0;
} }
int config_parse_vxlan_ttl(const char *unit, int config_parse_vxlan_ttl(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
VxLan *v = userdata; VxLan *v = userdata;
unsigned f; unsigned f;
int r; int r;

View File

@ -460,16 +460,17 @@ int config_parse_section_route_table(
return 0; return 0;
} }
int config_parse_iaid(const char *unit, int config_parse_iaid(
const char *filename, const char *unit,
unsigned line, const char *filename,
const char *section, unsigned line,
unsigned section_line, const char *section,
const char *lvalue, unsigned section_line,
int ltype, const char *lvalue,
const char *rvalue, int ltype,
void *data, const char *rvalue,
void *userdata) { void *data,
void *userdata) {
Network *network = userdata; Network *network = userdata;
uint32_t iaid; uint32_t iaid;

View File

@ -1844,7 +1844,8 @@ int config_parse_dhcp_ip_service_type(
return 0; return 0;
} }
int config_parse_dhcp_fallback_lease_lifetime(const char *unit, int config_parse_dhcp_fallback_lease_lifetime(
const char *unit,
const char *filename, const char *filename,
unsigned line, unsigned line,
const char *section, const char *section,
@ -1854,6 +1855,7 @@ int config_parse_dhcp_fallback_lease_lifetime(const char *unit,
const char *rvalue, const char *rvalue,
void *data, void *data,
void *userdata) { void *userdata) {
Network *network = userdata; Network *network = userdata;
uint32_t k; uint32_t k;

View File

@ -715,7 +715,8 @@ bool network_has_static_ipv6_configurations(Network *network) {
return false; return false;
} }
int config_parse_stacked_netdev(const char *unit, int config_parse_stacked_netdev(
const char *unit,
const char *filename, const char *filename,
unsigned line, unsigned line,
const char *section, const char *section,
@ -725,6 +726,7 @@ int config_parse_stacked_netdev(const char *unit,
const char *rvalue, const char *rvalue,
void *data, void *data,
void *userdata) { void *userdata) {
_cleanup_free_ char *name = NULL; _cleanup_free_ char *name = NULL;
NetDevKind kind = ltype; NetDevKind kind = ltype;
Hashmap **h = data; Hashmap **h = data;
@ -855,26 +857,26 @@ int config_parse_hostname(
void *data, void *data,
void *userdata) { void *userdata) {
_cleanup_free_ char *hn = NULL;
char **hostname = data; char **hostname = data;
int r; int r;
assert(filename); assert(filename);
assert(lvalue); assert(lvalue);
assert(rvalue); assert(rvalue);
assert(hostname); assert(data);
r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &hn, userdata); if (isempty(rvalue)) {
if (r < 0) *hostname = mfree(*hostname);
return r; return 0;
}
if (!hostname_is_valid(hn, 0)) { if (!hostname_is_valid(rvalue, 0)) {
log_syntax(unit, LOG_WARNING, filename, line, 0, log_syntax(unit, LOG_WARNING, filename, line, 0,
"Hostname is not valid, ignoring assignment: %s", rvalue); "Hostname is not valid, ignoring assignment: %s", rvalue);
return 0; return 0;
} }
r = dns_name_is_valid(hn); r = dns_name_is_valid(rvalue);
if (r < 0) { if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r, log_syntax(unit, LOG_WARNING, filename, line, r,
"Failed to check validity of hostname '%s', ignoring assignment: %m", rvalue); "Failed to check validity of hostname '%s', ignoring assignment: %m", rvalue);
@ -886,7 +888,7 @@ int config_parse_hostname(
return 0; return 0;
} }
return free_and_replace(*hostname, hn); return free_and_strdup_warn(hostname, rvalue);
} }
int config_parse_timezone( int config_parse_timezone(
@ -901,26 +903,27 @@ int config_parse_timezone(
void *data, void *data,
void *userdata) { void *userdata) {
_cleanup_free_ char *tz = NULL; char **tz = data;
char **datap = data;
int r; int r;
assert(filename); assert(filename);
assert(lvalue); assert(lvalue);
assert(rvalue); assert(rvalue);
assert(datap); assert(data);
r = config_parse_string(unit, filename, line, section, section_line, lvalue, ltype, rvalue, &tz, userdata); if (isempty(rvalue)) {
if (r < 0) *tz = mfree(*tz);
return r; return 0;
}
if (!timezone_is_valid(tz, LOG_WARNING)) { r = verify_timezone(rvalue, LOG_WARNING);
log_syntax(unit, LOG_WARNING, filename, line, 0, if (r < 0) {
log_syntax(unit, LOG_WARNING, filename, line, r,
"Timezone is not valid, ignoring assignment: %s", rvalue); "Timezone is not valid, ignoring assignment: %s", rvalue);
return 0; return 0;
} }
return free_and_replace(*datap, tz); return free_and_strdup_warn(tz, rvalue);
} }
int config_parse_dns( int config_parse_dns(