mirror of
https://github.com/systemd/systemd.git
synced 2025-09-17 21:45:23 +03:00
Merge pull request #27578 from yuwata/sd-dhcp-client-client-id-len
sd-dhcp-client: several cleanups for client_id_len
This commit is contained in:
@@ -339,25 +339,32 @@ int sd_dhcp_client_set_mac(
|
|||||||
|
|
||||||
int sd_dhcp_client_get_client_id(
|
int sd_dhcp_client_get_client_id(
|
||||||
sd_dhcp_client *client,
|
sd_dhcp_client *client,
|
||||||
uint8_t *type,
|
uint8_t *ret_type,
|
||||||
const uint8_t **data,
|
const uint8_t **ret_data,
|
||||||
size_t *data_len) {
|
size_t *ret_data_len) {
|
||||||
|
|
||||||
assert_return(client, -EINVAL);
|
assert_return(client, -EINVAL);
|
||||||
assert_return(type, -EINVAL);
|
|
||||||
assert_return(data, -EINVAL);
|
|
||||||
assert_return(data_len, -EINVAL);
|
|
||||||
|
|
||||||
if (client->client_id_len) {
|
if (client->client_id_len > 0) {
|
||||||
*type = client->client_id.type;
|
if (client->client_id_len < offsetof(sd_dhcp_client_id, raw.data))
|
||||||
*data = client->client_id.raw.data;
|
return -EINVAL;
|
||||||
*data_len = client->client_id_len - sizeof(client->client_id.type);
|
|
||||||
} else {
|
if (ret_type)
|
||||||
*type = 0;
|
*ret_type = client->client_id.type;
|
||||||
*data = NULL;
|
if (ret_data)
|
||||||
*data_len = 0;
|
*ret_data = client->client_id.raw.data;
|
||||||
|
if (ret_data_len)
|
||||||
|
*ret_data_len = client->client_id_len - offsetof(sd_dhcp_client_id, raw.data);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ret_type)
|
||||||
|
*ret_type = 0;
|
||||||
|
if (ret_data)
|
||||||
|
*ret_data = NULL;
|
||||||
|
if (ret_data_len)
|
||||||
|
*ret_data_len = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -828,14 +835,12 @@ static int client_message_init(
|
|||||||
|
|
||||||
/* Some DHCP servers will refuse to issue an DHCP lease if the Client
|
/* Some DHCP servers will refuse to issue an DHCP lease if the Client
|
||||||
Identifier option is not set */
|
Identifier option is not set */
|
||||||
if (client->client_id_len) {
|
|
||||||
r = dhcp_option_append(&packet->dhcp, optlen, &optoffset, 0,
|
r = dhcp_option_append(&packet->dhcp, optlen, &optoffset, 0,
|
||||||
SD_DHCP_OPTION_CLIENT_IDENTIFIER,
|
SD_DHCP_OPTION_CLIENT_IDENTIFIER,
|
||||||
client->client_id_len,
|
client->client_id_len,
|
||||||
&client->client_id);
|
&client->client_id);
|
||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
/* RFC2131 section 3.5:
|
/* RFC2131 section 3.5:
|
||||||
in its initial DHCPDISCOVER or DHCPREQUEST message, a
|
in its initial DHCPDISCOVER or DHCPREQUEST message, a
|
||||||
@@ -1472,7 +1477,7 @@ static int client_handle_offer(sd_dhcp_client *client, DHCPMessage *offer, size_
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (client->client_id_len) {
|
if (client->client_id_len > 0) {
|
||||||
r = dhcp_lease_set_client_id(lease,
|
r = dhcp_lease_set_client_id(lease,
|
||||||
(uint8_t *) &client->client_id,
|
(uint8_t *) &client->client_id,
|
||||||
client->client_id_len);
|
client->client_id_len);
|
||||||
@@ -1566,7 +1571,7 @@ static int client_handle_ack(sd_dhcp_client *client, DHCPMessage *ack, size_t le
|
|||||||
if (r < 0)
|
if (r < 0)
|
||||||
return r;
|
return r;
|
||||||
|
|
||||||
if (client->client_id_len) {
|
if (client->client_id_len > 0) {
|
||||||
r = dhcp_lease_set_client_id(lease,
|
r = dhcp_lease_set_client_id(lease,
|
||||||
(uint8_t *) &client->client_id,
|
(uint8_t *) &client->client_id,
|
||||||
client->client_id_len);
|
client->client_id_len);
|
||||||
|
@@ -279,9 +279,9 @@ int sd_dhcp_client_set_duid_llt(
|
|||||||
uint64_t llt_time);
|
uint64_t llt_time);
|
||||||
int sd_dhcp_client_get_client_id(
|
int sd_dhcp_client_get_client_id(
|
||||||
sd_dhcp_client *client,
|
sd_dhcp_client *client,
|
||||||
uint8_t *type,
|
uint8_t *ret_type,
|
||||||
const uint8_t **data,
|
const uint8_t **ret_data,
|
||||||
size_t *data_len);
|
size_t *ret_data_len);
|
||||||
int sd_dhcp_client_set_mtu(
|
int sd_dhcp_client_set_mtu(
|
||||||
sd_dhcp_client *client,
|
sd_dhcp_client *client,
|
||||||
uint32_t mtu);
|
uint32_t mtu);
|
||||||
|
Reference in New Issue
Block a user