2018-01-10 01:23:54 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2018 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
|
|
|
#include <rte_arp.h>
|
|
|
|
|
|
|
|
#define RARP_PKT_SIZE 64
|
2018-01-22 01:48:06 +00:00
|
|
|
struct rte_mbuf * __rte_experimental
|
2018-01-18 02:32:24 +00:00
|
|
|
rte_net_make_rarp_packet(struct rte_mempool *mpool,
|
2019-05-21 16:13:03 +00:00
|
|
|
const struct rte_ether_addr *mac)
|
2018-01-10 01:23:54 +00:00
|
|
|
{
|
2019-05-21 16:13:03 +00:00
|
|
|
struct rte_ether_hdr *eth_hdr;
|
2019-05-21 16:13:01 +00:00
|
|
|
struct rte_arp_hdr *rarp;
|
2018-01-18 02:32:24 +00:00
|
|
|
struct rte_mbuf *mbuf;
|
2018-01-10 01:23:54 +00:00
|
|
|
|
2018-01-18 02:32:24 +00:00
|
|
|
if (mpool == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
mbuf = rte_pktmbuf_alloc(mpool);
|
|
|
|
if (mbuf == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2019-05-21 16:13:03 +00:00
|
|
|
eth_hdr = (struct rte_ether_hdr *)
|
|
|
|
rte_pktmbuf_append(mbuf, RARP_PKT_SIZE);
|
2018-01-18 02:32:24 +00:00
|
|
|
if (eth_hdr == NULL) {
|
|
|
|
rte_pktmbuf_free(mbuf);
|
|
|
|
return NULL;
|
|
|
|
}
|
2018-01-10 01:23:54 +00:00
|
|
|
|
|
|
|
/* Ethernet header. */
|
|
|
|
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);
|
|
|
|
|
|
|
|
/* RARP header. */
|
2019-05-21 16:13:01 +00:00
|
|
|
rarp = (struct rte_arp_hdr *)(eth_hdr + 1);
|
2019-05-21 16:13:02 +00:00
|
|
|
rarp->arp_hardware = htons(RTE_ARP_HRD_ETHER);
|
2019-05-21 16:13:01 +00:00
|
|
|
rarp->arp_protocol = htons(ETHER_TYPE_IPv4);
|
|
|
|
rarp->arp_hlen = ETHER_ADDR_LEN;
|
|
|
|
rarp->arp_plen = 4;
|
2019-05-21 16:13:02 +00:00
|
|
|
rarp->arp_opcode = htons(RTE_ARP_OP_REVREQUEST);
|
2018-01-10 01:23:54 +00:00
|
|
|
|
|
|
|
ether_addr_copy(mac, &rarp->arp_data.arp_sha);
|
|
|
|
ether_addr_copy(mac, &rarp->arp_data.arp_tha);
|
|
|
|
memset(&rarp->arp_data.arp_sip, 0x00, 4);
|
|
|
|
memset(&rarp->arp_data.arp_tip, 0x00, 4);
|
|
|
|
|
2018-01-18 02:32:24 +00:00
|
|
|
return mbuf;
|
2018-01-10 01:23:54 +00:00
|
|
|
}
|