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
|
2019-06-29 11:58:52 +00:00
|
|
|
struct rte_mbuf *
|
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. */
|
2019-05-21 16:13:05 +00:00
|
|
|
memset(eth_hdr->d_addr.addr_bytes, 0xff, RTE_ETHER_ADDR_LEN);
|
2019-05-21 16:13:04 +00:00
|
|
|
rte_ether_addr_copy(mac, ð_hdr->s_addr);
|
2019-05-21 16:13:05 +00:00
|
|
|
eth_hdr->ether_type = htons(RTE_ETHER_TYPE_RARP);
|
2018-01-10 01:23:54 +00:00
|
|
|
|
|
|
|
/* 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-29 11:29:16 +00:00
|
|
|
rarp->arp_protocol = htons(RTE_ETHER_TYPE_IPV4);
|
2019-05-21 16:13:05 +00:00
|
|
|
rarp->arp_hlen = RTE_ETHER_ADDR_LEN;
|
2019-05-21 16:13:01 +00:00
|
|
|
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
|
|
|
|
2019-05-21 16:13:04 +00:00
|
|
|
rte_ether_addr_copy(mac, &rarp->arp_data.arp_sha);
|
|
|
|
rte_ether_addr_copy(mac, &rarp->arp_data.arp_tha);
|
2018-01-10 01:23:54 +00:00
|
|
|
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
|
|
|
}
|