From c629354e84cd154ac30ec0a70ff7d937f02dff0b Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 4 Dec 2018 13:47:53 +0100 Subject: 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. --- src/libsystemd/sd-network/sd-network.c | 19 +++++++++++++++++++ src/systemd/sd-network.h | 3 +++ 2 files changed, 22 insertions(+) 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); -- cgit v1.2.3-65-gdbad