]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-network: introduce network_link_get_boolean() helper function
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 24 Sep 2022 00:20:36 +0000 (09:20 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 27 Sep 2022 01:42:31 +0000 (10:42 +0900)
src/libsystemd/sd-network/sd-network.c

index 92ee8bc073ccb1d3f5c12f8e4535745c9f36b4ea..9d00470fe1e07b90b9d1d33ad1dda90a02271e20 100644 (file)
@@ -120,6 +120,17 @@ static int network_link_get_string(int ifindex, const char *field, char **ret) {
         return 0;
 }
 
+static int network_link_get_boolean(int ifindex, const char *key) {
+        _cleanup_free_ char *s = NULL;
+        int r;
+
+        r = network_link_get_string(ifindex, key, &s);
+        if (r < 0)
+                return r;
+
+        return parse_boolean(s);
+}
+
 static int network_link_get_strv(int ifindex, const char *key, char ***ret) {
         char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex)];
         _cleanup_strv_free_ char **a = NULL;
@@ -307,20 +318,7 @@ int sd_network_link_get_route_domains(int ifindex, char ***ret) {
 }
 
 int sd_network_link_get_dns_default_route(int ifindex) {
-        char path[STRLEN("/run/systemd/netif/links/") + DECIMAL_STR_MAX(ifindex)];
-        _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 < 0)
-                return r;
-        if (isempty(s))
-                return -ENODATA;
-        return parse_boolean(s);
+        return network_link_get_boolean(ifindex, "DNS_DEFAULT_ROUTE");
 }
 
 static int network_link_get_ifindexes(int ifindex, const char *key, int **ret) {