[systemd-commits] 3 commits - Makefile.am Makefile-man.am src/libsystemd-network

Tom Gundersen tomegun at kemper.freedesktop.org
Tue Apr 29 06:42:18 PDT 2014


 Makefile-man.am                        |    5 -
 Makefile.am                            |    3 
 src/libsystemd-network/sd-dhcp-lease.c |  133 ++++++++++++++++++---------------
 3 files changed, 79 insertions(+), 62 deletions(-)

New commits:
commit 4c06153f7b7d1af4fc8df4602c1d6714734bf9fd
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Apr 29 15:42:05 2014 +0200

    networkd: fix distcheck

diff --git a/Makefile-man.am b/Makefile-man.am
index 262e4b1..f9ca87e 100644
--- a/Makefile-man.am
+++ b/Makefile-man.am
@@ -1046,8 +1046,11 @@ MANPAGES_ALIAS += \
 	man/systemd-networkd.8 \
 	man/systemd-networkd-wait-online.8
 man/systemd-networkd.8: man/systemd-networkd.service.8
-man/systemd-networkd.html: man/systemd-networkd.service.html
 man/systemd-networkd-wait-online.8: man/systemd-networkd-wait-online.service.8
+
+man/systemd-networkd.html: man/systemd-networkd.service.html
+	$(html-alias)
+
 man/systemd-networkd-wait-online.html: man/systemd-networkd-wait-online.service.html
 	$(html-alias)
 
diff --git a/Makefile.am b/Makefile.am
index 4661a2a..365fa54 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -4200,7 +4200,8 @@ tests += \
 EXTRA_DIST += \
 	src/network/networkd-network-gperf.gperf \
 	src/network/networkd-netdev-gperf.gperf \
-	units/systemd-networkd.service.in
+	units/systemd-networkd.service.in \
+	units/systemd-networkd-wait-online.service.in
 
 CLEANFILES += \
 	src/network/networkd-network-gperf.c \

commit 109731eb250705e055b98b844d7c0dfb74bcf728
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Apr 29 13:29:12 2014 +0200

    sd-dhcp-lease: (de)serialize DNS and NTP servers
    
    Also use inet_ntoa rather than inet_ntop.

diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 61822ab..648e6e2 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -303,11 +303,51 @@ int dhcp_lease_new(sd_dhcp_lease **ret) {
         return 0;
 }
 
+static void serialize_addresses(FILE *f, const char *key, struct in_addr *addresses, size_t size) {
+        unsigned i;
+
+        assert(key);
+        assert(addresses);
+        assert(size);
+
+        fputs("DNS=", f);
+
+        for (i = 0; i < size; i++)
+                fprintf(f, "%s%s", inet_ntoa(addresses[i]),
+                        (i < (size - 1)) ? " ": "");
+
+        fputs("\n", f);
+}
+
+static int deserialize_addresses(struct in_addr **addresses, size_t *size, const char *string) {
+        char *word, *state;
+        size_t len;
+
+        FOREACH_WORD(word, len, string, state) {
+                struct in_addr *new_addresses;
+                int r;
+
+                new_addresses = realloc(*addresses, (*size + 1) * sizeof(struct in_addr));
+                if (!new_addresses)
+                        return -ENOMEM;
+
+                r = inet_aton(word, &(new_addresses[*size]));
+                if (r < 0)
+                        continue;
+
+                *addresses = new_addresses;
+                (*size)++;
+        }
+
+        return 0;
+}
+
 int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
         _cleanup_free_ char *temp_path = NULL;
         _cleanup_fclose_ FILE *f = NULL;
-        char buf[INET_ADDRSTRLEN];
         struct in_addr address;
+        struct in_addr *addresses;
+        size_t addresses_size;
         const char *string;
         uint16_t mtu;
         int r;
@@ -325,71 +365,42 @@ int dhcp_lease_save(sd_dhcp_lease *lease, const char *lease_file) {
         if (r < 0)
                 goto finish;
 
-        string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
-        if (!string) {
-                r = -errno;
-                goto finish;
-        }
-
         fprintf(f,
                 "# This is private data. Do not parse.\n"
-                "ADDRESS=%s\n", string);
+                "ADDRESS=%s\n", inet_ntoa(address));
 
         r = sd_dhcp_lease_get_router(lease, &address);
         if (r < 0)
                 goto finish;
 
-        string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
-        if (!string) {
-                r = -errno;
-                goto finish;
-        }
-
-        fprintf(f,
-                "ROUTER=%s\n", string);
+        fprintf(f, "ROUTER=%s\n", inet_ntoa(address));
 
         r = sd_dhcp_lease_get_netmask(lease, &address);
         if (r < 0)
                 goto finish;
 
-        string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
-        if (!string) {
-                r = -errno;
-                goto finish;
-        }
-
-        fprintf(f,
-                "NETMASK=%s\n", string);
+        fprintf(f, "NETMASK=%s\n", inet_ntoa(address));
 
         r = sd_dhcp_lease_get_server_identifier(lease, &address);
-        if (r >= 0) {
-                string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
-                if (!string) {
-                        r = -errno;
-                        goto finish;
-                }
-
-                fprintf(f,
-                        "SERVER_ADDRESS=%s\n", string);
-        }
+        if (r >= 0)
+                fprintf(f, "SERVER_ADDRESS=%s\n",
+                        inet_ntoa(address));
 
         r = sd_dhcp_lease_get_next_server(lease, &address);
-        if (r >= 0) {
-                string = inet_ntop(AF_INET, &address, buf, INET_ADDRSTRLEN);
-                if (!string) {
-                        r = -errno;
-                        goto finish;
-                }
-
-                fprintf(f,
-                        "NEXT_SERVER=%s\n", string);
-        }
+        if (r >= 0)
+                fprintf(f, "NEXT_SERVER=%s\n", inet_ntoa(address));
 
         r = sd_dhcp_lease_get_mtu(lease, &mtu);
         if (r >= 0)
                 fprintf(f, "MTU=%" PRIu16 "\n", mtu);
 
-/* TODO: DNS. See resolv.conf writing in network-manager.c */
+        r = sd_dhcp_lease_get_dns(lease, &addresses, &addresses_size);
+        if (r >= 0)
+                serialize_addresses(f, "DNS", addresses, addresses_size);
+
+        r = sd_dhcp_lease_get_ntp(lease, &addresses, &addresses_size);
+        if (r >= 0)
+                serialize_addresses(f, "NTP", addresses, addresses_size);
 
         r = sd_dhcp_lease_get_domainname(lease, &string);
         if (r >= 0)
@@ -424,7 +435,7 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
         _cleanup_dhcp_lease_unref_ sd_dhcp_lease *lease = NULL;
         _cleanup_free_ char *address = NULL, *router = NULL, *netmask = NULL,
                             *server_address = NULL, *next_server = NULL,
-                            *mtu = NULL;
+                            *dns = NULL, *ntp = NULL, *mtu = NULL;
         struct in_addr addr;
         int r;
 
@@ -441,6 +452,8 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
                            "NETMASK", &netmask,
                            "SERVER_IDENTIFIER", &server_address,
                            "NEXT_SERVER", &next_server,
+                           "DNS", &dns,
+                           "NTP", &ntp,
                            "MTU", &mtu,
                            "DOMAINNAME", &lease->domainname,
                            "HOSTNAME", &lease->hostname,
@@ -488,6 +501,18 @@ int dhcp_lease_load(const char *lease_file, sd_dhcp_lease **ret) {
                 lease->next_server = addr.s_addr;
         }
 
+        if (dns) {
+                r = deserialize_addresses(&lease->dns, &lease->dns_size, dns);
+                if (r < 0)
+                        return r;
+        }
+
+        if (ntp) {
+                r = deserialize_addresses(&lease->ntp, &lease->ntp_size, dns);
+                if (r < 0)
+                        return r;
+        }
+
         if (mtu) {
                 uint16_t u;
                 if (sscanf(mtu, "%" SCNu16, &u) > 0)

commit 0b21bde96d6d33313bac42ae1d5802a83a4e7b2f
Author: Tom Gundersen <teg at jklm.no>
Date:   Tue Apr 29 12:46:06 2014 +0200

    sd-dhcp-leaes: use newdup()

diff --git a/src/libsystemd-network/sd-dhcp-lease.c b/src/libsystemd-network/sd-dhcp-lease.c
index 69418d9..61822ab 100644
--- a/src/libsystemd-network/sd-dhcp-lease.c
+++ b/src/libsystemd-network/sd-dhcp-lease.c
@@ -211,36 +211,24 @@ int dhcp_lease_parse_options(uint8_t code, uint8_t len, const uint8_t *option,
 
         case DHCP_OPTION_DOMAIN_NAME_SERVER:
                 if (len && !(len % 4)) {
-                        unsigned i;
-
                         lease->dns_size = len / 4;
 
                         free(lease->dns);
-                        lease->dns = new0(struct in_addr, lease->dns_size);
+                        lease->dns = newdup(struct in_addr, option, lease->dns_size);
                         if (!lease->dns)
                                 return -ENOMEM;
-
-                        for (i = 0; i < lease->dns_size; i++) {
-                                memcpy(&lease->dns[i].s_addr, option + 4 * i, 4);
-                        }
                 }
 
                 break;
 
         case DHCP_OPTION_NTP_SERVER:
                 if (len && !(len % 4)) {
-                        unsigned i;
-
                         lease->ntp_size = len / 4;
 
                         free(lease->ntp);
-                        lease->ntp = new0(struct in_addr, lease->ntp_size);
+                        lease->ntp = newdup(struct in_addr, option, lease->ntp_size);
                         if (!lease->ntp)
                                 return -ENOMEM;
-
-                        for (i = 0; i < lease->ntp_size; i++) {
-                                memcpy(&lease->ntp[i].s_addr, option + 4 * i, 4);
-                        }
                 }
 
                 break;



More information about the systemd-commits mailing list