Skip to content

Commit

Permalink
wifi: replace the previously defined AP with the new one
Browse files Browse the repository at this point in the history
If we find an AP with the same name in the same interface, we drop the
first one and use the new one. This is done to maintain the documented
behavior of respecting the order in which the files are parsed. We still
need to implement support for merging AP settings.
  • Loading branch information
daniloegea committed Oct 16, 2023
1 parent cb6893c commit b6020cb
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/parse.c
Expand Up @@ -1448,11 +1448,20 @@ handle_wifi_access_points(NetplanParser* npp, yaml_node_t* node, const char* key

ssid = scalar(key);

/* Skip access-points that already exist in the netdef */
if (npp->current.netdef->access_points && g_hash_table_contains(npp->current.netdef->access_points, ssid))
continue;
/*
* Delete the access-point if it already exists in the netdef and let the new
* one be added. It has the side effect of reprocessing APs if the parser requires a
* second pass.
*
* TODO: implement support for merging AP settings if they were previously defined
*/
if (npp->current.netdef->access_points && g_hash_table_contains(npp->current.netdef->access_points, ssid)) {
NetplanWifiAccessPoint *ap = g_hash_table_lookup(npp->current.netdef->access_points, ssid);
g_hash_table_remove(npp->current.netdef->access_points, ssid);
free_access_point(NULL, ap, NULL);
}

/* Check if there's already an SSID with that name in the list of APs we are parsing */
/* Check if the SSID was already defined in the same netdef in this YAML file we are parsing */
if (g_hash_table_contains(access_points, ssid)) {
g_hash_table_foreach(access_points, free_access_point, NULL);
g_hash_table_destroy(access_points);
Expand Down
31 changes: 31 additions & 0 deletions tests/generator/test_common.py
Expand Up @@ -1795,4 +1795,35 @@ def test_wifi_access_points_merging(self):
ieee80211w=1
psk="aaaaaaaa"
}
""")

def test_wifi_access_points_overwriting(self):
''' If we find an AP that is already defined we drop the first one.
XXX: this test must be removed once we implement support for AP merging
'''
self.generate('''network:
version: 2
wifis:
wlan0:
dhcp4: true
access-points:
"mywifi":
password: "aaaaaaaa"''',
confs={'newwifi': '''network:
version: 2
wifis:
wlan0:
dhcp4: true
access-points:
"mywifi":
password: "bbbbbbbb"'''})

self.assert_wpa_supplicant("wlan0", """ctrl_interface=/run/wpa_supplicant
network={
ssid="mywifi"
key_mgmt=WPA-PSK WPA-PSK-SHA256 SAE
ieee80211w=1
psk="bbbbbbbb"
}
""")

0 comments on commit b6020cb

Please sign in to comment.