mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-11 05:17:44 +03:00
Merge pull request #16124 from ssahani/dhcpv6-duid
network: Display DHCPv6 DUID
This commit is contained in:
commit
241616d57d
@ -18,6 +18,7 @@
|
||||
#include "dns-domain.h"
|
||||
#include "event-util.h"
|
||||
#include "fd-util.h"
|
||||
#include "hexdecoct.h"
|
||||
#include "hostname-util.h"
|
||||
#include "in-addr-util.h"
|
||||
#include "network-internal.h"
|
||||
@ -331,6 +332,48 @@ int sd_dhcp6_client_set_duid_llt(
|
||||
return dhcp6_client_set_duid_internal(client, DUID_TYPE_LLT, NULL, 0, llt_time);
|
||||
}
|
||||
|
||||
static const char* const dhcp6_duid_type_table[_DUID_TYPE_MAX] = {
|
||||
[DUID_TYPE_LLT] = "DUID-LLT",
|
||||
[DUID_TYPE_EN] = "DUID-EN/Vendor",
|
||||
[DUID_TYPE_LL] = "DUID-LL",
|
||||
[DUID_TYPE_UUID] = "UUID",
|
||||
};
|
||||
DEFINE_PRIVATE_STRING_TABLE_LOOKUP_TO_STRING(dhcp6_duid_type, DUIDType);
|
||||
|
||||
int sd_dhcp6_client_duid_as_string(
|
||||
sd_dhcp6_client *client,
|
||||
char **duid) {
|
||||
_cleanup_free_ char *p = NULL, *s = NULL, *t = NULL;
|
||||
const char *v;
|
||||
int r;
|
||||
|
||||
assert_return(client, -EINVAL);
|
||||
assert_return(client->duid_len > 0, -ENODATA);
|
||||
|
||||
v = dhcp6_duid_type_to_string(be16toh(client->duid.type));
|
||||
if (v) {
|
||||
s = strdup(v);
|
||||
if (!s)
|
||||
return -ENOMEM;
|
||||
} else {
|
||||
r = asprintf(&s, "%0x", client->duid.type);
|
||||
if (r < 0)
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
t = hexmem(&client->duid.raw.data, client->duid_len);
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
p = strjoin(s, ":", t);
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
*duid = TAKE_PTR(p);
|
||||
|
||||
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);
|
||||
|
@ -176,6 +176,10 @@ _public_ int sd_network_link_get_dhcp6_client_iaid_string(int ifindex, char **ia
|
||||
return network_link_get_string(ifindex, "DHCP6_CLIENT_IAID", iaid);
|
||||
}
|
||||
|
||||
_public_ int sd_network_link_get_dhcp6_client_duid_string(int ifindex, char **duid) {
|
||||
return network_link_get_string(ifindex, "DHCP6_CLIENT_DUID", duid);
|
||||
}
|
||||
|
||||
_public_ int sd_network_link_get_required_for_online(int ifindex) {
|
||||
_cleanup_free_ char *s = NULL;
|
||||
int r;
|
||||
|
@ -1380,9 +1380,9 @@ static int link_status_one(
|
||||
|
||||
_cleanup_strv_free_ char **dns = NULL, **ntp = NULL, **sip = NULL, **search_domains = NULL, **route_domains = NULL,
|
||||
**pop3_server = NULL, **smtp_server = NULL, **lpr_server = NULL;
|
||||
_cleanup_free_ char *setup_state = NULL, *operational_state = NULL, *tz = NULL;
|
||||
_cleanup_free_ char *t = NULL, *network = NULL, *client_id = NULL, *iaid = NULL;
|
||||
_cleanup_free_ char *t = NULL, *network = NULL, *client_id = NULL, *iaid = NULL, *duid = NULL;
|
||||
const char *driver = NULL, *path = NULL, *vendor = NULL, *model = NULL, *link = NULL;
|
||||
_cleanup_free_ char *setup_state = NULL, *operational_state = NULL, *tz = NULL;
|
||||
const char *on_color_operational, *off_color_operational,
|
||||
*on_color_setup, *off_color_setup;
|
||||
_cleanup_free_ int *carrier_bound_to = NULL, *carrier_bound_by = NULL;
|
||||
@ -2093,6 +2093,16 @@ static int link_status_one(
|
||||
return table_log_add_error(r);
|
||||
}
|
||||
|
||||
r = sd_network_link_get_dhcp6_client_duid_string(info->ifindex, &duid);
|
||||
if (r >= 0) {
|
||||
r = table_add_many(table,
|
||||
TABLE_EMPTY,
|
||||
TABLE_STRING, "DHCP6 Client DUID:",
|
||||
TABLE_STRING, duid);
|
||||
if (r < 0)
|
||||
return table_log_add_error(r);
|
||||
}
|
||||
|
||||
r = dump_lldp_neighbors(table, "Connected To:", info->ifindex);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
@ -4086,7 +4086,6 @@ int link_save(Link *link) {
|
||||
const char *admin_state, *oper_state, *carrier_state, *address_state;
|
||||
_cleanup_free_ char *temp_path = NULL;
|
||||
_cleanup_fclose_ FILE *f = NULL;
|
||||
uint32_t iaid;
|
||||
Route *route;
|
||||
Address *a;
|
||||
Iterator i;
|
||||
@ -4421,9 +4420,18 @@ int link_save(Link *link) {
|
||||
}
|
||||
}
|
||||
|
||||
r = sd_dhcp6_client_get_iaid(link->dhcp6_client, &iaid);
|
||||
if (r >= 0)
|
||||
fprintf(f, "DHCP6_CLIENT_IAID=0x%x\n", iaid);
|
||||
if (link->dhcp6_client) {
|
||||
_cleanup_free_ char *duid = NULL;
|
||||
uint32_t iaid;
|
||||
|
||||
r = sd_dhcp6_client_get_iaid(link->dhcp6_client, &iaid);
|
||||
if (r >= 0)
|
||||
fprintf(f, "DHCP6_CLIENT_IAID=0x%x\n", iaid);
|
||||
|
||||
r = sd_dhcp6_client_duid_as_string(link->dhcp6_client, &duid);
|
||||
if (r >= 0)
|
||||
fprintf(f, "DHCP6_CLIENT_DUID=%s\n", duid);
|
||||
}
|
||||
|
||||
r = fflush_and_check(f);
|
||||
if (r < 0)
|
||||
|
@ -113,6 +113,9 @@ int sd_dhcp6_client_set_iaid(
|
||||
int sd_dhcp6_client_get_iaid(
|
||||
sd_dhcp6_client *client,
|
||||
uint32_t *iaid);
|
||||
int sd_dhcp6_client_duid_as_string(
|
||||
sd_dhcp6_client *client,
|
||||
char **duid);
|
||||
int sd_dhcp6_client_set_fqdn(
|
||||
sd_dhcp6_client *client,
|
||||
const char *fqdn);
|
||||
|
@ -194,6 +194,9 @@ int sd_network_link_get_dhcp4_client_id_string(int ifindex, char **client_id);
|
||||
/* Get DHCPv6 client IAID for a given link. */
|
||||
int sd_network_link_get_dhcp6_client_iaid_string(int ifindex, char **iaid);
|
||||
|
||||
/* Get DHCPv6 client DUID for a given link. */
|
||||
int sd_network_link_get_dhcp6_client_duid_string(int ifindex, char **duid);
|
||||
|
||||
/* Monitor object */
|
||||
typedef struct sd_network_monitor sd_network_monitor;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user