mirror of
https://github.com/systemd/systemd.git
synced 2025-01-06 00:24:19 +08:00
sd-network: add support for wildcard domains
This commit is contained in:
parent
6192b846ca
commit
67272d157a
@ -210,6 +210,25 @@ _public_ int sd_network_link_get_domains(int ifindex, char ***ret) {
|
||||
return network_get_link_strv("DOMAINS", ifindex, ret);
|
||||
}
|
||||
|
||||
_public_ int sd_network_link_get_wildcard_domain(int ifindex) {
|
||||
int r;
|
||||
_cleanup_free_ char *p = NULL, *s = NULL;
|
||||
|
||||
assert_return(ifindex > 0, -EINVAL);
|
||||
|
||||
if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
|
||||
return -ENOMEM;
|
||||
|
||||
r = parse_env_file(p, NEWLINE, "WILDCARD_DOMAIN", &s, NULL);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!s)
|
||||
return -EIO;
|
||||
|
||||
return parse_boolean(s);
|
||||
}
|
||||
|
||||
static inline int MONITOR_TO_FD(sd_network_monitor *m) {
|
||||
return (int) (unsigned long) m - 1;
|
||||
}
|
||||
|
@ -366,6 +366,13 @@ static int link_status_one(sd_rtnl *rtnl, struct udev *udev, const char *name) {
|
||||
sd_network_link_get_dns(ifindex, &dns);
|
||||
sd_network_link_get_ntp(ifindex, &ntp);
|
||||
sd_network_link_get_domains(ifindex, &domains);
|
||||
r = sd_network_link_get_wildcard_domain(ifindex);
|
||||
if (r > 0) {
|
||||
char *wildcard;
|
||||
|
||||
wildcard = strdup("*");
|
||||
strv_push(&domains, wildcard);
|
||||
}
|
||||
|
||||
sprintf(devid, "n%i", ifindex);
|
||||
d = udev_device_new_from_device_id(udev, devid);
|
||||
|
@ -1784,6 +1784,9 @@ int link_save(Link *link) {
|
||||
|
||||
fputs("\n", f);
|
||||
|
||||
fprintf(f, "WILDCARD_DOMAIN=%s\n",
|
||||
yes_no(link->network->wildcard_domain));
|
||||
|
||||
fprintf(f, "LLMNR=%s\n",
|
||||
llmnr_support_to_string(link->network->llmnr));
|
||||
}
|
||||
|
@ -351,6 +351,7 @@ int config_parse_domains(const char *unit,
|
||||
const char *rvalue,
|
||||
void *data,
|
||||
void *userdata) {
|
||||
Network *network = userdata;
|
||||
char ***domains = data;
|
||||
char **domain;
|
||||
int r;
|
||||
@ -362,6 +363,11 @@ int config_parse_domains(const char *unit,
|
||||
|
||||
strv_uniq(*domains);
|
||||
|
||||
if (strv_isempty(*domains))
|
||||
network->wildcard_domain = false;
|
||||
else if (strv_find(*domains, "*"))
|
||||
network->wildcard_domain = true;
|
||||
|
||||
STRV_FOREACH(domain, *domains)
|
||||
if (is_localhost(*domain) || !hostname_is_valid(*domain))
|
||||
strv_remove(*domains, *domain);
|
||||
|
@ -111,6 +111,7 @@ struct Network {
|
||||
Hashmap *addresses_by_section;
|
||||
Hashmap *routes_by_section;
|
||||
|
||||
bool wildcard_domain;
|
||||
char **domains, **dns, **ntp;
|
||||
|
||||
LLMNRSupport llmnr;
|
||||
|
@ -107,6 +107,10 @@ int sd_network_link_get_llmnr(int ifindex, char **llmnr);
|
||||
/* Get the DNS domain names for a given link. */
|
||||
int sd_network_link_get_domains(int ifindex, char ***domains);
|
||||
|
||||
/* Returns whether or not domains that don't match any link should be resolved
|
||||
* on this link. 1 for yes, 0 for no and negative value for error */
|
||||
int sd_network_link_get_wildcard_domain(int ifindex);
|
||||
|
||||
/* Monitor object */
|
||||
typedef struct sd_network_monitor sd_network_monitor;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user