3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-11-25 17:59:25 +01:00

netconfig: Unify static and dynamic addressing APIs

This commit is contained in:
Tim Kourt 2019-07-16 17:49:47 -07:00 committed by Denis Kenzior
parent 2d007a25b6
commit 18119537f7

View File

@ -310,14 +310,14 @@ gateway:
return true; return true;
} }
enum lease_action { enum netconfig_action {
LEASE_ACTION_INSTALL, NETCONFIG_ACTION_INSTALL,
LEASE_ACTION_UNINSTALL, NETCONFIG_ACTION_UNINSTALL,
}; };
static void netconfig_dhcp_lease_received(struct netconfig *netconfig, static void netconfig_dhcp_addressing(struct netconfig *netconfig,
const struct l_dhcp_client *client, const struct l_dhcp_client *client,
enum lease_action action) enum netconfig_action action)
{ {
const struct l_dhcp_lease *lease; const struct l_dhcp_lease *lease;
struct netconfig_ifaddr ifaddr; struct netconfig_ifaddr ifaddr;
@ -351,10 +351,10 @@ static void netconfig_dhcp_lease_received(struct netconfig *netconfig,
ifaddr.proto = RTPROT_DHCP; ifaddr.proto = RTPROT_DHCP;
switch (action) { switch (action) {
case LEASE_ACTION_INSTALL: case NETCONFIG_ACTION_INSTALL:
netconfig_install_addresses(netconfig, &ifaddr, gateway, dns); netconfig_install_addresses(netconfig, &ifaddr, gateway, dns);
break; break;
case LEASE_ACTION_UNINSTALL: case NETCONFIG_ACTION_UNINSTALL:
netconfig_uninstall_addresses(netconfig, &ifaddr, gateway, dns); netconfig_uninstall_addresses(netconfig, &ifaddr, gateway, dns);
break; break;
} }
@ -379,13 +379,13 @@ static void netconfig_dhcp_event_handler(struct l_dhcp_client *client,
case L_DHCP_CLIENT_EVENT_LEASE_RENEWED: case L_DHCP_CLIENT_EVENT_LEASE_RENEWED:
case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED: case L_DHCP_CLIENT_EVENT_LEASE_OBTAINED:
case L_DHCP_CLIENT_EVENT_IP_CHANGED: case L_DHCP_CLIENT_EVENT_IP_CHANGED:
netconfig_dhcp_lease_received(netconfig, client, netconfig_dhcp_addressing(netconfig, client,
LEASE_ACTION_INSTALL); NETCONFIG_ACTION_INSTALL);
break; break;
case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED: case L_DHCP_CLIENT_EVENT_LEASE_EXPIRED:
netconfig_dhcp_lease_received(netconfig, client, netconfig_dhcp_addressing(netconfig, client,
LEASE_ACTION_UNINSTALL); NETCONFIG_ACTION_UNINSTALL);
/* Fall through. */ /* Fall through. */
case L_DHCP_CLIENT_EVENT_NO_LEASE: case L_DHCP_CLIENT_EVENT_NO_LEASE:
/* /*
@ -424,8 +424,9 @@ static bool netconfig_dhcp_create(struct netconfig *netconfig,
return true; return true;
} }
static bool netconfig_load_static_addresses(struct netconfig *netconfig, static bool netconfig_static_addressing(struct netconfig *netconfig,
struct station *station) struct station *station,
enum netconfig_action action)
{ {
const struct network *network; const struct network *network;
const struct l_settings *settings; const struct l_settings *settings;
@ -487,13 +488,14 @@ static void netconfig_station_state_changed(enum station_state state,
l_debug(""); l_debug("");
station = station_find(netconfig->ifindex);
if (!station)
return;
switch (state) { switch (state) {
case STATION_STATE_CONNECTED: case STATION_STATE_CONNECTED:
station = station_find(netconfig->ifindex); if (netconfig_static_addressing(netconfig, station,
if (!station) NETCONFIG_ACTION_INSTALL))
break;
if (netconfig_load_static_addresses(netconfig, station))
break; break;
if (netconfig->station_state == STATION_STATE_ROAMING) { if (netconfig->station_state == STATION_STATE_ROAMING) {
@ -511,10 +513,14 @@ static void netconfig_station_state_changed(enum station_state state,
break; break;
case STATION_STATE_DISCONNECTED: case STATION_STATE_DISCONNECTED:
l_dhcp_client_stop(netconfig->dhcp_client); if (netconfig_static_addressing(netconfig, station,
NETCONFIG_ACTION_UNINSTALL))
break;
l_queue_foreach_remove(netconfig->ifaddr_list, netconfig_dhcp_addressing(netconfig, netconfig->dhcp_client,
netconfig_ifaddr_remove, netconfig); NETCONFIG_ACTION_UNINSTALL);
l_dhcp_client_stop(netconfig->dhcp_client);
break; break;
case STATION_STATE_ROAMING: case STATION_STATE_ROAMING: