From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) by dpdk.org (Postfix) with ESMTP id 30D1D71B5 for ; Thu, 18 Jan 2018 04:16:50 +0100 (CET) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id C287A2093D; Wed, 17 Jan 2018 22:16:49 -0500 (EST) Received: from frontend1 ([10.202.2.160]) by compute1.internal (MEProxy); Wed, 17 Jan 2018 22:16:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fridaylinux.org; h=cc:date:from:in-reply-to:message-id:references:subject:to :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; bh=jRh+MSpunWX+pgNdD oUwpI6+cqD2NRDyxt+30a5P8cQ=; b=Qzuk8N7hEgS7ufFwoJj+Rd6SNeNG/GEOy 2sUQjqfO0ykwDWFbtS1Pq2yEXvYY+2ykmeDgnmkJqh39uYX0FHklFuJL41TQC0dT skVjlA9kNTWTnQ8FI2BjaRZuAViwZlB30I61e8bmohtjQ8NLGGArCiEH1aCOv3Uq cF8Qr+yWdCZW61xR7sXdG9KB12VG9imRsoI2vZofn9+RUhsfBqI9Nv4p0/1a37ld moVtaP9VX7JuiWJaDUKdAEUlFYuYz2s/MX83Qh5x9NuZsRi0TbhnDKWsxHp6jb/J zLQ3vA+XF73aAqDdoZ9dRwPR7txphtcNrHgI6BaWbhpr3Ooxemndw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=jRh+MSpunWX+pgNdDoUwpI6+cqD2NRDyxt+30a5P8cQ=; b=ZKxXUq// rRSg4F/yNjLLqKl+V49VOiBbts3oXJUnl909odVCyeIvek8wo7PbPKbzXfdJr/Sn 3qduSL2cfL85Y5a/p7hnI/0Q2GRCjmDToSwsehu8/6znBzzWtLg99yoqKwJzOa9M vNg51WfE2PRPDVW3+YH387ic6HcvWXMV6CqpVQY+lFwm03cwajiK74gr4TnIcnzB sysFYTXQl+3lTDNBOsL5OYH6JhD1X2EgfYdUnN9T3+nKacYbyLF+PNJt6jYLfa8A 9UzGTxp9Ahx0/TpUhKKP9FRK16wHHJk1fdVR7JU/eKw5lhGgeSvAt4x3wHXLWS1x 5+OW0f4vPTLLpQ== X-ME-Sender: Received: from localhost.localdomain (unknown [115.148.90.22]) by mail.messagingengine.com (Postfix) with ESMTPA id 116C47E38D; Wed, 17 Jan 2018 22:16:46 -0500 (EST) From: Yuanhan Liu To: dev@dpdk.org Cc: Thomas Monjalon , Xiao Wang , Ferruh Yigit , Olivier Matz , Yuanhan Liu Date: Thu, 18 Jan 2018 11:14:42 +0800 Message-Id: <1516245283-23990-1-git-send-email-yliu@fridaylinux.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <20180118030921.GW29540@yliu-mob> References: <20180118030921.GW29540@yliu-mob> Subject: [dpdk-dev] [PATCH 1/2] net: fixup RARP generation X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 18 Jan 2018 03:16:50 -0000 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 --- 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 #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, ð_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