mirror of
https://git.kernel.org/pub/scm/network/wireless/iwd.git
synced 2024-12-21 20:12:37 +01:00
netconfig: Add station state watch
netconfig is interested in three station states: connected, disconnected and connected after it has roamed. On connected it tries to obtain a new DHCP lease, on disconnected it stops the DHCP client and discards all addresses from interface, on connected after roaming it will try to request a previously issued address.
This commit is contained in:
parent
3d40f3a38b
commit
b70ff5d091
@ -40,6 +40,7 @@
|
|||||||
|
|
||||||
struct netconfig {
|
struct netconfig {
|
||||||
uint32_t ifindex;
|
uint32_t ifindex;
|
||||||
|
enum station_state station_state;
|
||||||
struct l_dhcp_client *dhcp_client;
|
struct l_dhcp_client *dhcp_client;
|
||||||
struct l_queue *ifaddr_list;
|
struct l_queue *ifaddr_list;
|
||||||
};
|
};
|
||||||
@ -219,6 +220,11 @@ static void netconfig_ifaddr_cmd_cb(int error, uint16_t type,
|
|||||||
netconfig_ifaddr_notify(type, data, len, user_data);
|
netconfig_ifaddr_notify(type, data, len, user_data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool netconfig_ifaddr_remove(void *data, void *user_data)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static bool netconfig_install_addresses(struct netconfig *netconfig,
|
static bool netconfig_install_addresses(struct netconfig *netconfig,
|
||||||
const struct netconfig_ifaddr *ifaddr,
|
const struct netconfig_ifaddr *ifaddr,
|
||||||
const char *gateway, char **dns)
|
const char *gateway, char **dns)
|
||||||
@ -346,6 +352,50 @@ static bool netconfig_dhcp_create(struct netconfig *netconfig,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void netconfig_station_state_changed(enum station_state state,
|
||||||
|
void *userdata)
|
||||||
|
{
|
||||||
|
struct netconfig *netconfig = userdata;
|
||||||
|
struct station *station;
|
||||||
|
|
||||||
|
l_debug("");
|
||||||
|
|
||||||
|
switch (state) {
|
||||||
|
case STATION_STATE_CONNECTED:
|
||||||
|
station = station_find(netconfig->ifindex);
|
||||||
|
if (!station)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (netconfig->station_state == STATION_STATE_ROAMING) {
|
||||||
|
/*
|
||||||
|
* TODO l_dhcp_client to try to request a previously
|
||||||
|
* used address.
|
||||||
|
*
|
||||||
|
* break;
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!l_dhcp_client_start(netconfig->dhcp_client))
|
||||||
|
l_error("netconfig: Failed to start DHCPv4 client for "
|
||||||
|
"interface %u", netconfig->ifindex);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case STATION_STATE_DISCONNECTED:
|
||||||
|
l_dhcp_client_stop(netconfig->dhcp_client);
|
||||||
|
|
||||||
|
l_queue_foreach_remove(netconfig->ifaddr_list,
|
||||||
|
netconfig_ifaddr_remove, netconfig);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case STATION_STATE_ROAMING:
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
netconfig->station_state = state;
|
||||||
|
}
|
||||||
|
|
||||||
bool netconfig_ifindex_add(uint32_t ifindex)
|
bool netconfig_ifindex_add(uint32_t ifindex)
|
||||||
{
|
{
|
||||||
struct netconfig *netconfig;
|
struct netconfig *netconfig;
|
||||||
@ -370,6 +420,9 @@ bool netconfig_ifindex_add(uint32_t ifindex)
|
|||||||
|
|
||||||
netconfig_dhcp_create(netconfig, station);
|
netconfig_dhcp_create(netconfig, station);
|
||||||
|
|
||||||
|
station_add_state_watch(station, netconfig_station_state_changed,
|
||||||
|
netconfig, NULL);
|
||||||
|
|
||||||
l_queue_push_tail(netconfig_list, netconfig);
|
l_queue_push_tail(netconfig_list, netconfig);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
Loading…
Reference in New Issue
Block a user