All of lore.kernel.org
 help / color / mirror / Atom feed
From: Yuanhan Liu <yliu@fridaylinux.org>
To: dev@dpdk.org
Cc: Thomas Monjalon <thomas@monjalon.net>,
	Xiao Wang <xiao.w.wang@intel.com>,
	Ferruh Yigit <ferruh.yigit@intel.com>,
	Olivier Matz <olivier.matz@6wind.com>,
	Yuanhan Liu <yliu@fridaylinux.org>
Subject: [PATCH 1/2] net: fixup RARP generation
Date: Thu, 18 Jan 2018 11:14:42 +0800	[thread overview]
Message-ID: <1516245283-23990-1-git-send-email-yliu@fridaylinux.org> (raw)
In-Reply-To: <20180118030921.GW29540@yliu-mob>

Due to a mistake operation from me, older version (v10) was merged to
master branch. It's the v11 should be applied. However, the master branch
is not rebase-able. Thus, this patch is made, from the diff between v10
and v11.

Code is from Xiao Wang.

Signed-off-by: Yuanhan Liu <yliu@fridaylinux.org>
---
 lib/librte_net/rte_arp.c      | 26 +++++++++++++++++---------
 lib/librte_net/rte_arp.h      | 11 ++++++-----
 lib/librte_vhost/virtio_net.c | 12 +++---------
 3 files changed, 26 insertions(+), 23 deletions(-)

diff --git a/lib/librte_net/rte_arp.c b/lib/librte_net/rte_arp.c
index d7223b0..b953bcd 100644
--- a/lib/librte_net/rte_arp.c
+++ b/lib/librte_net/rte_arp.c
@@ -7,17 +7,28 @@
 #include <rte_arp.h>
 
 #define RARP_PKT_SIZE	64
-int
-rte_net_make_rarp_packet(struct rte_mbuf *mbuf, const struct ether_addr *mac)
+struct rte_mbuf *
+rte_net_make_rarp_packet(struct rte_mempool *mpool,
+		const struct ether_addr *mac)
 {
 	struct ether_hdr *eth_hdr;
 	struct arp_hdr *rarp;
+	struct rte_mbuf *mbuf;
 
-	if (mbuf->buf_len < RARP_PKT_SIZE)
-		return -1;
+	if (mpool == NULL)
+		return NULL;
+
+	mbuf = rte_pktmbuf_alloc(mpool);
+	if (mbuf == NULL)
+		return NULL;
+
+	eth_hdr = (struct ether_hdr *)rte_pktmbuf_append(mbuf, RARP_PKT_SIZE);
+	if (eth_hdr == NULL) {
+		rte_pktmbuf_free(mbuf);
+		return NULL;
+	}
 
 	/* Ethernet header. */
-	eth_hdr = rte_pktmbuf_mtod(mbuf, struct ether_hdr *);
 	memset(eth_hdr->d_addr.addr_bytes, 0xff, ETHER_ADDR_LEN);
 	ether_addr_copy(mac, &eth_hdr->s_addr);
 	eth_hdr->ether_type = htons(ETHER_TYPE_RARP);
@@ -35,8 +46,5 @@ rte_net_make_rarp_packet(struct rte_mbuf *mbuf, const struct ether_addr *mac)
 	memset(&rarp->arp_data.arp_sip, 0x00, 4);
 	memset(&rarp->arp_data.arp_tip, 0x00, 4);
 
-	mbuf->data_len = RARP_PKT_SIZE;
-	mbuf->pkt_len = RARP_PKT_SIZE;
-
-	return 0;
+	return mbuf;
 }
diff --git a/lib/librte_net/rte_arp.h b/lib/librte_net/rte_arp.h
index dad7423..457a39b 100644
--- a/lib/librte_net/rte_arp.h
+++ b/lib/librte_net/rte_arp.h
@@ -82,16 +82,17 @@ struct arp_hdr {
  *
  * Make a RARP packet based on MAC addr.
  *
- * @param mbuf
- *   Pointer to the rte_mbuf structure
+ * @param mpool
+ *   Pointer to the rte_mempool
  * @param mac
  *   Pointer to the MAC addr
  *
  * @return
- *   - 0 on success, negative on error
+ *   - RARP packet pointer on success, or NULL on error
  */
-int
-rte_net_make_rarp_packet(struct rte_mbuf *mbuf, const struct ether_addr *mac);
+struct rte_mbuf *
+rte_net_make_rarp_packet(struct rte_mempool *mpool,
+		const struct ether_addr *mac);
 
 #ifdef __cplusplus
 }
diff --git a/lib/librte_vhost/virtio_net.c b/lib/librte_vhost/virtio_net.c
index ca89288..a1d8026 100644
--- a/lib/librte_vhost/virtio_net.c
+++ b/lib/librte_vhost/virtio_net.c
@@ -1162,19 +1162,13 @@ rte_vhost_dequeue_burst(int vid, uint16_t queue_id,
 			rte_atomic16_cmpset((volatile uint16_t *)
 				&dev->broadcast_rarp.cnt, 1, 0))) {
 
-		rarp_mbuf = rte_pktmbuf_alloc(mbuf_pool);
+		rarp_mbuf = rte_net_make_rarp_packet(mbuf_pool, &dev->mac);
 		if (rarp_mbuf == NULL) {
 			RTE_LOG(ERR, VHOST_DATA,
-				"Failed to allocate memory for mbuf.\n");
+				"Failed to make RARP packet.\n");
 			return 0;
 		}
-
-		if (rte_net_make_rarp_packet(rarp_mbuf, &dev->mac) < 0) {
-			rte_pktmbuf_free(rarp_mbuf);
-			rarp_mbuf = NULL;
-		} else {
-			count -= 1;
-		}
+		count -= 1;
 	}
 
 	free_entries = *((volatile uint16_t *)&vq->avail->idx) -
-- 
2.7.4

  reply	other threads:[~2018-01-18  3:16 UTC|newest]

Thread overview: 112+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-11-24 11:03 [PATCH 0/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2017-11-24 11:03 ` [PATCH 1/2] net/virtio: make control queue thread-safe Xiao Wang
2017-11-24  5:38   ` Tiwei Bie
2017-11-30  2:10     ` Wang, Xiao W
2017-11-30  2:59   ` Stephen Hemminger
2017-12-01  1:38     ` Wang, Xiao W
2017-12-04 14:02   ` [PATCH v2 0/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2017-12-04 14:02     ` [PATCH v2 1/2] net/virtio: make control queue thread-safe Xiao Wang
2017-12-04 14:02     ` [PATCH v2 2/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2017-12-04  8:46       ` Tiwei Bie
2018-01-03  1:37         ` Wang, Xiao W
2018-01-03  8:42         ` Wang, Xiao W
2017-12-06 11:23       ` Tiwei Bie
2017-12-06 14:22         ` Yuanhan Liu
2018-01-03  1:41         ` Wang, Xiao W
2018-01-04  7:41       ` [PATCH v3 0/2] " Xiao Wang
2018-01-04  7:41         ` [PATCH v3 1/2] net/virtio: make control queue thread-safe Xiao Wang
2018-01-04  7:41         ` [PATCH v3 2/2] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-04  2:51           ` Tiwei Bie
2018-01-04  7:11             ` Wang, Xiao W
2018-01-04 15:59           ` [PATCH v4 0/3] " Xiao Wang
2018-01-04 15:59             ` [PATCH v4 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-04 15:59             ` [PATCH v4 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-04  7:56               ` Tiwei Bie
2018-01-05 16:46               ` [PATCH v5 0/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-05 16:46                 ` [PATCH v5 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-05 16:46                 ` [PATCH v5 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-05 18:00                   ` Tiwei Bie
2018-01-07  2:37                     ` Wang, Xiao W
2018-01-05 16:46                 ` [PATCH v5 3/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-05 17:56                   ` Tiwei Bie
2018-01-07  2:29                     ` Wang, Xiao W
2018-01-07 12:05                   ` [PATCH v6 0/3] " Xiao Wang
2018-01-07 12:05                     ` [PATCH v6 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-08 13:06                       ` Yuanhan Liu
2018-01-08 15:25                         ` Wang, Xiao W
2018-01-07 12:05                     ` [PATCH v6 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-08 13:03                       ` Yuanhan Liu
2018-01-08 15:11                         ` Wang, Xiao W
2018-01-09  2:55                           ` Wang, Xiao W
2018-01-09 14:26                       ` [PATCH v7 0/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 14:26                         ` [PATCH v7 1/3] net/virtio: make control queue thread-safe Xiao Wang
2018-01-09 14:26                         ` [PATCH v7 2/3] net/virtio: add packet injection method Xiao Wang
2018-01-09 14:26                         ` [PATCH v7 3/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09  8:49                           ` Maxime Coquelin
2018-01-09 10:58                             ` Wang, Xiao W
2018-01-09 11:03                             ` Wang, Xiao W
2018-01-09 11:41                               ` Thomas Monjalon
2018-01-09 13:36                                 ` Yuanhan Liu
2018-01-09 13:26                           ` [PATCH v8 0/5] " Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-09 13:48                               ` Thomas Monjalon
2018-01-09 15:52                                 ` Wang, Xiao W
2018-01-09 16:09                               ` [PATCH v9 0/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-09 17:22                                   ` Thomas Monjalon
2018-01-10  1:23                                   ` [PATCH v10 0/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-10 13:06                                       ` Yuanhan Liu
2018-01-10 14:10                                         ` Thomas Monjalon
2018-01-16  9:01                                       ` Olivier Matz
2018-01-16  9:43                                         ` Wang, Xiao W
2018-01-16 10:42                                           ` Olivier Matz
2018-01-16 11:03                                             ` Wang, Xiao W
2018-01-16 11:42                                             ` Wang, Xiao W
2018-01-16 21:40                                       ` [PATCH v11 0/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-16 21:40                                         ` [PATCH v11 1/5] net/virtio: make control queue thread-safe Xiao Wang
2018-01-16 21:41                                         ` [PATCH v11 2/5] net/virtio: add packet injection method Xiao Wang
2018-01-16 21:41                                         ` [PATCH v11 3/5] net: add a helper for making RARP packet Xiao Wang
2018-01-16 14:29                                           ` Olivier Matz
2018-01-16 21:41                                         ` [PATCH v11 4/5] vhost: use lib API to make " Xiao Wang
2018-01-16 21:41                                         ` [PATCH v11 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-19 17:33                                           ` Ferruh Yigit
2018-01-20 14:31                                             ` Ferruh Yigit
2018-01-21  1:31                                               ` Wang, Xiao W
2018-01-18  3:09                                         ` [PATCH v11 0/5] " Yuanhan Liu
2018-01-18  3:14                                           ` Yuanhan Liu [this message]
2018-01-18  3:14                                             ` [PATCH 2/2] net: fix build error Yuanhan Liu
2018-01-18  7:38                                               ` Thomas Monjalon
2018-01-18  7:45                                                 ` Wang, Xiao W
2018-01-18  8:03                                                   ` Yuanhan Liu
2018-01-18  8:36                                                     ` Thomas Monjalon
2018-01-18  8:48                                                       ` Yuanhan Liu
2018-01-18  8:38                                             ` [PATCH 1/2] net: fixup RARP generation Thomas Monjalon
2018-01-18  8:51                                               ` Yuanhan Liu
2018-01-18  8:53                                                 ` Wang, Xiao W
2018-01-19 16:04                                             ` Ferruh Yigit
2018-01-10  1:23                                     ` [PATCH v10 4/5] vhost: use lib API to make RARP packet Xiao Wang
2018-01-10  1:23                                     ` [PATCH v10 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 4/5] vhost: use lib API to make RARP packet Xiao Wang
2018-01-09 16:09                                 ` [PATCH v9 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 4/5] vhost: use lib API to make RARP packet Xiao Wang
2018-01-09 13:26                             ` [PATCH v8 5/5] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-09 14:38                             ` [PATCH v8 0/5] " Maxime Coquelin
2018-01-07 12:05                     ` [PATCH v6 3/3] " Xiao Wang
2018-01-05 20:27               ` [PATCH v4 2/3] net/virtio: add packet injection method Stephen Hemminger
2018-01-06  4:41                 ` Tiwei Bie
2018-01-04 15:59             ` [PATCH v4 3/3] net/virtio: support GUEST ANNOUNCE Xiao Wang
2018-01-04 11:13               ` Tiwei Bie
2017-11-24 11:04 ` [PATCH 2/2] " Xiao Wang
2017-11-24  6:04   ` Tiwei Bie
2017-11-30  2:37     ` Wang, Xiao W
2017-11-27 12:48   ` Yuanhan Liu
2017-11-30  2:41     ` Wang, Xiao W
2017-12-05 14:26       ` Yuanhan Liu
2018-01-03  1:43         ` Wang, Xiao W

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=1516245283-23990-1-git-send-email-yliu@fridaylinux.org \
    --to=yliu@fridaylinux.org \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=olivier.matz@6wind.com \
    --cc=thomas@monjalon.net \
    --cc=xiao.w.wang@intel.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.