diff -uNr systemd-228/src/libsystemd/sd-network/sd-network.c systemd-228-query-duid/src/libsystemd/sd-network/sd-network.c
--- systemd-228/src/libsystemd/sd-network/sd-network.c 2015-11-18 07:59:06.000000000 +0000
+++ systemd-228-query-duid/src/libsystemd/sd-network/sd-network.c 2016-04-01 00:28:06.272671837 +0000
@@ -297,6 +297,51 @@
return network_get_link_strv("CARRIER_BOUND_BY", ifindex, ret);
}
+static int network_get_file_str(const char *key, const char *fpath, int ifindex, char **ret) {
+ _cleanup_free_ char *p = NULL, *s = NULL;
+ int r;
+
+ assert_return(ifindex > 0, -EINVAL);
+ assert_return(fpath, -EINVAL);
+ assert_return(ret, -EINVAL);
+
+ if (asprintf(&p, "%s/%d", fpath, ifindex) < 0)
+ return -ENOMEM;
+
+ r = parse_env_file(p, NEWLINE, key, &s, NULL);
+ if (r == -ENOENT)
+ return -ENODATA;
+ if (r < 0)
+ return r;
+ if (isempty(s))
+ return -ENODATA;
+
+ *ret = s;
+ s = NULL;
+ return 0;
+}
+
+_public_ int sd_network_link_get_clientid(int ifindex, char **clientid) {
+ return network_get_file_str("CLIENTID",
+ "/run/systemd/netif/leases",
+ ifindex,
+ clientid);
+}
+
+_public_ int sd_network_link_get_iaid(int ifindex, char **iaid) {
+ return network_get_file_str("IAID",
+ "/run/systemd/netif/leases6",
+ ifindex,
+ iaid);
+}
+
+_public_ int sd_network_link_get_duid(int ifindex, char **duid) {
+ return network_get_file_str("DUID",
+ "/run/systemd/netif/leases6",
+ ifindex,
+ duid);
+}
+
_public_ int sd_network_link_get_wildcard_domain(int ifindex) {
int r;
_cleanup_free_ char *p = NULL, *s = NULL;
diff -uNr systemd-228/src/libsystemd-network/dhcp6-lease-internal.h systemd-228-query-duid/src/libsystemd-network/dhcp6-lease-internal.h
--- systemd-228/src/libsystemd-network/dhcp6-lease-internal.h 2015-11-18 07:59:06.000000000 +0000
+++ systemd-228-query-duid/src/libsystemd-network/dhcp6-lease-internal.h 2016-04-01 00:33:09.083805301 +0000
@@ -25,6 +25,7 @@
#include <stdint.h>
#include "sd-dhcp6-lease.h"
+#include "dhcp-identifier.h"
#include "dhcp6-internal.h"
struct sd_dhcp6_lease {
@@ -36,6 +37,8 @@
bool rapid_commit;
DHCP6IA ia;
+ struct duid *duid;
+ size_t duid_len;
DHCP6Address *addr_iter;
@@ -64,6 +67,7 @@
int dhcp6_lease_get_rapid_commit(sd_dhcp6_lease *lease, bool *rapid_commit);
int dhcp6_lease_get_iaid(sd_dhcp6_lease *lease, be32_t *iaid);
+int dhcp6_lease_set_duid(sd_dhcp6_lease *lease, struct duid *duid, size_t duid_len);
int dhcp6_lease_set_dns(sd_dhcp6_lease *lease, uint8_t *optval, size_t optlen);
int dhcp6_lease_set_domains(sd_dhcp6_lease *lease, uint8_t *optval,
@@ -74,5 +78,7 @@
int dhcp6_lease_new(sd_dhcp6_lease **ret);
+int dhcp6_lease_save(sd_dhcp6_lease *lease, const char *lease_file);
+
DEFINE_TRIVIAL_CLEANUP_FUNC(sd_dhcp6_lease*, sd_dhcp6_lease_unref);
#define _cleanup_dhcp6_lease_free_ _cleanup_(sd_dhcp6_lease_unrefp)
diff -uNr systemd-228/src/libsystemd-network/sd-dhcp6-client.c systemd-228-query-duid/src/libsystemd-network/sd-dhcp6-client.c
--- systemd-228/src/libsystemd-network/sd-dhcp6-client.c 2016-04-01 00:10:28.311819290 +0000
+++ systemd-228-query-duid/src/libsystemd-network/sd-dhcp6-client.c 2016-04-01 07:27:44.868086900 +0000
@@ -202,6 +202,23 @@
return 0;
}
+int sd_dhcp6_client_get_duid(sd_dhcp6_client *client, uint16_t *duid_type,
+ const uint8_t **duid, size_t *duid_len) {
+ assert_return(client, -EINVAL);
+ assert_return(IN_SET(client->state, DHCP6_STATE_STOPPED), -EBUSY);
+
+ *duid_type = 0;
+ *duid_len = 0;
+ *duid = NULL;
+ if (client->duid_len > 0) {
+ *duid_type = be16toh(client->duid.type);
+ *duid_len = client->duid_len - sizeof(client->duid.type);
+ *duid = client->duid.raw.data;
+ }
+
+ return 0;
+}
+
int sd_dhcp6_client_set_iaid(sd_dhcp6_client *client, uint32_t iaid) {
assert_return(client, -EINVAL);
assert_return(IN_SET(client->state, DHCP6_STATE_STOPPED), -EBUSY);
@@ -211,6 +228,14 @@
return 0;
}
+int sd_dhcp6_client_get_iaid(sd_dhcp6_client *client, uint32_t *iaid) {
+ assert_return(client, -EINVAL);
+
+ *iaid = be32toh(client->ia_na.id);
+
+ return 0;
+}
+
int sd_dhcp6_client_set_information_request(sd_dhcp6_client *client, int enabled) {
assert_return(client, -EINVAL);
assert_return(IN_SET(client->state, DHCP6_STATE_STOPPED), -EBUSY);
@@ -746,6 +771,10 @@
if (r < 0 && r != -ENOMSG)
return r;
+ r = dhcp6_lease_set_duid(lease, &client->duid, client->duid_len);
+ if (r < 0)
+ return r;
+
r = dhcp6_lease_get_iaid(lease, &iaid_lease);
if (r < 0)
return r;
diff -uNr systemd-228/src/libsystemd-network/sd-dhcp6-lease.c systemd-228-query-duid/src/libsystemd-network/sd-dhcp6-lease.c
--- systemd-228/src/libsystemd-network/sd-dhcp6-lease.c 2015-11-18 07:59:06.000000000 +0000
+++ systemd-228-query-duid/src/libsystemd-network/sd-dhcp6-lease.c 2016-04-01 07:27:03.013301683 +0000
@@ -20,14 +20,19 @@
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
+#include <arpa/inet.h>
#include <errno.h>
#include "alloc-util.h"
#include "dhcp6-lease-internal.h"
#include "dhcp6-protocol.h"
+#include "fd-util.h"
+#include "fileio.h"
+#include "hexdecoct.h"
#include "strv.h"
#include "util.h"
+
int dhcp6_lease_clear_timers(DHCP6IA *ia) {
assert_return(ia, -EINVAL);
@@ -150,6 +155,15 @@
return 0;
}
+int dhcp6_lease_set_duid(sd_dhcp6_lease *lease, struct duid *duid, size_t duid_len) {
+ assert_return(lease, -EINVAL);
+ assert_return(duid, -EINVAL);
+
+ lease->duid = duid;
+ lease->duid_len = duid_len;
+ return 0;
+}
+
int sd_dhcp6_lease_get_address(sd_dhcp6_lease *lease, struct in6_addr *addr,
uint32_t *lifetime_preferred,
uint32_t *lifetime_valid) {
@@ -410,3 +424,74 @@
*ret = lease;
return 0;
}
+
+int dhcp6_lease_save(sd_dhcp6_lease *lease, const char *lease_file) {
+ _cleanup_free_ char *temp_path = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
+ char addr6[INET6_ADDRSTRLEN];
+ const char *paddr6;
+ struct in6_addr ip6_addr;
+ uint32_t lifetime_preferred, lifetime_valid;
+ be32_t iaid_lease;
+ const struct in6_addr *addresses;
+ int r;
+
+ assert(lease);
+ assert(lease_file);
+
+ r = fopen_temporary(lease_file, &f, &temp_path);
+ if (r < 0)
+ goto fail;
+
+ fchmod(fileno(f), 0644);
+
+ fprintf(f, "# This is private data. Do not parse.\n");
+
+ sd_dhcp6_lease_reset_address_iter(lease);
+ do {
+ r = sd_dhcp6_lease_get_address(lease, &ip6_addr,
+ &lifetime_preferred,
+ &lifetime_valid);
+ if (r >= 0) {
+ paddr6 = inet_ntop(AF_INET6, &ip6_addr, addr6,
+ INET6_ADDRSTRLEN);
+ if (paddr6 != NULL) {
+ fprintf(f, "ADDRESS=%s\n", paddr6);
+ fprintf(f, "LIFETIME_PREFERRED=%u\n", lifetime_preferred);
+ fprintf(f, "LIFETIME_VALID=%u\n", lifetime_valid);
+ }
+ }
+ } while (r >=0);
+
+ r = dhcp6_lease_get_iaid(lease, &iaid_lease);
+ if (r == 0)
+ fprintf(f, "IAID=%u\n", be32toh(iaid_lease));
+
+ if (lease->duid_len > 0) {
+ _cleanup_free_ char *duid_hex;
+
+ duid_hex = hexmem(lease->duid, lease->duid_len);
+ if (duid_hex == NULL) {
+ r = -ENOMEM;
+ goto fail;
+ }
+ fprintf(f, "DUID=%s\n", duid_hex);
+ }
+
+ r = fflush_and_check(f);
+ if (r < 0)
+ goto fail;
+
+ if (rename(temp_path, lease_file) < 0) {
+ r = -errno;
+ goto fail;
+ }
+
+ return 0;
+
+fail:
+ if (temp_path)
+ (void) unlink(temp_path);
+
+ return log_error_errno(r, "Failed to save lease data %s: %m", lease_file);
+}
diff -uNr systemd-228/src/network/networkctl.c systemd-228-query-duid/src/network/networkctl.c
--- systemd-228/src/network/networkctl.c 2015-11-18 07:59:06.000000000 +0000
+++ systemd-228-query-duid/src/network/networkctl.c 2016-04-01 00:34:03.926201756 +0000
@@ -502,6 +502,7 @@
const char *name) {
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **domains = NULL;
_cleanup_free_ char *setup_state = NULL, *operational_state = NULL, *tz = NULL;
+ _cleanup_free_ char *clientid = NULL, *duid = NULL, *iaid = NULL;
_cleanup_netlink_message_unref_ sd_netlink_message *req = NULL, *reply = NULL;
_cleanup_device_unref_ sd_device *d = NULL;
char devid[2 + DECIMAL_STR_MAX(int)];
@@ -668,7 +669,19 @@
(void) sd_network_link_get_timezone(ifindex, &tz);
if (tz)
- printf(" Time Zone: %s", tz);
+ printf(" Time Zone: %s\n", tz);
+
+ (void) sd_network_link_get_clientid(ifindex, &clientid);
+ if (clientid)
+ printf(" CLIENTID: %s\n", clientid);
+
+ (void) sd_network_link_get_iaid(ifindex, &iaid);
+ if (iaid)
+ printf(" IAID: %s\n", iaid);
+
+ (void) sd_network_link_get_duid(ifindex, &duid);
+ if (duid)
+ printf(" DUID: %s", duid);
return 0;
}
diff -uNr systemd-228/src/network/networkd-dhcp6.c systemd-228-query-duid/src/network/networkd-dhcp6.c
--- systemd-228/src/network/networkd-dhcp6.c 2016-04-01 00:10:28.311819290 +0000
+++ systemd-228-query-duid/src/network/networkd-dhcp6.c 2016-04-01 07:18:35.972253096 +0000
@@ -113,6 +113,8 @@
return r;
}
+ link->dhcp6_lease = sd_dhcp6_lease_ref(lease);
+
return 0;
}
@@ -134,7 +136,9 @@
if (sd_dhcp6_client_get_lease(client, NULL) >= 0)
log_link_warning(link, "DHCPv6 lease lost");
+ link->dhcp6_lease = sd_dhcp6_lease_unref(link->dhcp6_lease);
link->dhcp6_configured = false;
+ link_dirty(link);
break;
case SD_DHCP6_CLIENT_EVENT_IP_ACQUIRE:
@@ -153,6 +157,7 @@
}
link->dhcp6_configured = true;
+ link_dirty(link);
break;
default:
diff -uNr systemd-228/src/network/networkd-link.c systemd-228-query-duid/src/network/networkd-link.c
--- systemd-228/src/network/networkd-link.c 2016-04-01 00:10:28.311819290 +0000
+++ systemd-228-query-duid/src/network/networkd-link.c 2016-04-01 07:17:01.523047845 +0000
@@ -26,6 +26,7 @@
#include "alloc-util.h"
#include "bus-util.h"
#include "dhcp-lease-internal.h"
+#include "dhcp6-lease-internal.h"
#include "event-util.h"
#include "fd-util.h"
#include "fileio.h"
@@ -371,6 +372,11 @@
if (r < 0)
return -ENOMEM;
+ r = asprintf(&link->lease6_file, "/run/systemd/netif/leases6/%d",
+ link->ifindex);
+ if (r < 0)
+ return -ENOMEM;
+
r = asprintf(&link->lldp_file, "/run/systemd/netif/lldp/%d",
link->ifindex);
if (r < 0)
@@ -421,8 +427,10 @@
sd_dhcp_server_unref(link->dhcp_server);
sd_dhcp_client_unref(link->dhcp_client);
sd_dhcp_lease_unref(link->dhcp_lease);
+ sd_dhcp_lease_unref(link->dhcp6_lease);
free(link->lease_file);
+ free(link->lease6_file);
sd_lldp_free(link->lldp);
@@ -2749,6 +2757,7 @@
assert(link);
assert(link->state_file);
assert(link->lease_file);
+ assert(link->lease6_file);
assert(link->manager);
if (link->state == LINK_STATE_LINGER) {
@@ -3004,6 +3013,31 @@
} else
unlink(link->lease_file);
+ if (link->dhcp6_lease) {
+ struct in6_addr addr6;
+ uint32_t lp, lv;
+ assert(link->network);
+
+ fputs("DHCP6_ADDRESS=", f);
+
+ sd_dhcp6_lease_reset_address_iter(link->dhcp6_lease);
+ while (sd_dhcp6_lease_get_address(link->dhcp6_lease,
+ &addr6, &lp, &lv) >= 0) {
+ serialize_in6_addrs(f, &addr6, 1);
+ fputc(' ', f);
+ }
+ fputc('\n', f);
+
+ r = dhcp6_lease_save(link->dhcp6_lease, link->lease6_file);
+ if (r < 0)
+ goto fail;
+
+ fprintf(f,
+ "DHCP6_LEASE=%s\n",
+ link->lease6_file);
+ } else
+ unlink(link->lease6_file);
+
if (link->ipv4ll) {
struct in_addr address;
diff -uNr systemd-228/src/network/networkd-link.h systemd-228-query-duid/src/network/networkd-link.h
--- systemd-228/src/network/networkd-link.h 2015-11-18 07:59:06.000000000 +0000
+++ systemd-228-query-duid/src/network/networkd-link.h 2016-04-01 00:36:41.985533245 +0000
@@ -92,6 +92,7 @@
sd_dhcp_client *dhcp_client;
sd_dhcp_lease *dhcp_lease;
char *lease_file;
+ char *lease6_file;
uint16_t original_mtu;
unsigned dhcp4_messages;
bool dhcp4_configured;
@@ -111,6 +112,7 @@
sd_ndisc *ndisc_router_discovery;
sd_dhcp6_client *dhcp6_client;
+ sd_dhcp6_lease *dhcp6_lease;
bool rtnl_extended_attrs;
sd_lldp *lldp;
diff -uNr systemd-228/src/network/networkd.c systemd-228-query-duid/src/network/networkd.c
--- systemd-228/src/network/networkd.c 2016-04-01 00:10:28.311819290 +0000
+++ systemd-228-query-duid/src/network/networkd.c 2016-04-01 00:34:47.084920360 +0000
@@ -66,6 +66,10 @@
if (r < 0)
log_warning_errno(r, "Could not create runtime directory 'leases': %m");
+ r = mkdir_safe_label("/run/systemd/netif/leases6", 0755, uid, gid);
+ if (r < 0)
+ log_warning_errno(r, "Could not create runtime directory 'leases6': %m");
+
r = mkdir_safe_label("/run/systemd/netif/lldp", 0755, uid, gid);
if (r < 0)
log_warning_errno(r, "Could not create runtime directory 'lldp': %m");
diff -uNr systemd-228/src/systemd/sd-dhcp6-client.h systemd-228-query-duid/src/systemd/sd-dhcp6-client.h
--- systemd-228/src/systemd/sd-dhcp6-client.h 2016-04-01 00:10:28.311819290 +0000
+++ systemd-228-query-duid/src/systemd/sd-dhcp6-client.h 2016-04-01 00:27:00.250621617 +0000
@@ -54,7 +54,10 @@
size_t addr_len, uint16_t arp_type);
int sd_dhcp6_client_set_duid(sd_dhcp6_client *client, uint16_t duid_type,
uint8_t *duid, size_t duid_len);
+int sd_dhcp6_client_get_duid(sd_dhcp6_client *client, uint16_t *duid_type,
+ const uint8_t **duid, size_t *duid_len);
int sd_dhcp6_client_set_iaid(sd_dhcp6_client *client, uint32_t iaid);
+int sd_dhcp6_client_get_iaid(sd_dhcp6_client *client, uint32_t *iaid);
int sd_dhcp6_client_set_information_request(sd_dhcp6_client *client, int enabled);
int sd_dhcp6_client_get_information_request(sd_dhcp6_client *client, int *enabled);
int sd_dhcp6_client_set_request_option(sd_dhcp6_client *client,
diff -uNr systemd-228/src/systemd/sd-network.h systemd-228-query-duid/src/systemd/sd-network.h
--- systemd-228/src/systemd/sd-network.h 2015-11-18 07:59:06.000000000 +0000
+++ systemd-228-query-duid/src/systemd/sd-network.h 2016-04-01 00:27:00.250621617 +0000
@@ -122,6 +122,15 @@
/* Get the CARRIERS that are bound to current link. */
int sd_network_link_get_carrier_bound_by(int ifindex, char ***carriers);
+/* Get the CLIENTID if the link has a IPv4 DHCP address. */
+int sd_network_link_get_clientid(int ifindex, char **clientid);
+
+/* Get the IAID if the link has a IPv6 DHCP address. */
+int sd_network_link_get_iaid(int ifindex, char **iaid);
+
+/* Get the DUID if the link has a IPv6 DHCP address. */
+int sd_network_link_get_duid(int ifindex, char **duid);
+
/* Get the timezone that was learnt on a specific link. */
int sd_network_link_get_timezone(int ifindex, char **timezone);