DPDK patches and discussions
 help / color / mirror / Atom feed
From: Gur Stavi <gur.stavi@huawei.com>
To: Gur Stavi <gur.stavi@huawei.com>
Cc: <dev@dpdk.org>, "John W. Linville" <linville@tuxdriver.com>
Subject: [PATCH v01] net/af_packet: don't specify protocol on socket create
Date: Sun, 13 Oct 2024 16:59:47 +0300	[thread overview]
Message-ID: <a6f63e072bea2b3771922b0949b859bfafb660de.1728827368.git.gur.stavi@huawei.com> (raw)

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 <gur.stavi@huawei.com>
---
 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


             reply	other threads:[~2024-10-14 17:28 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-13 13:59 Gur Stavi [this message]
2024-10-16 23:49 ` Ferruh Yigit
2024-10-17  1:38 ` Stephen Hemminger

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=a6f63e072bea2b3771922b0949b859bfafb660de.1728827368.git.gur.stavi@huawei.com \
    --to=gur.stavi@huawei.com \
    --cc=dev@dpdk.org \
    --cc=linville@tuxdriver.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).