chiark / gitweb /
sd-network: add _get_network_file api
authorTom Gundersen <teg@jklm.no>
Mon, 8 Sep 2014 11:50:52 +0000 (13:50 +0200)
committerTom Gundersen <teg@jklm.no>
Mon, 8 Sep 2014 13:09:07 +0000 (15:09 +0200)
src/libsystemd/sd-network/sd-network.c
src/network/networkd-link.c
src/systemd/sd-network.h

index 3a3f535..d63e6f9 100644 (file)
@@ -120,6 +120,30 @@ _public_ int sd_network_link_get_setup_state(int ifindex, char **state) {
         return 0;
 }
 
+_public_ int sd_network_link_get_network_file(int ifindex, char **filename) {
+        _cleanup_free_ char *s = NULL, *p = NULL;
+        int r;
+
+        assert_return(ifindex > 0, -EINVAL);
+        assert_return(filename, -EINVAL);
+
+        if (asprintf(&p, "/run/systemd/netif/links/%d", ifindex) < 0)
+                return -ENOMEM;
+
+        r = parse_env_file(p, NEWLINE, "NETWORK_FILE", &s, NULL);
+        if (r == -ENOENT)
+                return -ENODATA;
+        if (r < 0)
+                return r;
+        if (isempty(s))
+                return -ENODATA;
+
+        *filename = s;
+        s = NULL;
+
+        return 0;
+}
+
 _public_ int sd_network_link_get_operational_state(int ifindex, char **state) {
         _cleanup_free_ char *s = NULL, *p = NULL;
         int r;
index a88cf48..11ac130 100644 (file)
@@ -1785,6 +1785,8 @@ int link_save(Link *link) {
                 char **address, **domain;
                 bool space;
 
+                fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
+
                 fputs("DNS=", f);
                 space = false;
                 STRV_FOREACH(address, link->network->dns) {
index b2086c7..203a2a6 100644 (file)
@@ -93,6 +93,9 @@ int sd_network_link_get_setup_state(int ifindex, char **state);
  */
 int sd_network_link_get_operational_state(int ifindex, char **state);
 
+/* Get path to .network file applied to link */
+int sd_network_link_get_network_file(int ifindex, char **filename);
+
 /* Get DNS entries for a given link. These are string representations of
  * IP addresses */
 int sd_network_link_get_dns(int ifindex, char ***addr);