From 0c42b613485978eb82d7aff7ed426b8a8bb327af Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 10 Aug 2021 21:36:04 +0900 Subject: [PATCH 1/3] sd-dhcp6-client: fix copy-and-paste mistake Fix bug introduced by b47fb949b338a8e77be789542fffb8c86da79284. --- src/libsystemd-network/sd-dhcp6-client.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index b067afc800..0b5a36aaa9 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -1218,7 +1218,7 @@ static int client_parse_message( if (lease->ia.addresses) { lt_t1 = MIN(lt_t1, be32toh(lease->ia.ia_na.lifetime_t1)); - lt_t2 = MIN(lt_t2, be32toh(lease->ia.ia_na.lifetime_t1)); + lt_t2 = MIN(lt_t2, be32toh(lease->ia.ia_na.lifetime_t2)); } break; From de949e911ee15d1c9daaf5ba5a3cff806fb2b514 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 10 Aug 2021 21:39:27 +0900 Subject: [PATCH 2/3] sd-dhcp6-client: cirtainly adjust T1 and T2 This fixes a bug introduced by 99f1d3fc5043b33dea5faa88f7015a487965333f. Note that in the information requesting mode, the lease has neither addresses nor PD prefixes. --- src/libsystemd-network/sd-dhcp6-client.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 0b5a36aaa9..83352d9dc8 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -1327,17 +1327,16 @@ static int client_parse_message( dhcp6_message_type_to_string(message->type)); return -EINVAL; } + } - } else { - if (lease->ia.addresses) { - lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1); - lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2); - } + if (lease->ia.addresses) { + lease->ia.ia_na.lifetime_t1 = htobe32(lt_t1); + lease->ia.ia_na.lifetime_t2 = htobe32(lt_t2); + } - if (lease->pd.addresses) { - lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1); - lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2); - } + if (lease->pd.addresses) { + lease->pd.ia_pd.lifetime_t1 = htobe32(lt_t1); + lease->pd.ia_pd.lifetime_t2 = htobe32(lt_t2); } client->information_refresh_time_usec = MAX(irt, IRT_MINIMUM); From 0eec7f5ffa3f2663c59f32e07079d112b8e626ed Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Tue, 10 Aug 2021 21:57:42 +0900 Subject: [PATCH 3/3] sd-dhcp6-client: use SYNTHETIC_ERRNO() --- src/libsystemd-network/sd-dhcp6-client.c | 79 +++++++++--------------- 1 file changed, 29 insertions(+), 50 deletions(-) diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index 83352d9dc8..d4ab9df992 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -1134,30 +1134,24 @@ static int client_parse_message( switch (optcode) { case SD_DHCP6_OPTION_CLIENTID: - if (clientid) { - log_dhcp6_client(client, "%s contains multiple clientids", - dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } + if (clientid) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple clientids", + dhcp6_message_type_to_string(message->type)); if (optlen != client->duid_len || - memcmp(&client->duid, optval, optlen) != 0) { - log_dhcp6_client(client, "%s DUID does not match", - dhcp6_message_type_to_string(message->type)); + memcmp(&client->duid, optval, optlen) != 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s DUID does not match", + dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } clientid = true; break; case SD_DHCP6_OPTION_SERVERID: r = dhcp6_lease_get_serverid(lease, NULL, NULL); - if (r >= 0) { - log_dhcp6_client(client, "%s contains multiple serverids", - dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } + if (r >= 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s contains multiple serverids", + dhcp6_message_type_to_string(message->type)); r = dhcp6_lease_set_serverid(lease, optval, optlen); if (r < 0) @@ -1180,20 +1174,16 @@ static int client_parse_message( if (status < 0) return status; - if (status > 0) { - log_dhcp6_client(client, "%s Status %s", - dhcp6_message_type_to_string(message->type), - dhcp6_message_status_to_string(status)); - - return -EINVAL; - } + if (status > 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s Status %s", + dhcp6_message_type_to_string(message->type), + dhcp6_message_status_to_string(status)); break; case SD_DHCP6_OPTION_IA_NA: if (client->state == DHCP6_STATE_INFORMATION_REQUEST) { - log_dhcp6_client(client, "Information request ignoring IA NA option"); - + log_dhcp6_client(client, "Ignoring IA NA option in information requesting mode."); break; } @@ -1210,11 +1200,9 @@ static int client_parse_message( if (r < 0) return r; - if (client->ia_na.ia_na.id != iaid_lease) { - log_dhcp6_client(client, "%s has wrong IAID for IA NA", - dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } + if (client->ia_na.ia_na.id != iaid_lease) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has wrong IAID for IA NA", + dhcp6_message_type_to_string(message->type)); if (lease->ia.addresses) { lt_t1 = MIN(lt_t1, be32toh(lease->ia.ia_na.lifetime_t1)); @@ -1225,8 +1213,7 @@ static int client_parse_message( case SD_DHCP6_OPTION_IA_PD: if (client->state == DHCP6_STATE_INFORMATION_REQUEST) { - log_dhcp6_client(client, "Information request ignoring IA PD option"); - + log_dhcp6_client(client, "Ignoring IA PD option in information requesting mode."); break; } @@ -1243,11 +1230,9 @@ static int client_parse_message( if (r < 0) return r; - if (client->ia_pd.ia_pd.id != iaid_lease) { - log_dhcp6_client(client, "%s has wrong IAID for IA PD", - dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } + if (client->ia_pd.ia_pd.id != iaid_lease) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has wrong IAID for IA PD", + dhcp6_message_type_to_string(message->type)); if (lease->pd.addresses) { lt_t1 = MIN(lt_t1, be32toh(lease->pd.ia_pd.lifetime_t1)); @@ -1309,24 +1294,18 @@ static int client_parse_message( pos += offsetof(DHCP6Option, data) + optlen; } - if (ia_na_status > 0 && ia_pd_status > 0) { - log_dhcp6_client(client, "No IA_PD prefix or IA_NA address received. Ignoring."); - return -EINVAL; - } + if (ia_na_status > 0 && ia_pd_status > 0) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "No IA_PD prefix or IA_NA address received. Ignoring."); - if (!clientid) { - log_dhcp6_client(client, "%s has incomplete options", - dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } + if (!clientid) + return log_dhcp6_client_errno(client, SYNTHETIC_ERRNO(EINVAL), "%s has incomplete options", + dhcp6_message_type_to_string(message->type)); if (client->state != DHCP6_STATE_INFORMATION_REQUEST) { r = dhcp6_lease_get_serverid(lease, NULL, NULL); - if (r < 0) { - log_dhcp6_client(client, "%s has no server id", - dhcp6_message_type_to_string(message->type)); - return -EINVAL; - } + if (r < 0) + return log_dhcp6_client_errno(client, r, "%s has no server id", + dhcp6_message_type_to_string(message->type)); } if (lease->ia.addresses) {