mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-23 06:02:37 +01:00
handshake: Optimize replacement of IEs
During processing of Connect events by netdev, some of these elements might be updated even when already set. Instead of issuing l_free/l_memdup each time, check and see whether the elements are bitwise identical first.
This commit is contained in:
parent
7fafb627d8
commit
37bc48add4
@ -241,6 +241,26 @@ bool handshake_state_set_supplicant_ie(struct handshake_state *s,
|
|||||||
return handshake_state_setup_own_ciphers(s, &info);
|
return handshake_state_setup_own_ciphers(s, &info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void replace_ie(uint8_t **old, const uint8_t *new)
|
||||||
|
{
|
||||||
|
if (*old == NULL) {
|
||||||
|
*old = new ? l_memdup(new, new[1] + 2) : NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!new) {
|
||||||
|
l_free(*old);
|
||||||
|
*old = NULL;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((*old)[1] == new[1] && !memcmp(*old, new, new[1] + 2))
|
||||||
|
return;
|
||||||
|
|
||||||
|
l_free(*old);
|
||||||
|
*old = l_memdup(new, new[1] + 2);
|
||||||
|
}
|
||||||
|
|
||||||
void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid,
|
void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid,
|
||||||
size_t ssid_len)
|
size_t ssid_len)
|
||||||
{
|
{
|
||||||
@ -250,18 +270,12 @@ void handshake_state_set_ssid(struct handshake_state *s, const uint8_t *ssid,
|
|||||||
|
|
||||||
void handshake_state_set_mde(struct handshake_state *s, const uint8_t *mde)
|
void handshake_state_set_mde(struct handshake_state *s, const uint8_t *mde)
|
||||||
{
|
{
|
||||||
if (s->mde)
|
replace_ie(&s->mde, mde);
|
||||||
l_free(s->mde);
|
|
||||||
|
|
||||||
s->mde = mde ? l_memdup(mde, mde[1] + 2) : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handshake_state_set_fte(struct handshake_state *s, const uint8_t *fte)
|
void handshake_state_set_fte(struct handshake_state *s, const uint8_t *fte)
|
||||||
{
|
{
|
||||||
if (s->fte)
|
replace_ie(&s->fte, fte);
|
||||||
l_free(s->fte);
|
|
||||||
|
|
||||||
s->fte = fte ? l_memdup(fte, fte[1] + 2) : NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void handshake_state_set_kh_ids(struct handshake_state *s,
|
void handshake_state_set_kh_ids(struct handshake_state *s,
|
||||||
|
Loading…
Reference in New Issue
Block a user