[systemd-devel] [PATCH 11/11] network: Save DNS and NTP data for a DHCPv6 link

Patrik Flykt patrik.flykt at linux.intel.com
Fri Jul 10 05:30:35 PDT 2015


Append DNS and NTP data obtained via DHCPv6 when the Link is saved.
---
 src/network/networkd-link.c | 62 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index dff81a5..2f36abe 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -2161,6 +2161,14 @@ int link_save(Link *link) {
         if (link->network) {
                 char **address, **domain;
                 bool space;
+                sd_dhcp6_lease *dhcp6_lease = NULL;
+
+                if (link->dhcp6_client) {
+                        r = sd_dhcp6_client_get_lease(link->dhcp6_client,
+                                                      &dhcp6_lease);
+                        if (r < 0)
+                                log_link_debug(link, "No DHCPv6 lease");
+                }
 
                 fprintf(f, "NETWORK_FILE=%s\n", link->network->filename);
 
@@ -2182,6 +2190,19 @@ int link_save(Link *link) {
                                 if (space)
                                         fputc(' ', f);
                                 serialize_in_addrs(f, addresses, r);
+                                space = true;
+                        }
+                }
+
+                if (link->network->dhcp_dns && dhcp6_lease) {
+                        struct in6_addr *in6_addrs;
+
+                        r = sd_dhcp6_lease_get_dns(dhcp6_lease, &in6_addrs);
+                        if (r > 0) {
+                                if (space)
+                                        fputc(' ', f);
+                                serialize_in6_addrs(f, in6_addrs, r);
+                                space = true;
                         }
                 }
 
@@ -2205,6 +2226,32 @@ int link_save(Link *link) {
                                 if (space)
                                         fputc(' ', f);
                                 serialize_in_addrs(f, addresses, r);
+                                space = true;
+                        }
+                }
+
+                if (link->network->dhcp_ntp && dhcp6_lease) {
+                        struct in6_addr *in6_addrs;
+                        char **hosts;
+                        char **hostname;
+
+                        r = sd_dhcp6_lease_get_ntp_addrs(dhcp6_lease,
+                                                         &in6_addrs);
+                        if (r > 0) {
+                                if (space)
+                                        fputc(' ', f);
+                                serialize_in6_addrs(f, in6_addrs, r);
+                                space = true;
+                        }
+
+                        r = sd_dhcp6_lease_get_ntp_fqdn(dhcp6_lease, &hosts);
+                        if (r > 0) {
+                                STRV_FOREACH(hostname, hosts) {
+                                        if (space)
+                                                fputc(' ', f);
+                                        fputs(*hostname, f);
+                                        space = true;
+                                }
                         }
                 }
 
@@ -2228,6 +2275,21 @@ int link_save(Link *link) {
                                 if (space)
                                         fputc(' ', f);
                                 fputs(domainname, f);
+                                space = true;
+                        }
+                }
+
+                if (link->network->dhcp_domains && dhcp6_lease) {
+                        char **domains;
+
+                        r = sd_dhcp6_lease_get_domains(dhcp6_lease, &domains);
+                        if (r >= 0) {
+                                STRV_FOREACH(domain, domains) {
+                                        if (space)
+                                                fputc(' ', f);
+                                        fputs(*domain, f);
+                                        space = true;
+                                }
                         }
                 }
 
-- 
2.1.4



More information about the systemd-devel mailing list