systemd/0192-sd-network-add-_get_network_file-api.patch
Zbigniew Jędrzejewski-Szmek 62fe9450da Update to latest git
2014-10-07 15:51:56 -04:00

74 lines
2.6 KiB
Diff

From adc5b2e2ebcb91ee18b6a32681b8ec1e52793473 Mon Sep 17 00:00:00 2001
From: Tom Gundersen <teg@jklm.no>
Date: Mon, 8 Sep 2014 13:50:52 +0200
Subject: [PATCH] sd-network: add _get_network_file api
---
src/libsystemd/sd-network/sd-network.c | 24 ++++++++++++++++++++++++
src/network/networkd-link.c | 2 ++
src/systemd/sd-network.h | 3 +++
3 files changed, 29 insertions(+)
diff --git a/src/libsystemd/sd-network/sd-network.c b/src/libsystemd/sd-network/sd-network.c
index 3a3f53576f..d63e6f9dfa 100644
--- a/src/libsystemd/sd-network/sd-network.c
+++ b/src/libsystemd/sd-network/sd-network.c
@@ -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;
diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index a88cf48d9d..11ac1307d8 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -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) {
diff --git a/src/systemd/sd-network.h b/src/systemd/sd-network.h
index b2086c7836..203a2a6a47 100644
--- a/src/systemd/sd-network.h
+++ b/src/systemd/sd-network.h
@@ -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);