From: Xiao Wang Date: Thu, 18 Jan 2018 02:32:24 +0000 (+0800) Subject: net: fix RARP generation X-Git-Tag: spdx-start~58 X-Git-Url: http://git.droids-corp.org/?p=dpdk.git;a=commitdiff_plain;h=c09141e56f99ace1a695bdae829b337e2fdd1fdf net: fix RARP generation 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. The diffs are: - Add check for parameter and tailroom in rte_net_make_rarp_packet - Allocate mbuf in rte_net_make_rarp_packet Besides that, a link error is fixed when shared lib is enabled. Fixes: 45ae05df824c ("net: add a helper for making RARP packet") Fixes: c3ffdba0e88a ("vhost: use API to make RARP packet") Signed-off-by: Xiao Wang Signed-off-by: Yuanhan Liu --- diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile index ab290c382a..95ff54900d 100644 --- a/lib/librte_net/Makefile +++ b/lib/librte_net/Makefile @@ -6,7 +6,7 @@ include $(RTE_SDK)/mk/rte.vars.mk LIB = librte_net.a CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3 -LDLIBS += -lrte_mbuf -lrte_eal +LDLIBS += -lrte_mbuf -lrte_eal -lrte_mempool EXPORT_MAP := rte_net_version.map LIBABIVER := 1 diff --git a/lib/librte_net/rte_arp.c b/lib/librte_net/rte_arp.c index d7223b044d..b953bcd7e4 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 dad7423ad3..457a39b152 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 ca892886de..a1d8026071 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) -