From patchwork Fri Oct 18 18: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: 836753 Received: from mail-ot1-f44.google.com (mail-ot1-f44.google.com [209.85.210.44]) (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 4C7E9204937; Fri, 18 Oct 2024 18:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275616; cv=none; b=nP51eHc34Edl1lpIBAE5H39B7xGvtr9iZJqouU8PFXH1JNrNgM3EO0Hx8kjohyKSsdc9+K7UjlhaodYfHoWjDocoGILLjHaGfHVChytc+PSLUAcvFEQzrjfLH8hwidM9miFozBoEdAXK/zOvBM/nASn9Y7S6LJMYM0O1vowi36g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275616; c=relaxed/simple; bh=4CxVELtCiC1PGqAMrMDaZY++hvnaH/4mDabb37qz28Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Gq82gvo/pLYCc1OCx9D/9nPUSeeVjBVDy1YMJWzHoOu7/f4Uefb7Ma5uiAmssqXLViCn8kPTqd+eJckgTc/mW3El1+CSU53Hfw39Fy9rGetuSgYWvuasG/fuNy7zrDS08oFy+j3ZYfg139LTvpsD3dz1nydJPTlZV9OBwDGqiJ0= 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=kvFHcF1X; arc=none smtp.client-ip=209.85.210.44 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="kvFHcF1X" Received: by mail-ot1-f44.google.com with SMTP id 46e09a7af769-7180bd5b79dso826380a34.2; Fri, 18 Oct 2024 11:20:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275613; x=1729880413; darn=vger.kernel.org; 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=bEtsWUfg8YbHWegd1g+Jr8qqOJM5RSkKK7SlSHJ9GsA=; b=kvFHcF1XIFh1bqhCiT7nsTvEq6SDeRjBIVGxi9vmR7wv6ttSqDsVn5URFjIgmEBPWd jb6ECOFCDFZcDp5/GNrlJepIclSqMqg24K0BEWdxQlTSwo6WLuP3ToRxSlJS07bL8HbC j+/waD+qRw8BY18AYtIugbcP5k0Vm1OGo2rH6qszjQGCDSsRmwXDiVdw2c16o4Alod4d KXNODQz90VAlmyQD8ZA1yrhzzBVCk99jQhC8/yrhykJ/M0AuIdGvdHLSC4758y5NAbuA b1K8t/Jt23wxqg26Yd9DaZV89MQMkgPHqTh7yxB0NohNYcbmwX/CiN0gn+d6M04RFEKn eAtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275613; x=1729880413; 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=bEtsWUfg8YbHWegd1g+Jr8qqOJM5RSkKK7SlSHJ9GsA=; b=KyaTdjCJyRHrdqYdPbm78BO6MnJ5xy+d8qRUOxoZzj4GXqcLvtezwk6PsvRw7imyVC jnbbXL4gpzYT71X0P1ZEZSDbZV9Y5BzYgoMVarx+yO/qw4Dpy6YYes+QVeXpar1Zbban ZRXgU7zEHz4h3OOswxjrKnUino+CyKFXylvHFzQbQ/Oq4skwz/F1ZttsJOIte0VQUeDV wP60Y2j6a5dGu8tap9x9bX+a4JbCY8Oyh2gLL0tIn1edBWTx3Wj4VKdBb3hMBeqMHFuU KYpOQIyo+Wyz34/5HFta45Iq3x10ES6axOXkiNK64CR6x/xwUO9/sl80fqYKcvl4ctSl 5Y6w== X-Forwarded-Encrypted: i=1; AJvYcCVWNmL6jet60QGmORUFRYXBCz1geEETsvxFCkZDOVTv99QW1psj+BZpxS4vmdX0U23iREupZz2yeUcSyvj4@vger.kernel.org, AJvYcCXOjSVIFBAgYgJIMsWdNQaXFXy1rrQHS6v4bG4SOx71Kg3gO/LX+0ksFVlgiMd0dtrI/S31Auk1sG+1aDdu@vger.kernel.org X-Gm-Message-State: AOJu0YxahSm5c9aTP1x8nSmAX1X9T4yuRJ384rYQQSIMeE1O+zVwN8M+ DpsZui7DisklwwOz71Jo5VX+YvNbmRYi+8ZqqCFYjGMPXI1fxH8fnLM2gw== X-Google-Smtp-Source: AGHT+IH/ZwPbMR+tkggdmm11Pqicm2tPVZQJBJrQzdCvwhafo8if+1UoU0Ata2i19T16kZzjOo3q/A== X-Received: by 2002:a05:6830:91b:b0:718:15a9:505a with SMTP id 46e09a7af769-7181a89f0e0mr2549619a34.23.1729275611695; Fri, 18 Oct 2024 11:20:11 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:11 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 01/10] net: qrtr: ns: validate msglen before ctrl_pkt use Date: Fri, 18 Oct 2024 13:18:19 -0500 Message-ID: <20241018181842.1368394-2-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The qrtr_ctrl_pkt structure is currently accessed without checking if the received payload is large enough to hold the structure's fields. Add a check to ensure the payload length is sufficient. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/ns.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 3de9350cbf30..6158e08c0252 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -619,6 +619,9 @@ static void qrtr_ns_worker(struct work_struct *work) break; } + if ((size_t)msglen < sizeof(pkt)) + break; + pkt = recv_buf; cmd = le32_to_cpu(pkt->cmd); if (cmd < ARRAY_SIZE(qrtr_ctrl_pkt_strings) && From patchwork Fri Oct 18 18:18:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 836752 Received: from mail-oo1-f47.google.com (mail-oo1-f47.google.com [209.85.161.47]) (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 A2D89204F7E; Fri, 18 Oct 2024 18:20:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275618; cv=none; b=mR2nUj/FYecPe8+LgbSjN/ninHHNdnIr/aXodyufxR4kLabdBhXyyfwde0/rSvlISf01DWVGumMxfOhodtAd/pIYRWGV96DLZthHU0BB4fuzn9RwmwVTlK8mUSwKXA2UsAl1cG8KMP0hkZtY+cjDVcJ4MqLy7UNGPkomQRMX804= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275618; c=relaxed/simple; bh=WudN9ftC6DeqlaCrwSUWzPCAN0Q9s+iy462O/XnUrdU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AyDTT6g4LjBnJXoobjgnU09LTnZxW4xKXbfHV5XuQYRe9m8q+7GSWpNrOzp7ucFeWCzzWpeAcjNX7tZG+VPqWNrtvQ8eDgzK+VAr50pEjVWFY1lI1R4mdlzzKfTeK3fuG4iQ4u1Xy/x+HEmwfzMM5JfsumfrmECLS7hGzpQl5ac= 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=NtyTox00; arc=none smtp.client-ip=209.85.161.47 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="NtyTox00" Received: by mail-oo1-f47.google.com with SMTP id 006d021491bc7-5eb8099f2e2so815337eaf.3; Fri, 18 Oct 2024 11:20:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275615; x=1729880415; darn=vger.kernel.org; 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=33FckhCRiLLoBZH7c4mWURCUmvTf+hn2g56oXXwJibo=; b=NtyTox0042+vaO6foqBp/QM+OSiO7FwrUklF6o94otzoW5QHML9Uw9ZXjbouSc4lQG xjgM5ECty2Tz6XR88gdNrBtZoDeAqqgDQ9/D/o7Oc/rfhZH6bo4ViED3eSuPTkYD2SQz ybWshcL2Y+l2zfgQKDxVcr9Kk49uqp91uZdCqJnuffq1zsbv/47y7ewcZRtZrZ6337Ix H0SpntncP5zcKyuAs10Kp/h9Cs4XtOnfRMv3KuiOjYy27hAIv0weBXbdK3J2nwD5CMoG ijDLDZiPOvAH1/e82AE39F/ZGEPtgntR4B0jFpR5QabqCW101Szp+houkt7j/tmJ3/MO 1gzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275615; x=1729880415; 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=33FckhCRiLLoBZH7c4mWURCUmvTf+hn2g56oXXwJibo=; b=oA67Kfwjaf9vlVwNcjgBCgvrAq60tD2muiSHnu4CXkjXvz+ymxFdF0kwYueDbsi41o DmpVJ7raaJm4VWGPIO2t4EOsC92pprYSf8ep3jBLzVNjZkdh7WUOJfybovSXPNBoukd4 Ax88krXtWE5xgj3jWMobu6wEzxjXRVxNVLePDRFa7mldohOcLhGncTBnre6o5HjnPCel UqRTdZeBaadXfkeGPSwRhqHX2PgTGEpuvviMmNa5eR4u66KoTt7bvyqUmgzpBiY32ACN g4uaKYgeB91gWBMwfPbdqi/d19lCoxQBFJUoOsOKloSOqGIiDIyaIImFkI+3Kl2Ec/9/ 5txg== X-Forwarded-Encrypted: i=1; AJvYcCW619WKqyrkUfAulmOtECJZI+dkeQN7bf+/HIA5HUOvsd8OdS0+6EESxhR37qkdoIEy6csSdUNERbvjFsgf@vger.kernel.org, AJvYcCX67aESW8B8QD5Qr1x8wmZ75gJpnJojJE5lxj0HGqrhNq3a8JL0U5zrauvmeqEGmuZLIzO5V8JBqqZSGzhc@vger.kernel.org X-Gm-Message-State: AOJu0YwsEwRsDHLl4FD2HGs2JRcuS6R3aZ24QjjOaa0WlITe+ukYJL9Z tO/VlrzNdIoNgZY3jAEO3mxgO9VZGvsW54z1uS/tMldVe76na4JsESNhYg== X-Google-Smtp-Source: AGHT+IHyWOcgr4FWztL1ijnQ1zPOX+9VjBTxIsRdSUtYUaREeHMbbj4CLzZSuGU1zUiyi3qwWZiqZQ== X-Received: by 2002:a05:6820:610:b0:5e7:caf5:ae1f with SMTP id 006d021491bc7-5eb8b36af65mr3052839eaf.2.1729275615643; Fri, 18 Oct 2024 11:20:15 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:15 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 03/10] net: qrtr: support identical node ids Date: Fri, 18 Oct 2024 13:18:21 -0500 Message-ID: <20241018181842.1368394-4-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Add support for tracking multiple endpoints that may have conflicting node identifiers. This is achieved by using both the node and endpoint identifiers as the key inside the radix_tree data structure. For backward compatibility with existing clients, the previous key schema (node identifier only) is preserved. However, this schema will only support the first endpoint/node combination. This is acceptable for legacy clients as support for multiple endpoints with conflicting node identifiers was not previously possible. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index be275871fb2a..e83d491a8da9 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -418,12 +418,20 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid) static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid) { unsigned long flags; + unsigned long key; if (nid == QRTR_EP_NID_AUTO) return; spin_lock_irqsave(&qrtr_nodes_lock, flags); - radix_tree_insert(&qrtr_nodes, nid, node); + + /* Always insert with the endpoint_id + node_id */ + key = (unsigned long)node->ep->id << 32 | nid; + radix_tree_insert(&qrtr_nodes, key, node); + + if (!radix_tree_lookup(&qrtr_nodes, nid)) + radix_tree_insert(&qrtr_nodes, nid, node); + if (node->nid == QRTR_EP_NID_AUTO) node->nid = nid; spin_unlock_irqrestore(&qrtr_nodes_lock, flags); From patchwork Fri Oct 18 18:18:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 836751 Received: from mail-oo1-f49.google.com (mail-oo1-f49.google.com [209.85.161.49]) (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 2FE0020697D; Fri, 18 Oct 2024 18:20:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.161.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275625; cv=none; b=qFZ7+07uapnEx8pEzQbngKwZSps1NQgdIGlTYWNARkvcRZquIMCIsL2/hkNt7VsoZnNHCbrBTVfV9KRsrheaBlY/hBdCHlT40hsNYu5JOSDfEATKpR92A5vP6nmTu7kRfNPBO7GcghrjdVpYXrme7LSQw3Ml1n5YHBgVQGfzavU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275625; c=relaxed/simple; bh=Jqk9t6WqUxgOSLlvZ3OiYUOtfU662Z01mQkIZRFbT5U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=TBCuRthCuKH1rQ5lXLOBUNeZ1i6WV0OSvWLGLMKd4KSGHAbN9LB6X4yCRGz2lJIZEVVS6kY/Oh9T0Up+hbGYlxXTjNUA4fRNRcwmYANwgoMgZ2yzeQYwBQ6QwGB/I54l17gxhMEfZcW3IcSt9aQrtdBHY5MmtlSIhKcOvF8c5z8= 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=XS22+Iaq; arc=none smtp.client-ip=209.85.161.49 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="XS22+Iaq" Received: by mail-oo1-f49.google.com with SMTP id 006d021491bc7-5eb6abc6342so1478258eaf.0; Fri, 18 Oct 2024 11:20:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275622; x=1729880422; darn=vger.kernel.org; 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=wTMpYIXHYNCs7bSRCpbxFRGF6reME+eyLPM7z+f7+Fc=; b=XS22+IaqqXUujk3Gitl8xsdZ67QD4MDiUcNzDDHvOzNGCPcnbX+0AY5xLKjMK+0+8s wljLMblcQoUmiDeZwoqb13GgQmsqyw2rOlCKamwdfFMCl0pvA2ExgbgIThnFQvnOIXy2 xDui7pNzJi774cID7xctFUt5LnScCb/TYSpyh1hWp7qdOg3W8AuQLvQ6OGvDZ2ooUMCm 3H8IWV/4cdi4E7q3CD3ZGk817lcKRZf0ttnht81MFwomUnlSEZcjgtVu4rVWl0CyqBwF JMzLySzHSr+WEX59qKCL1iACJzsijguUpQS+m4b8Emzp4eSigiGDGw0NFbYjLDNkb4nR PkGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275622; x=1729880422; 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=wTMpYIXHYNCs7bSRCpbxFRGF6reME+eyLPM7z+f7+Fc=; b=hmvZ7QTQ2FBNR2Nl5ztico4SCLk3YxQG8S+qUJvoGE5UK7+DoR1sBsJBIV/0xfJsbZ DPC6IlDB6P1ataGX3HOGn9gClPEUoQlnfnSzGg4SvQhQvUbLI1Ud3OGDwhmCyRb/OSrM KFRZTfvuy+UhDkyI31WTOEfnClQfz/o3qR8/+lCsfToWfOJGgEjAV0zDllSpG/ZBhc9t 5VC1hbY3er5dmfJ2UQ3LAcpwyJb3P3w5Ox4wDIc3KGy6dP90VeZE2vaElzv1y/z8B9Dd UH0oD37jBtVjQ9suYDn+QdMuGfI61yhsK3UvhxFOuWNFBtpt/NEpN/a0bjSoZUPUTSc7 h6kA== X-Forwarded-Encrypted: i=1; AJvYcCVDmqriWoef0YpXoyq0Bqa7DtZE+JeqQib/6doVyYmotVDTeMHExL8Me2GrbTDAO9TXifmS/mi4ccVeU2UO@vger.kernel.org, AJvYcCVTCfaoWWe2iVSUdUoo2FKy0VnAEM+L5dRJwamMBIPiUEYBowfDy811mieOQ6a6rS25bIqjgELcefzV8KRZ@vger.kernel.org X-Gm-Message-State: AOJu0Yz5vo/S+hnmjkPZWPQFkC2G/m2PelcUlJ3oOrWnv4UOsXp0hRIH RVGH2XChZYFKk8Q5WHaVwe5eRXR3lsfNxujNvzCOlFWdYS6CflNZImEgRw== X-Google-Smtp-Source: AGHT+IHrr5ctvzud0yteza2a9cQOrgEySRGHiYN8KdAn2gGnVum2L6yeh0XMgP24bYfrrwCWYJSZMw== X-Received: by 2002:a05:6820:1ac5:b0:5e3:b361:e457 with SMTP id 006d021491bc7-5eb8b378a7fmr2949706eaf.1.1729275622139; Fri, 18 Oct 2024 11:20:22 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:21 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 05/10] net: qrtr: Report endpoint for locally generated messages Date: Fri, 18 Oct 2024 13:18:23 -0500 Message-ID: <20241018181842.1368394-6-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 For messages generated by the local endpoint destined to the local endpoint, report the local endpoint identifier. Same QRTR_ENDPOINT auxiliary data and QRTR_REPORT_ENDPOINT socket option semantics apply as for messages generated by remote endpoints. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index cb7bd1c71e6d..568ccb1d8574 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -163,9 +163,11 @@ struct qrtr_tx_flow { #define QRTR_TX_FLOW_LOW 5 static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to); static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to); static struct qrtr_sock *qrtr_port_lookup(int port); @@ -349,6 +351,7 @@ static void qrtr_tx_flow_failed(struct qrtr_node *node, int dest_node, /* Pass an outgoing packet socket buffer to the endpoint driver. */ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { @@ -678,7 +681,8 @@ void qrtr_endpoint_unregister(struct qrtr_endpoint *ep) skb = qrtr_alloc_ctrl_packet(&pkt, GFP_ATOMIC); if (skb) { pkt->cmd = cpu_to_le32(QRTR_TYPE_BYE); - qrtr_local_enqueue(NULL, skb, QRTR_TYPE_BYE, &src, &dst); + qrtr_local_enqueue(NULL, skb, endpoint_id, + QRTR_TYPE_BYE, &src, &dst); } } spin_unlock_irqrestore(&qrtr_nodes_lock, flags); @@ -745,8 +749,8 @@ static void qrtr_port_remove(struct qrtr_sock *ipc) pkt->client.port = cpu_to_le32(ipc->us.sq_port); skb_set_owner_w(skb, &ipc->sk); - qrtr_bcast_enqueue(NULL, skb, QRTR_TYPE_DEL_CLIENT, &ipc->us, - &to); + qrtr_bcast_enqueue(NULL, skb, qrtr_local_nid, + QRTR_TYPE_DEL_CLIENT, &ipc->us, &to); } if (port == QRTR_PORT_CTRL) @@ -886,6 +890,7 @@ static int qrtr_bind(struct socket *sock, struct sockaddr *saddr, int len) /* Queue packet to local peer socket. */ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { @@ -903,6 +908,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, cb = (struct qrtr_cb *)skb->cb; cb->src_node = from->sq_node; cb->src_port = from->sq_port; + cb->endpoint_id = endpoint_id; if (sock_queue_rcv_skb(&ipc->sk, skb)) { qrtr_port_put(ipc); @@ -917,6 +923,7 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, /* Queue packet for broadcast. */ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, + u32 endpoint_id, int type, struct sockaddr_qrtr *from, struct sockaddr_qrtr *to) { @@ -928,11 +935,11 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, if (!skbn) break; skb_set_owner_w(skbn, skb->sk); - qrtr_node_enqueue(node, skbn, type, from, to); + qrtr_node_enqueue(node, skbn, endpoint_id, type, from, to); } mutex_unlock(&qrtr_node_lock); - qrtr_local_enqueue(NULL, skb, type, from, to); + qrtr_local_enqueue(NULL, skb, endpoint_id, type, from, to); return 0; } @@ -940,12 +947,13 @@ static int qrtr_bcast_enqueue(struct qrtr_node *node, struct sk_buff *skb, static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) { DECLARE_SOCKADDR(struct sockaddr_qrtr *, addr, msg->msg_name); - int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, int, + int (*enqueue_fn)(struct qrtr_node *, struct sk_buff *, u32, int, struct sockaddr_qrtr *, struct sockaddr_qrtr *); __le32 qrtr_type = cpu_to_le32(QRTR_TYPE_DATA); struct qrtr_sock *ipc = qrtr_sk(sock->sk); struct sock *sk = sock->sk; struct qrtr_node *node; + u32 endpoint_id = qrtr_local_nid; struct sk_buff *skb; size_t plen; u32 type; @@ -1029,7 +1037,7 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) } type = le32_to_cpu(qrtr_type); - rc = enqueue_fn(node, skb, type, &ipc->us, addr); + rc = enqueue_fn(node, skb, endpoint_id, type, &ipc->us, addr); if (rc >= 0) rc = len; @@ -1061,7 +1069,8 @@ static int qrtr_send_resume_tx(struct qrtr_cb *cb) pkt->client.node = cpu_to_le32(cb->dst_node); pkt->client.port = cpu_to_le32(cb->dst_port); - ret = qrtr_node_enqueue(node, skb, QRTR_TYPE_RESUME_TX, &local, &remote); + ret = qrtr_node_enqueue(node, skb, cb->endpoint_id, + QRTR_TYPE_RESUME_TX, &local, &remote); qrtr_node_release(node); From patchwork Fri Oct 18 18:18:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Denis Kenzior X-Patchwork-Id: 836750 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 6593A20969D; Fri, 18 Oct 2024 18:20:27 +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=1729275629; cv=none; b=KlMm75/82e85FzwMJaIMpH/Z7kdGKWg4s9O0mOqPkA8M5+lMTIyJJTZn6Ogts70lj46BJh3CMtJAWgN0jY7lJKAxx7NQZz/dUaxnyS5kG3LwglaxkQ5ogfWjwZLsBKk1ySkL5Xh1B795LTAMWukaNqMdCQ86uKTfPStnN/UB8Bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275629; c=relaxed/simple; bh=3XACKo/pFuD+zNXmFPGHbf4kk7ld46ZIOgUe2iuHHBI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SzvgrTTUJxP1sAwgRe0VNtQpgkKF/d6tEqPhvY2gbr9GNzdc1YqtKVjRp66R1mTT27j1Evw0EPs4dubE+c0ZACBeItI8kfXf+Qlyd18IqazEYyTJ/owGf+8Wbc6zjRaO7i+wPYrlKUL+Zmu4td6pmwLBoMdqxCfeVL+k5sw2K6s= 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=aW+h6HfU; 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="aW+h6HfU" Received: by mail-oo1-f50.google.com with SMTP id 006d021491bc7-5eb70a772ccso1195294eaf.0; Fri, 18 Oct 2024 11:20:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275626; x=1729880426; darn=vger.kernel.org; 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=ndKcW9vvldcHXXks3zBgM3lQGpSUMPL+gKrZxYgEdL4=; b=aW+h6HfUukK+MwsF2Rkbua3GUm6VAEZKyty2jst41Jjj9mzTV/oyPi1/Bm1FULzWRv zYh8RRmWU52m4q3/TqjqbpGni0DY1V8kQmc5xLAMAXWQLt7V00BcD9d3U1aaHhIsoKaw ZX3SI0OoL9VpHOnAjCWGm4LedRCQjNto6HPhYZx3bcg6GT3Kj9ny9mQZbP1Tb6F5Bnaj C0HOLZ4I/SZ9MBc6L2QIY0jP/dkE5SMFH6rFfAL15hkuO8le3sKG/gZ9n26MBF9f3rla pfxbsQWdMugOQYKU77+GJq5UZBp7tBI4tLvEDvFcnlN1QBybLm50Mta+1Sf4dqJ6ol6p In+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275626; x=1729880426; 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=ndKcW9vvldcHXXks3zBgM3lQGpSUMPL+gKrZxYgEdL4=; b=gchnV7IGvPfHNbsDkmgaDQFDVNo43ZvGD0ifGNtG9l71230Y/4/afXvPeMyRJtmTky PrACX8ueXLbpG/jtgLbQ2H8ZKD+QXhKorWA2NJBAPR0gPiM88WSt5viF4rK+/H3pHntJ 0Jp98W02jRnVPUySYagv+fV6UxviofV1mgx+q7j9fNRPPeCYmC7wagqmmhDyn72vFjkX EAn++5Y0cocpPaLbTXi9yGTRLCM7uqrgNC7HTVvSuCk1P0Toa45xNf6aaV2ALcPiqkwR XqCGuINN8bPAy1M5Rr4S3MG5na3gEJSfCV5nVOGH+8uOOCiQoDXRCg1pDR2Rs2IHGSzB RjmQ== X-Forwarded-Encrypted: i=1; AJvYcCUoXqBk9xhycRehwqR07++fAxkN5o+RfaGSDVaB3g4e+i5KCOtRAeFJNJDOo6MxaBESg908KgluburXYkBq@vger.kernel.org, AJvYcCVfqYKA6GVeJp4cRC7fbl/zEBcui+/MxAtombYBwJitAXtvDx/VjOclRuBifhM0ctRQf3CrI+djs8igoNpF@vger.kernel.org X-Gm-Message-State: AOJu0YxhdnFdpKGl/eL2MrNfOyD8CNQwhpKTr8amiwEfjVwf1PYzUD4J edvnZ97jUWOb+t5+c3b2/LOv3lDkEt0mLBZ4PqbSsGIJ8/Nwzcw4TAKXrg== X-Google-Smtp-Source: AGHT+IHOOMjMq52wLrdAP+g4LwRWu1SqN7ru4viQIFijEXQNfxYMvFv0Wz4XN7fg+mnLor72B1cwQQ== X-Received: by 2002:a05:6820:610:b0:5eb:7e7c:5303 with SMTP id 006d021491bc7-5eb8b3a7aa3mr2374335eaf.2.1729275626329; Fri, 18 Oct 2024 11:20:26 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:25 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 07/10] net: qrtr: allow socket endpoint binding Date: Fri, 18 Oct 2024 13:18:25 -0500 Message-ID: <20241018181842.1368394-8-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Introduce the ability to bind a QIPCRTR family socket to a specific endpoint. When a socket is bound, only messages from the bound endpoint can be received, and any messages sent from the socket are by default directed to the bound endpoint. Clients can bind a socket by using the setsockopt system call with the QRTR_BIND_ENDPOINT option set to the desired endpoint binding. A previously set binding can be reset by setting QRTR_BIND_ENDPOINT option to zero. This behavior matches that of SO_BINDTOIFINDEX. This functionality is useful for clients that need to communicate with a specific device (i.e. endpoint), such as a PCIe-based 5G modem, and are not interested in messages from other endpoints / nodes. Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- include/uapi/linux/qrtr.h | 1 + net/qrtr/af_qrtr.c | 54 ++++++++++++++++++++++++++++----------- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/include/uapi/linux/qrtr.h b/include/uapi/linux/qrtr.h index 6d0911984a05..0a8667b049c3 100644 --- a/include/uapi/linux/qrtr.h +++ b/include/uapi/linux/qrtr.h @@ -48,6 +48,7 @@ struct qrtr_ctrl_pkt { /* setsockopt / getsockopt */ #define QRTR_REPORT_ENDPOINT 1 +#define QRTR_BIND_ENDPOINT 2 /* CMSG */ #define QRTR_ENDPOINT 1 diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 23749a0b0c15..b2f9c25ba8f8 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -98,6 +98,7 @@ struct qrtr_sock { struct sockaddr_qrtr us; struct sockaddr_qrtr peer; unsigned long flags; + u32 bound_endpoint; }; static inline struct qrtr_sock *qrtr_sk(struct sock *sk) @@ -587,9 +588,13 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len) if (!ipc) goto err; - if (sock_queue_rcv_skb(&ipc->sk, skb)) { - qrtr_port_put(ipc); - goto err; + /* Sockets bound to an endpoint only rx from that endpoint */ + if (!ipc->bound_endpoint || + ipc->bound_endpoint == cb->endpoint_id) { + if (sock_queue_rcv_skb(&ipc->sk, skb)) { + qrtr_port_put(ipc); + goto err; + } } qrtr_port_put(ipc); @@ -928,29 +933,41 @@ static int qrtr_local_enqueue(struct qrtr_node *node, struct sk_buff *skb, { struct qrtr_sock *ipc; struct qrtr_cb *cb; + int ret = -ENODEV; ipc = qrtr_port_lookup(to->sq_port); - if (!ipc || &ipc->sk == skb->sk) { /* do not send to self */ - if (ipc) - qrtr_port_put(ipc); - kfree_skb(skb); - return -ENODEV; - } + if (!ipc) + goto done; + + if (&ipc->sk == skb->sk) /* do not send to self */ + goto done; + + /* + * Filter out unwanted packets that are not on behalf of the bound + * endpoint. Certain special packets (such as an empty NEW_SERVER + * packet that serves as a sentinel value) always go through. + */ + if (endpoint_id && ipc->bound_endpoint && + ipc->bound_endpoint != endpoint_id) + goto done; cb = (struct qrtr_cb *)skb->cb; cb->src_node = from->sq_node; cb->src_port = from->sq_port; cb->endpoint_id = endpoint_id; - if (sock_queue_rcv_skb(&ipc->sk, skb)) { - qrtr_port_put(ipc); - kfree_skb(skb); - return -ENOSPC; - } + ret = -ENOSPC; + if (sock_queue_rcv_skb(&ipc->sk, skb)) + goto done; qrtr_port_put(ipc); return 0; +done: + if (ipc) + qrtr_port_put(ipc); + kfree_skb(skb); + return ret; } /* Queue packet for broadcast. */ @@ -1034,7 +1051,8 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) } else if (addr->sq_node == ipc->us.sq_node) { enqueue_fn = qrtr_local_enqueue; } else { - endpoint_id = msg_endpoint_id; + endpoint_id = msg_endpoint_id ? + msg_endpoint_id : ipc->bound_endpoint; node = qrtr_node_lookup(endpoint_id, addr->sq_node); if (!node) { @@ -1313,6 +1331,9 @@ static int qrtr_setsockopt(struct socket *sock, int level, int optname, case QRTR_REPORT_ENDPOINT: assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, val); break; + case QRTR_BIND_ENDPOINT: + ipc->bound_endpoint = val; + break; default: rc = -ENOPROTOOPT; } @@ -1346,6 +1367,9 @@ static int qrtr_getsockopt(struct socket *sock, int level, int optname, case QRTR_REPORT_ENDPOINT: val = test_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags); break; + case QRTR_BIND_ENDPOINT: + val = ipc->bound_endpoint; + break; default: rc = -ENOPROTOOPT; } From patchwork Fri Oct 18 18:18: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: 836749 Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.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 6EE2F20E034; Fri, 18 Oct 2024 18:20:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.42 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275634; cv=none; b=CT5z0RjB/ruyhi4QySgHnNHvqByj8Wr+P8EGgQ8uNQKkpE7waJSUS4xkYp68xEePv8uFZpkc4so007qWEZO9041XZW6pfXglaSnMyEd3FCaq9sPq4SLATPvIqHMqaQQ+YcRKne/met6m8Gd0b3/nZvUXb4ursBdgzdUVPRnKHn8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729275634; c=relaxed/simple; bh=aA2jSJoNyalqp8WXqjcCcmVDza8tosKbDMDvAIGniio=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=SEVhsIbj3bzScwR7mbaPkAs9/jCFatFlSFV07JY3XTfWl2D7I8x3YM3eO9YX7+unWXgEu1jN3I+BlifjhIiCrSxC9yUdFkgwsqP4hW8zfOwwlaHXULrwCq4EgCrhhHpN48OVcGWn4t/bfGYKWYzU3zQsSU790MVGmrjsds8Boto= 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=eAYGNToP; arc=none smtp.client-ip=209.85.210.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="eAYGNToP" Received: by mail-ot1-f42.google.com with SMTP id 46e09a7af769-7181b86a749so475005a34.3; Fri, 18 Oct 2024 11:20:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729275630; x=1729880430; darn=vger.kernel.org; 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=tPt7HWg9o/t9Kiabv7bBS/POb/GbeQprp+oLjeSGecY=; b=eAYGNToPLAjEPukGK+pjA2OkSroXQ3RktIdg+kEu6h5I/0ysuOqBe+ZGseyqBGlXB3 is6gvUQj9Zq3RINA52eilSyfn9PfUBwbe9r9uIyt4Lqe2ujCyje3dAR7mZ2fW70GqKV4 iKPOHp2FfTLxQHaWZm/3TtoPx8CkNwIvZFB0sp83/96z7oFbrCazy1dj5iOEzlneGKA/ RMgnNR0Fs2kfYsbm2PZodlpkHqxtUzPFbtjdXkEsScKpQRfY3Kb6+JDw7LWVvLN0DSuf 40sE7BWgGW6yTeSpgtAS1YIS4e1z2GH+1GrAlAGJC5QrRuapEG2oR1fG5kkVZ/wiGM67 vgBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729275630; x=1729880430; 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=tPt7HWg9o/t9Kiabv7bBS/POb/GbeQprp+oLjeSGecY=; b=OFZK4GTe6HDNBIC1sjQCUcg3/oGchKqpyQZQtE0qLUNIK59RVjrStYZtZnmD5VUbii tM3NhZsj5g3Hy/9+clFnPcWGEHBCEfALr8DlPfaD6/O5qh1EC68umo2xIk9xIkLB+HNP sVBwHhijRPk6oUphjmzwcRIDjWXDlD1cfrzaRvCCEJVUX+sBKjo3RTAj//ANSRiDOlHg vfsWwfj24KN9ORk13UJUdTDrKGHx2HuMgv9IwWnoB7YiHKsYAWv4bWaQeNezQgChILvO x3bJD0bBiqhowN+SZg8G0JwaS/cI9+dCz9gtj0x77Bm1M0bh6rZM0R82+PZmSYdf3TiF HHgA== X-Forwarded-Encrypted: i=1; AJvYcCX9xvLbr9b+nzh0n5hgJxMq0CauoeeOlSdnT5YwsngHD4I+iiA58mJFSbCXooY2zak5qr1yWDqoFO53fACN@vger.kernel.org, AJvYcCXBbG4/2xaQkzyzsVPRHnnvokWMmaEu0343I8TuhlP7B/W0vmg0clptri4ULzf9OeyKk9P8ZBvXZmEcv6Ky@vger.kernel.org X-Gm-Message-State: AOJu0YzrLaVUy5pKgsrMhwNCAH2KKZ1gfEpX/Pabf9sq0BV07gOttO0+ /EIFJ0nqBItJrLrl4hPLTDwOhdMmGwwK0UlSk0+ftAV6OcIB47rc+O+qiA== X-Google-Smtp-Source: AGHT+IELXxVKa8uSNHsrmFkWlSULMmo+HrSU9FKGLh9XpdiQDGAyW7oTf42WeF24URvVoJpzBZQzIQ== X-Received: by 2002:a05:6830:3989:b0:717:f707:cb92 with SMTP id 46e09a7af769-7181a8c20d7mr2879917a34.28.1729275630276; Fri, 18 Oct 2024 11:20:30 -0700 (PDT) Received: from localhost.localdomain (syn-070-114-247-242.res.spectrum.com. [70.114.247.242]) by smtp.gmail.com with ESMTPSA id 006d021491bc7-5eb8aa2f668sm340542eaf.44.2024.10.18.11.20.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 11:20:29 -0700 (PDT) From: Denis Kenzior To: netdev@vger.kernel.org Cc: denkenz@gmail.com, Marcel Holtmann , Andy Gross , Manivannan Sadhasivam , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH v1 09/10] net: qrtr: ns: support multiple endpoints Date: Fri, 18 Oct 2024 13:18:27 -0500 Message-ID: <20241018181842.1368394-10-denkenz@gmail.com> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241018181842.1368394-1-denkenz@gmail.com> References: <20241018181842.1368394-1-denkenz@gmail.com> Precedence: bulk X-Mailing-List: linux-arm-msm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extend the qrtr name service with the concept of an endpoint. Endpoints can be remote or local, and are represented by a unique endpoint id. This allows the qrtr name service to support multiple devices (endpoints) that might have overlapping node / port combinations. The socket used by the name service is subscribed to receive endpoint information via a mechanism similar to the SOL_QRTR QRTR_REPORT_ENDPOINT socket option. Internal data structures are then extended to track endpoint information in addition to nodes and ports. The name service directs packets to the endpoint originating the request. For NEW_SERVER and DEL_SERVER messages triggered using lookups or due to remote endpoints sending the corresponding message, qrtr name service generates a NEW_SERVER and DEL_SERVER messages to all local sockets registered to receive such notifications. The messages are made to look as if they're coming from the remote endpoint using a special extension to AF_QRTR sendmsg operation. This extension only works for the local socket that owns the QRTR_PORT_CTRL port (name service). Signed-off-by: Denis Kenzior Reviewed-by: Marcel Holtmann Reviewed-by: Andy Gross --- net/qrtr/af_qrtr.c | 14 +++ net/qrtr/ns.c | 296 +++++++++++++++++++++++++++------------------ net/qrtr/qrtr.h | 1 + 3 files changed, 193 insertions(+), 118 deletions(-) diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c index 95c9679725ee..ea678c3c5752 100644 --- a/net/qrtr/af_qrtr.c +++ b/net/qrtr/af_qrtr.c @@ -107,6 +107,15 @@ static inline struct qrtr_sock *qrtr_sk(struct sock *sk) return container_of(sk, struct qrtr_sock, sk); } +void qrtr_sock_set_report_endpoint(struct sock *sk) +{ + struct qrtr_sock *ipc = qrtr_sk(sk); + + lock_sock(sk); + assign_bit(QRTR_F_REPORT_ENDPOINT, &ipc->flags, 1); + release_sock(sk); +} + int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id) { struct cmsghdr *cmsg; @@ -1092,6 +1101,11 @@ static int qrtr_sendmsg(struct socket *sock, struct msghdr *msg, size_t len) /* control messages already require the type as 'command' */ skb_copy_bits(skb, 0, &qrtr_type, 4); + /* + * Allow local name service to make packets appear as if + * they originated remotely + */ + endpoint_id = msg_endpoint_id; } type = le32_to_cpu(qrtr_type); diff --git a/net/qrtr/ns.c b/net/qrtr/ns.c index 6158e08c0252..a3118a05dcb8 100644 --- a/net/qrtr/ns.c +++ b/net/qrtr/ns.c @@ -5,6 +5,7 @@ * Copyright (c) 2020, Linaro Ltd. */ +#define pr_fmt(fmt) "QRTR NS: "fmt #include #include #include @@ -16,7 +17,7 @@ #define CREATE_TRACE_POINTS #include -static DEFINE_XARRAY(nodes); +static DEFINE_XARRAY(endpoints); static struct { struct socket *sock; @@ -60,6 +61,7 @@ struct qrtr_server { unsigned int node; unsigned int port; + u32 endpoint_id; struct list_head qli; }; @@ -69,28 +71,70 @@ struct qrtr_node { struct xarray servers; }; -static struct qrtr_node *node_get(unsigned int node_id) +struct qrtr_ns_endpoint { + unsigned int id; + struct xarray nodes; +}; + +static struct qrtr_node *node_lookup(u32 endpoint_id, unsigned int node_id) +{ + struct qrtr_ns_endpoint *endpoint; + + endpoint = xa_load(&endpoints, endpoint_id); + if (!endpoint) + return NULL; + + return xa_load(&endpoint->nodes, node_id); +} + +static struct qrtr_node *node_new(u32 endpoint_id, unsigned int node_id) { + struct qrtr_ns_endpoint *endpoint; struct qrtr_node *node; + bool new_endpoint = false; - node = xa_load(&nodes, node_id); - if (node) - return node; + endpoint = xa_load(&endpoints, endpoint_id); + if (!endpoint) { + endpoint = kzalloc(sizeof(*endpoint), GFP_KERNEL); + if (!endpoint) + return NULL; + + endpoint->id = endpoint_id; + xa_init(&endpoint->nodes); + + if (xa_store(&endpoints, endpoint_id, endpoint, GFP_KERNEL)) { + kfree(endpoint); + return NULL; + } + + new_endpoint = true; + } else { + node = xa_load(&endpoint->nodes, node_id); + if (node) + return node; + } /* If node didn't exist, allocate and insert it to the tree */ node = kzalloc(sizeof(*node), GFP_KERNEL); if (!node) - return NULL; + goto error; node->id = node_id; xa_init(&node->servers); - if (xa_store(&nodes, node_id, node, GFP_KERNEL)) { + if (xa_store(&endpoint->nodes, node_id, node, GFP_KERNEL)) { kfree(node); - return NULL; + goto error; } return node; +error: + if (new_endpoint) { + xa_erase(&endpoints, endpoint_id); + kfree(endpoint); + } + + return NULL; } static int server_match(const struct qrtr_server *srv, @@ -106,19 +150,42 @@ static int server_match(const struct qrtr_server *srv, return (srv->instance & ifilter) == f->instance; } -static int service_announce_new(struct sockaddr_qrtr *dest, - struct qrtr_server *srv) +static int qrtr_ns_sendmsg(u32 endpoint_id, struct sockaddr_qrtr *dest, + struct qrtr_ctrl_pkt *pkt) { - struct qrtr_ctrl_pkt pkt; struct msghdr msg = { }; struct kvec iv; + u8 control[CMSG_SPACE(sizeof(endpoint_id))]; + struct cmsghdr *cmsg; + + iv.iov_base = pkt; + iv.iov_len = sizeof(*pkt); + + msg.msg_name = (struct sockaddr *)dest; + msg.msg_namelen = sizeof(*dest); + + if (endpoint_id) { + msg.msg_control = control; + msg.msg_controllen = sizeof(control); + + cmsg = CMSG_FIRSTHDR(&msg); + cmsg->cmsg_level = SOL_QRTR; + cmsg->cmsg_type = QRTR_ENDPOINT; + cmsg->cmsg_len = CMSG_LEN(sizeof(endpoint_id)); + memcpy(CMSG_DATA(cmsg), &endpoint_id, sizeof(endpoint_id)); + } + + return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(*pkt)); +} + +static int service_announce_new(u32 endpoint_id, struct sockaddr_qrtr *dest, + struct qrtr_server *srv) +{ + struct qrtr_ctrl_pkt pkt; trace_qrtr_ns_service_announce_new(srv->service, srv->instance, srv->node, srv->port); - iv.iov_base = &pkt; - iv.iov_len = sizeof(pkt); - memset(&pkt, 0, sizeof(pkt)); pkt.cmd = cpu_to_le32(QRTR_TYPE_NEW_SERVER); pkt.server.service = cpu_to_le32(srv->service); @@ -126,26 +193,18 @@ static int service_announce_new(struct sockaddr_qrtr *dest, pkt.server.node = cpu_to_le32(srv->node); pkt.server.port = cpu_to_le32(srv->port); - msg.msg_name = (struct sockaddr *)dest; - msg.msg_namelen = sizeof(*dest); - - return kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + return qrtr_ns_sendmsg(endpoint_id, dest, &pkt); } -static void service_announce_del(struct sockaddr_qrtr *dest, +static void service_announce_del(u32 endpoint_id, struct sockaddr_qrtr *dest, struct qrtr_server *srv) { struct qrtr_ctrl_pkt pkt; - struct msghdr msg = { }; - struct kvec iv; int ret; trace_qrtr_ns_service_announce_del(srv->service, srv->instance, srv->node, srv->port); - iv.iov_base = &pkt; - iv.iov_len = sizeof(pkt); - memset(&pkt, 0, sizeof(pkt)); pkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_SERVER); pkt.server.service = cpu_to_le32(srv->service); @@ -153,27 +212,22 @@ static void service_announce_del(struct sockaddr_qrtr *dest, pkt.server.node = cpu_to_le32(srv->node); pkt.server.port = cpu_to_le32(srv->port); - msg.msg_name = (struct sockaddr *)dest; - msg.msg_namelen = sizeof(*dest); - - ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt); if (ret < 0 && ret != -ENODEV) pr_err("failed to announce del service\n"); - - return; } -static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv, - bool new) +static void lookup_notify(u32 endpoint_id, struct sockaddr_qrtr *to, + struct qrtr_server *srv, bool new) { struct qrtr_ctrl_pkt pkt; - struct msghdr msg = { }; - struct kvec iv; int ret; - iv.iov_base = &pkt; - iv.iov_len = sizeof(pkt); - + /* + * Notify a local client at @to about a server change. The aux data + * will look as if it came from the endpoint that reported the event + * (remote or local) + */ memset(&pkt, 0, sizeof(pkt)); pkt.cmd = new ? cpu_to_le32(QRTR_TYPE_NEW_SERVER) : cpu_to_le32(QRTR_TYPE_DEL_SERVER); @@ -184,28 +238,25 @@ static void lookup_notify(struct sockaddr_qrtr *to, struct qrtr_server *srv, pkt.server.port = cpu_to_le32(srv->port); } - msg.msg_name = (struct sockaddr *)to; - msg.msg_namelen = sizeof(*to); - - ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + ret = qrtr_ns_sendmsg(endpoint_id, to, &pkt); if (ret < 0 && ret != -ENODEV) pr_err("failed to send lookup notification\n"); } -static int announce_servers(struct sockaddr_qrtr *sq) +static int announce_servers(u32 endpoint_id, struct sockaddr_qrtr *sq) { struct qrtr_server *srv; struct qrtr_node *node; unsigned long index; int ret; - node = node_get(qrtr_ns.local_node); + node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node); if (!node) return 0; - /* Announce the list of servers registered in this node */ + /* Announce servers registered on local endpoint to remote endpoint */ xa_for_each(&node->servers, index, srv) { - ret = service_announce_new(sq, srv); + ret = service_announce_new(endpoint_id, sq, srv); if (ret < 0) { if (ret == -ENODEV) continue; @@ -217,7 +268,8 @@ static int announce_servers(struct sockaddr_qrtr *sq) return 0; } -static struct qrtr_server *server_add(unsigned int service, +static struct qrtr_server *server_add(u32 endpoint_id, + unsigned int service, unsigned int instance, unsigned int node_id, unsigned int port) @@ -238,7 +290,7 @@ static struct qrtr_server *server_add(unsigned int service, srv->node = node_id; srv->port = port; - node = node_get(node_id); + node = node_new(endpoint_id, node_id); if (!node) goto err; @@ -264,7 +316,8 @@ static struct qrtr_server *server_add(unsigned int service, return NULL; } -static int server_del(struct qrtr_node *node, unsigned int port, bool bcast) +static int server_del(u32 endpoint_id, struct qrtr_node *node, + unsigned int port, bool bcast) { struct qrtr_lookup *lookup; struct qrtr_server *srv; @@ -276,9 +329,10 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast) xa_erase(&node->servers, port); - /* Broadcast the removal of local servers */ + /* Broadcast the removal of local servers to remote endpoints */ if (srv->node == qrtr_ns.local_node && bcast) - service_announce_del(&qrtr_ns.bcast_sq, srv); + service_announce_del(qrtr_ns.local_node, + &qrtr_ns.bcast_sq, srv); /* Announce the service's disappearance to observers */ list_for_each(li, &qrtr_ns.lookups) { @@ -288,7 +342,7 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast) if (lookup->instance && lookup->instance != srv->instance) continue; - lookup_notify(&lookup->sq, srv, false); + lookup_notify(endpoint_id, &lookup->sq, srv, false); } kfree(srv); @@ -296,23 +350,15 @@ static int server_del(struct qrtr_node *node, unsigned int port, bool bcast) return 0; } -static int say_hello(struct sockaddr_qrtr *dest) +static int say_hello(u32 endpoint_id, struct sockaddr_qrtr *dest) { struct qrtr_ctrl_pkt pkt; - struct msghdr msg = { }; - struct kvec iv; int ret; - iv.iov_base = &pkt; - iv.iov_len = sizeof(pkt); - memset(&pkt, 0, sizeof(pkt)); pkt.cmd = cpu_to_le32(QRTR_TYPE_HELLO); - msg.msg_name = (struct sockaddr *)dest; - msg.msg_namelen = sizeof(*dest); - - ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + ret = qrtr_ns_sendmsg(endpoint_id, dest, &pkt); if (ret < 0) pr_err("failed to send hello msg\n"); @@ -320,42 +366,38 @@ static int say_hello(struct sockaddr_qrtr *dest) } /* Announce the list of servers registered on the local node */ -static int ctrl_cmd_hello(struct sockaddr_qrtr *sq) +static int ctrl_cmd_hello(u32 endpoint_id, struct sockaddr_qrtr *sq) { int ret; - ret = say_hello(sq); + /* Send Hello and New Server messages to remote endpoint */ + ret = say_hello(endpoint_id, sq); if (ret < 0) return ret; - return announce_servers(sq); + return announce_servers(endpoint_id, sq); } -static int ctrl_cmd_bye(struct sockaddr_qrtr *from) +static int ctrl_cmd_bye(u32 endpoint_id, struct sockaddr_qrtr *from) { struct qrtr_node *local_node; struct qrtr_ctrl_pkt pkt; struct qrtr_server *srv; struct sockaddr_qrtr sq; - struct msghdr msg = { }; struct qrtr_node *node; unsigned long index; - struct kvec iv; int ret; - iv.iov_base = &pkt; - iv.iov_len = sizeof(pkt); - - node = node_get(from->sq_node); + node = node_lookup(endpoint_id, from->sq_node); if (!node) return 0; /* Advertise removal of this client to all servers of remote node */ xa_for_each(&node->servers, index, srv) - server_del(node, srv->port, true); + server_del(endpoint_id, node, srv->port, true); /* Advertise the removal of this client to all local servers */ - local_node = node_get(qrtr_ns.local_node); + local_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node); if (!local_node) return 0; @@ -368,10 +410,8 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) sq.sq_node = srv->node; sq.sq_port = srv->port; - msg.msg_name = (struct sockaddr *)&sq; - msg.msg_namelen = sizeof(sq); - - ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + /* Bye will look as if it came from endpoint_id */ + ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt); if (ret < 0 && ret != -ENODEV) { pr_err("failed to send bye cmd\n"); return ret; @@ -380,25 +420,20 @@ static int ctrl_cmd_bye(struct sockaddr_qrtr *from) return 0; } -static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, +static int ctrl_cmd_del_client(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int node_id, unsigned int port) { struct qrtr_node *local_node; struct qrtr_lookup *lookup; struct qrtr_ctrl_pkt pkt; - struct msghdr msg = { }; struct qrtr_server *srv; struct sockaddr_qrtr sq; struct qrtr_node *node; struct list_head *tmp; struct list_head *li; unsigned long index; - struct kvec iv; int ret; - iv.iov_base = &pkt; - iv.iov_len = sizeof(pkt); - /* Don't accept spoofed messages */ if (from->sq_node != node_id) return -EINVAL; @@ -423,12 +458,12 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, * DEL_SERVER. Neighbours would've already removed the server belonging * to this port due to the DEL_CLIENT broadcast from qrtr_port_remove(). */ - node = node_get(node_id); + node = node_lookup(endpoint_id, node_id); if (node) - server_del(node, port, false); + server_del(endpoint_id, node, port, false); /* Advertise the removal of this client to all local servers */ - local_node = node_get(qrtr_ns.local_node); + local_node = node_lookup(qrtr_ns.local_node, qrtr_ns.local_node); if (!local_node) return 0; @@ -442,10 +477,8 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, sq.sq_node = srv->node; sq.sq_port = srv->port; - msg.msg_name = (struct sockaddr *)&sq; - msg.msg_namelen = sizeof(sq); - - ret = kernel_sendmsg(qrtr_ns.sock, &msg, &iv, 1, sizeof(pkt)); + /* Del Client will look as if it came from endpoint_id */ + ret = qrtr_ns_sendmsg(endpoint_id, &sq, &pkt); if (ret < 0 && ret != -ENODEV) { pr_err("failed to send del client cmd\n"); return ret; @@ -454,7 +487,7 @@ static int ctrl_cmd_del_client(struct sockaddr_qrtr *from, return 0; } -static int ctrl_cmd_new_server(struct sockaddr_qrtr *from, +static int ctrl_cmd_new_server(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance, unsigned int node_id, unsigned int port) { @@ -469,12 +502,16 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from, port = from->sq_port; } - srv = server_add(service, instance, node_id, port); - if (!srv) + srv = server_add(endpoint_id, service, instance, node_id, port); + if (!srv) { + pr_err("Failed to add server\n"); return -EINVAL; + } if (srv->node == qrtr_ns.local_node) { - ret = service_announce_new(&qrtr_ns.bcast_sq, srv); + /* Broadcast local server info to all peer endpoints */ + ret = service_announce_new(qrtr_ns.local_node, + &qrtr_ns.bcast_sq, srv); if (ret < 0) { pr_err("failed to announce new service\n"); return ret; @@ -489,13 +526,13 @@ static int ctrl_cmd_new_server(struct sockaddr_qrtr *from, if (lookup->instance && lookup->instance != instance) continue; - lookup_notify(&lookup->sq, srv, true); + lookup_notify(endpoint_id, &lookup->sq, srv, true); } return ret; } -static int ctrl_cmd_del_server(struct sockaddr_qrtr *from, +static int ctrl_cmd_del_server(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance, unsigned int node_id, unsigned int port) { @@ -511,24 +548,22 @@ static int ctrl_cmd_del_server(struct sockaddr_qrtr *from, if (from->sq_node == qrtr_ns.local_node && from->sq_port != port) return -EINVAL; - node = node_get(node_id); + node = node_lookup(endpoint_id, node_id); if (!node) return -ENOENT; - server_del(node, port, true); + server_del(endpoint_id, node, port, true); return 0; } -static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, +static int ctrl_cmd_new_lookup(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance) { struct qrtr_server_filter filter; struct qrtr_lookup *lookup; - struct qrtr_server *srv; - struct qrtr_node *node; - unsigned long node_idx; - unsigned long srv_idx; + unsigned long id; + struct qrtr_ns_endpoint *endpoint; /* Accept only local observers */ if (from->sq_node != qrtr_ns.local_node) @@ -547,22 +582,30 @@ static int ctrl_cmd_new_lookup(struct sockaddr_qrtr *from, filter.service = service; filter.instance = instance; - xa_for_each(&nodes, node_idx, node) { - xa_for_each(&node->servers, srv_idx, srv) { - if (!server_match(srv, &filter)) - continue; + xa_for_each(&endpoints, id, endpoint) { + struct qrtr_node *node; + unsigned long node_idx; - lookup_notify(from, srv, true); + xa_for_each(&endpoint->nodes, node_idx, node) { + unsigned long srv_idx; + struct qrtr_server *srv; + + xa_for_each(&node->servers, srv_idx, srv) { + if (!server_match(srv, &filter)) + continue; + + lookup_notify(id, from, srv, true); + } } } /* Empty notification, to indicate end of listing */ - lookup_notify(from, NULL, true); + lookup_notify(0, from, NULL, true); return 0; } -static void ctrl_cmd_del_lookup(struct sockaddr_qrtr *from, +static void ctrl_cmd_del_lookup(u32 endpoint_id, struct sockaddr_qrtr *from, unsigned int service, unsigned int instance) { struct qrtr_lookup *lookup; @@ -595,6 +638,7 @@ static void qrtr_ns_worker(struct work_struct *work) ssize_t msglen; void *recv_buf; struct kvec iv; + u8 control[32]; int ret; msg.msg_name = (struct sockaddr *)&sq; @@ -605,8 +649,12 @@ static void qrtr_ns_worker(struct work_struct *work) return; for (;;) { + u32 endpoint_id; + iv.iov_base = recv_buf; iv.iov_len = recv_buf_size; + msg.msg_control = control; + msg.msg_controllen = sizeof(control); msglen = kernel_recvmsg(qrtr_ns.sock, &msg, &iv, 1, iv.iov_len, MSG_DONTWAIT); @@ -619,6 +667,16 @@ static void qrtr_ns_worker(struct work_struct *work) break; } + /* AUX data is written direct into the control buffer */ + msg.msg_control = control; + msg.msg_controllen = sizeof(control) - msg.msg_controllen; + + ret = qrtr_msg_get_endpoint(&msg, &endpoint_id); + if (ret < 0) { + pr_err("error receiving endpoint id: %d\n", ret); + break; + } + if ((size_t)msglen < sizeof(pkt)) break; @@ -632,25 +690,25 @@ static void qrtr_ns_worker(struct work_struct *work) ret = 0; switch (cmd) { case QRTR_TYPE_HELLO: - ret = ctrl_cmd_hello(&sq); + ret = ctrl_cmd_hello(endpoint_id, &sq); break; case QRTR_TYPE_BYE: - ret = ctrl_cmd_bye(&sq); + ret = ctrl_cmd_bye(endpoint_id, &sq); break; case QRTR_TYPE_DEL_CLIENT: - ret = ctrl_cmd_del_client(&sq, + ret = ctrl_cmd_del_client(endpoint_id, &sq, le32_to_cpu(pkt->client.node), le32_to_cpu(pkt->client.port)); break; case QRTR_TYPE_NEW_SERVER: - ret = ctrl_cmd_new_server(&sq, + ret = ctrl_cmd_new_server(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance), le32_to_cpu(pkt->server.node), le32_to_cpu(pkt->server.port)); break; case QRTR_TYPE_DEL_SERVER: - ret = ctrl_cmd_del_server(&sq, + ret = ctrl_cmd_del_server(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance), le32_to_cpu(pkt->server.node), @@ -661,12 +719,12 @@ static void qrtr_ns_worker(struct work_struct *work) case QRTR_TYPE_RESUME_TX: break; case QRTR_TYPE_NEW_LOOKUP: - ret = ctrl_cmd_new_lookup(&sq, + ret = ctrl_cmd_new_lookup(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance)); break; case QRTR_TYPE_DEL_LOOKUP: - ctrl_cmd_del_lookup(&sq, + ctrl_cmd_del_lookup(endpoint_id, &sq, le32_to_cpu(pkt->server.service), le32_to_cpu(pkt->server.instance)); break; @@ -700,6 +758,8 @@ int qrtr_ns_init(void) if (ret < 0) return ret; + qrtr_sock_set_report_endpoint(qrtr_ns.sock->sk); + ret = kernel_getsockname(qrtr_ns.sock, (struct sockaddr *)&sq); if (ret < 0) { pr_err("failed to get socket name\n"); @@ -727,7 +787,7 @@ int qrtr_ns_init(void) qrtr_ns.bcast_sq.sq_node = QRTR_NODE_BCAST; qrtr_ns.bcast_sq.sq_port = QRTR_PORT_CTRL; - ret = say_hello(&qrtr_ns.bcast_sq); + ret = say_hello(qrtr_ns.local_node, &qrtr_ns.bcast_sq); if (ret < 0) goto err_wq; diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h index 22fcecbf8de2..b4f50336ae75 100644 --- a/net/qrtr/qrtr.h +++ b/net/qrtr/qrtr.h @@ -35,5 +35,6 @@ int qrtr_ns_init(void); void qrtr_ns_remove(void); int qrtr_msg_get_endpoint(struct msghdr *msg, u32 *out_endpoint_id); +void qrtr_sock_set_report_endpoint(struct sock *sk); #endif