From: Benjamin Berg Date: Thu, 30 Oct 2025 08:24:46 +0000 (+0100) Subject: P2P2: Handle identity ID consistently within files X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cad3af08e2aeea88b69cb25d40ea659f85a42106;p=thirdparty%2Fhostap.git P2P2: Handle identity ID consistently within files Using an ID to reference a specific identity= block within the same file for the DIK has the problem that it requires the IDs to be stable. However, we also use a static int for the ID enumeration in case multiple files are read. Overall, it seems like it could be better to use the DIK as an identifier. However, we do not, so the numbering needs to be restored consistently within the file. The straight forward way to achieve this is to store the base of the counter as a static variable and adding it to both the go_dik_id and the id of the identity= blocks. For all of this to work, we also need to make sure that we write out the values with file-local indices. As such, we need to use the position in the internal list rather than the assigned ID when writing the values. Fixes: 417c67468b8d ("P2P2: Add device identity block to wpa_supplicant configuration") Fixes: ec4569174750 ("P2P2: Store ID of Device Identity block in network block") CC: Shivani Baranwal CC: Vinay Gannevaram Signed-off-by: Benjamin Berg --- diff --git a/wpa_supplicant/config_file.c b/wpa_supplicant/config_file.c index c8be83a87..ca27e62e9 100644 --- a/wpa_supplicant/config_file.c +++ b/wpa_supplicant/config_file.c @@ -367,7 +367,8 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp, struct wpa_config *config; static int id = 0; static int cred_id = 0; - static int identity_id = 1; + static int base_identity_id = 0; + int identity_id = base_identity_id; if (name == NULL) return NULL; @@ -416,6 +417,7 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp, errors++; continue; } + ssid->go_dik_id += base_identity_id; ssid->ro = ro; if (head == NULL) { head = tail = ssid; @@ -456,7 +458,7 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp, #endif /* CONFIG_NO_CONFIG_BLOBS */ } else if (os_strcmp(pos, "identity={") == 0) { identity = wpa_config_read_identity(f, &line, - identity_id++); + ++identity_id); if (!identity) { wpa_printf(MSG_ERROR, "Line %d: failed to parse identity block.", @@ -488,6 +490,8 @@ struct wpa_config * wpa_config_read(const char *name, struct wpa_config *cfgp, config->cred = cred_head; config->identity = identity_head; + base_identity_id = identity_id; + #ifndef WPA_IGNORE_CONFIG_ERRORS if (errors) { if (config != cfgp) @@ -768,7 +772,8 @@ static void write_mka_ckn(FILE *f, struct wpa_ssid *ssid) #endif /* CONFIG_MACSEC */ -static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid) +static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid, + struct wpa_config *config) { #define STR(t) write_str(f, #t, ssid) #define INT(t) write_int(f, #t, ssid->t, 0) @@ -910,7 +915,20 @@ static void wpa_config_write_network(FILE *f, struct wpa_ssid *ssid) write_p2p_client_list(f, ssid); write_p2p2_client_list(f, ssid); write_psk_list(f, ssid); - INT(go_dik_id); + { + struct wpa_dev_ik *dev_ik; + int i = 1, go_dik_id = 0; + + for (dev_ik = config->identity; + dev_ik; + dev_ik = dev_ik->next, i++) { + if (dev_ik->id == ssid->go_dik_id) { + go_dik_id = i; + break; + } + } + write_int(f, "go_dik_id", go_dik_id, 0); + } #endif /* CONFIG_P2P */ INT(ap_max_inactivity); INT(dtim_period); @@ -1860,7 +1878,7 @@ int wpa_config_write(const char *name, struct wpa_config *config) !ssid->pmk_valid) continue; /* do not save invalid network */ fprintf(f, "\nnetwork={\n"); - wpa_config_write_network(f, ssid); + wpa_config_write_network(f, ssid, config); fprintf(f, "}\n"); }