CNDP 22.08.0
Loading...
Searching...
No Matches
cnet_rarp.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright (c) 2019-2022 Intel Corporation
3 */
4
5#ifndef _CNE_RARP_H_
6#define _CNE_RARP_H_
7
13
14// IWYU pragma: no_forward_declare cne_mempool
15
16#include <stdint.h> // for uint16_t, uint32_t, uint8_t
17#include <net/cne_ether.h> // for ether_addr
18#include <net/ethernet.h> // for ether_addr
19
20#include <net/cne_arp.h>
21#include <mempool.h> // for cne_mempool
22#include <pktmbuf.h> // for pktmbuf_info_t, pktmbuf_t
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
28#define RARP_PKT_SIZE 64
40static inline pktmbuf_t *
42{
43 struct cne_ether_hdr *eth_hdr;
44 struct cne_arp_hdr *rarp;
45 pktmbuf_t *mbuf;
46
47 if (pi == NULL)
48 return NULL;
49
50 mbuf = pktmbuf_alloc(pi);
51 if (mbuf == NULL)
52 return NULL;
53
54 eth_hdr = (struct cne_ether_hdr *)pktmbuf_append(mbuf, RARP_PKT_SIZE);
55 if (eth_hdr == NULL) {
56 pktmbuf_free(mbuf);
57 return NULL;
58 }
59
60 /* Ethernet header. */
61 memset(eth_hdr->d_addr.ether_addr_octet, 0xff, ETH_ALEN);
62 ether_addr_copy(mac, &eth_hdr->s_addr);
63 eth_hdr->ether_type = htons(CNE_ETHER_TYPE_RARP);
64
65 /* RARP header. */
66 rarp = (struct cne_arp_hdr *)(eth_hdr + 1);
67 rarp->arp_hardware = htons(CNE_ARP_HRD_ETHER);
68 rarp->arp_protocol = htons(CNE_ETHER_TYPE_IPV4);
69 rarp->arp_hlen = ETH_ALEN;
70 rarp->arp_plen = 4;
71 rarp->arp_opcode = htons(CNE_ARP_OP_REVREQUEST);
72
73 ether_addr_copy(mac, &rarp->arp_data.arp_sha);
74 ether_addr_copy(mac, &rarp->arp_data.arp_tha);
75 memset(&rarp->arp_data.arp_sip, 0x00, 4);
76 memset(&rarp->arp_data.arp_tip, 0x00, 4);
77
78 return mbuf;
79}
80
81#ifdef __cplusplus
82}
83#endif
84
85#endif /* _CNE_RARP_H_ */
#define CNE_ETHER_TYPE_RARP
Definition cne_ether.h:84
#define CNE_ETHER_TYPE_IPV4
Definition cne_ether.h:81
CNDP_API __cne_always_inline void ether_addr_copy(const struct ether_addr *ea_from, struct ether_addr *ea_to)
Definition cne_ether.h:282
static pktmbuf_t * cne_net_make_rarp_packet(pktmbuf_info_t *pi, const struct ether_addr *mac)
Definition cnet_rarp.h:41
struct pktmbuf_info_s pktmbuf_info_t
uint32_t arp_sip
Definition cne_arp.h:30
uint32_t arp_tip
Definition cne_arp.h:32
struct ether_addr arp_tha
Definition cne_arp.h:31
struct ether_addr arp_sha
Definition cne_arp.h:29
struct ether_addr s_addr
Definition cne_ether.h:66
struct ether_addr d_addr
Definition cne_ether.h:65
uint16_t ether_type
Definition cne_ether.h:67
uint8_t ether_addr_octet[ETH_ALEN]
Definition cne_ether.h:53