diff --git a/sys/net/application_layer/dhcpv6/client.c b/sys/net/application_layer/dhcpv6/client.c index 6a3eb3cd3221..04c3d9440e6c 100644 --- a/sys/net/application_layer/dhcpv6/client.c +++ b/sys/net/application_layer/dhcpv6/client.c @@ -369,6 +369,15 @@ static bool _check_sid_opt(dhcpv6_opt_duid_t *sid) (memcmp(sid->duid, server.duid.u8, server.duid_len) == 0)); } +/* discard stale messages in the receive buffer */ +static void _flush_stale_replies(sock_udp_t *sock) +{ + int res; + while ((res = sock_udp_recv(sock, recv_buf, sizeof(recv_buf), 0, NULL)) >= 0) { + DEBUG("DHCPv6 client: discarding %d stale bytes\n", res); + } +} + static int _preparse_advertise(uint8_t *adv, size_t len, uint8_t **buf) { dhcpv6_opt_duid_t *cid = NULL, *sid = NULL; @@ -696,6 +705,7 @@ static void _solicit_servers(event_t *event) ARRAY_SIZE(oro_opts)); msg_len += _add_ia_pd_from_config(&send_buf[msg_len]); DEBUG("DHCPv6 client: send SOLICIT\n"); + _flush_stale_replies(&sock); res = sock_udp_send(&sock, send_buf, msg_len, &remote); assert(res > 0); /* something went terribly wrong */ while (((res = sock_udp_recv(&sock, recv_buf, sizeof(recv_buf), @@ -802,6 +812,7 @@ static void _request_renew_rebind(uint8_t type) msg_len += _compose_oro_opt((dhcpv6_opt_oro_t *)&send_buf[msg_len], oro_opts, ARRAY_SIZE(oro_opts)); msg_len += _add_ia_pd_from_config(&send_buf[msg_len]); + _flush_stale_replies(&sock); while (sock_udp_send(&sock, send_buf, msg_len, &remote) <= 0) {} while (((res = sock_udp_recv(&sock, recv_buf, sizeof(recv_buf), retrans_timeout, NULL)) <= 0) ||