Wireless Daemon for Linux
 help / color / mirror / Atom feed
From: Tim Kourt <tim.a.kourt@linux.intel.com>
To: iwd@lists.01.org
Subject: [PATCH v2 1/8] netconfig: Decouple from station state
Date: Mon, 30 Sep 2019 09:35:51 -0700	[thread overview]
Message-ID: <20190930163558.28123-1-tim.a.kourt@linux.intel.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 4756 bytes --]

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.
---
 src/netconfig.c | 79 ++++++++++++++++++++++++++++++---------------------------
 src/netconfig.h |  6 +++++
 2 files changed, 48 insertions(+), 37 deletions(-)

diff --git a/src/netconfig.c b/src/netconfig.c
index 2074689f..88d2588e 100644
--- a/src/netconfig.c
+++ b/src/netconfig.c
@@ -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);
+	netconfig_ipv4_select_and_install(netconfig);
 
-		/* TODO: IPv6 addressing */
+	/* TODO: IPv6 addressing */
 
-		break;
-	case STATION_STATE_DISCONNECTED:
-		netconfig_ipv4_select_and_uninstall(netconfig);
+	return true;
+}
 
-		/* TODO: IPv6 addressing */
+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;
+		 */
+	}
 
-		resolve_remove(netconfig->ifindex);
+	netconfig_ipv4_select_and_install(netconfig);
 
-		break;
-	case STATION_STATE_ROAMING:
-		break;
-	default:
-		return;
-	}
+	/* TODO: IPv6 addressing */
 
-	netconfig->station_state = state;
+	return true;
+}
+
+bool netconfig_reset(struct netconfig *netconfig)
+{
+	netconfig_ipv4_select_and_uninstall(netconfig);
+
+	/* TODO: IPv6 addressing */
+
+	resolve_remove(netconfig->ifindex);
+
+	netconfig->rtm_protocol = 0;
+
+	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. */
diff --git a/src/netconfig.h b/src/netconfig.h
index fd344830..cacd384a 100644
--- a/src/netconfig.h
+++ b/src/netconfig.h
@@ -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);
-- 
2.13.6

             reply	other threads:[~2019-09-30 16:35 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30 16:35 Tim Kourt [this message]
2019-09-30 16:35 ` [PATCH v2 2/8] station: netconfig devices based on station state Tim Kourt
2019-09-30 16:35 ` [PATCH v2 3/8] netconfig: Switch to internal active network settings Tim Kourt
2019-09-30 16:35 ` [PATCH v2 4/8] netconfig: Subscribe for IPv6 address changes Tim Kourt
2019-09-30 20:13   ` Denis Kenzior
2019-09-30 16:35 ` [PATCH v2 5/8] netconfig: Request all known IPv6 addresses Tim Kourt
2019-09-30 16:35 ` [PATCH v2 6/8] netconfig: Add IPv6 static address installation/removal Tim Kourt
2019-09-30 16:35 ` [PATCH v2 7/8] netconfig: Install IPv6 default route Tim Kourt
2019-09-30 16:35 ` [PATCH v2 8/8] netconfig: Install IPv6 DNS Tim Kourt
2019-09-30 20:12 ` [PATCH v2 1/8] netconfig: Decouple from station state Denis Kenzior

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190930163558.28123-1-tim.a.kourt@linux.intel.com \
    --to=tim.a.kourt@linux.intel.com \
    --cc=iwd@lists.01.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox