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

Tom Gundersen tomegun at kemper.freedesktop.org
Wed Jan 21 14:04:00 PST 2015


 Makefile.am                              |   10 ++-
 src/libsystemd-network/dhcp-identifier.c |  101 +++++++++++++++++++++++++++++++
 src/libsystemd-network/dhcp-identifier.h |   64 +++++++++++++++++++
 src/libsystemd-network/sd-dhcp6-client.c |  100 +++---------------------------
 src/network/networkd-link.c              |    2 
 5 files changed, 188 insertions(+), 89 deletions(-)

New commits:
commit 07e10d1a7c7535bd3938b09a11bf29b94a9dae77
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Jan 21 23:02:22 2015 +0100

    networkd: plug lldp leak

diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c
index bc363f9..310eb6c 100644
--- a/src/network/networkd-link.c
+++ b/src/network/networkd-link.c
@@ -286,6 +286,8 @@ static void link_free(Link *link) {
         unlink(link->lease_file);
         free(link->lease_file);
 
+        sd_lldp_free(link->lldp);
+
         unlink(link->lldp_file);
         free(link->lldp_file);
 

commit cfb5b3805759e63dc5e0cae6e92e1df885b5c5b6
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Jan 21 22:25:20 2015 +0100

    network: dhcp - split out dhcp_identifier_set_{iaid,duid_en} from dhcp6-client
    
    This will also be used in dhcp4-client.

diff --git a/Makefile.am b/Makefile.am
index 4f536ee..ca5d3ba 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -3187,6 +3187,8 @@ libsystemd_network_la_SOURCES = \
 	src/libsystemd-network/dhcp6-option.c \
 	src/libsystemd-network/dhcp6-lease-internal.h \
 	src/libsystemd-network/sd-dhcp6-lease.c \
+	src/libsystemd-network/dhcp-identifier.h \
+	src/libsystemd-network/dhcp-identifier.c \
 	src/libsystemd-network/lldp.h \
 	src/libsystemd-network/lldp-tlv.h \
 	src/libsystemd-network/lldp-tlv.c \
@@ -3259,7 +3261,9 @@ test_icmp6_rs_SOURCES = \
 	src/systemd/sd-dhcp6-client.h \
 	src/systemd/sd-icmp6-nd.h \
 	src/libsystemd-network/dhcp6-internal.h \
-	src/libsystemd-network/test-icmp6-rs.c
+	src/libsystemd-network/test-icmp6-rs.c \
+	src/libsystemd-network/dhcp-identifier.h \
+	src/libsystemd-network/dhcp-identifier.c
 
 test_icmp6_rs_LDADD = \
 	libsystemd-network.la \
@@ -3269,7 +3273,9 @@ test_icmp6_rs_LDADD = \
 test_dhcp6_client_SOURCES = \
 	src/systemd/sd-dhcp6-client.h \
 	src/libsystemd-network/dhcp6-internal.h \
-	src/libsystemd-network/test-dhcp6-client.c
+	src/libsystemd-network/test-dhcp6-client.c \
+	src/libsystemd-network/dhcp-identifier.h \
+	src/libsystemd-network/dhcp-identifier.c
 
 test_dhcp6_client_LDADD = \
 	libsystemd-network.la \
diff --git a/src/libsystemd-network/dhcp-identifier.c b/src/libsystemd-network/dhcp-identifier.c
new file mode 100644
index 0000000..5386dca
--- /dev/null
+++ b/src/libsystemd-network/dhcp-identifier.c
@@ -0,0 +1,101 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2015 Tom Gundersen <teg at jklmen>
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <net/ethernet.h>
+
+#include "sd-id128.h"
+#include "libudev.h"
+#include "udev-util.h"
+
+#include "virt.h"
+#include "sparse-endian.h"
+#include "siphash24.h"
+#include "util.h"
+
+#include "dhcp6-protocol.h"
+#include "dhcp-identifier.h"
+#include "network-internal.h"
+
+#define SYSTEMD_PEN 43793
+#define HASH_KEY SD_ID128_MAKE(80,11,8c,c2,fe,4a,03,ee,3e,d6,0c,6f,36,39,14,09)
+
+int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len) {
+        sd_id128_t machine_id;
+        int r;
+
+        assert(duid);
+        assert(len);
+
+        r = sd_id128_get_machine(&machine_id);
+        if (r < 0)
+                return r;
+
+        duid->type = htobe16(DHCP6_DUID_EN);
+        duid->en.pen = htobe32(SYSTEMD_PEN);
+        *len = sizeof(duid->type) + sizeof(duid->en);
+
+        /* a bit of snake-oil perhaps, but no need to expose the machine-id
+           directly */
+        siphash24(duid->en.id, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
+
+        return 0;
+}
+
+
+int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, uint32_t *_id) {
+        /* name is a pointer to memory in the udev_device struct, so must
+           have the same scope */
+        _cleanup_udev_device_unref_ struct udev_device *device = NULL;
+        const char *name = NULL;
+        uint64_t id;
+
+        if (detect_container(NULL) <= 0) {
+                /* not in a container, udev will be around */
+                _cleanup_udev_unref_ struct udev *udev;
+                char ifindex_str[2 + DECIMAL_STR_MAX(int)];
+
+                udev = udev_new();
+                if (!udev)
+                        return -ENOMEM;
+
+                sprintf(ifindex_str, "n%d", ifindex);
+                device = udev_device_new_from_device_id(udev, ifindex_str);
+                if (!device)
+                        return -errno;
+
+                if (udev_device_get_is_initialized(device) <= 0)
+                        /* not yet ready */
+                        return -EBUSY;
+
+                name = net_get_name(device);
+        }
+
+        if (name)
+                siphash24((uint8_t*)&id, name, strlen(name), HASH_KEY.bytes);
+        else
+                /* fall back to mac address if no predictable name available */
+                siphash24((uint8_t*)&id, mac, mac_len, HASH_KEY.bytes);
+
+        /* fold into 32 bits */
+        *_id = (id & 0xffffffff) ^ (id >> 32);
+
+        return 0;
+}
diff --git a/src/libsystemd-network/dhcp-identifier.h b/src/libsystemd-network/dhcp-identifier.h
index af95f07..cbec03e 100644
--- a/src/libsystemd-network/dhcp-identifier.h
+++ b/src/libsystemd-network/dhcp-identifier.h
@@ -59,3 +59,6 @@ struct duid {
                 } _packed_ raw;
         };
 } _packed_;
+
+int dhcp_identifier_set_duid_en(struct duid *duid, size_t *len);
+int dhcp_identifier_set_iaid(int ifindex, uint8_t *mac, size_t mac_len, uint32_t *_id);
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index 9386453..a432bbf 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -26,8 +26,6 @@
 
 #include "udev.h"
 #include "udev-util.h"
-#include "virt.h"
-#include "siphash24.h"
 #include "util.h"
 #include "refcnt.h"
 
@@ -38,9 +36,6 @@
 #include "dhcp6-lease-internal.h"
 #include "dhcp-identifier.h"
 
-#define SYSTEMD_PEN 43793
-#define HASH_KEY SD_ID128_MAKE(80,11,8c,c2,fe,4a,03,ee,3e,d6,0c,6f,36,39,14,09)
-
 #define MAX_MAC_ADDR_LEN INFINIBAND_ALEN
 
 struct sd_dhcp6_client {
@@ -628,47 +623,16 @@ error:
 }
 
 static int client_ensure_iaid(sd_dhcp6_client *client) {
-        /* name is a pointer to memory in the udev_device struct, so must
-           have the same scope */
-        _cleanup_udev_device_unref_ struct udev_device *device = NULL;
-        const char *name = NULL;
-        uint64_t id;
+        int r;
 
         assert(client);
 
         if (client->ia_na.id)
                 return 0;
 
-        if (detect_container(NULL) <= 0) {
-                /* not in a container, udev will be around */
-                _cleanup_udev_unref_ struct udev *udev;
-                char ifindex_str[2 + DECIMAL_STR_MAX(int)];
-
-                udev = udev_new();
-                if (!udev)
-                        return -ENOMEM;
-
-                sprintf(ifindex_str, "n%d", client->index);
-                device = udev_device_new_from_device_id(udev, ifindex_str);
-                if (!device)
-                        return -errno;
-
-                if (udev_device_get_is_initialized(device) <= 0)
-                        /* not yet ready */
-                        return -EBUSY;
-
-                name = net_get_name(device);
-        }
-
-        if (name)
-                siphash24((uint8_t*)&id, name, strlen(name), HASH_KEY.bytes);
-        else
-                /* fall back to mac address if no predictable name available */
-                siphash24((uint8_t*)&id, &client->mac_addr,
-                          client->mac_addr_len, HASH_KEY.bytes);
-
-        /* fold into 32 bits */
-        client->ia_na.id = (id & 0xffffffff) ^ (id >> 32);
+        r = dhcp_identifier_set_iaid(client->index, client->mac_addr, client->mac_addr_len, &client->ia_na.id);
+        if (r < 0)
+                return r;
 
         return 0;
 }
@@ -1241,7 +1205,6 @@ sd_dhcp6_client *sd_dhcp6_client_unref(sd_dhcp6_client *client) {
 int sd_dhcp6_client_new(sd_dhcp6_client **ret)
 {
         _cleanup_dhcp6_client_unref_ sd_dhcp6_client *client = NULL;
-        sd_id128_t machine_id;
         int r;
         size_t t;
 
@@ -1260,18 +1223,10 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
         client->fd = -1;
 
         /* initialize DUID */
-        client->duid.type = htobe16(DHCP6_DUID_EN);
-        client->duid.en.pen = htobe32(SYSTEMD_PEN);
-        client->duid_len = sizeof(client->duid.en);
-
-        r = sd_id128_get_machine(&machine_id);
+        r = dhcp_identifier_set_duid_en(&client->duid, &client->duid_len);
         if (r < 0)
                 return r;
 
-        /* a bit of snake-oil perhaps, but no need to expose the machine-id
-           directly */
-        siphash24(client->duid.en.id, &machine_id, sizeof(machine_id), HASH_KEY.bytes);
-
         client->req_opts_len = ELEMENTSOF(default_req_opts);
 
         client->req_opts = new0(be16_t, client->req_opts_len);

commit 764aad6258eec3bd4ae62ea341ea507bd69ce628
Author: Tom Gundersen <teg at jklm.no>
Date:   Wed Jan 21 21:23:47 2015 +0100

    network: dhcp - split out the duid structure into a new header file
    
    We will use the same in both dhcp4 and dhcp6.

diff --git a/src/libsystemd-network/dhcp-identifier.h b/src/libsystemd-network/dhcp-identifier.h
new file mode 100644
index 0000000..af95f07
--- /dev/null
+++ b/src/libsystemd-network/dhcp-identifier.h
@@ -0,0 +1,61 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+  This file is part of systemd.
+
+  Copyright (C) 2015 Tom Gundersen <teg at jklmen>
+
+  systemd is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published by
+  the Free Software Foundation; either version 2.1 of the License, or
+  (at your option) any later version.
+
+  systemd is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <net/ethernet.h>
+
+#include "sparse-endian.h"
+#include "sd-id128.h"
+
+/* RFC 3315 section 9.1:
+ *      A DUID can be no more than 128 octets long (not including the type code).
+ */
+#define MAX_DUID_LEN 128
+
+struct duid {
+        uint16_t type;
+        union {
+                struct {
+                        /* DHCP6_DUID_LLT */
+                        uint16_t htype;
+                        uint32_t time;
+                        uint8_t haddr[0];
+                } _packed_ llt;
+                struct {
+                        /* DHCP6_DUID_EN */
+                        uint32_t pen;
+                        uint8_t id[8];
+                } _packed_ en;
+                struct {
+                        /* DHCP6_DUID_LL */
+                        int16_t htype;
+                        uint8_t haddr[0];
+                } _packed_ ll;
+                struct {
+                        /* DHCP6_DUID_UUID */
+                        sd_id128_t uuid;
+                } _packed_ uuid;
+                struct {
+                        uint8_t data[MAX_DUID_LEN];
+                } _packed_ raw;
+        };
+} _packed_;
diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c
index bee322f..9386453 100644
--- a/src/libsystemd-network/sd-dhcp6-client.c
+++ b/src/libsystemd-network/sd-dhcp6-client.c
@@ -36,15 +36,11 @@
 #include "dhcp6-protocol.h"
 #include "dhcp6-internal.h"
 #include "dhcp6-lease-internal.h"
+#include "dhcp-identifier.h"
 
 #define SYSTEMD_PEN 43793
 #define HASH_KEY SD_ID128_MAKE(80,11,8c,c2,fe,4a,03,ee,3e,d6,0c,6f,36,39,14,09)
 
-/* RFC 3315 section 9.1:
- *      A DUID can be no more than 128 octets long (not including the type code).
- */
-#define MAX_DUID_LEN 128
-
 #define MAX_MAC_ADDR_LEN INFINIBAND_ALEN
 
 struct sd_dhcp6_client {
@@ -73,32 +69,7 @@ struct sd_dhcp6_client {
         sd_event_source *timeout_resend_expire;
         sd_dhcp6_client_cb_t cb;
         void *userdata;
-        union {
-                struct {
-                        uint16_t type; /* DHCP6_DUID_LLT */
-                        uint16_t htype;
-                        uint32_t time;
-                        uint8_t haddr[0];
-                } _packed_ llt;
-                struct {
-                        uint16_t type; /* DHCP6_DUID_EN */
-                        uint32_t pen;
-                        uint8_t id[8];
-                } _packed_ en;
-                struct {
-                        uint16_t type; /* DHCP6_DUID_LL */
-                        uint16_t htype;
-                        uint8_t haddr[0];
-                } _packed_ ll;
-                struct {
-                        uint16_t type; /* DHCP6_DUID_UUID */
-                        sd_id128_t uuid;
-                } _packed_ uuid;
-                struct {
-                        uint16_t type;
-                        uint8_t data[MAX_DUID_LEN];
-                } _packed_ raw;
-        } duid;
+        struct duid duid;
         size_t duid_len;
 };
 
@@ -201,19 +172,19 @@ int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t type, uint8_t *du
 
         switch (type) {
         case DHCP6_DUID_LLT:
-                if (duid_len <= sizeof(client->duid.llt) - 2)
+                if (duid_len <= sizeof(client->duid.llt))
                         return -EINVAL;
                 break;
         case DHCP6_DUID_EN:
-                if (duid_len != sizeof(client->duid.en) - 2)
+                if (duid_len != sizeof(client->duid.en))
                         return -EINVAL;
                 break;
         case DHCP6_DUID_LL:
-                if (duid_len <= sizeof(client->duid.ll) - 2)
+                if (duid_len <= sizeof(client->duid.ll))
                         return -EINVAL;
                 break;
         case DHCP6_DUID_UUID:
-                if (duid_len != sizeof(client->duid.uuid) - 2)
+                if (duid_len != sizeof(client->duid.uuid))
                         return -EINVAL;
                 break;
         default:
@@ -221,9 +192,9 @@ int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t type, uint8_t *du
                 break;
         }
 
-        client->duid.raw.type = htobe16(type);
+        client->duid.type = htobe16(type);
         memcpy(&client->duid.raw.data, duid, duid_len);
-        client->duid_len = duid_len + 2;  /* +2 for sizeof(type) */
+        client->duid_len = duid_len + sizeof(client->duid.type);
 
         return 0;
 }
@@ -1289,7 +1260,7 @@ int sd_dhcp6_client_new(sd_dhcp6_client **ret)
         client->fd = -1;
 
         /* initialize DUID */
-        client->duid.en.type = htobe16(DHCP6_DUID_EN);
+        client->duid.type = htobe16(DHCP6_DUID_EN);
         client->duid.en.pen = htobe32(SYSTEMD_PEN);
         client->duid_len = sizeof(client->duid.en);
 



More information about the systemd-commits mailing list