diff options
author | 2018-12-04 13:47:53 +0100 | |
---|---|---|
committer | 2018-12-21 12:10:07 +0100 | |
commit | c629354e84cd154ac30ec0a70ff7d937f02dff0b (patch) | |
tree | f314f72fa2e08ee411440788abcbf051745d8d2c | |
parent | networkd: permit DNS "DefaultRoute" configuration in .network files (diff) | |
download | systemd-c629354e84cd154ac30ec0a70ff7d937f02dff0b.tar.gz systemd-c629354e84cd154ac30ec0a70ff7d937f02dff0b.tar.bz2 systemd-c629354e84cd154ac30ec0a70ff7d937f02dff0b.zip |
sd-network: add new API sd_network_link_get_dns_default_route()
This simply reads from networkd's state files whether a link shall be
used as DNS default route.
-rw-r--r-- | src/libsystemd/sd-network/sd-network.c | 19 | ||||
-rw-r--r-- | src/systemd/sd-network.h | 3 |
2 files changed, 22 insertions, 0 deletions
diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c index 4b66a9220..d4b5e248c 100644 --- a/src/libsystemd/sd-network/sd-network.c +++ b/src/libsystemd/sd-network/sd-network.c @@ -204,6 +204,25 @@ _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_dns_default_route(int ifindex) { + char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; + _cleanup_free_ char *s = NULL; + int r; + + assert_return(ifindex > 0, -EINVAL); + + xsprintf(path, "/run/systemd/netif/links/%i", ifindex); + + r = parse_env_file(NULL, path, "DNS_DEFAULT_ROUTE", &s); + if (r == -ENOENT) + return -ENODATA; + if (r < 0) + return r; + if (isempty(s)) + return -ENODATA; + return parse_boolean(s); +} + static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) { char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex) + 1]; _cleanup_free_ int *ifis = NULL; diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h index c8b7226bc..cc6bca9f5 100644 --- a/src/systemd/sd-network.h +++ b/src/systemd/sd-network.h @@ -151,6 +151,9 @@ 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 whether this link shall be used as 'default route' for DNS queries */ +int sd_network_link_get_dns_default_route(int ifindex); + /* Get the carrier interface indexes to which current link is bound to. */ int sd_network_link_get_carrier_bound_to(int ifindex, int **ifindexes); |