1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright(c) 2018 Intel Corporation 3 */ 4 5 #include <rte_arp.h> 6 #include <rte_byteorder.h> 7 8 #define RARP_PKT_SIZE 64 9 struct rte_mbuf * 10 rte_net_make_rarp_packet(struct rte_mempool *mpool, 11 const struct rte_ether_addr *mac) 12 { 13 struct rte_ether_hdr *eth_hdr; 14 struct rte_arp_hdr *rarp; 15 struct rte_mbuf *mbuf; 16 17 if (mpool == NULL) 18 return NULL; 19 20 mbuf = rte_pktmbuf_alloc(mpool); 21 if (mbuf == NULL) 22 return NULL; 23 24 eth_hdr = (struct rte_ether_hdr *) 25 rte_pktmbuf_append(mbuf, RARP_PKT_SIZE); 26 if (eth_hdr == NULL) { 27 rte_pktmbuf_free(mbuf); 28 return NULL; 29 } 30 31 /* Ethernet header. */ 32 memset(eth_hdr->dst_addr.addr_bytes, 0xff, RTE_ETHER_ADDR_LEN); 33 rte_ether_addr_copy(mac, ð_hdr->src_addr); 34 eth_hdr->ether_type = RTE_BE16(RTE_ETHER_TYPE_RARP); 35 36 /* RARP header. */ 37 rarp = (struct rte_arp_hdr *)(eth_hdr + 1); 38 rarp->arp_hardware = RTE_BE16(RTE_ARP_HRD_ETHER); 39 rarp->arp_protocol = RTE_BE16(RTE_ETHER_TYPE_IPV4); 40 rarp->arp_hlen = RTE_ETHER_ADDR_LEN; 41 rarp->arp_plen = 4; 42 rarp->arp_opcode = RTE_BE16(RTE_ARP_OP_REVREQUEST); 43 44 rte_ether_addr_copy(mac, &rarp->arp_data.arp_sha); 45 rte_ether_addr_copy(mac, &rarp->arp_data.arp_tha); 46 memset(&rarp->arp_data.arp_sip, 0x00, 4); 47 memset(&rarp->arp_data.arp_tip, 0x00, 4); 48 49 return mbuf; 50 } 51