From: Michael Braun Date: Tue, 22 Aug 2017 15:02:48 +0000 (+0200) Subject: macsec_linux: Exit early when missing macsec kernel module X-Git-Tag: hostap_2_7~1115 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73b3de01cecdd1e0af5901e9a279eb8a468ca995;p=thirdparty%2Fhostap.git macsec_linux: Exit early when missing macsec kernel module Using driver macsec_linux makes no sense without macsec kernel module loaded. Signed-off-by: Michael Braun --- diff --git a/src/drivers/driver_macsec_linux.c b/src/drivers/driver_macsec_linux.c index 0694e6088..e89b3ba14 100644 --- a/src/drivers/driver_macsec_linux.c +++ b/src/drivers/driver_macsec_linux.c @@ -234,10 +234,44 @@ static void macsec_drv_wpa_deinit(void *priv) } +static int macsec_check_macsec(void) +{ + struct nl_sock *sk; + int err = -1; + + sk = nl_socket_alloc(); + if (!sk) { + wpa_printf(MSG_ERROR, DRV_PREFIX "failed to alloc genl socket"); + return -1; + } + + if (genl_connect(sk) < 0) { + wpa_printf(MSG_ERROR, + DRV_PREFIX "connection to genl socket failed"); + goto out_free; + } + + if (genl_ctrl_resolve(sk, "macsec") < 0) { + wpa_printf(MSG_ERROR, + DRV_PREFIX "genl resolve failed - macsec kernel module not present?"); + goto out_free; + } + + err = 0; + +out_free: + nl_socket_free(sk); + return err; +} + + static void * macsec_drv_wpa_init(void *ctx, const char *ifname) { struct macsec_drv_data *drv; + if (macsec_check_macsec() < 0) + return NULL; + drv = os_zalloc(sizeof(*drv)); if (!drv) return NULL;