Hi David and ports@, I've built a little patch to security/wpa_supplicant that lets it listen to changes in the associated network SSID (thanks to Ken's RTM_80211INFO) and reassociate itself.
This essentially means that now you can run `wpa_supplicant` in the background
and configure e.g. eduroam like `ifconfig iwm0 join eduroam wpaakms 802.1x`
without having to manually kick wpa_supplicant by restarting it or running
`wpa_cli reassoc`.
I'll be out of range of my usual eduroam access points until next week, so I
haven't tested this beyond "wpa_supplicant doesn't crash and it tries to reassoc
if the NWID changes".
I'd be really grateful if a few of you who do run wpa_supplicant for wireless
802.1x networks could give this a spin. All that's needed is applying the patch
below my signature to `/usr/ports/security/wpa_supplicant` and running `make
reinstall`.
--
Gregor
Index: patches/patch-src_drivers_driver_openbsd_c
===================================================================
RCS file:
/home/cvs/ports/security/wpa_supplicant/patches/patch-src_drivers_driver_openbsd_c,v
retrieving revision 1.5
diff -u -p -u -r1.5 patch-src_drivers_driver_openbsd_c
--- patches/patch-src_drivers_driver_openbsd_c 17 May 2016 08:29:27 -0000
1.5
+++ patches/patch-src_drivers_driver_openbsd_c 20 Nov 2018 17:59:00 -0000
@@ -2,23 +2,130 @@ $OpenBSD: patch-src_drivers_driver_openb
Fix includes
---- src/drivers/driver_openbsd.c.orig Sun Sep 27 21:02:05 2015
-+++ src/drivers/driver_openbsd.c Mon Sep 28 09:51:53 2015
-@@ -9,13 +9,14 @@
+Index: src/drivers/driver_openbsd.c
+--- src/drivers/driver_openbsd.c.orig
++++ src/drivers/driver_openbsd.c
+@@ -9,19 +9,31 @@
#include "includes.h"
#include <sys/ioctl.h>
+#include "common.h"
+#include "driver.h"
++#include "eloop.h"
+
++#include <sys/socket.h>
#include <net/if.h>
+#include <net/if_var.h>
++#include <net/route.h>
#include <net80211/ieee80211.h>
#include <net80211/ieee80211_crypto.h>
#include <net80211/ieee80211_ioctl.h>
--
+
-#include "common.h"
-#include "driver.h"
++#define RTM_READSZ 2048
struct openbsd_driver_data {
- char ifname[IFNAMSIZ + 1];
+- char ifname[IFNAMSIZ + 1];
+ void *ctx;
+
+- int sock; /* open socket for 802.11 ioctls */
++ char ifname[IFNAMSIZ + 1];
++ int ifindex; /* Ifindex of the configured interface */
++
++ int sock; /* open socket for 802.11 ioctls */
++ int rtsock; /* routing socket for interface state messages */
++
++ int nwid_len; /* Length of last seen SSID (as per routing message) */
++ char nwid[IEEE80211_NWID_LEN]; /* Last seen SSID (as per routing
message) */
+ };
+
+
+@@ -90,6 +102,54 @@ wpa_driver_openbsd_set_key(const char *ifname, void *p
+ return 0;
+ }
+
++static void
++wpa_driver_openbsd_event_receive(int sock, void *global, void *sock_ctx)
++{
++ struct openbsd_driver_data *drv = sock_ctx;
++ struct rt_msghdr *rtm;
++ struct if_ieee80211_data *ifie;
++ char *rtmmsg;
++ ssize_t n;
++
++ rtmmsg = os_zalloc(RTM_READSZ);
++ if (rtmmsg == NULL) {
++ wpa_printf(MSG_ERROR, "Can't allocate space for routing
message");
++ return;
++ }
++
++ do {
++ n = read(sock, rtmmsg, RTM_READSZ);
++ } while (n == -1 && errno == EINTR);
++
++ if (n == -1)
++ goto done;
++
++ rtm = (struct rt_msghdr *)rtmmsg;
++
++ if ((size_t)n < sizeof(rtm->rtm_msglen) ||
++ n < rtm->rtm_msglen ||
++ rtm->rtm_version != RTM_VERSION)
++ goto done;
++
++ if ((rtm->rtm_type != RTM_80211INFO) ||
++ (rtm->rtm_index != drv->ifindex))
++ goto done;
++
++ ifie = &((struct if_ieee80211_msghdr *)rtm)->ifim_ifie;
++
++ if ((ifie->ifie_nwid_len != drv->nwid_len) ||
++ (os_memcmp(drv->nwid, ifie->ifie_nwid, ifie->ifie_nwid_len) != 0)) {
++ os_memcpy(drv->nwid, ifie->ifie_nwid, ifie->ifie_nwid_len);
++ drv->nwid_len = ifie->ifie_nwid_len;
++
++ /* Emit ASSOC event */
++ wpa_supplicant_event(drv->ctx, EVENT_ASSOC, NULL);
++ }
++
++done:
++ os_free(rtmmsg);
++}
++
+ static void *
+ wpa_driver_openbsd_init(void *ctx, const char *ifname)
+ {
+@@ -103,9 +163,20 @@ wpa_driver_openbsd_init(void *ctx, const char *ifname)
+ if (drv->sock < 0)
+ goto fail;
+
++ drv->rtsock = socket(PF_ROUTE, SOCK_RAW, AF_UNSPEC);
++ if (drv->rtsock < 0)
++ goto fail;
++
+ drv->ctx = ctx;
+ os_strlcpy(drv->ifname, ifname, sizeof(drv->ifname));
+
++ drv->ifindex = if_nametoindex(drv->ifname);
++ if (drv->ifindex == 0) /* No interface with that name */
++ goto fail;
++
++ drv->nwid_len = wpa_driver_openbsd_get_ssid(drv, drv->nwid);
++
++ eloop_register_read_sock(drv->rtsock, wpa_driver_openbsd_event_receive,
NULL, drv);
+ return drv;
+
+ fail:
+@@ -119,7 +190,11 @@ wpa_driver_openbsd_deinit(void *priv)
+ {
+ struct openbsd_driver_data *drv = priv;
+
++ eloop_unregister_read_sock(drv->rtsock);
++
+ close(drv->sock);
++ close(drv->rtsock);
++
+ os_free(drv);
+ }
+
signature.asc
Description: PGP signature
