From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from emea01-db3-obe.outbound.protection.outlook.com (mail-db3on0074.outbound.protection.outlook.com [157.55.234.74]) by dpdk.org (Postfix) with ESMTP id 3322B959 for ; Fri, 27 Feb 2015 14:42:59 +0100 (CET) Received: from VI1PR04CA0023.eurprd04.prod.outlook.com (25.163.3.33) by AM2PR04MB1090.eurprd04.prod.outlook.com (25.162.36.151) with Microsoft SMTP Server (TLS) id 15.1.93.16; Fri, 27 Feb 2015 13:42:58 +0000 Received: from AM1FFO11FD032.protection.gbl (2a01:111:f400:7e00::179) by VI1PR04CA0023.outlook.office365.com (2a01:111:e400:58e9::33) with Microsoft SMTP Server (TLS) id 15.1.99.14 via Frontend Transport; Fri, 27 Feb 2015 13:42:58 +0000 Received: from usnvwwmspedge02.tellabs-west.tellabsinc.net (204.154.129.150) by AM1FFO11FD032.mail.protection.outlook.com (10.174.64.221) with Microsoft SMTP Server (TLS) id 15.1.99.6 via Frontend Transport; Fri, 27 Feb 2015 13:42:57 +0000 Received: from usnvwwmspht02.tellabs-west.tellabsinc.net (172.23.211.70) by usnvwwmspedge02.tellabs-west.tellabsinc.net (204.154.131.191) with Microsoft SMTP Server (TLS) id 8.3.377.0; Fri, 27 Feb 2015 07:42:29 -0600 Received: from T430.tellabs-east.tellabsinc.net (172.23.229.50) by usnvwwmspht02.tellabs-west.tellabsinc.net (172.23.211.70) with Microsoft SMTP Server id 8.3.298.1; Fri, 27 Feb 2015 07:42:55 -0600 From: Tero Aho To: Date: Fri, 27 Feb 2015 15:42:39 +0200 Message-ID: <1425044560-23397-3-git-send-email-tero.aho@coriant.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1425044560-23397-1-git-send-email-tero.aho@coriant.com> References: <1425044560-23397-1-git-send-email-tero.aho@coriant.com> MIME-Version: 1.0 Content-Type: text/plain Content-Transfer-Encoding: quoted-printable X-EOPAttributedMessage: 0 Received-SPF: Pass (protection.outlook.com: domain of coriant.com designates 204.154.129.150 as permitted sender) receiver=protection.outlook.com; client-ip=204.154.129.150; helo=usnvwwmspedge02.tellabs-west.tellabsinc.net; Authentication-Results: spf=pass (sender IP is 204.154.129.150) smtp.mailfrom=Tero.Aho@coriant.com; dpdk.org; dkim=none (message not signed) header.d=none; X-Forefront-Antispam-Report: CIP:204.154.129.150; CTRY:US; IPV:NLI; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(438002)(87936001)(107886001)(50986999)(2351001)(229853001)(77156002)(62966003)(76176999)(19580395003)(6806004)(19580405001)(16796002)(46102003)(106466001)(450100001)(2950100001)(77096005)(92566002)(110136001)(575784001)(50226001)(33646002)(48376002)(36756003)(47776003)(50466002)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:AM2PR04MB1090; H:usnvwwmspedge02.tellabs-west.tellabsinc.net; FPR:; SPF:Pass; MLV:sfv; LANG:en; X-Microsoft-Antispam: UriScan:; X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;SRVR:AM2PR04MB1090; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(601004)(5005006); SRVR:AM2PR04MB1090; X-Forefront-PRVS: 05009853EF X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:;SRVR:AM2PR04MB1090; X-OriginatorOrg: coriant.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2015 13:42:57.4509 (UTC) X-MS-Exchange-CrossTenant-Id: 76595477-907e-4695-988b-a6b39087332d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=76595477-907e-4695-988b-a6b39087332d; Ip=[204.154.129.150] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM2PR04MB1090 Subject: [dpdk-dev] [PATCH 2/3] pcap: add support for jumbo frames X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 27 Feb 2015 13:42:59 -0000 Extend eth_pcap_rx and eth_pcap_tx to support jumbo frames. On receive side read large packets into multiple mbufs and on the transmit side do the opposite. Signed-off-by: Tero Aho --- lib/librte_pmd_pcap/rte_eth_pcap.c | 88 ++++++++++++++++++++++++++++++++--= ---- 1 file changed, 75 insertions(+), 13 deletions(-) diff --git a/lib/librte_pmd_pcap/rte_eth_pcap.c b/lib/librte_pmd_pcap/rte_e= th_pcap.c index 289af28..3f23f0a 100644 --- a/lib/librte_pmd_pcap/rte_eth_pcap.c +++ b/lib/librte_pmd_pcap/rte_eth_pcap.c @@ -52,7 +52,7 @@ #include #define RTE_ETH_PCAP_SNAPSHOT_LEN 65535 -#define RTE_ETH_PCAP_SNAPLEN 4096 +#define RTE_ETH_PCAP_SNAPLEN ETHER_MAX_JUMBO_FRAME_LEN #define RTE_ETH_PCAP_PROMISC 1 #define RTE_ETH_PCAP_TIMEOUT -1 #define ETH_PCAP_RX_PCAP_ARG "rx_pcap" @@ -132,6 +132,43 @@ static struct rte_eth_link pmd_link =3D { .link_status =3D 0 }; +/* + * Helper function to read mbuf chain. + */ +static int +eth_pcap_rx_jumbo(struct rte_mempool *mb_pool, + struct rte_mbuf *mbuf, + const u_char *data, + uint16_t data_len) +{ + struct rte_mbuf *m =3D mbuf; + /* copy first segment */ + uint16_t len =3D rte_pktmbuf_tailroom(mbuf); + rte_memcpy(rte_pktmbuf_append(mbuf, len), data, len); + data_len -=3D len; + data +=3D len; + + while (data_len > 0) { + /* allocate next mbuf and point to that */ + m->next =3D rte_pktmbuf_alloc(mb_pool); + if (unlikely(m->next =3D=3D NULL)) + return -1; + m =3D m->next; + + /* no headroom needed in chained mbufs */ + rte_pktmbuf_prepend(m, rte_pktmbuf_headroom(m)); + m->data_len =3D m->pkt_len =3D 0; + + /* copy next segment */ + len =3D RTE_MIN(rte_pktmbuf_tailroom(m), data_len); + rte_memcpy(rte_pktmbuf_append(m, len), data, len); + + mbuf->nb_segs++; + data_len -=3D len; + data +=3D len; + } + return mbuf->nb_segs; +} static uint16_t eth_pcap_rx(void *queue, @@ -173,17 +210,18 @@ eth_pcap_rx(void *queue, rte_memcpy(rte_pktmbuf_mtod(mbuf, void *), packet, header.len); mbuf->data_len =3D (uint16_t)header.len; - mbuf->pkt_len =3D mbuf->data_len; - mbuf->port =3D pcap_q->in_port; - bufs[num_rx] =3D mbuf; - num_rx++; } else { - /* pcap packet will not fit in the mbuf, so drop pa= cket */ - RTE_LOG(ERR, PMD, - "PCAP packet %d bytes will not fit = in mbuf (%d bytes)\n", - header.len, buf_size); - rte_pktmbuf_free(mbuf); + /* pcap packet will not fit in a single mbuf */ + if (unlikely(eth_pcap_rx_jumbo(pcap_q->mb_pool, mbu= f, + packet, header.len) =3D=3D -1)) { + rte_pktmbuf_free(mbuf); + break; + } } + mbuf->pkt_len =3D (uint16_t)header.len; + mbuf->port =3D pcap_q->in_port; + bufs[num_rx] =3D mbuf; + num_rx++; } pcap_q->rx_pkts +=3D num_rx; return num_rx; @@ -241,6 +279,27 @@ eth_pcap_tx_dumper(void *queue, } /* + * Helper function to write mbuf chain. + */ +static uint16_t +eth_pcap_tx_jumbo(pcap_t *pcap, + struct rte_mbuf *mbuf) +{ + u_char data[ETHER_MAX_JUMBO_FRAME_LEN]; + uint16_t data_len =3D 0; + + while (mbuf !=3D NULL) { + /* There is no writev style function in libpcap, */ + /* we unfortunately have to copy data to a buffer. */ + rte_memcpy(data + data_len, rte_pktmbuf_mtod(mbuf, void *), + mbuf->data_len); + data_len +=3D mbuf->data_len; + mbuf =3D mbuf->next; + } + return pcap_sendpacket(pcap, data, data_len); +} + +/* * Callback to handle sending packets through a real NIC. */ static uint16_t @@ -259,9 +318,12 @@ eth_pcap_tx(void *queue, for (i =3D 0; i < nb_pkts; i++) { mbuf =3D bufs[i]; - ret =3D pcap_sendpacket(tx_queue->pcap, - rte_pktmbuf_mtod(mbuf, u_char *), - mbuf->data_len); + if (likely(mbuf->nb_segs =3D=3D 1)) + ret =3D pcap_sendpacket(tx_queue->pcap, + rte_pktmbuf_mtod(mbuf, u_char= *), + mbuf->data_len); + else + ret =3D eth_pcap_tx_jumbo(tx_queue->pcap, mbuf); if (unlikely(ret !=3D 0)) break; num_tx++; -- 1.9.1 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D The information contained in this message may be privileged and confidential and protected from disclosure. If the reader of this message is not the intended recipient, or an employee or agent responsible for delivering this message to the intended recipient, you are hereby notified that any reproduction, dissemination or distribution of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by replying to the message and deleting it from your computer. Thank you. Coriant-Tellabs =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D