199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson * Copyright(c) 2018 Intel Corporation
399a2dd95SBruce Richardson */
499a2dd95SBruce Richardson
599a2dd95SBruce Richardson #include <rte_arp.h>
699a2dd95SBruce Richardson
799a2dd95SBruce Richardson #define RARP_PKT_SIZE 64
899a2dd95SBruce Richardson struct rte_mbuf *
rte_net_make_rarp_packet(struct rte_mempool * mpool,const struct rte_ether_addr * mac)999a2dd95SBruce Richardson rte_net_make_rarp_packet(struct rte_mempool *mpool,
1099a2dd95SBruce Richardson const struct rte_ether_addr *mac)
1199a2dd95SBruce Richardson {
1299a2dd95SBruce Richardson struct rte_ether_hdr *eth_hdr;
1399a2dd95SBruce Richardson struct rte_arp_hdr *rarp;
1499a2dd95SBruce Richardson struct rte_mbuf *mbuf;
1599a2dd95SBruce Richardson
1699a2dd95SBruce Richardson if (mpool == NULL)
1799a2dd95SBruce Richardson return NULL;
1899a2dd95SBruce Richardson
1999a2dd95SBruce Richardson mbuf = rte_pktmbuf_alloc(mpool);
2099a2dd95SBruce Richardson if (mbuf == NULL)
2199a2dd95SBruce Richardson return NULL;
2299a2dd95SBruce Richardson
2399a2dd95SBruce Richardson eth_hdr = (struct rte_ether_hdr *)
2499a2dd95SBruce Richardson rte_pktmbuf_append(mbuf, RARP_PKT_SIZE);
2599a2dd95SBruce Richardson if (eth_hdr == NULL) {
2699a2dd95SBruce Richardson rte_pktmbuf_free(mbuf);
2799a2dd95SBruce Richardson return NULL;
2899a2dd95SBruce Richardson }
2999a2dd95SBruce Richardson
3099a2dd95SBruce Richardson /* Ethernet header. */
31*04d43857SDmitry Kozlyuk memset(eth_hdr->dst_addr.addr_bytes, 0xff, RTE_ETHER_ADDR_LEN);
32*04d43857SDmitry Kozlyuk rte_ether_addr_copy(mac, ð_hdr->src_addr);
3399a2dd95SBruce Richardson eth_hdr->ether_type = RTE_BE16(RTE_ETHER_TYPE_RARP);
3499a2dd95SBruce Richardson
3599a2dd95SBruce Richardson /* RARP header. */
3699a2dd95SBruce Richardson rarp = (struct rte_arp_hdr *)(eth_hdr + 1);
3799a2dd95SBruce Richardson rarp->arp_hardware = RTE_BE16(RTE_ARP_HRD_ETHER);
3899a2dd95SBruce Richardson rarp->arp_protocol = RTE_BE16(RTE_ETHER_TYPE_IPV4);
3999a2dd95SBruce Richardson rarp->arp_hlen = RTE_ETHER_ADDR_LEN;
4099a2dd95SBruce Richardson rarp->arp_plen = 4;
4199a2dd95SBruce Richardson rarp->arp_opcode = RTE_BE16(RTE_ARP_OP_REVREQUEST);
4299a2dd95SBruce Richardson
4399a2dd95SBruce Richardson rte_ether_addr_copy(mac, &rarp->arp_data.arp_sha);
4499a2dd95SBruce Richardson rte_ether_addr_copy(mac, &rarp->arp_data.arp_tha);
4599a2dd95SBruce Richardson memset(&rarp->arp_data.arp_sip, 0x00, 4);
4699a2dd95SBruce Richardson memset(&rarp->arp_data.arp_tip, 0x00, 4);
4799a2dd95SBruce Richardson
4899a2dd95SBruce Richardson return mbuf;
4999a2dd95SBruce Richardson }
50