3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-29 05:39:24 +01:00

netconfig: Decouple from station state

Instead of relying on station state changed signal, netconfig
introduces three new API calls to configure, re-configure and
reset the network configurations. The owner of netconfig object
is responsible for initiating the re-configuration of the device
depending on its state.
This commit is contained in:
Tim Kourt 2019-09-30 09:35:51 -07:00 committed by Denis Kenzior
parent 57095eaa2c
commit fb65b5f92c
2 changed files with 49 additions and 38 deletions

View File

@ -48,6 +48,8 @@ struct netconfig {
struct l_dhcp_client *dhcp_client;
struct l_queue *ifaddr_list;
uint8_t rtm_protocol;
const struct l_settings *active_settings;
};
struct netconfig_ifaddr {
@ -589,16 +591,10 @@ static void netconfig_ipv4_dhcp_event_handler(struct l_dhcp_client *client,
}
}
static bool netconfig_ipv4_dhcp_create(struct netconfig *netconfig,
struct station *station)
static bool netconfig_ipv4_dhcp_create(struct netconfig *netconfig)
{
netconfig->dhcp_client = l_dhcp_client_new(netconfig->ifindex);
l_dhcp_client_set_address(netconfig->dhcp_client, ARPHRD_ETHER,
netdev_get_address(
station_get_netdev(station)),
ETH_ALEN);
l_dhcp_client_set_event_handler(netconfig->dhcp_client,
netconfig_ipv4_dhcp_event_handler,
netconfig, NULL);
@ -654,41 +650,57 @@ static void netconfig_ipv4_select_and_uninstall(struct netconfig *netconfig)
l_dhcp_client_stop(netconfig->dhcp_client);
}
static void netconfig_station_state_changed(enum station_state state,
void *userdata)
bool netconfig_configure(struct netconfig *netconfig,
const struct l_settings *active_settings,
const uint8_t *mac_address)
{
struct netconfig *netconfig = userdata;
netconfig->active_settings = active_settings;
l_debug("");
l_dhcp_client_set_address(netconfig->dhcp_client, ARPHRD_ETHER,
mac_address, ETH_ALEN);
switch (state) {
case STATION_STATE_CONNECTED:
netconfig_ipv4_select_and_install(netconfig);
/* TODO: IPv6 addressing */
break;
case STATION_STATE_DISCONNECTED:
return true;
}
bool netconfig_reconfigure(struct netconfig *netconfig)
{
if (netconfig->rtm_protocol == RTPROT_DHCP) {
/*
*
* TODO l_dhcp_client to try to request a
* previously used address.
*
* return;
*/
}
netconfig_ipv4_select_and_install(netconfig);
/* TODO: IPv6 addressing */
return true;
}
bool netconfig_reset(struct netconfig *netconfig)
{
netconfig_ipv4_select_and_uninstall(netconfig);
/* TODO: IPv6 addressing */
resolve_remove(netconfig->ifindex);
break;
case STATION_STATE_ROAMING:
break;
default:
return;
}
netconfig->rtm_protocol = 0;
netconfig->station_state = state;
return true;
}
struct netconfig *netconfig_new(uint32_t ifindex)
{
struct netconfig *netconfig;
struct station *station;
if (!netconfig_list)
return NULL;
@ -699,18 +711,11 @@ struct netconfig *netconfig_new(uint32_t ifindex)
if (netconfig)
return netconfig;
station = station_find(ifindex);
if (!station)
return NULL;
netconfig = l_new(struct netconfig, 1);
netconfig->ifindex = ifindex;
netconfig->ifaddr_list = l_queue_new();
netconfig_ipv4_dhcp_create(netconfig, station);
station_add_state_watch(station, netconfig_station_state_changed,
netconfig, NULL);
netconfig_ipv4_dhcp_create(netconfig);
l_queue_push_tail(netconfig_list, netconfig);
@ -726,7 +731,7 @@ void netconfig_destroy(struct netconfig *netconfig)
l_queue_remove(netconfig_list, netconfig);
if (netconfig->station_state != STATION_STATE_DISCONNECTED) {
if (netconfig->rtm_protocol) {
netconfig_ipv4_select_and_uninstall(netconfig);
/* TODO Uninstall IPv6 addresses. */

View File

@ -22,5 +22,11 @@
struct netconfig;
bool netconfig_configure(struct netconfig *netconfig,
const struct l_settings *active_settings,
const uint8_t *mac_address);
bool netconfig_reconfigure(struct netconfig *netconfig);
bool netconfig_reset(struct netconfig *netconfig);
struct netconfig *netconfig_new(uint32_t ifindex);
void netconfig_destroy(struct netconfig *netconfig);