From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2A57B45B3A; Mon, 14 Oct 2024 19:28:12 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 15D33402F2; Mon, 14 Oct 2024 19:28:12 +0200 (CEST) Received: from frasgout.his.huawei.com (frasgout.his.huawei.com [185.176.79.56]) by mails.dpdk.org (Postfix) with ESMTP id BC89740273 for ; Sun, 13 Oct 2024 13:49:20 +0200 (CEST) Received: from mail.maildlp.com (unknown [172.18.186.231]) by frasgout.his.huawei.com (SkyGuard) with ESMTP id 4XRJSP5H4Wz67Q86; Sun, 13 Oct 2024 19:44:53 +0800 (CST) Received: from frapeml500005.china.huawei.com (unknown [7.182.85.13]) by mail.maildlp.com (Postfix) with ESMTPS id 5B3481400F4; Sun, 13 Oct 2024 19:49:19 +0800 (CST) Received: from china (10.220.118.114) by frapeml500005.china.huawei.com (7.182.85.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Sun, 13 Oct 2024 13:49:16 +0200 From: Gur Stavi To: Gur Stavi CC: , "John W. Linville" Subject: [PATCH v01] net/af_packet: don't specify protocol on socket create Date: Sun, 13 Oct 2024 16:59:47 +0300 Message-ID: X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.220.118.114] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To frapeml500005.china.huawei.com (7.182.85.13) X-Mailman-Approved-At: Mon, 14 Oct 2024 19:28:10 +0200 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org When creating AF_PACKET socket with specified protocol it is immediately implicitly bound to any existing interface and becomes RUNNING. Calling bind on such socket is affectively unbind from "any interface", then bind to the specific interface. When creating socket with 0 as protocol, it is created in non-RUNNING state, then it can be bound to interface and protocol in a single bind call and switch to RUNNING state. Especially with ETH_P_ALL, binding to any interface is not a good idea. It is safer and faster to use the 2nd approach. This patch replaces protocol in socket creation from ETH_P_ALL to 0. Signed-off-by: Gur Stavi --- drivers/net/af_packet/rte_eth_af_packet.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/net/af_packet/rte_eth_af_packet.c b/drivers/net/af_packet/rte_eth_af_packet.c index 68870dd3e2..b30f88d618 100644 --- a/drivers/net/af_packet/rte_eth_af_packet.c +++ b/drivers/net/af_packet/rte_eth_af_packet.c @@ -650,7 +650,7 @@ open_packet_iface(const char *key __rte_unused, int *sockfd = extra_args; /* Open an AF_PACKET socket... */ - *sockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + *sockfd = socket(AF_PACKET, SOCK_RAW, 0); if (*sockfd == -1) { PMD_LOG(ERR, "Could not open AF_PACKET socket"); return -1; @@ -778,7 +778,7 @@ rte_pmd_init_internals(struct rte_vdev_device *dev, for (q = 0; q < nb_queues; q++) { /* Open an AF_PACKET socket for this queue... */ - qsockfd = socket(AF_PACKET, SOCK_RAW, htons(ETH_P_ALL)); + qsockfd = socket(AF_PACKET, SOCK_RAW, 0); if (qsockfd == -1) { PMD_LOG_ERRNO(ERR, "%s: could not open AF_PACKET socket", base-commit: 98613d32e3dac58d685f4f236cf8cc9733abaaf3 -- 2.40.1