commit b70ff5d0918002b7f51395ef5c516bc37f9dc57d
parent 3d40f3a38b60eeba93f144977094f718dc1abf1d
Author: Tim Kourt <tim.a.kourt@linux.intel.com>
Date: Tue, 25 Jun 2019 15:20:57 -0700
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.
Diffstat:
1 file changed, 53 insertions(+), 0 deletions(-)
diff --git a/src/netconfig.c b/src/netconfig.c
@@ -40,6 +40,7 @@
struct netconfig {
uint32_t ifindex;
+ enum station_state station_state;
struct l_dhcp_client *dhcp_client;
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);
}
+static bool netconfig_ifaddr_remove(void *data, void *user_data)
+{
+ return false;
+}
+
static bool netconfig_install_addresses(struct netconfig *netconfig,
const struct netconfig_ifaddr *ifaddr,
const char *gateway, char **dns)
@@ -346,6 +352,50 @@ static bool netconfig_dhcp_create(struct netconfig *netconfig,
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)
{
struct netconfig *netconfig;
@@ -370,6 +420,9 @@ bool netconfig_ifindex_add(uint32_t ifindex)
netconfig_dhcp_create(netconfig, station);
+ station_add_state_watch(station, netconfig_station_state_changed,
+ netconfig, NULL);
+
l_queue_push_tail(netconfig_list, netconfig);
return true;