09/01/2018 12:03, Wang, Xiao W: > > From: Maxime Coquelin [mailto:maxime.coque...@redhat.com] > > On 01/09/2018 03:26 PM, Xiao Wang wrote: > > > +#define RARP_PKT_SIZE 64 > > > +static int > > > +make_rarp_packet(struct rte_mbuf *rarp_mbuf, const struct ether_addr > > *mac) > > > +{ > > > + struct ether_hdr *eth_hdr; > > > + struct arp_hdr *rarp; > > > + > > > + if (rarp_mbuf->buf_len < RARP_PKT_SIZE) { > > > + PMD_DRV_LOG(ERR, "mbuf size too small %u (< %d)", > > > + rarp_mbuf->buf_len, RARP_PKT_SIZE); > > > + return -1; > > > + } > > > + > > > + /* Ethernet header. */ > > > + eth_hdr = rte_pktmbuf_mtod(rarp_mbuf, struct ether_hdr *); > > > + memset(eth_hdr->d_addr.addr_bytes, 0xff, ETHER_ADDR_LEN); > > > + ether_addr_copy(mac, ð_hdr->s_addr); > > > + eth_hdr->ether_type = htons(ETHER_TYPE_RARP); > > > + > > > + /* RARP header. */ > > > + rarp = (struct arp_hdr *)(eth_hdr + 1); > > > + rarp->arp_hrd = htons(ARP_HRD_ETHER); > > > + rarp->arp_pro = htons(ETHER_TYPE_IPv4); > > > + rarp->arp_hln = ETHER_ADDR_LEN; > > > + rarp->arp_pln = 4; > > > + rarp->arp_op = htons(ARP_OP_REVREQUEST); > > > + > > > + ether_addr_copy(mac, &rarp->arp_data.arp_sha); > > > + ether_addr_copy(mac, &rarp->arp_data.arp_tha); > > > + memset(&rarp->arp_data.arp_sip, 0x00, 4); > > > + memset(&rarp->arp_data.arp_tip, 0x00, 4); > > > + > > > + rarp_mbuf->data_len = RARP_PKT_SIZE; > > > + rarp_mbuf->pkt_len = RARP_PKT_SIZE; > > > + > > > + return 0; > > > +} > > > > Do you think it could make sense to have this function in a lib, as > > vhost user lib does exactly the same? > > > > I don't know if it could be useful to others than vhost/virtio though. > > Hi Thomas, > > Do you think it's worth adding a new helper for ARP in lib/librte_net/? > Currently we just need a helper to build RARP packet (the above > make_rarp_packet)
Yes, good idea