From patchwork Fri Nov 15 22:00:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877364 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B821A1E0E0C for ; Fri, 15 Nov 2024 22:00:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708059; cv=none; b=O8qbJhyI8z0DAJydOmRBGGsqtXR6gVZnMYOOCe4O/q+WPgL4VuGEQgmB2iV+sE7C/yzO9MMRsSr3HWf1UZ38Ou5Gep5W+uR9e5Q+C/plY7JJ3GM3tJUv1dbzapDoyuWWW8z0VooCW8s80swtPzFVqnNa+wIrn7Ii0+LP+mUvFuY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708059; c=relaxed/simple; bh=2y3yf7W5FTQF4oAsUzgpFbw55n/dVLzxrntw8T01hLo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=IrllQ3x+PsVIw94WktFJPrRVVNJIqImtnP4zu76oR9LElQOsn/thPiQZWopAuU5hWtBH8A/aQ675m11L0SdpxSfcclY/oEAraAYojQJ3ry8Lzj1h/k0ygibkIOhxwv2Fv7Jnw8t7LtwGJUsn1eCkeMwfCE7Taxbxvtfh+yBBSlg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=mNfIbzgV; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="mNfIbzgV" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3e604425aa0so1267207b6e.0 for ; Fri, 15 Nov 2024 14:00:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708056; x=1732312856; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=76ipTuZs611cMa72IIm7uS2EmczVP9AEscq2U3NN+rk=; b=mNfIbzgV3GiOZhQhfuiPRJv67YgC765c7MKg2DbL4AjqKGPSMtFikR9GDPVF/gcFPw Jac4aIYQynWq3c3GWm3UJ+wwnCmlMiPIigsum5Yo2Et0GIfXm1duRWWzg/P0cTwJmvjR UWhmlPbuY6URvED2sYVpc4caQi1FQ+fP/ApVuJypQI8h+w/hdsmD7LrWQy4rR6sguary g6QgGn3VBX+5ZRDas7DB35EVB9rtZBQu562hlYHLJUa82M9MA1urZ7DMPeqAJHyogBlC l5aMRNVVHTjDiixa/FhSKtuSMH+4bvhyx/XxYF8PmS52MCIgXOoTlNw34a1iaZm1Wxxp +h8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708056; x=1732312856; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=76ipTuZs611cMa72IIm7uS2EmczVP9AEscq2U3NN+rk=; b=DY48Ol3PlQOgd0TOqz5RZHoWfBJy3wflRYDYwMFC9qU2UDU6lbJJBmkD2CKj3vmfQG 3r3zWdLudzdis8jow0ko0owDNZSqxV0jZEVhzjSOHWvsLrvFTvWWdkSYDr658ZMslmFF sBxWTY4OiIqu+8RG7ERWZb1IfD4kd4gR9Imo7y96irrIqm3cp/Q6zXyYgKsAmRz7qkXB s0VtOy7t2nknLsfCoZYTSyisQyd54FdHaIzjyg6J+dpo8t+eidrewCBbvW9OqJW6kjIx 6EVWc5/W5WOwIhblLfZB08tDd2pRHEuaDpsAzwKD69eeacNyjwmNnfZF9JmNmYg7wDXS wdCQ== X-Gm-Message-State: AOJu0YylLchWcovWGBj6cScCf5QXAUCGUZtWI932KGy+Ne8Ie4WqG29w 3icrlfWYtsZZVxq7RfTVp9P4PK1H0do7KPtkn3JwDF4poUjgY0nxMx16Uw== X-Google-Smtp-Source: AGHT+IGug2tYoh5ACxQH1BpitYfoEiZ5oAeOLY43cpy7gZlaEb1d18BrRePyTsqDGfRdV1O+b08Jvg== X-Received: by 2002:a05:6808:1449:b0:3e6:4f5b:afd1 with SMTP id 5614622812f47-3e7bc7a58c6mr4141333b6e.6.1731708056570; Fri, 15 Nov 2024 14:00:56 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.00.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:00:56 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 1/8] rmnet: Add skeleton Date: Fri, 15 Nov 2024 16:00:26 -0600 Message-ID: <20241115220053.49613-1-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add skeleton of the RMNet interface management module. Implement the basic API structure and register the module with oFono core. --- Makefile.am | 2 ++ src/rmnet.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/rmnet.h | 25 +++++++++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 src/rmnet.c create mode 100644 src/rmnet.h diff --git a/Makefile.am b/Makefile.am index d379201d362b..d107dc410fd2 100644 --- a/Makefile.am +++ b/Makefile.am @@ -353,6 +353,8 @@ builtin_sources += plugins/u8500.c endif if QMIMODEM +builtin_sources += src/rmnet.h src/rmnet.c + qmi_sources = drivers/qmimodem/qmi.h drivers/qmimodem/qmi.c \ drivers/qmimodem/ctl.h \ drivers/qmimodem/dms.h \ diff --git a/src/rmnet.c b/src/rmnet.c new file mode 100644 index 000000000000..58f841a49a59 --- /dev/null +++ b/src/rmnet.c @@ -0,0 +1,59 @@ +/* + * oFono - Open Source Telephony + * Copyright (C) 2024 Cruise, LLC + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include + +#include "ofono.h" +#include "rmnet.h" + +static struct l_netlink *rtnl; + +int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, + rmnet_new_interfaces_func_t cb, + void *user_data, rmnet_destroy_func_t destroy) +{ + return -ENOTSUP; +} + +int rmnet_del_interfaces(unsigned int n_interfaces, + const struct rmnet_ifinfo *interfaces) +{ + return -ENOTSUP; +} + +int rmnet_cancel(int id) +{ + return -ENOTSUP; +} + +static int rmnet_init(void) +{ + DBG(""); + + rtnl = l_netlink_new(NETLINK_ROUTE); + if (!rtnl) + return -EIO; + + return 0; +} + +static void rmnet_exit(void) +{ + l_netlink_destroy(rtnl); +} + +OFONO_MODULE(rmnet, rmnet_init, rmnet_exit) diff --git a/src/rmnet.h b/src/rmnet.h new file mode 100644 index 000000000000..dc416e0d5d51 --- /dev/null +++ b/src/rmnet.h @@ -0,0 +1,25 @@ +/* + * oFono - Open Source Telephony + * Copyright (C) 2024 Cruise, LLC + * + * SPDX-License-Identifier: LGPL-2.1-or-later + */ + +struct rmnet_ifinfo { + uint32_t ifindex; + uint16_t mux_id; + char ifname[IF_NAMESIZE]; +}; + +typedef void (*rmnet_new_interfaces_func_t)(int error, + unsigned int n_interfaces, + const struct rmnet_ifinfo *interfaces, + void *user_data); +typedef void (*rmnet_destroy_func_t)(void *user_data); + +int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, + rmnet_new_interfaces_func_t cb, + void *user_data, rmnet_destroy_func_t destroy); +int rmnet_del_interfaces(unsigned int n_interfaces, + const struct rmnet_ifinfo *interfaces); +int rmnet_cancel(int id); From patchwork Fri Nov 15 22:00:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877366 Received: from mail-oi1-f172.google.com (mail-oi1-f172.google.com [209.85.167.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BC04B1E1C1A for ; Fri, 15 Nov 2024 22:00:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.172 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708061; cv=none; b=ona90bPgloUN3Q/X/Pi+PJgjWoxRNXR/uZUqIOWHnn3evEqTSY6p8nmWUlUodwS+QO6PfCkz/dHArLMr47mWTpnhgpLhlzIWkvOxz0KaamsrOp3/KQ4GPh+KH0HUEeh/95hKf2wZsCnPYBaXxy91G87SUHjH/G//R6GVYRBfFmQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708061; c=relaxed/simple; bh=wbcKLV/018BZ9/D+Mvk0vpozH+SVVnAbvny9zGKhZh4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=C68+TJY/ihHU+NN8zHryDKxiWObuwutjWrQ9BoxV+bg6g6gp4qcwXfpiM+QxQ1OZnbuqgXzBzGR/kwLOWtNDzLT/V5C+I+jS4tm5PBeIFHgz04BLYyA1rxRwTCmc9DrepRIr/iK50oGMgvx7cFRXpappSgd2uX32U8Doo2u2zYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=d7d/jSrz; arc=none smtp.client-ip=209.85.167.172 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="d7d/jSrz" Received: by mail-oi1-f172.google.com with SMTP id 5614622812f47-3e60e57a322so1279536b6e.3 for ; Fri, 15 Nov 2024 14:00:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708057; x=1732312857; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=GP6czIhnJ5P0HljULdD+C+9TEwzs31YC5RIioRSmfn0=; b=d7d/jSrzSord5ihXSWLWwEFtlXZ5APLqt8ZU30nqYu3C4oovU5eNMQgaDGK6/ogKW6 c6JufYKnpqG9BNNq3rzouCgP32NhaonsimM0ICCLxT4wN2rq88u07rqp6xBwTNPLqK6G MBFzuvs9jc0MHLdjl31y0o6l6/AcPPNbOdrME4Xmvfexa2l5bFj6m4plAn+l2onS8CfR ru7qOVMh0b6jP5SPQrG+v0sLnKwA1PhWffGtGxMOJ2QA4gQnRhJEkNtaEOV+FQ7gMXoM FtnKDpccmE/+2O4Ri+A5rlWlfSKpnYieJ0BK56AIxJc/PqLFfE628PNa6iYqIHiXpitI FPxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708057; x=1732312857; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GP6czIhnJ5P0HljULdD+C+9TEwzs31YC5RIioRSmfn0=; b=op5m+trfhhKJPWm4TZ8JTfpQ+6mUhz32Az/ums7mDLtNaycbxIqPcQVOPodD3PKXN7 4Fmq/5dVOdk4hfaG7/l5xddfSF3bryuZYkMDbkYGrsh33EH/exRBa1w62xo2aYab7m9R c2N9pVm4xB5rJGgI0+5CZAciVMgclLDTG+BgBQOiTU27ez2yE38tbGqB16j/6VeOqAOA oLOYYNlqSEN9lw7+7UHpH3r8vVWPrjNcucZ7UmXET+UHFYVALSPiLkABVk0WBmwOb6/H O6GiUwUyoOrqjQQharWK9yMdcFtS8ooQ+gxaiP44uk6YLISc6gyZa75m05wFPXIUwTGZ +96A== X-Gm-Message-State: AOJu0YwpX9vhsbApO21luUg12WJXwhmqMeGeykr5IWgEltp7lrQmFGBr +uK7NMHm5spWlqlHF8EO31QaxNjNgsHAjefwm62i1wh20O60XxJwtgbe0Q== X-Google-Smtp-Source: AGHT+IFYcVEYjZKQLPHJZuzA1XREUymi4xymAehDq3hilAFj8GHX+05agb9zofImh4E8FPxWcJuCuw== X-Received: by 2002:a05:6808:1496:b0:3e6:cdc:2288 with SMTP id 5614622812f47-3e7bc85dc56mr5600553b6e.31.1731708057521; Fri, 15 Nov 2024 14:00:57 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.00.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:00:57 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 2/8] rmnet: Add logic to dump out RMNet interfaces Date: Fri, 15 Nov 2024 16:00:27 -0600 Message-ID: <20241115220053.49613-2-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 This logic is triggered at startup to dump RMNet only links. This is accomplished by using RTM_GETLINK dump with a filter based on IFLA_LINKINFO attribute setup for IFLA_INFO_KIND being "rmnet". For now, links are simply printed and not acted upon. --- src/rmnet.c | 162 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) diff --git a/src/rmnet.c b/src/rmnet.c index 58f841a49a59..52f47a03b27c 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -14,13 +14,19 @@ #include #include #include +#include +#include #include #include "ofono.h" #include "rmnet.h" +#define RMNET_TYPE "rmnet" +#define MAX_MUX_IDS 254U + static struct l_netlink *rtnl; +static uint32_t dump_id; int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb, @@ -40,15 +46,171 @@ int rmnet_cancel(int id) return -ENOTSUP; } +static int rmnet_parse_info_data(struct l_netlink_attr *linkinfo, + uint16_t *out_mux_id) +{ + struct l_netlink_attr info_data; + bool have_info_data = false; + uint16_t rta_type; + uint16_t rta_len; + const void *rta_data; + uint16_t mux_id; + + while (!l_netlink_attr_next(linkinfo, &rta_type, &rta_len, &rta_data)) { + switch (rta_type) { + case IFLA_INFO_KIND: + if (strncmp(rta_data, RMNET_TYPE, rta_len)) + return -EPROTOTYPE; + + break; + case IFLA_INFO_DATA: + if (l_netlink_attr_recurse(linkinfo, &info_data) < 0) + return -EBADMSG; + + have_info_data = true; + break; + } + } + + if (!have_info_data) + return -ENOENT; + + while (!l_netlink_attr_next(&info_data, + &rta_type, &rta_len, &rta_data)) { + if (rta_type != IFLA_RMNET_MUX_ID) + continue; + + if (rta_len != sizeof(uint16_t)) + return -EBADMSG; + + mux_id = l_get_u16(rta_data); + if (mux_id > MAX_MUX_IDS || !mux_id) + return -ERANGE; + + if (out_mux_id) + *out_mux_id = mux_id; + + return 0; + } + + return -ENOENT; +} + +static int rmnet_parse_link(const void *data, uint32_t len, + char *out_ifname, + uint32_t *out_ifindex, + uint16_t *out_mux_id) +{ + const struct ifaddrmsg *ifa = data; + struct l_netlink_attr attr; + struct l_netlink_attr linkinfo; + bool have_linkinfo = false; + const char *ifname = NULL; + uint16_t ifnamelen = 0; + uint16_t rta_type; + uint16_t rta_len; + const void *rta_data; + int r; + + if (l_netlink_attr_init(&attr, sizeof(struct ifinfomsg), + data, len) < 0) + return -EBADMSG; + + while (!l_netlink_attr_next(&attr, &rta_type, &rta_len, &rta_data)) { + switch (rta_type) { + case IFLA_IFNAME: + ifname = rta_data; + ifnamelen = rta_len; + break; + case IFLA_LINKINFO: + if (l_netlink_attr_recurse(&attr, &linkinfo) < 0) + return -EBADMSG; + + have_linkinfo = true; + break; + } + } + + if (!have_linkinfo || !ifname || !ifnamelen) + return -ENOENT; + + r = rmnet_parse_info_data(&linkinfo, out_mux_id); + if (r < 0) + return r; + + if (out_ifname) + l_strlcpy(out_ifname, ifname, MIN(ifnamelen + 1, IF_NAMESIZE)); + + if (out_ifindex) + *out_ifindex = ifa->ifa_index; + + return 0; +} + +static void rmnet_link_dump_destroy(void *user_data) +{ + dump_id = 0; +} + +static void rmnet_link_dump_cb(int error, + uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + struct rmnet_ifinfo info; + + /* Check conditions that can't happen on a dump */ + if (error || type != RTM_NEWLINK) + return; + + if (rmnet_parse_link(data, len, + info.ifname, &info.ifindex, &info.mux_id) < 0) + return; + + DBG("Existing rmnet link: %s(%u) mux_id: %u", + info.ifname, info.ifindex, info.mux_id); +} + +static int rmnet_link_dump() +{ + struct ifinfomsg ifi; + struct l_netlink_message *nlm = + l_netlink_message_new_sized(RTM_GETLINK, NLM_F_DUMP, + sizeof(ifi)); + + memset(&ifi, 0, sizeof(ifi)); + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); + + l_netlink_message_enter_nested(nlm, IFLA_LINKINFO); + l_netlink_message_append_string(nlm, IFLA_INFO_KIND, RMNET_TYPE); + l_netlink_message_leave_nested(nlm); + + dump_id = l_netlink_send(rtnl, nlm, rmnet_link_dump_cb, NULL, + rmnet_link_dump_destroy); + if (dump_id > 0) + return 0; + + l_netlink_message_unref(nlm); + return -EIO; +} + static int rmnet_init(void) { + int r; + DBG(""); rtnl = l_netlink_new(NETLINK_ROUTE); if (!rtnl) return -EIO; + r = rmnet_link_dump(); + if (r < 0) + goto dump_failed; + return 0; +dump_failed: + l_netlink_destroy(rtnl); + return r; } static void rmnet_exit(void) From patchwork Fri Nov 15 22:00:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877365 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 938BD1E0E0C for ; Fri, 15 Nov 2024 22:00:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708061; cv=none; b=u4woBLOhb5bnvOQUGLKkGTjnEsjy9y1FS8YDM0oJwQsKxh5RX+b/1QIu30ZLN5EBYS8WRMYmrZMzb5hntBpOXrWo0QVOJUvDZmqEWYxZ7dqfGdTZgrJOUE7J79EmKr8u/naQJKevLmyvBxXZ+OJaeN98hRKRYm7Z/+SRsNEtueE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708061; c=relaxed/simple; bh=nyhI5sQ0RPl/B5rbF0HJ/gy3SZNMo9HzP6gx0KzpX5M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Q8oVMIhjtho7aqtY92XjlN6vvusulmzTq3SJ/dpd7/zDaxSqA6Wy24budG2fHgDgUfDNwb03sL6OUPOjvbtZUN+3wFPY54EHLod3YcWUQI0L1K9oUH0pRgL7a95hgqPywp7ZS4fRs9wzmmMNzJczQK3HwQWPi27tFtk6f+uN1QI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=IRnPpuhm; arc=none smtp.client-ip=209.85.167.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="IRnPpuhm" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-3e5f533e1c2so1235353b6e.3 for ; Fri, 15 Nov 2024 14:00:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708058; x=1732312858; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=biw1u32cDJnxKZA/EHCGpJKcvcrOQqu+ff0P0WJZsEg=; b=IRnPpuhmbj/lEqGw5CqcfHCcZx7rBHMi3adPqrGcfYbAJjMeuAJsh3PkilxeLWyhDP Ua6Lbi4CfO5dfmsDwUgVDgxIYFaPQzdx845zaqlQBIYoJQNMdUvpnHUbfSGWUjXQle+m eTqQ5fh5GfluL+UO49pNSpfLPrWn/Sm2Agoi00X8VGZ84vylvlD1wNxyiYav43g3Git8 7du/UYBP4c4i1JC7q5iC5R46shGDV4nMcWfFzP+INUiYQawE1RHJSwH7M/s68GH224nD h8pX/9Egl9WumiivIojtqCFVgYdd82xo1KTNCus1jfZ9zV+0lmk60HHVhyQxKIdZzTYC zR5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708058; x=1732312858; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=biw1u32cDJnxKZA/EHCGpJKcvcrOQqu+ff0P0WJZsEg=; b=AoZXVewDthy95gGsly4y7DVxPj69JEjgPUF+R4/Z6rGNVII3Rx2jQ5SO5xzXKadDyR ngIxfG9BS6JMzuslXL9V6OElJ6ZRV1LEueyikHe3yZTapeFF2e+gHRIcgxTIJu7bCJLo ReujB/Kn5LJfJWifQ0zcpLHo++XZ/J86zmNjnuaPZtG1Bgav/2+wgl/6MXtY3a+wxQ+v IuQRpZvKv+3lL24X5glNU31qGURyQUsdVH4XBkuGk6I5nXfBbV/aVdojxhDmnvqPJTKi wHkOUXi228gC12jGTtAv0yHmr80HFCU1u4sK2/NZlycWy4mC7MG7JOksQT7HgR7a/HL+ Z2zw== X-Gm-Message-State: AOJu0YyOoaasNqX4e0s++PRvs/nlGXs/7CakOjmIPfbqIP3q3fazppu4 DkjwfH186Z6nvWrA274bIbxV+Wxy2lYeuzCTieJ30bZ5fsdNfS84nSqjsw== X-Google-Smtp-Source: AGHT+IGCrVtK4L7PTDirdTYJXvfxtKn9rohQ4Tk4LMv0qFVHHzlJem3sttI9iHQ9UAEHLTVL5/A5jQ== X-Received: by 2002:a05:6808:1520:b0:3e3:e713:b293 with SMTP id 5614622812f47-3e7bc7c6a4cmr4167628b6e.16.1731708058501; Fri, 15 Nov 2024 14:00:58 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.00.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:00:58 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 3/8] rmnet: Track link notifications Date: Fri, 15 Nov 2024 16:00:28 -0600 Message-ID: <20241115220053.49613-3-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Track link notifications that arrive via RTM_NEWLINK and RTM_DELLINK. This will be used in the future to try to de-conflict use of RMNet mux_ids that might have been (unlikely) created by other processes. --- src/rmnet.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/rmnet.c b/src/rmnet.c index 52f47a03b27c..920525006e0a 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -27,6 +27,7 @@ static struct l_netlink *rtnl; static uint32_t dump_id; +static uint32_t link_notify_id; int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb, @@ -193,6 +194,23 @@ static int rmnet_link_dump() return -EIO; } +static void rmnet_link_notification(uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + char ifname[IF_NAMESIZE]; + uint16_t mux_id; + uint32_t ifindex; + + if (type != RTM_NEWLINK && type != RTM_DELLINK) + return; + + if (rmnet_parse_link(data, len, ifname, &ifindex, &mux_id) < 0) + return; + + DBG("link_notification: %s(%u) with mux_id: %u", + ifname, ifindex, mux_id); +} + static int rmnet_init(void) { int r; @@ -207,6 +225,9 @@ static int rmnet_init(void) if (r < 0) goto dump_failed; + link_notify_id = l_netlink_register(rtnl, RTNLGRP_LINK, + rmnet_link_notification, NULL, NULL); + return 0; dump_failed: l_netlink_destroy(rtnl); @@ -215,6 +236,7 @@ dump_failed: static void rmnet_exit(void) { + l_netlink_unregister(rtnl, link_notify_id); l_netlink_destroy(rtnl); } From patchwork Fri Nov 15 22:00:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877367 Received: from mail-oi1-f176.google.com (mail-oi1-f176.google.com [209.85.167.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 533891E1C2F for ; Fri, 15 Nov 2024 22:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708062; cv=none; b=OJ6Jvy8EXLuRBArDI3SkK8CZQNzTa1dmuQk8V3mIt2eFahomShcBsii026PqGi+iQ8aVqUv9vnqCqQJmCSHRHOmzeRPEfb7OshDvlez6qYGdd7fY3lCwVSuY1rgKxp3mq/Zn/dHjMurcRmBtbyqwuQIfmI3JCD6ZBvcHvbysopQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708062; c=relaxed/simple; bh=8X50KO9dgv+6wBLlul3LmCGeoxqGPpBqxrutVDFmY7k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=vC9ggfvgnnnabQpmNe2VbQjLTGEFV6KnJlvw4zCr61T0JXroS0HF+DZSg/2LsjPRve9dH1F1zY32l3T+0z/0drhWCkkZA9nPi8CKeD9wuXlNme4csY2dbZIa4XmQ6oATrfV57M6B3wT+JwWqN5U90owBGLq/Ukmz5ehPF04C9LQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=F/GK0Lwj; arc=none smtp.client-ip=209.85.167.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="F/GK0Lwj" Received: by mail-oi1-f176.google.com with SMTP id 5614622812f47-3e600ae1664so1139864b6e.2 for ; Fri, 15 Nov 2024 14:01:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708059; x=1732312859; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PsLG7UOstf+by9gur4AzUthrycYxuv+711sgoD+Ncpo=; b=F/GK0Lwj9sdyCO6dJX9T5OFWlWTCyVoAuviTi+X7FhmHumft3fzGb49Ue+/BfDQzFO /IA48GZ9IuPG/U9p0DzbSp6dDni/OhKucAc3FLfJ14+r7lkWxBg5DoXthlBGdtVgLe/K cPS59dWcoAd0AIco9J+JC9yfAQFXC+4k2ENEZyrenp5T3RU1RkneOqznLn/ZN1I3coQM v3m3ZAKzCUO6umAxdYXS/BEEqA5j1nMHAwTrjYEZSYDaqXpZN2700LRuxX1BVhV5No5M h45P7b9l3krgayGKGIMkA3cF+shtYhND+/ShXciynw2RxJK28fGSpFBvFsDTu7cxoPqM GpSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708059; x=1732312859; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PsLG7UOstf+by9gur4AzUthrycYxuv+711sgoD+Ncpo=; b=dFhy0gygGXo+r01Y193etbm27QMjjDU+pO5ZD4Qa14bb8fMbZlrJjP0vWWvfQv4PmJ lTa+8frVTAmBkU0ybqUuU/+/xjr8AdHu4uhPVJ4gvl5KWe4vvLqpRbu78uyBTYHebP4G sDHt5hcP4bu2znFA7/rmp1LXvHGmKvxoID9r5IMqmmdZnsjgSUgRWreyW7nwjnQdlch6 /4lSY514rg0W4H2YMPRHJRLAe8MbH+K+dYCEmQMJFFrqT6VLkfJZDES34Oh06akMlaap vy94D1yEkvP2nIl7ZsxPa4hYL+ZrS578xOyzubB0meV8eapt11BUsiDaEeC/+7ERKikH QYTA== X-Gm-Message-State: AOJu0YxJ1d3zSktcUZtuISnVGe16BlEodWcGyQQDVkQpAR0VI7mKNgmy Quxa6/PoJIcVnY+nnvDfgw0wiWsdEoL5AewHyeQj2zIHcwxOi3fIps4Dhw== X-Google-Smtp-Source: AGHT+IFgZTlqslw00jUweut8wECvdF2dxNlxJKdUI+Ad2OWjGjXLqIZALMYmCShZktMk2Rr16+Xzqg== X-Received: by 2002:a05:6808:13c6:b0:3e6:134e:3b90 with SMTP id 5614622812f47-3e7bc854642mr4579371b6e.30.1731708059334; Fri, 15 Nov 2024 14:00:59 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.00.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:00:59 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 4/8] rmnet: Track used mux ids Date: Fri, 15 Nov 2024 16:00:29 -0600 Message-ID: <20241115220053.49613-4-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Track used mux identifiers. This uintset can later be used to allocate unused mux identifiers. --- src/rmnet.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/rmnet.c b/src/rmnet.c index 920525006e0a..f784e5cc4bb2 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -28,6 +28,7 @@ static struct l_netlink *rtnl; static uint32_t dump_id; static uint32_t link_notify_id; +static struct l_uintset *mux_ids; int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb, @@ -169,6 +170,7 @@ static void rmnet_link_dump_cb(int error, DBG("Existing rmnet link: %s(%u) mux_id: %u", info.ifname, info.ifindex, info.mux_id); + l_uintset_put(mux_ids, info.mux_id); } static int rmnet_link_dump() @@ -207,6 +209,11 @@ static void rmnet_link_notification(uint16_t type, const void *data, if (rmnet_parse_link(data, len, ifname, &ifindex, &mux_id) < 0) return; + if (type == RTM_NEWLINK) + l_uintset_put(mux_ids, mux_id); + else + l_uintset_take(mux_ids, mux_id); + DBG("link_notification: %s(%u) with mux_id: %u", ifname, ifindex, mux_id); } @@ -227,6 +234,7 @@ static int rmnet_init(void) link_notify_id = l_netlink_register(rtnl, RTNLGRP_LINK, rmnet_link_notification, NULL, NULL); + mux_ids = l_uintset_new_from_range(1, MAX_MUX_IDS); return 0; dump_failed: @@ -236,6 +244,7 @@ dump_failed: static void rmnet_exit(void) { + l_uintset_free(mux_ids); l_netlink_unregister(rtnl, link_notify_id); l_netlink_destroy(rtnl); } From patchwork Fri Nov 15 22:00:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877368 Received: from mail-oi1-f181.google.com (mail-oi1-f181.google.com [209.85.167.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52EA61E0E0C for ; Fri, 15 Nov 2024 22:01:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708062; cv=none; b=jAeTrzL/weCaaUYeRToVE5bktjxwPoi2hfuUThFdxXHA5vR4WMDWs+LqeSEiyWDmrKZVmS15faryDaNR5QT33o3oI4qVaBwBEpeIVDoBFE+LTq2+xpymhhTL0ZVc0WPPpDRslTrqzeOQIhs33EQzh/7ouqldauInARWH4WFteqI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708062; c=relaxed/simple; bh=x9VBbmJBxjMr69p1fANWE89ficpFFP7PaAODDhjBeWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=slkBCz2iK5rG1+r4Nm1qRKCy/swOc4LfgrHWickpdAPdwnI7P8/XtISpxwg4OSVdYPAPk5Jh5tb7sl9OQNoY3IuUPXuj/Vjwpnofw7v1yXd2uUnBhgyKcaPSmp/0sR4ZmMEbUeZPw3ud0NF/wro1KlqVxXufzhb2lF9RaEPphUs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iIht1lCb; arc=none smtp.client-ip=209.85.167.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iIht1lCb" Received: by mail-oi1-f181.google.com with SMTP id 5614622812f47-3e602a73ba1so710691b6e.2 for ; Fri, 15 Nov 2024 14:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708060; x=1732312860; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xUL0Kx++Pj9Tfylq5J60SQMHiOefPlFV+N1FQtLLg+s=; b=iIht1lCbj4cyUzhL+T27QEQYMGcxBXtyF58H78Qoqm6GorMDcP05W/HoakYH3swTbl zJHi6/bSDEs0Xxs6i+e9bFeWlLA+/Pb6OEsX28vPdGCwtH4lCZAHIrRtoywq1CrzWlqJ gL8qdTIErYTVmUQTHMounT2oxt6A9IyZBKInSg1PblHJKgC3V0pQwod4Uqb3sB6pJVFg fSsJ0rGdJITiPCv1oGNwsX5U1WxR82PGGPeNQq2qqqYxXbreVMfUn4LD95Icgk+o4jq6 hHMS6j15XWNIDIuIrh2OsCCm27jd09X/ZFpblfffNxNkXVl3M4RpxKDZ7RkXp7OJAKUJ E+3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708060; x=1732312860; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xUL0Kx++Pj9Tfylq5J60SQMHiOefPlFV+N1FQtLLg+s=; b=KR/HO9o9+SGRgXdlYqucveNeo75QsvrJ3vukZi9a//fVdvSYKYmOKsJm1Il9rACHH3 cxN1hTyxj3WcXGsG6hrR0yTT346xiZpPfByMiSp8rk1cTU+KRe2i3fruNDN4FAjgtvfB mcQ3OtKkuDcbanFmOFOFIUx4xqasrTsd81LIRqRcz0Eo1Wl/6T1XU4K6+eNVk0jRX9uv mCoKGpTCvFleSWtVUddSgcXO9QFasJzDL3wcIzSnF25DSqx1r3j1ogyFYrqmXajbO9qu n9mI0edwf2vZ9Dy2nERI54qGBbSE65ZatXN0UzNDd5UXGBcVKIfuFy0MfbCHfWD7l3oi O4GA== X-Gm-Message-State: AOJu0Yztoyqx+IWbvdCm34LyHIODrZNfL3MFsQ4di7Ri5sqo070KdWw1 2uZFjQ60ffG+ajlCMDssl8zQwjs8BhGbA1R2EYGSYD/lssloxdR6wa/axg== X-Google-Smtp-Source: AGHT+IFgffhKxbaONWidKgGV5qf5Fl32tVqSLnJKjLb2JWrqXj+3QRUdQKRjB+/IbfbuLMHVNyC4PA== X-Received: by 2002:a54:4602:0:b0:3e7:bcab:8f0b with SMTP id 5614622812f47-3e7bcab8f8cmr3872788b6e.24.1731708060234; Fri, 15 Nov 2024 14:01:00 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.00.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:00:59 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 5/8] rmnet: Delete stale RMnet links at startup Date: Fri, 15 Nov 2024 16:00:30 -0600 Message-ID: <20241115220053.49613-5-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Most likely such links could be left over from ofono not exiting cleanly. There's unfortunately no easy way to mark links as belonging to a particular process, so remove all of them. --- src/rmnet.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 118 insertions(+), 1 deletion(-) diff --git a/src/rmnet.c b/src/rmnet.c index f784e5cc4bb2..bb5a2ed1805b 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -25,10 +25,118 @@ #define RMNET_TYPE "rmnet" #define MAX_MUX_IDS 254U +struct rmnet_request { + uint32_t parent_ifindex; + rmnet_new_interfaces_func_t new_cb; + void *user_data; + rmnet_destroy_func_t destroy; + int id; + uint32_t netlink_id; + uint16_t request_type; + uint8_t current; + uint8_t n_interfaces; + struct rmnet_ifinfo infos[]; +}; + static struct l_netlink *rtnl; static uint32_t dump_id; static uint32_t link_notify_id; static struct l_uintset *mux_ids; +struct l_queue *request_q; + +static void rmnet_request_free(struct rmnet_request *req) +{ + if (req->destroy) + req->destroy(req->user_data); + + l_free(req); +} + +static struct rmnet_request *__rmnet_del_request_new(unsigned int n_interfaces, + const struct rmnet_ifinfo *interfaces) +{ + struct rmnet_request *req; + + req = l_malloc(sizeof(struct rmnet_request) + + sizeof(struct rmnet_ifinfo) * n_interfaces); + memset(req, 0, sizeof(struct rmnet_request)); + req->request_type = RTM_DELLINK; + req->n_interfaces = n_interfaces; + memcpy(req->infos, interfaces, + sizeof(struct rmnet_ifinfo) * n_interfaces); + + return req; +} + +static int rmnet_link_del(uint32_t ifindex, l_netlink_command_func_t cb, + void *userdata, l_netlink_destroy_func_t destroy, + uint32_t *out_command_id) +{ + struct l_netlink_message *nlm = + l_netlink_message_new(RTM_DELLINK, 0); + struct ifinfomsg ifi; + uint32_t id; + + memset(&ifi, 0, sizeof(ifi)); + ifi.ifi_family = AF_UNSPEC; + ifi.ifi_index = ifindex; + + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); + + id = l_netlink_send(rtnl, nlm, cb, userdata, destroy); + if (!id) { + l_netlink_message_unref(nlm); + return -EIO; + } + + if (out_command_id) + *out_command_id = id; + + return 0; +} + +static void rmnet_start_next_request(); + +static void rmnet_del_link_cb(int error, uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + struct rmnet_request *req = l_queue_peek_head(request_q); + + DBG("DELLINK %u (%u/%u) complete, error: %d", + req->netlink_id, req->current, req->n_interfaces, error); + + req->netlink_id = 0; + req->current += 1; + + if (req->current < req->n_interfaces) + goto next_request; + + l_queue_pop_head(request_q); + rmnet_request_free(req); + +next_request: + if (l_queue_length(request_q) > 0) + rmnet_start_next_request(); +} + +static void rmnet_start_next_request() +{ + struct rmnet_request *req = l_queue_peek_head(request_q); + + if (!req) + return; + + if (req->request_type == RTM_DELLINK) { + uint32_t ifindex = req->infos[req->current].ifindex; + + L_WARN_ON(rmnet_link_del(ifindex, rmnet_del_link_cb, NULL, NULL, + &req->netlink_id) < 0); + DBG("Start DELLINK: ifindex: %u, interface: %u/%u, request: %u", + ifindex, req->current, + req->n_interfaces, req->netlink_id); + return; + } +} int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb, @@ -152,6 +260,9 @@ static int rmnet_parse_link(const void *data, uint32_t len, static void rmnet_link_dump_destroy(void *user_data) { dump_id = 0; + + if (l_queue_length(request_q) > 0) + rmnet_start_next_request(); } static void rmnet_link_dump_cb(int error, @@ -159,6 +270,7 @@ static void rmnet_link_dump_cb(int error, uint32_t len, void *user_data) { struct rmnet_ifinfo info; + struct rmnet_request *req; /* Check conditions that can't happen on a dump */ if (error || type != RTM_NEWLINK) @@ -168,9 +280,12 @@ static void rmnet_link_dump_cb(int error, info.ifname, &info.ifindex, &info.mux_id) < 0) return; - DBG("Existing rmnet link: %s(%u) mux_id: %u", + DBG("Removing existing rmnet link: %s(%u) mux_id: %u", info.ifname, info.ifindex, info.mux_id); l_uintset_put(mux_ids, info.mux_id); + + req = __rmnet_del_request_new(1, &info); + l_queue_push_tail(request_q, req); } static int rmnet_link_dump() @@ -235,6 +350,7 @@ static int rmnet_init(void) link_notify_id = l_netlink_register(rtnl, RTNLGRP_LINK, rmnet_link_notification, NULL, NULL); mux_ids = l_uintset_new_from_range(1, MAX_MUX_IDS); + request_q = l_queue_new(); return 0; dump_failed: @@ -244,6 +360,7 @@ dump_failed: static void rmnet_exit(void) { + l_queue_destroy(request_q, (l_queue_destroy_func_t) rmnet_request_free); l_uintset_free(mux_ids); l_netlink_unregister(rtnl, link_notify_id); l_netlink_destroy(rtnl); From patchwork Fri Nov 15 22:00:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877369 Received: from mail-oi1-f177.google.com (mail-oi1-f177.google.com [209.85.167.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3925A1E1C1A for ; Fri, 15 Nov 2024 22:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708063; cv=none; b=e1lfDlacmJRLiLjQsq4t/vddlHX9fH+irp3vQ7WszErD2RH2XBFgYqEAkjfXlJ/s3Ox/FuDW8UwyA8V+EfGJTMkAzo0Rl1L8UeQUJUvOiSryNq57n8dIpgLT1Alb1UemRlcWZf4cz09IjLzDSbRozlmG5Tn1sFciaYs3gXABruA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708063; c=relaxed/simple; bh=XLkDfsX54R83PpWwRmQtTiozCKyGizqRYHOx9bAu3jU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EG9+tUuCEn1CSgJ+vF2e2NpLfecaR937WcYisMD1X26ZW8PCdfAq1SE0wthSyrqEqZRkuSiWgbncqo4hEmRB5fj0n46NjXVTLjAtVyrJ7auyp2UOkTxWx/qEHWP/j5gSB4MR8pSnglX8tNsHKAOqfRpfE0fQYT0ojbMdqsMM5xQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=fw8XP6eN; arc=none smtp.client-ip=209.85.167.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="fw8XP6eN" Received: by mail-oi1-f177.google.com with SMTP id 5614622812f47-3e5f9712991so24150b6e.2 for ; Fri, 15 Nov 2024 14:01:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708061; x=1732312861; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZyzOvrgRQIhS+tgoHq5dG+t4fKGIbjJdAWECxCkHaDU=; b=fw8XP6eNurDnKLYeqLDpas4OIyYyhdq51qsZV+YhLePbAawOWACBUQiUza7B/biJXC qHspsawYa3D/XlbQ8plCYlRLRT+yWEPW6aW1RVvJgzYkLI/jh1w7ticlRy/hUCan2OmA EZdaSwuMtAAa0BYYd0ZGHmfLdWgVVYfUTI6ndhisPkRAQo2CbidwjMOirRzoSapE4y8K BWj/7wvrlfjzq14USyYBY/LkuY8ewqk9+YX9eHgN9SownvxMihKEiEQ1lcfJB122AOYC o+rN5o9wxJHgZuOXqssVFF41jD7U5T/6IxW8KZDaoiHCDRTtPKxKNTXT55HBIumN7InK Yc/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708061; x=1732312861; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZyzOvrgRQIhS+tgoHq5dG+t4fKGIbjJdAWECxCkHaDU=; b=hmgm8HK54S5tGYjcqLC7dxtiXYDOlMnDnPKJUgUsh2rUElgynlufGLilnpDdCfS2mV 56xlWJTBpxAoym/f9wXvny55P63QGXl1dVIrGR7wCULqojRKeHf4uRLmZ7ahZuAmKhXw tg9ITXJo4tn9iNPEwoPO+HQH2+4Uh7w9nttreJRclsasX10OeyCRTck8Qa771fa56emQ pFF7Gv348fSD1FBI9mQQ0VIodNuOMUFJwVgvXM0DcUGXOZGoS7c5Axl1e/xt1AMIhl1G 15aAEjQr5fNIzloRFL0F2HobaU5Wcn8eXPlrA6ykaxn8fmIJDaGmGHoqCzlCJ8DYGVly L9pQ== X-Gm-Message-State: AOJu0Yywn4bjNQuHAV9OISxEWvdhF5WP0/71/JOcRflaRxj/i80dobLv 12HawaHMWDNDGMeRlNAo04MeOc0zE2Uxkx4B8I3gxJTdKZGi9pvFo70sTA== X-Google-Smtp-Source: AGHT+IF5A6zNxUv+A0httsijLNGPm1ttZFFWB4LxdMDu4hb2Hu6eTGA4ExOKg/UKKFKR53VV5vsSng== X-Received: by 2002:a05:6808:3094:b0:3e6:5f1d:411a with SMTP id 5614622812f47-3e7bc865a3bmr5918484b6e.31.1731708061223; Fri, 15 Nov 2024 14:01:01 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.01.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:01:00 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 6/8] rmnet: Implement rmnet_del_interfaces Date: Fri, 15 Nov 2024 16:00:31 -0600 Message-ID: <20241115220053.49613-6-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add implementation for rmnet_del_interfaces. This method will remove the interfaces based on the passed in struct rmnet_ifinfo array. --- src/rmnet.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/rmnet.c b/src/rmnet.c index bb5a2ed1805b..ed2fc6bcfdfd 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -148,7 +148,18 @@ int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, int rmnet_del_interfaces(unsigned int n_interfaces, const struct rmnet_ifinfo *interfaces) { - return -ENOTSUP; + struct rmnet_request *req; + + if (!n_interfaces || n_interfaces > MAX_MUX_IDS) + return -EINVAL; + + req = __rmnet_del_request_new(n_interfaces, interfaces); + l_queue_push_tail(request_q, req); + + if (l_queue_length(request_q) == 1 && !dump_id) + rmnet_start_next_request(); + + return 0; } int rmnet_cancel(int id) From patchwork Fri Nov 15 22:00:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877370 Received: from mail-oi1-f169.google.com (mail-oi1-f169.google.com [209.85.167.169]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0AD571FAC57 for ; Fri, 15 Nov 2024 22:01:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708064; cv=none; b=f5YLCu+4uWvKUlJL/o1EOvFyBIeNnxYLBMg02VB1keql7AIuNrWvvEBK4oj6e2RqHhWxPAjIljA7W3WGADIQ+SMNZd977bpmGNzNSzQrXicg3eaX+VGa71MNapFNrgBxTlYc/29CrUhopdreyMuagOYfuWxYHwPYSCyDAhXufd4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708064; c=relaxed/simple; bh=kSdoFCvRzXJbMLUgkuK4dyuuiNLeT7O23qGOYDVpynA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AxBN2q3wwnV3JwzhpfcsKJRxQ8hb5QVlwDrKeC9gg35LmxvQAOKoeyFX6pR+DpCxXofAtIsNaHt8A9bmQGhLPXdZM6uDwEhTaafkXAMVhfm6GNpf2iBECUT36tuSjkQPcHNtHnBmDeQ5+I2FTGivkFQZ2LItCpXLLX+Fr6QURVE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=b+kDg4nB; arc=none smtp.client-ip=209.85.167.169 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="b+kDg4nB" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3e6005781c0so1259193b6e.3 for ; Fri, 15 Nov 2024 14:01:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708062; x=1732312862; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=355cQRWSPtDUmYLFtUtJsbcKqU4be5VTXENQGfFIUYA=; b=b+kDg4nBMdIJni9GoBx0ZvRIuxWAVzQNInGtLAyzjFc7EwQ/OtVYc6SWnP9aRa75qX 4lLqztvojlLXBEd9XBrxNt8MQow5qfiZeJbpf8NNBNG0bVO7e/cGSOgAumeEO39vAQ75 /dw83AfzwMuJQV1HOowwT5SeSLYKfegc39ZRAT6JAFzTG+DZ7WNAMxEYTKdEoq1/5PJL H0u4DnaZIrh/F5j3WEfZbC00AdBFoXSRjMzr5CjkkWhYYaUMqirpo0nnLF3+hrhY2542 LPLefi4quhqH7qA9jicb5H/aRcRW1pSuh5L9sbOz7dfO78N7MwjoPnhZzrNugLx/fzPy DRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708062; x=1732312862; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=355cQRWSPtDUmYLFtUtJsbcKqU4be5VTXENQGfFIUYA=; b=hhkE/EsVMOLVJIGDVu6ZS8eIFgXqxshfbcDZykfklzyALXE96OObSXA+7agZU+xIUK 9VnTL9dtms8WBAuQmsbwJroXPaSu+QO8iz84lQ343L+zJAw7K3Ic5mGIvidxNwUjvVRO n+WxvqJ/RNgHDr4svLuWCfBSYzaLdt6uq8dzNGV+ZH5/oTN1IGZIS7b+gy4ve6uKo9mi vDwD3hJBm69ZO4XXGtVusv9uCh4sojJARs2k5JhjiuZMqaZy5Ln+Nm9np5ToMFjK0vE0 fWvZ02MY9AfjegUVzLnz+4emOEQmQrTTG4FxWljxCqptzjxWlXrZVWQZYOaNTGDf1ooJ yl9g== X-Gm-Message-State: AOJu0YyJDeQVxwX1RgpRRLq7RkP/X8Z3JjvY/Ab6wKuAdD8iYwk7H81Z 8XmGppomksoCyn5k2mPv+Rx1lsoOuA7hvOZpajSNCZ74CQvIUJxjmtgKoQ== X-Google-Smtp-Source: AGHT+IGrLIqF3Dpy97cdyQIJOqntz11ozlmYF7JmEPHi3r9MdAh0R4yrAMbRMsx+OdEllyzytprR0g== X-Received: by 2002:a05:6808:14cc:b0:3e6:6203:fb5e with SMTP id 5614622812f47-3e7bc79ceb3mr4765878b6e.2.1731708062093; Fri, 15 Nov 2024 14:01:02 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.01.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:01:01 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 7/8] rmnet: Implement getting new interfaces Date: Fri, 15 Nov 2024 16:00:32 -0600 Message-ID: <20241115220053.49613-7-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add method to create N rmnet interfaces for use by the gobi driver. The rmnet interfaces are created in sequence, which should result in sequential mux ids and interface names to be created (assuming no other process creates rmnet interfaces in the background). For now we hardcode the use of QMAPv5 as the aggregation protocol using EGRESS_MAP_CHKSUMV5 and INGRESS_MAP_CHKSUMV5. Support for QMAPv4 or QMAP is also possible in the future, but no devices are currently available for testing. --- src/rmnet.c | 164 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 161 insertions(+), 3 deletions(-) diff --git a/src/rmnet.c b/src/rmnet.c index ed2fc6bcfdfd..4a921b330b72 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -43,6 +44,7 @@ static uint32_t dump_id; static uint32_t link_notify_id; static struct l_uintset *mux_ids; struct l_queue *request_q; +static int next_request_id = 1; static void rmnet_request_free(struct rmnet_request *req) { @@ -95,6 +97,57 @@ static int rmnet_link_del(uint32_t ifindex, l_netlink_command_func_t cb, return 0; } +static int rmnet_link_new(uint32_t parent_ifindex, uint8_t mux_id, + const char ifname[static IF_NAMESIZE], + l_netlink_command_func_t cb, + void *userdata, + l_netlink_destroy_func_t destroy, + uint32_t *out_command_id) +{ + struct ifinfomsg ifi; + struct l_netlink_message *nlm = + l_netlink_message_new(RTM_NEWLINK, NLM_F_EXCL | NLM_F_CREATE); + struct ifla_rmnet_flags flags; + uint32_t id; + + memset(&ifi, 0, sizeof(ifi)); + ifi.ifi_family = AF_UNSPEC; + ifi.ifi_type = ARPHRD_RAWIP; + ifi.ifi_flags = 0; + ifi.ifi_change = 0xFFFFFFFF; + + l_netlink_message_add_header(nlm, &ifi, sizeof(ifi)); + l_netlink_message_append_u32(nlm, IFLA_LINK, parent_ifindex); + l_netlink_message_append_string(nlm, IFLA_IFNAME, ifname); + + l_netlink_message_enter_nested(nlm, IFLA_LINKINFO); + l_netlink_message_append_string(nlm, IFLA_INFO_KIND, RMNET_TYPE); + l_netlink_message_enter_nested(nlm, IFLA_INFO_DATA); + l_netlink_message_append_u16(nlm, IFLA_RMNET_MUX_ID, mux_id); + flags.flags = RMNET_FLAGS_INGRESS_DEAGGREGATION | + RMNET_FLAGS_INGRESS_MAP_CKSUMV5 | + RMNET_FLAGS_EGRESS_MAP_CKSUMV5; + flags.mask = RMNET_FLAGS_EGRESS_MAP_CKSUMV4 | + RMNET_FLAGS_INGRESS_MAP_CKSUMV4 | + RMNET_FLAGS_EGRESS_MAP_CKSUMV5 | + RMNET_FLAGS_INGRESS_MAP_CKSUMV5 | + RMNET_FLAGS_INGRESS_DEAGGREGATION; + l_netlink_message_append(nlm, IFLA_RMNET_FLAGS, &flags, sizeof(flags)); + l_netlink_message_leave_nested(nlm); + l_netlink_message_leave_nested(nlm); + + id = l_netlink_send(rtnl, nlm, cb, userdata, destroy); + if (!id) { + l_netlink_message_unref(nlm); + return -EIO; + } + + if (out_command_id) + *out_command_id = id; + + return 0; +} + static void rmnet_start_next_request(); static void rmnet_del_link_cb(int error, uint16_t type, const void *data, @@ -119,9 +172,54 @@ next_request: rmnet_start_next_request(); } +static void rmnet_new_link_cb(int error, uint16_t type, const void *data, + uint32_t len, void *user_data) +{ + struct rmnet_request *req = l_queue_peek_head(request_q); + + DBG("NEWLINK %u (%u/%u) complete, error: %d", + req->netlink_id, req->current + 1, req->n_interfaces, error); + + req->netlink_id = 0; + + if (!error) + req->current += 1; + + if (error) { + if (req->current > 0) { + struct rmnet_request *del_req = + __rmnet_del_request_new(req->current, + req->infos); + + l_queue_push_head(request_q, del_req); + } + + req->n_interfaces = 0; + goto finish_request; + } + + if (req->current < req->n_interfaces) + goto next_request; + +finish_request: + l_queue_pop_head(request_q); + + if (req->new_cb) + req->new_cb(error, req->n_interfaces, + req->n_interfaces ? req->infos : NULL, + req->user_data); + + rmnet_request_free(req); +next_request: + if (l_queue_length(request_q) > 0) + rmnet_start_next_request(); +} + static void rmnet_start_next_request() { struct rmnet_request *req = l_queue_peek_head(request_q); + uint32_t mux_id; + struct rmnet_ifinfo *info; if (!req) return; @@ -136,13 +234,55 @@ static void rmnet_start_next_request() req->n_interfaces, req->netlink_id); return; } + + info = req->infos + req->current; + mux_id = l_uintset_find_unused_min(mux_ids); + info->mux_id = mux_id; + sprintf(info->ifname, RMNET_TYPE"%u", mux_id - 1); + + L_WARN_ON(rmnet_link_new(req->parent_ifindex, mux_id, info->ifname, + rmnet_new_link_cb, NULL, NULL, + &req->netlink_id) < 0); + + DBG("Start NEWLINK: parent: %u, interface: %u/%u, request: %u", + req->parent_ifindex, req->current + 1, + req->n_interfaces, req->netlink_id); } int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, rmnet_new_interfaces_func_t cb, void *user_data, rmnet_destroy_func_t destroy) { - return -ENOTSUP; + struct rmnet_request *req; + + if (!n_interfaces || n_interfaces > MAX_MUX_IDS) + return -EINVAL; + + if (l_uintset_size(mux_ids) > MAX_MUX_IDS - n_interfaces) + return -ENOSPC; + + req = l_malloc(sizeof(struct rmnet_request) + + sizeof(struct rmnet_ifinfo) * n_interfaces); + req->parent_ifindex = parent_ifindex; + req->new_cb = cb; + req->user_data = user_data; + req->destroy = destroy; + req->id = next_request_id++; + req->request_type = RTM_NEWLINK; + req->netlink_id = 0; + req->current = 0; + req->n_interfaces = n_interfaces; + memset(req->infos, 0, sizeof(struct rmnet_ifinfo) * n_interfaces); + + if (next_request_id < 0) + next_request_id = 1; + + l_queue_push_tail(request_q, req); + + if (l_queue_length(request_q) == 1 && !dump_id) + rmnet_start_next_request(); + + return req->id; } int rmnet_del_interfaces(unsigned int n_interfaces, @@ -322,6 +462,23 @@ static int rmnet_link_dump() return -EIO; } +/* For NEW_LINK requests, the ifindex comes in the multicast message */ +static void update_new_link_ifindex(uint16_t mux_id, + const char ifname[static IF_NAMESIZE], + uint32_t ifindex) +{ + struct rmnet_request *req; + struct rmnet_ifinfo *info; + + req = l_queue_peek_head(request_q); + if (!req || req->request_type != RTM_NEWLINK) + return; + + info = req->infos + req->current; + if (info->mux_id == mux_id && !strcmp(info->ifname, ifname)) + info->ifindex = ifindex; +} + static void rmnet_link_notification(uint16_t type, const void *data, uint32_t len, void *user_data) { @@ -335,9 +492,10 @@ static void rmnet_link_notification(uint16_t type, const void *data, if (rmnet_parse_link(data, len, ifname, &ifindex, &mux_id) < 0) return; - if (type == RTM_NEWLINK) + if (type == RTM_NEWLINK) { l_uintset_put(mux_ids, mux_id); - else + update_new_link_ifindex(mux_id, ifname, ifindex); + } else l_uintset_take(mux_ids, mux_id); DBG("link_notification: %s(%u) with mux_id: %u", From patchwork Fri Nov 15 22:00:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13877371 Received: from mail-oi1-f179.google.com (mail-oi1-f179.google.com [209.85.167.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EA331E1A27 for ; Fri, 15 Nov 2024 22:01:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708067; cv=none; b=qPP/WU8Uc6uD0fQgXLZiyGXLc91b9W0HE8xQ6Cu89oeag2CDjU3z8SjaU6mw1RbrqXumAohrVrZ05GAAst6H6W5VJhU60I2CofL49jH0ZJWFKPDeUXUcn5KxkrXRQ6rBXagiQnoJfPlgcsQ/cOSWL4qwbyaDE920huYeOK7fktA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731708067; c=relaxed/simple; bh=P4V8J/afc4mb7yTWlu/NxnbQvNxFO13GUri1u0xgqZg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=D3LNSQZoIq1BWXlxuF+996sLV1lT9g+8RPEKxEokcNR8Xw831jj7rgSSPXuXL8VbIZdM4EUtDtbMWS+z0ExkNgzixjUzIgYg/a5cXAkQoTo5T/CnA6BgXFFd4BN169c8EfQQ9veFTJDtTMpk1SIu5f7gkWPdJYxYqkv9YVvi3i0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=m5xmrOMK; arc=none smtp.client-ip=209.85.167.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m5xmrOMK" Received: by mail-oi1-f179.google.com with SMTP id 5614622812f47-3e5f835c024so1371065b6e.2 for ; Fri, 15 Nov 2024 14:01:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731708064; x=1732312864; darn=lists.linux.dev; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zlSi7CskR4nIYpDQBuXZ8YEmhG4MKcXP/QM3vrlefF4=; b=m5xmrOMK2K94SVejjvo33aqnv1P+0nKLcECxjUICf+/EDB7K2pK+o7Kbr6qxYr9w7J NMUFvTDqcG0UP42w5VRW3JupXTjUa+/WmTsCLzN8f4NZjug2gShukgEiGpngrOTyocz3 8Pg0G/6h5CjNzdJfJVOiXJP7grEQ78Q84Je48xvv9is9MFTH2qinP3BqX2UOFjBYO3jS xZAdHBhVCEuhWm/Z7us3MVPcMrGKi9YH9r0wh65RviPtj3Qa1RHeDZivn4WZrllYJ369 bIpilH6wW4+P3DldmBrlxq4cEFC/z6LJ5INdxEVbu5ynh8ylSAm+Zf+Iwl1Pa8mS+1Vy KRsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731708064; x=1732312864; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zlSi7CskR4nIYpDQBuXZ8YEmhG4MKcXP/QM3vrlefF4=; b=nyjTfwrUCh+1dQ9QfB5IOTuE2h6pP4tjdipatlyYyR0aVr6ecJWDdOw3zIa5YZ0ykn lmvE1YmLtQ0wEZHwNPLYTPU+GfV/xG9FilnasbmUSF8YSHssvLwHU6cPqXh8Us+aNHpE p94r3Mc3//9haxHsaYjo+m2yi7FQQb9uBLpg684nJwsfRyE0dir3UmMMGO2gcU+Vfbge H5yZDN1qro6kMQ4OwRUZywsZKeqKvvN3Wvd74AqTFSsB9FXSameOy7uC3stiQJAf9hXX 0sUpEjTt4RfRUL2IYSAqCSJhfyOqSJfwRkSJbRDv2/03kdemGrWXul+se/DG3cFgQxFa kQOA== X-Gm-Message-State: AOJu0YymyCGm116ABXiubHfLwzK0k+s3wbStRbvHxGKJwCyIFAuHaax6 +AA+CH+9YYkLpaO7lJm37yQ8FJCFR+0zfYqh7mbcosDgiLOQtfj/g5tP0Q== X-Google-Smtp-Source: AGHT+IFXO20KhqoZqsfIUedOx4RZtQp/BwcNXDbDMVfXQCZRxwe8kM0oPQ1sPiUWNMjzKBe3Czu1ZQ== X-Received: by 2002:a05:6808:1204:b0:3e5:f4f9:3280 with SMTP id 5614622812f47-3e7bc7bfa12mr4170692b6e.10.1731708063011; Fri, 15 Nov 2024 14:01:03 -0800 (PST) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 5614622812f47-3e7bcd82997sm879003b6e.34.2024.11.15.14.01.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2024 14:01:02 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH 8/8] rmnet: Implement cancel Date: Fri, 15 Nov 2024 16:00:33 -0600 Message-ID: <20241115220053.49613-8-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115220053.49613-1-denkenz@gmail.com> References: <20241115220053.49613-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement cancelation of an ongoing rmnet request. Any links that have already been created are deleted by putting another request to the head of the queue. --- src/rmnet.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 67 insertions(+), 2 deletions(-) diff --git a/src/rmnet.c b/src/rmnet.c index 4a921b330b72..07dada9178ad 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -32,6 +32,7 @@ struct rmnet_request { void *user_data; rmnet_destroy_func_t destroy; int id; + bool canceled; uint32_t netlink_id; uint16_t request_type; uint8_t current; @@ -54,6 +55,14 @@ static void rmnet_request_free(struct rmnet_request *req) l_free(req); } +static bool rmnet_request_id_matches(const void *a, const void *b) +{ + const struct rmnet_request *req = a; + int id = L_PTR_TO_INT(b); + + return req->id == id; +} + static struct rmnet_request *__rmnet_del_request_new(unsigned int n_interfaces, const struct rmnet_ifinfo *interfaces) { @@ -185,7 +194,7 @@ static void rmnet_new_link_cb(int error, uint16_t type, const void *data, if (!error) req->current += 1; - if (error) { + if (error || req->canceled) { if (req->current > 0) { struct rmnet_request *del_req = __rmnet_del_request_new(req->current, @@ -268,6 +277,7 @@ int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces, req->user_data = user_data; req->destroy = destroy; req->id = next_request_id++; + req->canceled = false; req->request_type = RTM_NEWLINK; req->netlink_id = 0; req->current = 0; @@ -304,7 +314,62 @@ int rmnet_del_interfaces(unsigned int n_interfaces, int rmnet_cancel(int id) { - return -ENOTSUP; + struct rmnet_request *req; + + req = l_queue_peek_head(request_q); + if (!req) + return -ENOENT; + + /* Simple Case: Request not yet started (not queue head) */ + if (req->id != id) { + req = l_queue_remove_if(request_q, rmnet_request_id_matches, + L_INT_TO_PTR(id)); + if (!req) + return -ENOENT; + + DBG("Removing non-head of queue request %u", id); + rmnet_request_free(req); + return 0; + } + + /* Harder Case: In progress, but the next request not in flight */ + if (!l_netlink_request_sent(rtnl, req->netlink_id)) { + DBG("Removing in-progress request (not in flight) %u", id); + req = l_queue_pop_head(request_q); + l_netlink_cancel(rtnl, req->netlink_id); + + if (req->current > 0) { + struct rmnet_request *del_req = + __rmnet_del_request_new(req->current, + req->infos); + + l_queue_push_head(request_q, del_req); + } + + rmnet_request_free(req); + + if (l_queue_length(request_q)) + rmnet_start_next_request(); + + return 0; + } + + /* + * Hardest Case: In progress, next request in flight + * We have to wait until the next callback since the ifindex won't be + * known until then. + */ + if (req->destroy) + req->destroy(req->user_data); + + req->new_cb = NULL; + req->destroy = NULL; + req->user_data = NULL; + + DBG("Setting canceled on in-progress request %u", id); + req->canceled = true; + + return 0; } static int rmnet_parse_info_data(struct l_netlink_attr *linkinfo,