From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 05D5FA495 for ; Tue, 16 Jan 2018 10:43:47 +0100 (CET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jan 2018 01:43:46 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,367,1511856000"; d="scan'208";a="10766661" Received: from fmsmsx105.amr.corp.intel.com ([10.18.124.203]) by fmsmga008.fm.intel.com with ESMTP; 16 Jan 2018 01:43:46 -0800 Received: from fmsmsx158.amr.corp.intel.com (10.18.116.75) by FMSMSX105.amr.corp.intel.com (10.18.124.203) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 16 Jan 2018 01:43:46 -0800 Received: from shsmsx102.ccr.corp.intel.com (10.239.4.154) by fmsmsx158.amr.corp.intel.com (10.18.116.75) with Microsoft SMTP Server (TLS) id 14.3.319.2; Tue, 16 Jan 2018 01:43:46 -0800 Received: from shsmsx101.ccr.corp.intel.com ([169.254.1.159]) by shsmsx102.ccr.corp.intel.com ([169.254.2.189]) with mapi id 14.03.0319.002; Tue, 16 Jan 2018 17:43:44 +0800 From: "Wang, Xiao W" To: Olivier Matz CC: "yliu@fridaylinux.org" , "thomas@monjalon.net" , "Bie, Tiwei" , "dev@dpdk.org" , "stephen@networkplumber.org" , "maxime.coquelin@redhat.com" Thread-Topic: [dpdk-dev] [PATCH v10 3/5] net: add a helper for making RARP packet Thread-Index: AQHTibHnzBQFt0UasEaReUsWAXIo76N1t6gAgACPExA= Date: Tue, 16 Jan 2018 09:43:43 +0000 Message-ID: References: <20180109160918.29173-4-xiao.w.wang@intel.com> <20180110012356.57456-1-xiao.w.wang@intel.com> <20180110012356.57456-4-xiao.w.wang@intel.com> <20180116090122.fsvqrgzu5rjqcgre@platinum> In-Reply-To: <20180116090122.fsvqrgzu5rjqcgre@platinum> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ctpclassification: CTP_NT x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiZDE1MTcwMzYtMjdkZS00ZTJlLThjZGQtNWM3MDQ4NzA3ZmM1IiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjIuNS4xOCIsIlRydXN0ZWRMYWJlbEhhc2giOiJDOFBLUDVtTDM4UEZpYkhYcFwvenptZHNOcmFvbE5LeGhxT2tDSFFWQkhWbmlYWXF4dGZDSFo2cmxTNWFONXpYbiJ9 dlp-product: dlpe-windows dlp-version: 11.0.0.116 dlp-reaction: no-action x-originating-ip: [10.239.127.40] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: Re: [dpdk-dev] [PATCH v10 3/5] net: add a helper for making RARP packet X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 16 Jan 2018 09:43:48 -0000 Hi Olivier, > -----Original Message----- > From: Olivier Matz [mailto:olivier.matz@6wind.com] > Sent: Tuesday, January 16, 2018 5:01 PM > To: Wang, Xiao W > Cc: yliu@fridaylinux.org; thomas@monjalon.net; Bie, Tiwei > ; dev@dpdk.org; stephen@networkplumber.org; > maxime.coquelin@redhat.com > Subject: Re: [dpdk-dev] [PATCH v10 3/5] net: add a helper for making RARP > packet >=20 > Hi Xiao, >=20 > Please find few comments below. >=20 > On Wed, Jan 10, 2018 at 09:23:54AM +0800, Xiao Wang wrote: > > Suggested-by: Maxime Coquelin > > Signed-off-by: Xiao Wang > > Reviewed-by: Maxime Coquelin > > --- > > lib/librte_net/Makefile | 1 + > > lib/librte_net/rte_arp.c | 42 > ++++++++++++++++++++++++++++++++++++++ > > lib/librte_net/rte_arp.h | 17 +++++++++++++++ > > lib/librte_net/rte_net_version.map | 6 ++++++ > > 4 files changed, 66 insertions(+) > > create mode 100644 lib/librte_net/rte_arp.c > > > > diff --git a/lib/librte_net/Makefile b/lib/librte_net/Makefile > > index 5e8a76b68..ab290c382 100644 > > --- a/lib/librte_net/Makefile > > +++ b/lib/librte_net/Makefile > > @@ -13,6 +13,7 @@ LIBABIVER :=3D 1 > > > > SRCS-$(CONFIG_RTE_LIBRTE_NET) :=3D rte_net.c > > SRCS-$(CONFIG_RTE_LIBRTE_NET) +=3D rte_net_crc.c > > +SRCS-$(CONFIG_RTE_LIBRTE_NET) +=3D rte_arp.c > > > > # install includes > > SYMLINK-$(CONFIG_RTE_LIBRTE_NET)-include :=3D rte_ip.h rte_tcp.h > rte_udp.h rte_esp.h > > diff --git a/lib/librte_net/rte_arp.c b/lib/librte_net/rte_arp.c > > new file mode 100644 > > index 000000000..d7223b044 > > --- /dev/null > > +++ b/lib/librte_net/rte_arp.c > > @@ -0,0 +1,42 @@ > > +/* SPDX-License-Identifier: BSD-3-Clause > > + * Copyright(c) 2018 Intel Corporation > > + */ > > + > > +#include > > + > > +#include > > + > > +#define RARP_PKT_SIZE 64 > > +int > > +rte_net_make_rarp_packet(struct rte_mbuf *mbuf, const struct ether_add= r > *mac) > > +{ > > + struct ether_hdr *eth_hdr; > > + struct arp_hdr *rarp; > > + > > + if (mbuf->buf_len < RARP_PKT_SIZE) > > + return -1; > > + > > + /* Ethernet header. */ > > + eth_hdr =3D rte_pktmbuf_mtod(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 =3D htons(ETHER_TYPE_RARP); > > + > > + /* RARP header. */ > > + rarp =3D (struct arp_hdr *)(eth_hdr + 1); > > + rarp->arp_hrd =3D htons(ARP_HRD_ETHER); > > + rarp->arp_pro =3D htons(ETHER_TYPE_IPv4); > > + rarp->arp_hln =3D ETHER_ADDR_LEN; > > + rarp->arp_pln =3D 4; > > + rarp->arp_op =3D 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); > > + > > + mbuf->data_len =3D RARP_PKT_SIZE; > > + mbuf->pkt_len =3D RARP_PKT_SIZE; > > + > > + return 0; > > +} >=20 > You don't check that there is enough tailroom to write the packet data. Yes, tailroom can be used. > Also, nothing verifies that the mbuf passed to the function is empty. > I suggest to do the allocation in this function, what do you think? > I agree to allocate in this function and let it do all the checks. =20 > You can also use rte_pktmbuf_append() to check for the tailroom and > update data_len/pkt_len: >=20 > m =3D rte_pktmbuf_alloc(); > if (m =3D=3D NULL) > return NULL; > eth_hdr =3D rte_pktmbuf_append(m, RARP_PKT_SIZE); When data_len is not enough, we need to rte_pktmbuf_append(m, RARP_PKT_SIZE= - m->data_len); > if (eth_hdr =3D=3D NULL) { > m_freem(m); > return NULL; > } > eth_hdr->... =3D ...; > ... > rarp =3D (struct arp_hdr *)(eth_hdr + 1); > rarp->... =3D ...; > ... >=20 > return m; >=20 Will change it in next version, thanks for the comments. BRs, Xiao