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