From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga05.intel.com (mga05.intel.com [192.55.52.43]) by dpdk.org (Postfix) with ESMTP id 9341571B3 for ; Fri, 19 Jan 2018 17:04:45 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 19 Jan 2018 08:04:42 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,381,1511856000"; d="scan'208";a="11538950" Received: from fyigit-mobl1.ger.corp.intel.com (HELO [10.237.220.48]) ([10.237.220.48]) by fmsmga007.fm.intel.com with ESMTP; 19 Jan 2018 08:04:40 -0800 To: Yuanhan Liu , dev@dpdk.org Cc: Thomas Monjalon , Xiao Wang , Olivier Matz References: <20180118030921.GW29540@yliu-mob> <1516245283-23990-1-git-send-email-yliu@fridaylinux.org> From: Ferruh Yigit Message-ID: Date: Fri, 19 Jan 2018 16:04:40 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 In-Reply-To: <1516245283-23990-1-git-send-email-yliu@fridaylinux.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Subject: Re: [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: Fri, 19 Jan 2018 16:04:46 -0000 On 1/18/2018 3:14 AM, Yuanhan Liu wrote: > 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. Fixes: 45ae05df824c ("net: add a helper for making RARP packet") Fixes: c3ffdba0e88a ("vhost: use API to make RARP packet") Please correct me if there are wrong. > > 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) - >