return 0;
}
-int config_parse_dhcp_server_dns(
+static int config_parse_dhcp_lease_server_list(
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 *n = data;
- const char *p = rvalue;
- int r;
+ struct in_addr **addresses,
+ unsigned *n_addresses) {
assert(filename);
assert(lvalue);
assert(rvalue);
- for (;;) {
+ for (const char *p = rvalue;;) {
_cleanup_free_ char *w = NULL;
union in_addr_union a;
- struct in_addr *m;
+ int r;
r = extract_first_word(&p, &w, NULL, 0);
if (r == -ENOMEM)
return 0;
}
if (r == 0)
- break;
+ return 0;
r = in_addr_from_string(AF_INET, w, &a);
if (r < 0) {
log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to parse DNS server address '%s', ignoring assignment: %m", w);
+ "Failed to parse %s= address '%s', ignoring: %m", lvalue, w);
continue;
}
- m = reallocarray(n->dhcp_server_dns, n->n_dhcp_server_dns + 1, sizeof(struct in_addr));
+ struct in_addr *m = reallocarray(*addresses, *n_addresses + 1, sizeof(struct in_addr));
if (!m)
return log_oom();
- m[n->n_dhcp_server_dns++] = a.in;
- n->dhcp_server_dns = m;
+ m[(*n_addresses)++] = a.in;
+ *addresses = m;
}
-
- return 0;
}
-int config_parse_dhcp_server_ntp(
+int config_parse_dhcp_server_dns(
const char *unit,
const char *filename,
unsigned line,
void *userdata) {
Network *n = data;
- const char *p = rvalue;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
- for (;;) {
- _cleanup_free_ char *w = NULL;
- union in_addr_union a;
- struct in_addr *m;
-
- r = extract_first_word(&p, &w, NULL, 0);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to extract word, ignoring: %s", rvalue);
- return 0;
- }
- if (r == 0)
- return 0;
+ return config_parse_dhcp_lease_server_list(unit, filename, line,
+ lvalue, rvalue,
+ &n->dhcp_server_dns, &n->n_dhcp_server_dns);
+}
- r = in_addr_from_string(AF_INET, w, &a);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to parse NTP server address '%s', ignoring: %m", w);
- continue;
- }
+int config_parse_dhcp_server_ntp(
+ 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) {
- m = reallocarray(n->dhcp_server_ntp, n->n_dhcp_server_ntp + 1, sizeof(struct in_addr));
- if (!m)
- return log_oom();
+ Network *n = data;
- m[n->n_dhcp_server_ntp++] = a.in;
- n->dhcp_server_ntp = m;
- }
+ return config_parse_dhcp_lease_server_list(unit, filename, line,
+ lvalue, rvalue,
+ &n->dhcp_server_ntp, &n->n_dhcp_server_ntp);
}
int config_parse_dhcp_server_sip(
void *userdata) {
Network *n = data;
- const char *p = rvalue;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- for (;;) {
- _cleanup_free_ char *w = NULL;
- union in_addr_union a;
- struct in_addr *m;
-
- r = extract_first_word(&p, &w, NULL, 0);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to extract word, ignoring: %s", rvalue);
- return 0;
- }
- if (r == 0)
- return 0;
- r = in_addr_from_string(AF_INET, w, &a);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to parse SIP server address '%s', ignoring: %m", w);
- continue;
- }
-
- m = reallocarray(n->dhcp_server_sip, n->n_dhcp_server_sip + 1, sizeof(struct in_addr));
- if (!m)
- return log_oom();
-
- m[n->n_dhcp_server_sip++] = a.in;
- n->dhcp_server_sip = m;
- }
-
- return 0;
+ return config_parse_dhcp_lease_server_list(unit, filename, line,
+ lvalue, rvalue,
+ &n->dhcp_server_sip, &n->n_dhcp_server_sip);
}
int config_parse_dhcp_server_pop3_servers(
void *userdata) {
Network *n = data;
- const char *p = rvalue;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- for (;;) {
- _cleanup_free_ char *w = NULL;
- union in_addr_union a;
- struct in_addr *m;
-
- r = extract_first_word(&p, &w, NULL, 0);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to extract word, ignoring: %s", rvalue);
- return 0;
- }
- if (r == 0)
- return 0;
-
- r = in_addr_from_string(AF_INET, w, &a);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to parse POP3 server address '%s', ignoring: %m", w);
- continue;
- }
- m = reallocarray(n->dhcp_server_pop3, n->n_dhcp_server_pop3 + 1, sizeof(struct in_addr));
- if (!m)
- return log_oom();
-
- m[n->n_dhcp_server_pop3++] = a.in;
- n->dhcp_server_pop3 = m;
- }
-
- return 0;
+ return config_parse_dhcp_lease_server_list(unit, filename, line,
+ lvalue, rvalue,
+ &n->dhcp_server_pop3, &n->n_dhcp_server_pop3);
}
int config_parse_dhcp_server_smtp_servers(
void *userdata) {
Network *n = data;
- const char *p = rvalue;
- int r;
-
- assert(filename);
- assert(lvalue);
- assert(rvalue);
-
- for (;;) {
- _cleanup_free_ char *w = NULL;
- union in_addr_union a;
- struct in_addr *m;
-
- r = extract_first_word(&p, &w, NULL, 0);
- if (r == -ENOMEM)
- return log_oom();
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to extract word, ignoring: %s", rvalue);
- return 0;
- }
- if (r == 0)
- return 0;
-
- r = in_addr_from_string(AF_INET, w, &a);
- if (r < 0) {
- log_syntax(unit, LOG_ERR, filename, line, r,
- "Failed to parse SMTP server address '%s', ignoring: %m", w);
- continue;
- }
- m = reallocarray(n->dhcp_server_smtp, n->n_dhcp_server_smtp + 1, sizeof(struct in_addr));
- if (!m)
- return log_oom();
-
- m[n->n_dhcp_server_smtp++] = a.in;
- n->dhcp_server_smtp = m;
- }
+ return config_parse_dhcp_lease_server_list(unit, filename, line,
+ lvalue, rvalue,
+ &n->dhcp_server_smtp, &n->n_dhcp_server_smtp);
- return 0;
}