Skip to contentSkip to conversation

sysfs: introduce sysfs module

PATCH In review James Prestwood 2 participants 5 messages Nov 3, 2021 Kbuild

lore
Share & tools
lore

James Prestwood

author
#0 lore raw

PATCH 1/4 sysfs: introduce sysfs module

Netconfig was the only user of sysfs but now other modules will also need it.

Adding existing API for IPv6 settings, a IPv4 and IPv6 'supports' checker, and a setter for IPv4 settings.

---
 Makefile.am |   1 +
 src/sysfs.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/sysfs.h |  28 ++++++++++++++
 3 files changed, 138 insertions(+)
 create mode 100644 src/sysfs.c
 create mode 100644 src/sysfs.h
Makefile.am +1 -0
index a6dafe63..275dd1b9 100644
@@ -246,6 +246,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
 					src/diagnostic.h src/diagnostic.c \
 					src/ip-pool.h src/ip-pool.c \
 					src/band.h src/band.c \
+					src/sysfs.h src/sysfs.c \
 					$(eap_sources) \
 					$(builtin_sources)
 
src/sysfs.c new file +109 -0

109 lines not on this page · raw message

src/sysfs.h new file +28 -0
new file mode 100644
index 00000000..60207c13
@@ -0,0 +1,28 @@
+/*
+ *
+ *  Wireless daemon for Linux
+ *
+ *  Copyright (C) 2021  Intel Corporation. All rights reserved.
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+bool sysfs_supports_ipv6_setting(const char *ifname, const char *setting);
+int sysfs_write_ipv6_setting(const char *ifname, const char *setting,
+					const char *value);
+bool sysfs_supports_ipv4_setting(const char *ifname, const char *setting);
+int sysfs_write_ipv4_setting(const char *ifname, const char *setting,
+					const char *value);
Signature · 1 line
2.31.1
author
#1 lore raw

PATCH 2/4 netconfig: remove sysfs static functions

---
 src/netconfig.c | 33 +--------------------------------
 1 file changed, 1 insertion(+), 32 deletions(-)
src/netconfig.c +1 -32
index df9abd00..6e885546 100644
@@ -50,6 +50,7 @@
 #include "src/util.h"
 #include "src/ie.h"
 #include "src/netconfig.h"
+#include "src/sysfs.h"
 
 struct netconfig {
 	uint32_t ifindex;
@@ -102,38 +103,6 @@ static void do_debug(const char *str, void *user_data)
 	l_info("%s%s", prefix, str);
 }
 
-static int write_string(const char *file, const char *value)
-{
-	size_t l = strlen(value);
-	int fd;
-	int r;
-
-	fd = L_TFR(open(file, O_WRONLY));
-	if (fd < 0)
-		return -errno;
-
-	r = L_TFR(write(fd, value, l));
-	L_TFR(close(fd));
-
-	return r;
-}
-
-static int sysfs_write_ipv6_setting(const char *ifname, const char *setting,
-					const char *value)
-{
-	int r;
-
-	L_AUTO_FREE_VAR(char *, file) =
-		l_strdup_printf("/proc/sys/net/ipv6/conf/%s/%s",
-							ifname, setting);
-
-	r = write_string(file, value);
-	if (r < 0)
-		l_error("Unable to write %s to %s", setting, file);
-
-	return r;
-}
-
 static void netconfig_free_settings(struct netconfig *netconfig)
 {
 	l_rtnl_address_free(netconfig->v4_address);
Signature · 1 line
2.31.1
author
#2 lore raw

PATCH 3/4 station: set evict_nocarrier sysfs option during roaming

In reply to James Prestwood

If the kernel supports evict_nocarrier set this during the roam to prevent packet delays post roam.

---
 src/station.c | 29 ++++++++++++++++++++++++++---
 1 file changed, 26 insertions(+), 3 deletions(-)
src/station.c +26 -3
index 84f9d0c2..4bb8e60f 100644
@@ -57,12 +57,15 @@
 #include "src/anqputil.h"
 #include "src/diagnostic.h"
 #include "src/frame-xchg.h"
+#include "src/sysfs.h"
 
 static struct l_queue *station_list;
 static uint32_t netdev_watch;
 static uint32_t mfp_setting;
 static uint32_t roam_retry_interval;
 static bool anqp_disabled;
+static bool supports_arp_evict_nocarrier;
+static bool supports_ndisc_evict_nocarrier;
 static struct watchlist event_watches;
 
 struct station {
@@ -1384,6 +1387,19 @@ static const char *station_state_to_string(enum station_state state)
 	return "invalid";
 }
 
+static void station_set_evict_nocarrier(struct station *station, bool value)
+{
+	char *v = value ? "1" : "0";
+
+	if (supports_arp_evict_nocarrier)
+		sysfs_write_ipv4_setting(netdev_get_name(station->netdev),
+					"arp_evict_nocarrier", v);
+
+	if (supports_ndisc_evict_nocarrier)
+		sysfs_write_ipv6_setting(netdev_get_name(station->netdev),
+					"ndisc_evict_nocarrier", v);
+}
+
 static void station_enter_state(struct station *station,
 						enum station_state state)
 {
@@ -1429,9 +1445,6 @@ static void station_enter_state(struct station *station,
 				network_get_path(station->connected_network),
 				IWD_NETWORK_INTERFACE, "Connected");
 
-		periodic_scan_stop(station);
-		break;
-	case STATION_STATE_DISCONNECTED:
 		periodic_scan_stop(station);
 		break;
 	case STATION_STATE_CONNECTED:
@@ -1439,11 +1452,16 @@ static void station_enter_state(struct station *station,
 					netdev_get_path(station->netdev),
 					IWD_STATION_DIAGNOSTIC_INTERFACE,
 					station);
+		/* Fall through */
+	case STATION_STATE_DISCONNECTED:
 		periodic_scan_stop(station);
+
+		station_set_evict_nocarrier(station, true);
 		break;
 	case STATION_STATE_DISCONNECTING:
 		break;
 	case STATION_STATE_ROAMING:
+		station_set_evict_nocarrier(station, false);
 		break;
 	}
 
@@ -4457,6 +4475,11 @@ static int station_init(void)
 	if (!netconfig_enabled())
 		l_info("station: Network configuration is disabled.");
 
+	supports_arp_evict_nocarrier = sysfs_supports_ipv4_setting("all",
+						"arp_evict_nocarrier");
+	supports_ndisc_evict_nocarrier = sysfs_supports_ipv6_setting("all",
+						"ndisc_evict_nocarrier");
+
 	watchlist_init(&event_watches, NULL);
 
 	return 0;
Signature · 1 line
2.31.1
author
#3 lore raw

PATCH 4/4 netconfig: netconfig_reconfigure check bool for setting ARP

In reply to James Prestwood

Only set the gateway to the ARP cache if the caller requests.

---
 src/netconfig.c | 5 +++--
 src/netconfig.h | 2 +-
 src/station.c   | 3 ++-
 3 files changed, 6 insertions(+), 4 deletions(-)
src/netconfig.c +3 -2
index 6e885546..e7fd4855 100644
@@ -1468,7 +1468,7 @@ bool netconfig_configure(struct netconfig *netconfig,
 	return true;
 }
 
-bool netconfig_reconfigure(struct netconfig *netconfig)
+bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw)
 {
 	/*
 	 * Starting with kernel 4.20, ARP cache is flushed when the netdev
@@ -1477,7 +1477,8 @@ bool netconfig_reconfigure(struct netconfig *netconfig)
 	 * lost or delayed.  Try to force the gateway into the ARP cache
 	 * to alleviate this
 	 */
-	netconfig_gateway_to_arp(netconfig);
+	if (set_arp_gw)
+		netconfig_gateway_to_arp(netconfig);
 
 	if (netconfig->rtm_protocol == RTPROT_DHCP) {
 		/* TODO l_dhcp_client sending a DHCP inform request */
src/netconfig.h +1 -1
index c2e6a6f9..c9ac6f8f 100644
@@ -36,7 +36,7 @@ bool netconfig_load_settings(struct netconfig *netconfig,
 bool netconfig_configure(struct netconfig *netconfig,
 				netconfig_notify_func_t notify,
 				void *user_data);
-bool netconfig_reconfigure(struct netconfig *netconfig);
+bool netconfig_reconfigure(struct netconfig *netconfig, bool set_arp_gw);
 bool netconfig_reset(struct netconfig *netconfig);
 char *netconfig_get_dhcp_server_ipv4(struct netconfig *netconfig);
 bool netconfig_get_fils_ip_req(struct netconfig *netconfig,
src/station.c +2 -1
index 4bb8e60f..fcec0dfe 100644
@@ -1851,7 +1851,8 @@ static void station_roamed(struct station *station)
 		station_roam_timeout_rearm(station, roam_retry_interval);
 
 	if (station->netconfig)
-		netconfig_reconfigure(station->netconfig);
+		netconfig_reconfigure(station->netconfig,
+					!supports_arp_evict_nocarrier);
 
 	if (station->roam_freqs) {
 		scan_freq_set_free(station->roam_freqs);
Signature · 1 line
2.31.1
#4 lore raw
In reply to James Prestwood

Hi James,

Quoted 5 lines · James Prestwood

Netconfig was the only user of sysfs but now other modules will also need it.

Adding existing API for IPv6 settings, a IPv4 and IPv6 'supports' checker, and a setter for IPv4 settings.

Quoted 8 lines
---
  Makefile.am |   1 +
  src/sysfs.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++++
  src/sysfs.h |  28 ++++++++++++++
  3 files changed, 138 insertions(+)

create mode 100644 src/sysfs.c
create mode 100644 src/sysfs.h

All applied, thanks.

Regards,
-Denis