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:
committed by
Yu Watanabe
parent
d5da3ada8e
commit
2a71d57f4e
@@ -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);
|
||||
|
||||
+112
-275
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
/************************************************************/
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user