]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
P2P: Maintain ip_pool bitfield index separately
authorJouni Malinen <j@w1.fi>
Sun, 8 May 2022 13:59:31 +0000 (16:59 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 8 May 2022 13:59:31 +0000 (16:59 +0300)
Avoid the somewhat confusing mechanism of determining the bitfield index
from the assigned IP address to make this easier for static analyzers.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/ap/wpa_auth.c
src/ap/wpa_auth_i.h

index f817c4a7e6637d06d429e322ce4f47cbdc2cfea4..0ad5de9d812353c3a0b841a6d858ddb343130877 100644 (file)
@@ -731,16 +731,13 @@ static void wpa_free_sta_sm(struct wpa_state_machine *sm)
 {
 #ifdef CONFIG_P2P
        if (WPA_GET_BE32(sm->ip_addr)) {
-               u32 start;
                wpa_printf(MSG_DEBUG,
                           "P2P: Free assigned IP address %u.%u.%u.%u from "
-                          MACSTR,
+                          MACSTR " (bit %u)",
                           sm->ip_addr[0], sm->ip_addr[1],
                           sm->ip_addr[2], sm->ip_addr[3],
-                          MAC2STR(sm->addr));
-               start = WPA_GET_BE32(sm->wpa_auth->conf.ip_addr_start);
-               bitfield_clear(sm->wpa_auth->ip_pool,
-                              WPA_GET_BE32(sm->ip_addr) - start);
+                          MAC2STR(sm->addr), sm->ip_addr_bit);
+               bitfield_clear(sm->wpa_auth->ip_pool, sm->ip_addr_bit);
        }
 #endif /* CONFIG_P2P */
        if (sm->GUpdateStationKeys) {
@@ -3170,12 +3167,14 @@ SM_STATE(WPA_PTK, PTKCALCNEGOTIATING)
                if (idx >= 0) {
                        u32 start = WPA_GET_BE32(wpa_auth->conf.ip_addr_start);
                        bitfield_set(wpa_auth->ip_pool, idx);
+                       sm->ip_addr_bit = idx;
                        WPA_PUT_BE32(sm->ip_addr, start + idx);
                        wpa_printf(MSG_DEBUG,
                                   "P2P: Assigned IP address %u.%u.%u.%u to "
-                                  MACSTR, sm->ip_addr[0], sm->ip_addr[1],
+                                  MACSTR " (bit %u)",
+                                  sm->ip_addr[0], sm->ip_addr[1],
                                   sm->ip_addr[2], sm->ip_addr[3],
-                                  MAC2STR(sm->addr));
+                                  MAC2STR(sm->addr), sm->ip_addr_bit);
                }
        }
 #endif /* CONFIG_P2P */
index 17cb5a2e97711d909b18b5af26149810f838203b..5bd699c25d9c077d29799af080a4a31435254cd1 100644 (file)
@@ -152,6 +152,7 @@ struct wpa_state_machine {
 
 #ifdef CONFIG_P2P
        u8 ip_addr[4];
+       unsigned int ip_addr_bit;
 #endif /* CONFIG_P2P */
 
 #ifdef CONFIG_FILS