From patchwork Tue Nov 19 17:18:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880312 Received: from mail-oa1-f53.google.com (mail-oa1-f53.google.com [209.85.160.53]) (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 4FA81153598 for ; Tue, 19 Nov 2024 17:18:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036719; cv=none; b=nqPnF1ao9WVsCwBbRZQVDmX7alNPm+UJwa4BbYaQbAneuaelz3iqDOFOF4ghxAd2RT7KsnbGU1dEkdA4pGoMaT1GSxd7KqhfFdCG8F8Rb1Q8dkK850PhEEz40Ft2Ls3o1md2UCTc6JK1lkDuInfx/yNLIN/+uJ/oN+qF7GVVq2g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036719; c=relaxed/simple; bh=2y3yf7W5FTQF4oAsUzgpFbw55n/dVLzxrntw8T01hLo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=QxVyLmoAtRAMM00ilhmZYMNPlZ3TibueMAQ01SwRfMTXGyJVMI8HbvFbJyGENmTMMcsHq1avhopn6g4h0DJdQvjJg324vNF1NO0y0T8q9Y3daddwMjHHBgkXzEmeRm6fG49rkl8SlQ3RYArwGnMpeLAW3q+m6Bc4xEI/zjNibsQ= 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=cmJ1csWz; arc=none smtp.client-ip=209.85.160.53 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="cmJ1csWz" Received: by mail-oa1-f53.google.com with SMTP id 586e51a60fabf-2968322f5feso1129463fac.0 for ; Tue, 19 Nov 2024 09:18:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036715; x=1732641515; 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=cmJ1csWzVrZmnBwTGTVR7dWG1rT8Q6kyJACcbspktVdNXMWJszkATLvH8bcWXcrY5A hDT9j68wP9mE48V191XN0wg9oWnyzWl0xnzN44DisUl7+6ALRNp4bjTjNSUJ4aVr2oac p9XWXqrr3xvU9eP47MhNoaJV/TFDci553grI9N85YvBp4HFA1ZLvVI9LotAnuxGadzgS oKJwWcPwk9TZ2VlYDIbaqFEssyaRfMleRxYIVoCGpr138oSoYDzo/dl8Ybst8UIosRhP 6lgus6ST24plpAIGaj0tO7b16P61buvJuoHWWFzJB7r61jYp91sYtH5WiXMqaRlK78TZ 5rRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036715; x=1732641515; 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=chR2SDj5FlF5g5vxiOqQDfhXHeELdE94FERn6IX5iruzIwRg1SXuLwY9gsCa6tDXGq 1Xic4Hx3lLg+WYhDTgA1wZdYqkoR/XZknqnekITG2JabF3w6zkS+K9tlv4vR5V+o0988 DsyPOrImHo7vGLPuuTVktfhi8261p40H+1icTV5jlMU4PyW7EmfEF4skjDm1B0IHZK06 smgpm9lThHwKbzaJtqTjsL3Bp06e2axB1e0DUtap/QiKNlWS2uXEkpkRS/WdvbxNIb/k rtrJ4nN3hrlvPUyeCBR48iDqldOPeBlJcE/Y2nPuSyC1O/u8KbcdE3E1ESb3mmIRDCcu 8e+A== X-Gm-Message-State: AOJu0YyGnKQwnO2JnoJjL01H2HADZxxPegghTVPXYcOp1yb62y+lybxz TXDH/09F0ZfA6u+mZ41UdwK/z89wjO2j5b7aRAFiL3mKqCONkCJm5O/YVw== X-Google-Smtp-Source: AGHT+IGo4kNFylPtWmO4nBiwPXm1S/99YLLWsV2/onX/xBuazhOWEVpnNkGZ6AM8k6LOzp6DdCi7Xg== X-Received: by 2002:a05:6870:548a:b0:296:2cb4:2394 with SMTP id 586e51a60fabf-2962dd7564fmr12169719fac.17.1732036715155; Tue, 19 Nov 2024 09:18:35 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:34 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 1/8] rmnet: Add skeleton Date: Tue, 19 Nov 2024 11:18:12 -0600 Message-ID: <20241119171832.1119-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 Tue Nov 19 17:18:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880311 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 4FD301C07D5 for ; Tue, 19 Nov 2024 17:18:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036718; cv=none; b=ljWv1Q2SoMis7CZCWlDT1Ohq7ugaET8GQ75N/Cdr631X7RHAxc6A1a9/ScSwZVa7hmPTbQF8L6ODajryXpIkMlDgzSv8fqLLf/Z215vfz+ipqLpqXgFjywLQ/GvRY1brxVl3SJUzwLjb5t8WD6KxhQqz2rgwYGIbjq9pHQjzw3A= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036718; c=relaxed/simple; bh=KjaDqxLZ2kvnLENy9drZVByCv7QBo9FFKux8gvxHbCg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=hZnxrVr+IhTDAJQJNU4vHxgp1k3vpP3x6Wr8RadCfOf/SDvkOQt8BeBrxQK3G2aLO5RmIuzpBz9sCNA/wIJpfItJn51aCyPfsxjKEohdIdl9F9wh0wcTVCuA29RqsOmHjUs3IYcyyZq2kEq/uFf+FCyS05yP4Lra1ZKVWePvnmw= 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=gekpZBOF; arc=none smtp.client-ip=209.85.161.42 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="gekpZBOF" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5ee354637b4so698948eaf.3 for ; Tue, 19 Nov 2024 09:18:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036716; x=1732641516; 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=290KuaM5lStngyLx8qiGP5QT8XuAX4O1/xM7gxJwH6I=; b=gekpZBOFxgC0yFnRyp4pUD/q4Q1vc5XhplJNUVRcWl9Ya6btP3dYrbakqstmYIANCv 4GmaMHWRjaJfLEcl548bv4SwPfxoECw5vdZJYIFwNwwuN7mEiUYzn2XUqzmS7r9Fk34g 9IkYfZRvdHrqq6C5pO/ampdbvfVD8fHI7rtIhzTjLAcf8eqtWeeA4F+jYXT95OnkF0Jq kSEhHSuc/obLeO9nAH7UVxx/zvjngQPwz/j0BaLrb3wvqVsJsa+DKRmrEMg+hF1gfV8X bbNKsKRENbDjWPFDtp2l/P4ZIXvQFUYwdvh/WTguglAuyiYiH/J6Xfb/k02tIPEPL+vZ 5otw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036716; x=1732641516; 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=290KuaM5lStngyLx8qiGP5QT8XuAX4O1/xM7gxJwH6I=; b=U6+Ym/YXz+yBziW62nFF5MeJcR9pMqKeMILujgIXPhBD2fEIXo9YoEG3RJ1IbRn6SQ 0lW8Y5Iui7191T6ggeIBF9IjxGmoz9hRddSx6inzhdCSTGZT+/O+cL27vruw5Jca1fpR Z1giUNmU/P++KFn56UW0sSHzkO/gKEbXDNcYeXl7TcYuXRqqZZeuGFEM4I8nKK1sXui6 R5HujbdvVt64XyC6KcR3aDvRoCSfw9r153sZSqeimTGdO9nuuVDu3Wj+zYgj1TC4A5uQ BPvT5VS6CLMxc1+aSiTEogEwcCAXihMs8e1utlq99EZJ6j25SKY/dhL/tT1Cq2VYjhXh XEPA== X-Gm-Message-State: AOJu0YyGjj7fDb0mN5WYXoGaS3/HrsE1iPsGEJHffWpUD8YY8NK57LNS dvDrXkUPkAJUc4lKMSmlVj8HNz0L6f9M0nCOn17DUlmLbT84Q7+cPduEOg== X-Google-Smtp-Source: AGHT+IF5lxe6ORULg+NLNkiuhzjZABZjD1jeyaD3EeDoTwfSzmamMIumEh6HSbmkZ1qKwQPsgR8Mzw== X-Received: by 2002:a05:6820:4c09:b0:5ec:72be:25e0 with SMTP id 006d021491bc7-5eeab422193mr13852490eaf.5.1732036716124; Tue, 19 Nov 2024 09:18:36 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:35 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 2/8] rmnet: Add logic to dump out RMNet interfaces Date: Tue, 19 Nov 2024 11:18:13 -0600 Message-ID: <20241119171832.1119-2-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-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..325f1c503ca9 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(void) +{ + 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 Tue Nov 19 17:18:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880313 Received: from mail-oo1-f53.google.com (mail-oo1-f53.google.com [209.85.161.53]) (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 305281C07D5 for ; Tue, 19 Nov 2024 17:18:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.53 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036720; cv=none; b=l1jtb4ZFX68RkJjHjVwlj1RuBFVBy/bB4bY/7EnN7tGx4w1rIp/ZJfuWny2NruX1cBJozXs7Zp4HiDR2RC9ywb9fIiSBRq8nHZ4PhCAiy9JkxsEfi62jAY6fRvDEngao3Mv0PxclDywn9xvxb6R3OTgFjgpn+nMQGLAiJmnBKE4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036720; c=relaxed/simple; bh=oMuE9RPDU2bT19YhOEMpTCghj8RXXKcG6iBi+ffV6R0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Vfk/7TwxxKfqbJAMIrEonRjtlObab6eNOISX/is0/Q7mJFCj7h/DzzEzW3JpV+43QONaCKGncN2gRVovZSb2xYxWxi64+M4MVv5NiS2+zju8F3TIlrXRPKySvwGl7bvktmw/qEJAagpZguL7prkn2vyGEwiW1MJaAXGn0NydJQ8= 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=kf6KHGhc; arc=none smtp.client-ip=209.85.161.53 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="kf6KHGhc" Received: by mail-oo1-f53.google.com with SMTP id 006d021491bc7-5ee58c5c2e3so2015378eaf.2 for ; Tue, 19 Nov 2024 09:18:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036717; x=1732641517; 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=ZIRrEL/8rJLv9xIWnP8iJSawwIE6H+g1FdDCd1QdA98=; b=kf6KHGhchhdqpVD5xPbFbwKdobjpDzn1WgO29zhybrarbVTrcRSLLUoFfhJaAsVfGD qGMxdKvCnY0t0qPFvizFhRWZ69ZylX0TuwpNlQpeJAavx8lrI0V5yjr1v6JMz5CiT3Oh /gJVZRJ/viHnAqt85Fa1QkvMzhUiH2aBCQauitkLAbj09OTInM+IiwaoBo1eR9gj5ofI xohPg+1AgcDEq/fRNfJ7n/FjscnGrtcv7C3eq1jT0HhkqyKpX7LSIETqYhYXBQhQqxnk KJbRxs1IaCcvkNTERHhghGZ6RFZaiU7yfXOC9ouDYguXV3PBRRaml8YZoA3ZaWvW39a0 uRoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036717; x=1732641517; 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=ZIRrEL/8rJLv9xIWnP8iJSawwIE6H+g1FdDCd1QdA98=; b=MsVIhFGrwjIsZ/kotfM/V96D+uq9oEjXYSUJYoz9pOIvnMYsIEXIXt6IiYJhtyLI+C Hxv4nrAcfeSG5qJZrrfd3fMMms4NCYgQFW/SK0UNHqf2PNPloXrCmEEn+qIIVgKg0yjW kBUEAMCwWb3csauOhfe0KrKWBmYSKn7Bi76JIFbu99lTH0dauPTJMcGT57DM8rs7gRP5 jRJV9yxvZKaKn/2NwsMCSOQWqG7ly4bVbBWkoanv4wk/pafRK2rCB0YehqaUHqllec15 xNQHH7Gx8PsXhLZlO2d02nkHw6yJZr4XLmQBERRuvc6anitTb2SHDoqa4gskkmlHjccs r3Qw== X-Gm-Message-State: AOJu0YzfLAc1fGS4/SKQFfJq2CaFvAlFutu4wICuoFzTMG3e1bMGSdsR NKUK3KKXpzFh1+mvuoxygZaJx1CdQYMyODn3uEWY8r+PNv0itBtqqj1erA== X-Google-Smtp-Source: AGHT+IFDo70De7g7WWsWTLhLX+mJb9/uMJcgcJWMgZXkLwwon+iUcyS7Z07DuHlSV3/lf0eZFMk0jA== X-Received: by 2002:a05:6820:1a0b:b0:5e5:b652:9d14 with SMTP id 006d021491bc7-5eeab28ce0bmr14480254eaf.1.1732036717181; Tue, 19 Nov 2024 09:18:37 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:36 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 3/8] rmnet: Track link notifications Date: Tue, 19 Nov 2024 11:18:14 -0600 Message-ID: <20241119171832.1119-3-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-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 325f1c503ca9..5f40fcabcfb7 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(void) 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 Tue Nov 19 17:18:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880314 Received: from mail-oa1-f50.google.com (mail-oa1-f50.google.com [209.85.160.50]) (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 258A1153598 for ; Tue, 19 Nov 2024 17:18:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036721; cv=none; b=VmYELUqySriMZt2n0c20a9/AzNKgW+OrnHDIBeJOXwROorDP6gN1yExb551Om7n3wEHbX9K9Mruj2bhJfNNCYpKkcfu658nU2Blzlv/aiSB3QxK1uyN2c94OKKfRPtfMUMkr3kLrf4qDivBRphgcIxxczlWxOAEpZpFmBuiA0GY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036721; c=relaxed/simple; bh=zap4gEhh3pHftT4lAgiaK7lcfE6I3TfbT7rHvr+E0mQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AdVGaBT9dWLurEXsJG6HwVnEOlIOTRVhgf9IAZsugvJRMwfS7Ac5wk/7IFUBxDAw+/Xen+WBVim4dH2ddxTIuUGnhY+fkCECjad9o5t5//gue3oG7Hi5To2kJcKIrWn1ICstrq3Fe0XPkjfHXzT87V8V8x151y52f0uDnENPAuY= 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=VQOCpEBm; arc=none smtp.client-ip=209.85.160.50 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="VQOCpEBm" Received: by mail-oa1-f50.google.com with SMTP id 586e51a60fabf-2968322f5feso1129509fac.0 for ; Tue, 19 Nov 2024 09:18:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036718; x=1732641518; 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=KLjL2Vq7WRnQajfwKZlproHWYslJYQ4LqE5SYyHey78=; b=VQOCpEBm1z/+U8qCBvvn5a0PG5cCz6cGJKTixbkfd5Z0KsUHNlcDXeYz442A9rOd5N EymHtTSWsEXDKnqHJjpp/iWL1iuPpAPnWJCf4Z0sqDdEbX5cCmwtHnNPGXDPn/wgWkX3 fB0Dxcq1Q87BGlWyERAZ/EtzY3/E2OgAhuHgUzfz96GJTPHBZUFIOMbRkr1gQxwLhWEa sUjg+rPMp8j8rndCjFu7xHiGMx9Ke/2JfEAhbcn59XomTPxDM4Xjg3QgayGmAlRrCfXk +3P6Dv6SK8V2hNRZEAmp/W20UHQE2RnnecEJlgs3BfDV2/5u0WQ78ZJ13P3klVQYQ/ST uoPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036718; x=1732641518; 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=KLjL2Vq7WRnQajfwKZlproHWYslJYQ4LqE5SYyHey78=; b=vgmDXSnIAQKC+kl+sy5fPxohpLZQlbGd1iSqchsyyeurJ96zh/ATdJnoSghAyYV0Wd 5Qbdbg1XwnpDEox3jbWF/0wftJxH+zaS5kdZJb7SqJqbx3hrb4ZRrznJKwSFQSbRAY4s BohujVAg2HPbTZeEmSVB5/7KPpZP7FSMldfbh0OWPQ72sbPiWEYIBPzFDPUYK1F9GmN1 F5JYLqNd2wtDxk/EGkdCrJw0+ECVhd8J/cZzfQyo/ZR3ZjZpPNpvQwqU+tio4tcLm4Qf 4kcgAg5iTC0lq6Bpu5rZ80XTYB0JwhOOXXhrVn6tHn5PxHy5i61t/dVXN44xn1yliCgH Sf5w== X-Gm-Message-State: AOJu0YxWpziQX5MIMswf4mOvU8lgFVsZo3Fa82oveCHrxEKhkXQkpsyC FoOw9Xf25ur8ZyL7WR3VcdpRaFX/FkHwfUrIv09Yl47UWUSUJug8mfvY2Q== X-Google-Smtp-Source: AGHT+IGrNIZ8aIVMNemGT811n2y3m+oS83d/kKus9liC24p+OiEu9YrScX15mg/oq+9DK7yHX85HZQ== X-Received: by 2002:a05:6870:b19:b0:296:ae1d:a760 with SMTP id 586e51a60fabf-296ae1e9167mr4640035fac.6.1732036718028; Tue, 19 Nov 2024 09:18:38 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:37 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 4/8] rmnet: Track used mux ids Date: Tue, 19 Nov 2024 11:18:15 -0600 Message-ID: <20241119171832.1119-4-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-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 5f40fcabcfb7..350f0bf844a2 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(void) @@ -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 Tue Nov 19 17:18:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880315 Received: from mail-oo1-f52.google.com (mail-oo1-f52.google.com [209.85.161.52]) (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 4CAA01D0F49 for ; Tue, 19 Nov 2024 17:18:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.52 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036721; cv=none; b=lupSUvk4GtgWv68mbQGl5mywBYTQ0WSBasxXdI4Cavy766jEK+easp+doYAaxl41H5C41OB4rnAuCnhbQM+MR5n7LUxH6usrLCE0ya1W1l7lB0DhOqLkc3Nl7l3tnOF8L+HdXq2Ei507b88lm3zlJwUP4dxH+SdMzDefCkCFoB4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036721; c=relaxed/simple; bh=tIRExgsTCug/FAficn+ug9Kg+M4pNyQKEQk06YsZ+QM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MFL+QcPpjTU6QW3H/9p03e4GoMyQD5Aj2ZahDgnBiBoqb56Z+eutCmY5/GaF8jTRJ69JYCkPbWAUtJt9xeD2QsZXAAxutK4jpZcUYlP+k51MU4p3DDfhQomlvWsxOtiZmgmUYxQRh5yG+XagCXkBAmPMVOg1JQZX9N1srVUZcac= 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=i2VawLAK; arc=none smtp.client-ip=209.85.161.52 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="i2VawLAK" Received: by mail-oo1-f52.google.com with SMTP id 006d021491bc7-5ee645cf763so2874024eaf.2 for ; Tue, 19 Nov 2024 09:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036719; x=1732641519; 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=pmU66ukH50aNpB1cchpPwP74sAdwXN/lSZlAzR2W+LM=; b=i2VawLAKh5ZhrqYeDOTxNWr3MFyB1W5hFSy8aDdu110PpLNZVzwCCo+PsFB1QCjLOb JGE/Z+2F8hbTOm5UnTN9kodfZ/xTYOrFAAYTz2Co593bthFpBnpPXTkrCd4fNUZ3tunV tBTfg3CCKNQB2fPU/9TYrf6TR+qcg1uPoibxnha7XltdzftAyYDw33IWE9ShL+apJTAC hOySuZSUzfKnytd6o3gJ/fO5zOSZ91S1/I0eSz3b9dSK0udE6ltKh7sHOXPsnv9ERFub bYyR1AgsC3Qwgdrs4VqdH+W/3puXJ9sIziU2pp4poaQUc0ybWheucMzbqhx7V1aOygaq DrZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036719; x=1732641519; 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=pmU66ukH50aNpB1cchpPwP74sAdwXN/lSZlAzR2W+LM=; b=M5fDsXx0anJWxzaN+CJZPzYDHH7PZMSxiB7BXcEUliNaLRZ91yvle2JJTyO1eKOvNO PrA+MdUb3fN+kSWLc3NzVkVtd6AvqfUu1W1eqfsau+Q5APsxhe38PSY+1JKrjB7cDulK YYldrgkjX2FRROw7+ZoM8qR9lYOgnuCvIdJ/aXeMVZknu7WH6Fvqk0LT9BFJ6f8tmZQL L6fT5GdHAcvMvSKYFJi8iL3bQ9t6R7K7oJ77DSxsR2NvDf8i2glNkvyMfzn0pFLgHjP1 olerqvXRDIn7tONYfzUmLqnnqFeHgV11EBFCUV+8SfwOYmX0WBRWCtn+aUz1RYKV8oeH rPwg== X-Gm-Message-State: AOJu0Ywf7km3SypjinTneRFBn4lhZ0reoFzFbsc/wepWXvrvg6PCWBeJ QUXx4ax5gCqOxRsNRkHG9pPoex3mjrRNQzsi+Wq1jEEQKIGw8Kp+AnOl9w== X-Google-Smtp-Source: AGHT+IHsqQz6hcqIKo3kyo5ZzTXTkR0InyDmT0uQlm47TEGc2za4CTq/+KgzYqqigyKn7EuXiT6V5A== X-Received: by 2002:a05:6820:1a0a:b0:5ec:c22c:72db with SMTP id 006d021491bc7-5eeab29e337mr15342999eaf.2.1732036719227; Tue, 19 Nov 2024 09:18:39 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:38 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 5/8] rmnet: Delete stale RMnet links at startup Date: Tue, 19 Nov 2024 11:18:16 -0600 Message-ID: <20241119171832.1119-5-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-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 | 120 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 1 deletion(-) diff --git a/src/rmnet.c b/src/rmnet.c index 350f0bf844a2..4309f8e61ccc 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -25,10 +25,119 @@ #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(void); + +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(void) +{ + 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 +261,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 +271,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 +281,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(void) @@ -235,6 +351,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 +361,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 Tue Nov 19 17:18:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880316 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 25B401C07D5 for ; Tue, 19 Nov 2024 17:18:40 +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=1732036722; cv=none; b=S2zNgF/QMatIqpU5So7lYbKlf/IVf8vym763MMK/Pc5uylXnZ4MgNXqDC7UIajKN/B87pScu9gPnYL4HpzZU5Kmc9sYlqqyY9rt2n0RBivoqWPV4bVUVHmwbinP7Q8N5odIFDz6luaLd8EsKaO/nM/TZE9XHBlCNX5tGh7yXhSg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036722; c=relaxed/simple; bh=tlLXCONCtA4Xbvf4m1JxOMVuNvoRnkSQF9tYzySvHVY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qa4b3JNm4Q6iljUeI8EWJo/LXXN/szhnnzZqEape5E1PJO/IQnyc2ZJaOo2o4E2+Z5Sy5UUuV3cwaHqvYgH0JGsHSQwk2N0dJTAzqcc/KHpMVcu7zDJ7qbp53S5XKK2DRMgbcvfgX7fuG95L0lrLRhIM0TY+3Y6mH/EkjYsCY64= 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=XIkylmk+; 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="XIkylmk+" Received: by mail-oi1-f169.google.com with SMTP id 5614622812f47-3e5fee32e76so1173976b6e.1 for ; Tue, 19 Nov 2024 09:18:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036720; x=1732641520; 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=dLrgs/4EtUqg+fIuM3RBjKZkkgnr0rtb+7yMiXJNplI=; b=XIkylmk+krRMmm0uUVfQRk9lcBjbzxr0auWediIFKen8pzKwmqX7/uqXLu+HRYVJDz mGbCBOIxMzmTmLrNGMgAbthouYi4lzr+bLpGQE84mZ1GAupwnTuAAa98eEWM+owZCxsL r7l6NNlSuYsij/TUyqAXZk2yUgp3KPlV89cJD5+ku7eIi6SE4rK1AktYK3aYtC1Cb4jq ctIUFpKEQ6pVrYvr/R8+dAA8W+/TYsMW0i/wcp/UfUdRHD2tZy1tok+AAG8eyifLCS1n Wt32kHU6+kzSSvFDu9e27x1YI7yXU8099UYhpLcBYUoT/K8Wlr5ZU83nR47q1XlCtNTV zPeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036720; x=1732641520; 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=dLrgs/4EtUqg+fIuM3RBjKZkkgnr0rtb+7yMiXJNplI=; b=tvrzUI1yz7TrZC+celkLu32U/ywkgArk6a7nREdGyJI43SEYemcnI/5tUIYP/kzE6N S56BdaPrhB+vM0n7tWHWxoRos9sMf9AxDYKF9y3ichxqTGpvun50wvWFVHW5zrCDsOQ2 /9fUDm58T7Ef3UR703tEbiHPZ38d3SYEd/bb7hk0YKEYNPPUvuVo8OAHzy519kPhEa8i 1cegaooJRbLvmR4/Klrr8X0mgnZrUdP4a1ZCPR0swsAHSyH2jy1Olwwiyzjr4SEimvMp Esl55JAVSQ/4LGeZ6VJg6ZIEP00BbjT9ieFj8nCkPzhDqh/RurYnRYbmmK33ty/Gj6vk 3tpQ== X-Gm-Message-State: AOJu0YwkquyvtjADAfDXCGOFDc5S7Oke8yLM2v58hl4Tg8LPyk5nFrjK cTIt+Q2rmL4fRllb2+BCAz5kn2VG7chL+iDDvg5YpAZYdysCpHq3WeIGxw== X-Google-Smtp-Source: AGHT+IFmVtoDG1oIKfFGy+HeqWzfOifNHWgZtJNKr/RtxWzLr9S1l2KvsroJP2+hUNEzucAeIlAclA== X-Received: by 2002:aca:2b03:0:b0:3e7:63ce:1d6f with SMTP id 5614622812f47-3e7bc851773mr13888630b6e.34.1732036720173; Tue, 19 Nov 2024 09:18:40 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:39 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 6/8] rmnet: Implement rmnet_del_interfaces Date: Tue, 19 Nov 2024 11:18:17 -0600 Message-ID: <20241119171832.1119-6-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-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 4309f8e61ccc..adbe605effdb 100644 --- a/src/rmnet.c +++ b/src/rmnet.c @@ -149,7 +149,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 Tue Nov 19 17:18:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880318 Received: from mail-oo1-f42.google.com (mail-oo1-f42.google.com [209.85.161.42]) (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 285BF1D0F49 for ; Tue, 19 Nov 2024 17:18:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036723; cv=none; b=uwl5MT1DpRKc+8WHJyGwPGtIrOZMVuC8B750bhuUaOBX4rbGIukxsoT+jgPW0N5jTVQbTZqxnbjV0nJzYGT0C9NWxt12IQkvhjyguczMu2CscQ17P2AjKiHr8IkdYTxSD6pjyEyFnQjzEGEOfH6Xlbc/0opc5pyDnOCVGDAtFcY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036723; c=relaxed/simple; bh=t77tfj0vF645OCPc5XKqvZlu2OLLv4/IAiO1nhGyk8U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DNLvGvu4akKUEojMrRj8JtM049ZNOsEYsq+42F8D6qpfA0fyZ13YoPesbtF1Oia2bJ0H4OSycSuQxmJJmsR584X/wQPG8hNZeR9MYHRW01xS5F/ly5GRj+qWaxbORskfHuC56WftoFXxryOizUcoSj2J/Y3iMGUVAFVqP7O8fIw= 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=kN+RnODT; arc=none smtp.client-ip=209.85.161.42 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="kN+RnODT" Received: by mail-oo1-f42.google.com with SMTP id 006d021491bc7-5ebc349204cso1485015eaf.3 for ; Tue, 19 Nov 2024 09:18:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036721; x=1732641521; 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=KBSuJJHyA06W9R05h/LSJE3p1noZng8aPB4QWbPy0Qo=; b=kN+RnODTGIbiOO794NLmPQCfmX1szMpN0WVgdvSwsmo2T+ONWO90jedjpvlY6jOU5z Bhapbk6Krg6KfvlYaH7lWLHNOMLoTikTpCuE//JUyYSiR/cZcgcyxf07wY6eRbzzwaGL BQEEakscSbv+BIeml6lJbfLItYFwU7/YM+U0tP5NI4H5KVDL8+Fga7Muw/21LBkkekLt MvWP1g9Qp3hSj6B7x/9IOk8HZOAPdKTYUabJeObEuqLoS53Gm+3QrAOWp4EBvlVvKlxI q3zUeCryCEgo2hlZBCtbHF1kgnGXUs+QH+3PA2BnIChDgLHihvcbeRAvarNY5uuXmAXk bW1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036721; x=1732641521; 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=KBSuJJHyA06W9R05h/LSJE3p1noZng8aPB4QWbPy0Qo=; b=fOBQT2mnDraa2vGOiqTaC4hm6Uz/ITotCkDdLXS5fLWLk8BufqHrZCuPCa/LcfCa0p OilDXqo/tNFaa78bPCRihFxaHJM96Kd32V1iKv7DMUWVwfEajkRCWaXzFo/WiX7aa7zG 1SDetuRLCqv6KKA5yLzZCzuO74r1wkHAC3X1Hnoff2F+DB6JTrSLfFuMSIsavTlQCmhd QcE818lFV0IRSD0+S8PF2B5GrZE1ANW8XRjNpZn049vSWqRX1bcM0U3pbANYupKkfNQi pZiMUQgMu4wO27rpdpYkjR0E7lGqHqPCr08mem4QL8JKWEpe9pZgNzMV+nc7jrP9yOCV 50Lw== X-Gm-Message-State: AOJu0Yy13tTbSR0jC2cJTa+Ha8pWAxeQpQOH4qHdQTditREzK7q6gbG0 bW7X8MfzJNuOEq+asMcgtJKMvUJ5jXGdusTaelW6zybMO8MgjJditlJw1A== X-Google-Smtp-Source: AGHT+IH+GbVpI2I0KwfSg31eIL5XbPpXhO3cQUkUksolYlXSX9AkRGLifcw0jo2j4JuSKaU8fW8e7Q== X-Received: by 2002:a05:6820:1785:b0:5ee:d89f:1d2c with SMTP id 006d021491bc7-5eed89f2131mr4690554eaf.1.1732036721106; Tue, 19 Nov 2024 09:18:41 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:40 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 7/8] rmnet: Implement getting new interfaces Date: Tue, 19 Nov 2024 11:18:18 -0600 Message-ID: <20241119171832.1119-7-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-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 | 168 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 165 insertions(+), 3 deletions(-) diff --git a/src/rmnet.c b/src/rmnet.c index adbe605effdb..b51ebfd18f65 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) { @@ -68,6 +70,19 @@ static struct rmnet_request *__rmnet_del_request_new(unsigned int n_interfaces, return req; } +static struct rmnet_request *__rmnet_cancel_request(void) +{ + struct rmnet_request *req = l_queue_pop_head(request_q); + + if (req->current) { + struct rmnet_request *del_req = + __rmnet_del_request_new(req->current, req->infos); + l_queue_push_head(request_q, del_req); + } + + return req; +} + static int rmnet_link_del(uint32_t ifindex, l_netlink_command_func_t cb, void *userdata, l_netlink_destroy_func_t destroy, @@ -96,6 +111,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(void); static void rmnet_del_link_cb(int error, uint16_t type, const void *data, @@ -120,9 +186,45 @@ 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) { + __rmnet_cancel_request(); + req->n_interfaces = 0; + } else { + if (req->current < req->n_interfaces) + goto next_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(void) { struct rmnet_request *req = l_queue_peek_head(request_q); + uint32_t mux_id; + struct rmnet_ifinfo *info; if (!req) return; @@ -137,13 +239,55 @@ static void rmnet_start_next_request(void) 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, @@ -323,6 +467,23 @@ static int rmnet_link_dump(void) 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) { @@ -336,9 +497,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 Tue Nov 19 17:18:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 13880319 Received: from mail-oo1-f50.google.com (mail-oo1-f50.google.com [209.85.161.50]) (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 00C251C07D5 for ; Tue, 19 Nov 2024 17:18:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036724; cv=none; b=gIXGMayqzRz8iwJb/sJv+PSDhZ0Vgd/uK2nPm7iMdlHLF6/D0Ax/OdbMBXgrlbPsVBtbwy+WZRBB57b4X2/imePGV+u6zvlGNdLdPVFKPCHgqVde9CjFamwBlfpxJ4OZz9ji6N4oVwHrvGLdyoYkWWmUinzYrQ2fRN1EajMaqAY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732036724; c=relaxed/simple; bh=7UupV5U7V0Ks6seIWmf4hYiVCj2Sm3KN9bmB2RzOlSU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bQ0FMWJJhZD/x1HBzjtJ+t08ug9558HJEXqF1Sp2x+owKKBKgjN8JZMBvUnpgex8yIG+loJMfddKmBn8TQBNLl+gq2olucd42KlL5+EpPiIY8h67TryG1suSgYIn6t1Dm8iBocJ2dYlSQXnUo1meU/kzlY/4HhFiDsv4CpmU1IQ= 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=FaJ9Ej1a; arc=none smtp.client-ip=209.85.161.50 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="FaJ9Ej1a" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5edfe8c17c4so1495826eaf.2 for ; Tue, 19 Nov 2024 09:18:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1732036722; x=1732641522; 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=jvRSzLEw1nW6La6Iyj8LiVTVOvcPlwY7JWuWmeJ0nVs=; b=FaJ9Ej1aD4+0eVPkr66eAThXP5k9XkQToJXebWyR47L56fXT4tHjVAsRFaSPN/7rST wcGlGHXBr833CKeJeYur/MJXfZAxu+2hv3CpNxFJ+er9GcIekM9pWPp4m4KabZ3Yjzru 55hCrmR8hTT2G/U8WmoWB65P3BGXZdURO0sBzZYM4QleZiA1WdzVUiYuZC1YP5Pzxe3V Mz0QnIjIYfG1Wz/UeZVkGtshtG3wzAPCl9nEP6tncO5Oe860pskn1KYZOqW0zezsdwRl mUkmSoweTjSH/G2X91y4w+g+0k4u6vjsZ8SKtLhLf5KN+JRpsk+TWMs8ET1N42ZRdL06 RroA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732036722; x=1732641522; 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=jvRSzLEw1nW6La6Iyj8LiVTVOvcPlwY7JWuWmeJ0nVs=; b=CleBLF/hPCkhZppwUTAKOIw95MchxK7cGdacalCIJxzxgGcAdyZZJg9Fr6VJuksvO0 Zc3wCL06bd7GjvsKbPZafbcPLQkEK7s1FPhnz20/yHCrP/MwhwqfdZym3FKUJCKHh8IA wVNSrV9gkm1XH+pYRl6h1NVR7kK7snPWTAKYwynkjXu9euDTTCl0+BjjFASFEiQHqMTw 3uRUD6aejwCigK6YXkky9bM9ASM5vzIpIR+IepqL6F5CjU826A73+9y3HMNkI3D4sb5S 5PoqNpOfWrJ+iriYHVEtbSoFnf3XcMYd05GUf0FUpJmHWqlWiFNjeXYbn5sAGDiSl04w JsnQ== X-Gm-Message-State: AOJu0YxyL3k6kWmlGdOK3ZimAMjuixsbwa+FXUIunBGN+pIv0lKiCiea kUxkEj5VwCzzUdvPMbaEchIdTXrrnykHXnONgQc8iXiJTcMg0mi6G4ObbQ== X-Google-Smtp-Source: AGHT+IFFT6RnCGbpVFwzg8L3poXCenhVCnIXQk8iZbI2FVMftDJorIm5FITwekzwWJl6jDFi62h5PA== X-Received: by 2002:a05:6820:4ccc:b0:5eb:85ee:2cbd with SMTP id 006d021491bc7-5eeab446133mr13105320eaf.6.1732036721926; Tue, 19 Nov 2024 09:18:41 -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 006d021491bc7-5eeabd7feaesm3664016eaf.39.2024.11.19.09.18.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 09:18:41 -0800 (PST) From: Denis Kenzior To: ofono@lists.linux.dev Cc: Denis Kenzior Subject: [PATCH v2 8/8] rmnet: Implement cancel Date: Tue, 19 Nov 2024 11:18:19 -0600 Message-ID: <20241119171832.1119-8-denkenz@gmail.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241119171832.1119-1-denkenz@gmail.com> References: <20241119171832.1119-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: ofono@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Implement cancellation 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 | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/src/rmnet.c b/src/rmnet.c index b51ebfd18f65..83110c33a980 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) { @@ -199,7 +208,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) { __rmnet_cancel_request(); req->n_interfaces = 0; } else { @@ -273,6 +282,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; @@ -309,7 +319,53 @@ 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 %d", 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) %d", id); + req = __rmnet_cancel_request(); + l_netlink_cancel(rtnl, req->netlink_id); + 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 %d", id); + req->canceled = true; + + return 0; } static int rmnet_parse_info_data(struct l_netlink_attr *linkinfo,