1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

network: clean-up DHCP lease server data configuration

This is an attempt to clean up the POP3/SMTP/LPR/… DHCP lease server
data logic in networkd. This reduces code duplication and fixes a number
of bugs.

This removes any support for collecting POP3/SMPT/LPR servers acquired
via local DHCP client releases since noone uses that, and given how old
these protocols are I doubt this will change. It keeps support for
configuring them for the dhcp server however.

The differences between the DNS/NTP/SIP/POP3/SMTP/LPR configuration
logics are minimized.

This removes the relevant symbols from sd-network.h (which is an
internal API only at this point after all).

This is unfortunately not well test, given the old code for this had
barely any tests. But the new code should not perform worse at least,
and allow us to release, since it corrects some interfaces visible in
the .network configuration format.

Fixes: #15943
This commit is contained in:
Lennart Poettering 2020-06-16 20:35:18 +02:00 committed by Yu Watanabe
parent d5da3ada8e
commit 2a71d57f4e
15 changed files with 184 additions and 512 deletions

2
NEWS
View File

@ -76,7 +76,7 @@ CHANGES WITH 246 in spe:
field.
* systemd-networkd's [DHCPServer] section gained a new set of options
POP3Servers=, SMTPServers=, LPRServers= for including server
EmitPOP3=/POP3=, EmitSMTP=/SMTP=, EmitLPR=/LPR= for including server
information about these three protocols in the DHCP lease. It also
gained support for including "MUD" URLs ("Manufacturer Usage
Description"). Support for "MUD" URLs was also added to the LLDP

View File

@ -578,7 +578,7 @@
<varlistentry>
<term><varname>NTP=</varname></term>
<listitem>
<para>An NTP server address. This option may be specified more than once. This setting is read by
<para>An NTP server address (either an IP address, or a hostname). This option may be specified more than once. This setting is read by
<citerefentry><refentrytitle>systemd-timesyncd.service</refentrytitle><manvolnum>8</manvolnum></citerefentry>.</para>
</listitem>
</varlistentry>
@ -1412,17 +1412,16 @@
<varlistentry>
<term><varname>UseNTP=</varname></term>
<listitem>
<para>When true (the default), the NTP servers received
from the DHCP server will be used by systemd-timesyncd
and take precedence over any statically configured ones.</para>
<para>When true (the default), the NTP servers received from the DHCP server will be used by
<filename>systemd-timesyncd.service</filename> and take precedence over any statically configured
ones.</para>
</listitem>
</varlistentry>
<varlistentry>
<term><varname>UseSIP=</varname></term>
<listitem>
<para>When true (the default), the SIP servers received
from the DHCP server will be saved at the state files and can be
read via <function>sd_network_link_get_sip_servers()</function> function.</para>
<para>When true (the default), the SIP servers received from the DHCP server will be collected
and made available to client programs.</para>
</listitem>
</varlistentry>
@ -2010,79 +2009,37 @@
<term><varname>EmitDNS=</varname></term>
<term><varname>DNS=</varname></term>
<listitem><para>Takes a boolean. Configures whether the DHCP leases handed out
to clients shall contain DNS server information. Defaults to <literal>yes</literal>.
The DNS servers to pass to clients may be configured with the
<varname>DNS=</varname> option, which takes a list of IPv4
addresses. If the <varname>EmitDNS=</varname> option is
enabled but no servers configured, the servers are
automatically propagated from an "uplink" interface that has
appropriate servers set. The "uplink" interface is determined
by the default route of the system with the highest
priority. Note that this information is acquired at the time
the lease is handed out, and does not take uplink interfaces
into account that acquire DNS or NTP server information at a
later point. DNS server propagation does not take
<filename>/etc/resolv.conf</filename> into account. Also, note
that the leases are not refreshed if the uplink network
configuration changes. To ensure clients regularly acquire the
most current uplink DNS server information, it is thus
advisable to shorten the DHCP lease time via
<varname>MaxLeaseTimeSec=</varname> described
<listitem><para><varname>EmitDNS=</varname> takes a boolean. Configures whether the DHCP leases
handed out to clients shall contain DNS server information. Defaults to <literal>yes</literal>. The
DNS servers to pass to clients may be configured with the <varname>DNS=</varname> option, which takes
a list of IPv4 addresses. If the <varname>EmitDNS=</varname> option is enabled but no servers
configured, the servers are automatically propagated from an "uplink" interface that has appropriate
servers set. The "uplink" interface is determined by the default route of the system with the highest
priority. Note that this information is acquired at the time the lease is handed out, and does not
take uplink interfaces into account that acquire DNS server information at a later point. If no
suitable uplinkg interface is found the DNS server data from <filename>/etc/resolv.conf</filename> is
used. Also, note that the leases are not refreshed if the uplink network configuration changes. To
ensure clients regularly acquire the most current uplink DNS server information, it is thus advisable
to shorten the DHCP lease time via <varname>MaxLeaseTimeSec=</varname> described
above.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>EmitNTP=</varname></term>
<term><varname>NTP=</varname></term>
<listitem><para>Similar to the <varname>EmitDNS=</varname> and
<varname>DNS=</varname> settings described above, these
settings configure whether and what NTP server information
shall be emitted as part of the DHCP lease. The same syntax,
propagation semantics and defaults apply as for
<varname>EmitDNS=</varname> and
<varname>DNS=</varname>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>EmitSIP=</varname></term>
<term><varname>SIP=</varname></term>
<term><varname>EmitPOP3=</varname></term>
<term><varname>POP3=</varname></term>
<term><varname>EmitSMTP=</varname></term>
<term><varname>SMTP=</varname></term>
<term><varname>EmitLPR=</varname></term>
<term><varname>LPR=</varname></term>
<listitem><para>Similar to the <varname>EmitDNS=</varname> and
<varname>DNS=</varname> settings described above, these
settings configure whether and what SIP server information
shall be emitted as part of the DHCP lease. The same syntax,
propagation semantics and defaults apply as for
<varname>EmitDNS=</varname> and
<varname>DNS=</varname>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>POP3Servers=</varname></term>
<listitem><para>Similar to the <varname>DNS=</varname> setting described above, this setting
configures whether and what POP3 server information shall be emitted as part of the DHCP lease. The
same syntax, propagation semantics and defaults apply as for
<varname>DNS=</varname>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>SMTPServers=</varname></term>
<listitem><para>Similar to the <varname>DNS=</varname> setting described above, this
setting configures whether and what SMTP server information shall be emitted as part of
the DHCP lease. The same syntax, propagation semantics and defaults apply as for
<varname>DNS=</varname>.</para></listitem>
</varlistentry>
<varlistentry>
<term><varname>LPRServers=</varname></term>
<listitem><para>Similar to the <varname>DNS=</varname> setting described above, this
setting configures whether and what LPR (line printer) server information shall be emitted
as part of the DHCP lease. The same syntax, propagation semantics and defaults apply as for
<varname>DNS=</varname>.</para></listitem>
<listitem><para>Similar to the <varname>EmitDNS=</varname> and <varname>DNS=</varname> settings
described above, these settings configure whether and what server information for the indicate
protocol shall be emitted as part of the DHCP lease. The same syntax, propagation semantics and
defaults apply as for <varname>EmitDNS=</varname> and <varname>DNS=</varname>.</para></listitem>
</varlistentry>
<varlistentry>

View File

@ -264,22 +264,6 @@ _public_ int sd_network_link_get_route_domains(int ifindex, char ***ret) {
return network_link_get_strv(ifindex, "ROUTE_DOMAINS", ret);
}
_public_ int sd_network_link_get_sip_servers(int ifindex, char ***ret) {
return network_link_get_strv(ifindex, "SIP", ret);
}
_public_ int sd_network_link_get_pop3_servers(int ifindex, char ***pop3) {
return network_link_get_strv(ifindex, "POP3_SERVERS", pop3);
}
_public_ int sd_network_link_get_smtp_servers(int ifindex, char ***ret) {
return network_link_get_strv(ifindex, "SMTP_SERVERS", ret);
}
_public_ int sd_network_link_get_lpr_servers(int ifindex, char ***ret) {
return network_link_get_strv(ifindex, "LPR_SERVERS", ret);
}
_public_ int sd_network_link_get_dns_default_route(int ifindex) {
char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1];
_cleanup_free_ char *s = NULL;

View File

@ -1378,8 +1378,7 @@ static int link_status_one(
sd_hwdb *hwdb,
const LinkInfo *info) {
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL,
**pop3_server = NULL, **smtp_server = NULL, **lpr_server = NULL;
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL;
_cleanup_free_ char *t = NULL, *network = NULL, *client_id = NULL, *iaid = NULL, *duid = NULL;
const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL;
_cleanup_free_ char *setup_state = NULL, *operational_state = NULL, *tz = NULL;
@ -1406,9 +1405,6 @@ static int link_status_one(
(void) sd_network_link_get_route_domains(info->ifindex, &route_domains);
(void) sd_network_link_get_ntp(info->ifindex, &ntp);
(void) sd_network_link_get_sip(info->ifindex, &sip);
(void) sd_network_link_get_pop3_servers(info->ifindex, &pop3_server);
(void) sd_network_link_get_smtp_servers(info->ifindex, &smtp_server);
(void) sd_network_link_get_lpr_servers(info->ifindex, &lpr_server);
if (info->sd_device) {
(void) sd_device_get_property_value(info->sd_device, "ID_NET_LINK_FILE", &link);
@ -2045,15 +2041,6 @@ static int link_status_one(
if (r < 0)
return r;
r = dump_list(table, "SIP:", sip);
if (r < 0)
return r;
r = dump_list(table, "POP3 servers:", pop3_server);
if (r < 0)
return r;
r = dump_list(table, "SMTP servers:", smtp_server);
if (r < 0)
return r;
r = dump_list(table, "LPR servers:", lpr_server);
if (r < 0)
return r;
r = dump_ifindexes(table, "Carrier Bound To:", carrier_bound_to);

View File

@ -34,49 +34,6 @@ static Address* link_find_dhcp_server_address(Link *link) {
return NULL;
}
static int link_push_uplink_dns_to_dhcp_server(Link *link, sd_dhcp_server *s) {
_cleanup_free_ struct in_addr *addresses = NULL;
size_t n_addresses = 0, n_allocated = 0;
for (unsigned i = 0; i < link->network->n_dns; i++) {
struct in_addr ia;
/* Only look for IPv4 addresses */
if (link->network->dns[i].family != AF_INET)
continue;
ia = link->network->dns[i].address.in;
/* Never propagate obviously borked data */
if (in4_addr_is_null(&ia) || in4_addr_is_localhost(&ia))
continue;
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1))
return log_oom();
addresses[n_addresses++] = ia;
}
if (link->network->dhcp_use_dns && link->dhcp_lease) {
const struct in_addr *da;
int n = sd_dhcp_lease_get_dns(link->dhcp_lease, &da);
if (n > 0) {
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n))
return log_oom();
for (int j = 0; j < n; j++)
if (in4_addr_is_non_local(&da[j]))
addresses[n_addresses++] = da[j];
}
}
if (n_addresses <= 0)
return 0;
return sd_dhcp_server_set_dns(s, addresses, n_addresses);
}
static int link_push_uplink_to_dhcp_server(
Link *link,
sd_dhcp_lease_server_type what,
@ -84,68 +41,88 @@ static int link_push_uplink_to_dhcp_server(
_cleanup_free_ struct in_addr *addresses = NULL;
size_t n_addresses = 0, n_allocated = 0;
bool lease_condition;
char **servers;
bool use_dhcp_lease_data = true;
assert(link);
if (!link->network)
return 0;
assert(link->network);
log_link_debug(link, "Copying %s from link", dhcp_lease_server_type_to_string(what));
switch (what) {
case SD_DHCP_LEASE_DNS:
/* DNS servers are stored as parsed data, so special handling is required.
* TODO: check if DNS servers should be stored unparsed too. */
return link_push_uplink_dns_to_dhcp_server(link, s);
case SD_DHCP_LEASE_NTP:
servers = link->network->ntp;
lease_condition = link->network->dhcp_use_ntp;
case SD_DHCP_LEASE_DNS:
/* For DNS we have a special case. We the data configured explicitly locally along with the
* data from the DHCP lease. */
for (unsigned i = 0; i < link->network->n_dns; i++) {
struct in_addr ia;
/* Only look for IPv4 addresses */
if (link->network->dns[i].family != AF_INET)
continue;
ia = link->network->dns[i].address.in;
/* Never propagate obviously borked data */
if (in4_addr_is_null(&ia) || in4_addr_is_localhost(&ia))
continue;
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1))
return log_oom();
addresses[n_addresses++] = ia;
}
use_dhcp_lease_data = link->network->dhcp_use_dns;
break;
case SD_DHCP_LEASE_NTP: {
char **i;
/* For NTP things are similar, but for NTP hostnames can be configured too, which we cannot
* propagate via DHCP. Hence let's only propagate those which are IP addresses. */
STRV_FOREACH(i, link->network->ntp) {
union in_addr_union ia;
if (in_addr_from_string(AF_INET, *i, &ia) < 0)
continue;
/* Never propagate obviously borked data */
if (in4_addr_is_null(&ia.in) || in4_addr_is_localhost(&ia.in))
continue;
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1))
return log_oom();
addresses[n_addresses++] = ia.in;
}
use_dhcp_lease_data = link->network->dhcp_use_ntp;
break;
}
case SD_DHCP_LEASE_SIP:
/* For SIP we don't allow explicit, local configuration, but there's control whether to use the data */
use_dhcp_lease_data = link->network->dhcp_use_sip;
break;
case SD_DHCP_LEASE_POP3:
servers = link->network->pop3;
lease_condition = true;
break;
case SD_DHCP_LEASE_SMTP:
servers = link->network->smtp;
lease_condition = true;
break;
case SD_DHCP_LEASE_SIP:
servers = link->network->sip;
lease_condition = link->network->dhcp_use_sip;
break;
case SD_DHCP_LEASE_LPR:
servers = link->network->lpr;
lease_condition = true;
break;
/* For the other server types we currently do not allow local configuration of server data,
* since there are typically no local consumers of the data. */
;
default:
assert_not_reached("Unknown DHCP lease info item");
assert_not_reached("Unexpected server type");
}
char **a;
STRV_FOREACH(a, servers) {
union in_addr_union ia;
/* Only look for IPv4 addresses */
if (in_addr_from_string(AF_INET, *a, &ia) <= 0)
continue;
/* Never propagate obviously borked data */
if (in4_addr_is_null(&ia.in) || in4_addr_is_localhost(&ia.in))
continue;
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + 1))
return log_oom();
addresses[n_addresses++] = ia.in;
}
if (lease_condition && link->dhcp_lease) {
if (use_dhcp_lease_data && link->dhcp_lease) {
const struct in_addr *da;
int n = sd_dhcp_lease_get_servers(link->dhcp_lease, what, &da);
@ -153,9 +130,9 @@ static int link_push_uplink_to_dhcp_server(
if (!GREEDY_REALLOC(addresses, n_allocated, n_addresses + n))
return log_oom();
for (int i = 0; i < n; i++)
if (in4_addr_is_non_local(&da[i]))
addresses[n_addresses++] = da[i];
for (int j = 0; j < n; j++)
if (in4_addr_is_non_local(&da[j]))
addresses[n_addresses++] = da[j];
}
}
@ -285,71 +262,43 @@ int dhcp4_server_configure(Link *link) {
return log_link_error_errno(link, r, "Failed to set default lease time for DHCPv4 server instance: %m");
}
const struct {
bool condition;
const struct in_addr *servers;
unsigned n_servers;
} configs[] = {
[SD_DHCP_LEASE_DNS] = {
link->network->dhcp_server_emit_dns,
link->network->dhcp_server_dns,
link->network->n_dhcp_server_dns,
},
[SD_DHCP_LEASE_NTP] = {
link->network->dhcp_server_emit_ntp,
link->network->dhcp_server_ntp,
link->network->n_dhcp_server_ntp,
},
[SD_DHCP_LEASE_SIP] = {
link->network->dhcp_server_emit_sip,
link->network->dhcp_server_sip,
link->network->n_dhcp_server_sip,
},
[SD_DHCP_LEASE_POP3] = {
true,
link->network->dhcp_server_pop3,
link->network->n_dhcp_server_pop3,
},
[SD_DHCP_LEASE_SMTP] = {
true,
link->network->dhcp_server_smtp,
link->network->n_dhcp_server_smtp,
},
[SD_DHCP_LEASE_LPR] = {
true,
link->network->dhcp_server_lpr,
link->network->n_dhcp_server_lpr,
},
};
assert_cc(ELEMENTSOF(configs) == _SD_DHCP_LEASE_SERVER_TYPE_MAX);
for (sd_dhcp_lease_server_type type = 0; type < _SD_DHCP_LEASE_SERVER_TYPE_MAX; type ++) {
for (unsigned n = 0; n < ELEMENTSOF(configs); n++)
if (configs[n].condition) {
if (configs[n].n_servers > 0)
r = sd_dhcp_server_set_servers(link->dhcp_server, n,
configs[n].servers, configs[n].n_servers);
else {
if (!acquired_uplink) {
uplink = manager_find_uplink(link->manager, link);
acquired_uplink = true;
}
if (!link->network->dhcp_server_emit[type].emit)
continue;
if (!uplink) {
log_link_debug(link,
"Not emitting %s on link, couldn't find suitable uplink.",
dhcp_lease_server_type_to_string(n));
r = 0;
} else if (uplink->network)
r = link_push_uplink_to_dhcp_server(uplink, n, link->dhcp_server);
else if (n == SD_DHCP_LEASE_DNS)
r = dhcp4_server_set_dns_from_resolve_conf(link);
if (link->network->dhcp_server_emit[type].n_addresses > 0)
/* Explicitly specified servers to emit */
r = sd_dhcp_server_set_servers(
link->dhcp_server,
type,
link->network->dhcp_server_emit[type].addresses,
link->network->dhcp_server_emit[type].n_addresses);
else {
/* Emission is requested, but nothing explicitly configured. Let's find a suitable upling */
if (!acquired_uplink) {
uplink = manager_find_uplink(link->manager, link);
acquired_uplink = true;
}
if (uplink && uplink->network)
r = link_push_uplink_to_dhcp_server(uplink, type, link->dhcp_server);
else if (type == SD_DHCP_LEASE_DNS)
r = dhcp4_server_set_dns_from_resolve_conf(link);
else {
log_link_debug(link,
"Not emitting %s on link, couldn't find suitable uplink.",
dhcp_lease_server_type_to_string(type));
continue;
}
if (r < 0)
log_link_warning_errno(link, r,
"Failed to set %s for DHCP server, ignoring: %m",
dhcp_lease_server_type_to_string(n));
}
if (r < 0)
log_link_warning_errno(link, r,
"Failed to set %s for DHCP server, ignoring: %m",
dhcp_lease_server_type_to_string(type));
}
r = sd_dhcp_server_set_emit_router(link->dhcp_server, link->network->dhcp_server_emit_router);
if (r < 0)
return log_link_error_errno(link, r, "Failed to set router emission for DHCP server: %m");
@ -398,17 +347,21 @@ int dhcp4_server_configure(Link *link) {
return 0;
}
static int config_parse_dhcp_lease_server_list(
int config_parse_dhcp_server_emit(
const char *unit,
const char *filename,
unsigned line,
const char *section,
unsigned section_line,
const char *lvalue,
int ltype,
const char *rvalue,
struct in_addr **addresses,
unsigned *n_addresses) {
void *data,
void *userdata) {
assert(filename);
assert(lvalue);
NetworkDHCPServerEmitAddress *emit = data;
assert(emit);
assert(rvalue);
for (const char *p = rvalue;;) {
@ -434,127 +387,11 @@ static int config_parse_dhcp_lease_server_list(
continue;
}
struct in_addr *m = reallocarray(*addresses, *n_addresses + 1, sizeof(struct in_addr));
struct in_addr *m = reallocarray(emit->addresses, emit->n_addresses + 1, sizeof(struct in_addr));
if (!m)
return log_oom();
m[(*n_addresses)++] = a.in;
*addresses = m;
emit->addresses = m;
emit->addresses[emit->n_addresses++] = a.in;
}
}
int config_parse_dhcp_server_dns(
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;
return config_parse_dhcp_lease_server_list(unit, filename, line,
lvalue, rvalue,
&n->dhcp_server_dns, &n->n_dhcp_server_dns);
}
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) {
Network *n = data;
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(
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;
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(
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;
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(
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;
return config_parse_dhcp_lease_server_list(unit, filename, line,
lvalue, rvalue,
&n->dhcp_server_smtp, &n->n_dhcp_server_smtp);
}
int config_parse_dhcp_server_lpr_servers(
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;
return config_parse_dhcp_lease_server_list(unit, filename, line,
lvalue, rvalue,
&n->dhcp_server_lpr, &n->n_dhcp_server_lpr);
}

View File

@ -9,9 +9,4 @@ typedef struct Link Link;
int dhcp4_server_configure(Link *link);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_dns);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_ntp);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_sip);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_pop3_servers);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_smtp_servers);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_lpr_servers);
CONFIG_PARSER_PROTOTYPE(config_parse_dhcp_server_emit);

View File

@ -4196,32 +4196,11 @@ int link_save(Link *link) {
sd_dhcp6_lease_get_ntp_fqdn);
serialize_addresses(f, "SIP", NULL,
link->network->sip,
NULL,
link->dhcp_lease,
link->network->dhcp_use_sip,
SD_DHCP_LEASE_SIP,
false, NULL, NULL, NULL);
serialize_addresses(f, "POP3", NULL,
link->network->pop3,
link->dhcp_lease,
true,
SD_DHCP_LEASE_POP3,
false, NULL, NULL, NULL);
serialize_addresses(f, "SMTP", NULL,
link->network->smtp,
link->dhcp_lease,
true,
SD_DHCP_LEASE_SMTP,
false, NULL, NULL, NULL);
serialize_addresses(f, "LPR", NULL,
link->network->lpr,
link->dhcp_lease,
true,
SD_DHCP_LEASE_LPR,
false, NULL, NULL, NULL);
NULL, false, NULL, NULL);
/************************************************************/

View File

@ -159,7 +159,7 @@ typedef struct Link {
struct rtnl_link_stats64 stats_old, stats_new;
bool stats_updated;
/* All kinds of DNS configuration */
/* All kinds of DNS configuration the user configured via D-Bus */
struct in_addr_data *dns;
unsigned n_dns;
OrderedSet *search_domains, *route_domains;
@ -171,6 +171,7 @@ typedef struct Link {
DnsOverTlsMode dns_over_tls_mode;
Set *dnssec_negative_trust_anchors;
/* Similar, but NTP server configuration */
char **ntp;
} Link;

View File

@ -1499,8 +1499,7 @@ static int ordered_set_put_in4_addrv(OrderedSet *s,
}
static int manager_save(Manager *m) {
_cleanup_ordered_set_free_free_ OrderedSet *dns = NULL, *ntp = NULL, *sip = NULL, *pop3 = NULL,
*smtp = NULL, *lpr = NULL, *search_domains = NULL, *route_domains = NULL;
_cleanup_ordered_set_free_free_ OrderedSet *dns = NULL, *ntp = NULL, *sip = NULL, *search_domains = NULL, *route_domains = NULL;
const char *operstate_str, *carrier_state_str, *address_state_str;
LinkOperationalState operstate = LINK_OPERSTATE_OFF;
LinkCarrierState carrier_state = LINK_CARRIER_STATE_OFF;
@ -1508,7 +1507,6 @@ static int manager_save(Manager *m) {
_cleanup_free_ char *temp_path = NULL;
_cleanup_strv_free_ char **p = NULL;
_cleanup_fclose_ FILE *f = NULL;
const struct in_addr *addresses;
Link *link;
Iterator i;
int r;
@ -1529,18 +1527,6 @@ static int manager_save(Manager *m) {
if (!sip)
return -ENOMEM;
pop3 = ordered_set_new(&string_hash_ops);
if (!pop3)
return -ENOMEM;
smtp = ordered_set_new(&string_hash_ops);
if (!smtp)
return -ENOMEM;
lpr = ordered_set_new(&string_hash_ops);
if (!lpr)
return -ENOMEM;
search_domains = ordered_set_new(&dns_name_hash_ops);
if (!search_domains)
return -ENOMEM;
@ -1550,6 +1536,8 @@ static int manager_save(Manager *m) {
return -ENOMEM;
HASHMAP_FOREACH(link, m->links, i) {
const struct in_addr *addresses;
if (link->flags & IFF_LOOPBACK)
continue;
@ -1616,30 +1604,6 @@ static int manager_save(Manager *m) {
return r;
}
r = sd_dhcp_lease_get_pop3(link->dhcp_lease, &addresses);
if (r > 0) {
r = ordered_set_put_in4_addrv(pop3, addresses, r, in4_addr_is_non_local);
if (r < 0)
return r;
} else if (r < 0 && r != -ENODATA)
return r;
r = sd_dhcp_lease_get_smtp(link->dhcp_lease, &addresses);
if (r > 0) {
r = ordered_set_put_in4_addrv(smtp, addresses, r, in4_addr_is_non_local);
if (r < 0)
return r;
} else if (r < 0 && r != -ENODATA)
return r;
r = sd_dhcp_lease_get_lpr(link->dhcp_lease, &addresses);
if (r > 0) {
r = ordered_set_put_in4_addrv(lpr, addresses, r, in4_addr_is_non_local);
if (r < 0)
return r;
} else if (r < 0 && r != -ENODATA)
return r;
if (link->network->dhcp_use_domains != DHCP_USE_DOMAINS_NO) {
const char *domainname;
char **domains = NULL;
@ -1691,9 +1655,6 @@ static int manager_save(Manager *m) {
ordered_set_print(f, "DNS=", dns);
ordered_set_print(f, "NTP=", ntp);
ordered_set_print(f, "SIP=", sip);
ordered_set_print(f, "POP3_SERVERS=", pop3);
ordered_set_print(f, "SMTP_SERVERS=", smtp);
ordered_set_print(f, "LPR_SERVERS=", lpr);
ordered_set_print(f, "DOMAINS=", search_domains);
ordered_set_print(f, "ROUTE_DOMAINS=", route_domains);

View File

@ -217,15 +217,18 @@ IPv6AcceptRA.RouteTable, config_parse_section_route_table,
IPv6AcceptRA.BlackList, config_parse_ndisc_black_listed_prefix, 0, 0
DHCPServer.MaxLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_max_lease_time_usec)
DHCPServer.DefaultLeaseTimeSec, config_parse_sec, 0, offsetof(Network, dhcp_server_default_lease_time_usec)
DHCPServer.EmitDNS, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_dns)
DHCPServer.DNS, config_parse_dhcp_server_dns, 0, 0
DHCPServer.EmitNTP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_ntp)
DHCPServer.NTP, config_parse_dhcp_server_ntp, 0, 0
DHCPServer.EmitSIP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_sip)
DHCPServer.SIP, config_parse_dhcp_server_sip, 0, 0
DHCPServer.POP3Servers, config_parse_dhcp_server_pop3_servers, 0, 0
DHCPServer.SMTPServers, config_parse_dhcp_server_smtp_servers, 0, 0
DHCPServer.LPRServers, config_parse_dhcp_server_lpr_servers, 0, 0
DHCPServer.EmitDNS, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_DNS].emit)
DHCPServer.DNS, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_DNS])
DHCPServer.EmitNTP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_NTP].emit)
DHCPServer.NTP, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_NTP])
DHCPServer.EmitSIP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_SIP].emit)
DHCPServer.SIP, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_SIP])
DHCPServer.EmitPOP3, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_POP3].emit)
DHCPServer.POP3, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_POP3])
DHCPServer.EmitSMTP, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_SMTP].emit)
DHCPServer.SMTP, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_SMTP])
DHCPServer.EmitLPR, config_parse_bool, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_LPR].emit)
DHCPServer.LPR, config_parse_dhcp_server_emit, 0, offsetof(Network, dhcp_server_emit[SD_DHCP_LEASE_LPR])
DHCPServer.EmitRouter, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_router)
DHCPServer.EmitTimezone, config_parse_bool, 0, offsetof(Network, dhcp_server_emit_timezone)
DHCPServer.Timezone, config_parse_timezone, 0, offsetof(Network, dhcp_server_timezone)

View File

@ -416,9 +416,10 @@ int network_load_one(Manager *manager, OrderedHashmap **networks, const char *fi
.dhcp6_pd_assign_prefix = true,
.dhcp_server_emit_dns = true,
.dhcp_server_emit_ntp = true,
.dhcp_server_emit_sip = true,
.dhcp_server_emit[SD_DHCP_LEASE_DNS].emit = true,
.dhcp_server_emit[SD_DHCP_LEASE_NTP].emit = true,
.dhcp_server_emit[SD_DHCP_LEASE_SIP].emit = true,
.dhcp_server_emit_router = true,
.dhcp_server_emit_timezone = true,
@ -673,8 +674,6 @@ static Network *network_free(Network *network) {
strv_free(network->ntp);
free(network->dns);
strv_free(network->sip);
strv_free(network->smtp);
ordered_set_free_free(network->search_domains);
ordered_set_free_free(network->route_domains);
strv_free(network->bind_carrier);
@ -740,12 +739,9 @@ static Network *network_free(Network *network) {
free(network->name);
free(network->dhcp_server_timezone);
free(network->dhcp_server_dns);
free(network->dhcp_server_ntp);
free(network->dhcp_server_sip);
free(network->dhcp_server_pop3);
free(network->dhcp_server_smtp);
free(network->dhcp_server_lpr);
for (sd_dhcp_lease_server_type t = 0; t < _SD_DHCP_LEASE_SERVER_TYPE_MAX; t++)
free(network->dhcp_server_emit[t].addresses);
set_free_free(network->dnssec_negative_trust_anchors);

View File

@ -54,6 +54,12 @@ typedef enum KeepConfiguration {
typedef struct Manager Manager;
typedef struct NetworkDHCPServerEmitAddress {
bool emit;
struct in_addr *addresses;
size_t n_addresses;
} NetworkDHCPServerEmitAddress;
struct Network {
Manager *manager;
@ -149,28 +155,7 @@ struct Network {
/* DHCP Server Support */
bool dhcp_server;
bool dhcp_server_emit_dns;
struct in_addr *dhcp_server_dns;
unsigned n_dhcp_server_dns;
bool dhcp_server_emit_ntp;
struct in_addr *dhcp_server_ntp;
unsigned n_dhcp_server_ntp;
bool dhcp_server_emit_sip;
struct in_addr *dhcp_server_sip;
unsigned n_dhcp_server_sip;
struct in_addr *dhcp_server_pop3;
unsigned n_dhcp_server_pop3;
struct in_addr *dhcp_server_smtp;
unsigned n_dhcp_server_smtp;
struct in_addr *dhcp_server_lpr;
unsigned n_dhcp_server_lpr;
NetworkDHCPServerEmitAddress dhcp_server_emit[_SD_DHCP_LEASE_SERVER_TYPE_MAX];
bool dhcp_server_emit_router;
bool dhcp_server_emit_timezone;
char *dhcp_server_timezone;
@ -331,10 +316,6 @@ struct Network {
Set *dnssec_negative_trust_anchors;
char **ntp;
char **sip;
char **pop3;
char **smtp;
char **lpr;
char **bind_carrier;
};

View File

@ -68,8 +68,8 @@ int sd_dhcp_server_set_lpr(sd_dhcp_server *server, const struct in_addr lpr[], s
int sd_dhcp_server_set_dns(sd_dhcp_server *server, const struct in_addr dns[], size_t n);
int sd_dhcp_server_set_ntp(sd_dhcp_server *server, const struct in_addr ntp[], size_t n);
int sd_dhcp_server_set_sip(sd_dhcp_server *server, const struct in_addr sip[], size_t n);
int sd_dhcp_server_set_pop3(sd_dhcp_server *server, const struct in_addr pop3_server[], size_t n);
int sd_dhcp_server_set_smtp(sd_dhcp_server *server, const struct in_addr smtp_server[], size_t n);
int sd_dhcp_server_set_pop3(sd_dhcp_server *server, const struct in_addr pop3[], size_t n);
int sd_dhcp_server_set_smtp(sd_dhcp_server *server, const struct in_addr smtp[], size_t n);
int sd_dhcp_server_add_option(sd_dhcp_server *server, sd_dhcp_option *v);
int sd_dhcp_server_add_vendor_option(sd_dhcp_server *server, sd_dhcp_option *v);

View File

@ -164,18 +164,6 @@ int sd_network_link_get_search_domains(int ifindex, char ***domains);
/* Get the route DNS domain names for a given link. */
int sd_network_link_get_route_domains(int ifindex, char ***domains);
/* Get the sip servers for a given link. */
int sd_network_link_get_sip_servers(int ifindex, char ***sip);
/* Get the pop3 servers for a given link. */
int sd_network_link_get_pop3_servers(int ifindex, char ***pop3);
/* Get the SMTP servers for a given link. */
int sd_network_link_get_smtp_servers(int ifindex, char ***smtp);
/* Get the LPR servers for a given link. */
int sd_network_link_get_lpr_servers(int ifindex, char ***lpr);
/* Get whether this link shall be used as 'default route' for DNS queries */
int sd_network_link_get_dns_default_route(int ifindex);

View File

@ -289,9 +289,12 @@ EmitDNS=
NTP=
EmitSIP=
SIP=
POP3Servers=
SMTPServers=
LPRServers=
EmitPOP3=
POP3=
EmitSMTP=
SMTP=
EmitLPR=
LPR=
EmitRouter=
MaxLeaseTimeSec=
DefaultLeaseTimeSec=