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 <xiao.w.wang@intel.com>
Signed-off-by: Yuanhan Liu <yliu@fridaylinux.org>
This commit is contained in:
Xiao Wang 2018-01-18 10:32:24 +08:00 committed by Ferruh Yigit
parent 2651726def
commit c09141e56f
4 changed files with 27 additions and 24 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -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
}

View File

@ -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) -