From patchwork Thu Sep 14 03:00:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 112499 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp271487qgf; Wed, 13 Sep 2017 20:11:12 -0700 (PDT) X-Google-Smtp-Source: AOwi7QArh2sPYITeDneSvXBCu520q7xgIkks8O3C++6u5xgFCtzI+vbc5EQfJQ3wLVQfJjGR+uKP X-Received: by 10.55.72.215 with SMTP id v206mr828773qka.92.1505358671994; Wed, 13 Sep 2017 20:11:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1505358671; cv=none; d=google.com; s=arc-20160816; b=BNcS/MAfGAcXikCUiEE3+Xd1FKz7xNb5cuiE9jYis4/kmwpuizDyyBHoRoamuDZfS/ eth/j/32Xmd4RX5P9QuGvUq+JK7mjqfcnYEnma1NKB+O4+abA6z3FxmqzIPXobLjcX9o nRQ6Q2Y3+/o9004EDF8sQt7zOQAcAcT2ZiHLM2evOxSkpmrcvC8HVozTYpFvdIiPFIuz febFbYBDRRZx6N0McKK3aenMFMStXy6lPOn7e8kPwab3FzgSqWuKyAn1K4JBppKbxrRj RbUAdl/8UEVPQ2wv1mrMeAeumx9pjiPa62qHfp1qP5ApQfr1lRn0W8zvpgZvCiQpsbhL K1BA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=8mFgqZ7GblNMeRBm8C3X4YnjQXqI1Me5J/4CpTjx8c0=; b=g23IAFj4Rg9fKTaBnIOVaIrndguQTptXtRFEWulI3yTpWhtfr40dJgnsESddHoa5Op EFIZPDeSb9u2/cJ30E29N2LgAkNTl8ZMfzYBPbVtTKWzaKuz+QJHFFqxgao5QoqLjUPn JHP4+QVypeGtcP63fbpTokjuMhhvOKH+1W6BDzjFrICpJ8PE2eTuLFKJ2cFjqUF1VPJm dWTr6y/HzxkCSf/qAmU+V5xSul4t00uao/jNlHM86nM+sVVYdlLwiNhqVJg6YP+sU0C8 sNHdzaEKKsjd7QysE0ZdZgm3NoQaYbsyjK1iWhSIxaM6tu7MAGmKMwGUbLHbg6Ayx8+8 86Dg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id e31si16893032qtk.427.2017.09.13.20.11.11; Wed, 13 Sep 2017 20:11:11 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 9CB9F62D0E; Thu, 14 Sep 2017 03:11:11 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id EDBAB62C5C; Thu, 14 Sep 2017 03:01:36 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id C597462C5C; Thu, 14 Sep 2017 03:01:31 +0000 (UTC) Received: from forward104p.mail.yandex.net (forward104p.mail.yandex.net [77.88.28.107]) by lists.linaro.org (Postfix) with ESMTPS id 2B39460B3F for ; Thu, 14 Sep 2017 03:00:32 +0000 (UTC) Received: from mxback14j.mail.yandex.net (mxback14j.mail.yandex.net [IPv6:2a02:6b8:0:1619::90]) by forward104p.mail.yandex.net (Yandex) with ESMTP id E0C4D185D27 for ; Thu, 14 Sep 2017 06:00:30 +0300 (MSK) Received: from smtp4o.mail.yandex.net (smtp4o.mail.yandex.net [2a02:6b8:0:1a2d::28]) by mxback14j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id o5RhBEDV9g-0UU41svs; Thu, 14 Sep 2017 06:00:30 +0300 Received: by smtp4o.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id zmNnunofyZ-0UOKC3aN; Thu, 14 Sep 2017 06:00:30 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 14 Sep 2017 06:00:11 +0300 Message-Id: <1505358015-27878-8-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> References: <1505358015-27878-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 139 Subject: [lng-odp] [PATCH CLOUD-DEV v3 7/11] linux-gen: pktio: pcap: minor code refactory X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Yi He Move implementation specific data structure into dedicated header file. Signed-off-by: Yi He Reviewed-by: Brian Brooks Reviewed-by: Honnappa Nagarahalli Reviewed-by: Bill Fischofer --- /** Email created from pull request 139 (heyi-linaro:modular-pktio-ops) ** https://github.com/Linaro/odp/pull/139 ** Patch: https://github.com/Linaro/odp/pull/139.patch ** Base sha: a1f50ad720e11a54b13c4786cad4687cb5c4ec2a ** Merge commit sha: a25c44f448c9f01c48cfb51f6350d317baab8700 **/ platform/linux-generic/Makefile.am | 1 + .../linux-generic/include/odp_packet_io_internal.h | 18 ------------- .../linux-generic/include/odp_pktio_ops_pcap.h | 25 ++++++++++++++++++ .../include/odp_pktio_ops_subsystem.h | 2 ++ platform/linux-generic/pktio/pcap.c | 30 +++++++++++++--------- 5 files changed, 46 insertions(+), 30 deletions(-) create mode 100644 platform/linux-generic/include/odp_pktio_ops_pcap.h diff --git a/platform/linux-generic/Makefile.am b/platform/linux-generic/Makefile.am index 1e05c2c5..78283c01 100644 --- a/platform/linux-generic/Makefile.am +++ b/platform/linux-generic/Makefile.am @@ -192,6 +192,7 @@ noinst_HEADERS = \ ${srcdir}/include/odp_pktio_ops_ipc.h \ ${srcdir}/include/odp_pktio_ops_loopback.h \ ${srcdir}/include/odp_pktio_ops_netmap.h \ + ${srcdir}/include/odp_pktio_ops_pcap.h \ ${srcdir}/include/odp_pktio_ops_subsystem.h \ ${srcdir}/include/odp_pkt_queue_internal.h \ ${srcdir}/include/odp_pool_internal.h \ diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index af826b7e..a3890091 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -50,21 +50,6 @@ typedef union pktio_entry_u pktio_entry_t; * requested number of packets were not handled. */ #define SOCK_ERR_REPORT(e) (e != EAGAIN && e != EWOULDBLOCK && e != EINTR) -#ifdef HAVE_PCAP -typedef struct { - char *fname_rx; /**< name of pcap file for rx */ - char *fname_tx; /**< name of pcap file for tx */ - void *rx; /**< rx pcap handle */ - void *tx; /**< tx pcap handle */ - void *tx_dump; /**< tx pcap dumper handle */ - odp_pool_t pool; /**< rx pool */ - unsigned char *buf; /**< per-pktio temp buffer */ - int loops; /**< number of times to loop rx pcap */ - int loop_cnt; /**< number of loops completed */ - odp_bool_t promisc; /**< promiscuous mode state */ -} pkt_pcap_t; -#endif - struct pktio_entry { const pktio_ops_module_t *ops; /**< Implementation specific methods */ pktio_ops_data_t ops_data; /**< IO operation specific data */ @@ -78,9 +63,6 @@ struct pktio_entry { pkt_sock_mmap_t pkt_sock_mmap; /**< using socket mmap * API for IO */ pkt_dpdk_t pkt_dpdk; /**< using DPDK for IO */ -#ifdef HAVE_PCAP - pkt_pcap_t pkt_pcap; /**< Using pcap for IO */ -#endif pkt_tap_t pkt_tap; /**< using TAP for IO */ }; enum { diff --git a/platform/linux-generic/include/odp_pktio_ops_pcap.h b/platform/linux-generic/include/odp_pktio_ops_pcap.h new file mode 100644 index 00000000..6911710c --- /dev/null +++ b/platform/linux-generic/include/odp_pktio_ops_pcap.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2017, ARM Limited. All rights reserved. + * + * Copyright (c) 2017, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef ODP_PKTIO_OPS_PCAP_H_ +#define ODP_PKTIO_OPS_PCAP_H_ + +typedef struct { + char *fname_rx; /**< name of pcap file for rx */ + char *fname_tx; /**< name of pcap file for tx */ + void *rx; /**< rx pcap handle */ + void *tx; /**< tx pcap handle */ + void *tx_dump; /**< tx pcap dumper handle */ + odp_pool_t pool; /**< rx pool */ + unsigned char *buf; /**< per-pktio temp buffer */ + int loops; /**< number of times to loop rx pcap */ + int loop_cnt; /**< number of loops completed */ + odp_bool_t promisc; /**< promiscuous mode state */ +} pktio_ops_pcap_data_t; + +#endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index b1b735ce..fc461be7 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -82,6 +82,7 @@ typedef ODP_MODULE_CLASS(pktio_ops) { #include #include #include +#include /* Per implementation private data * TODO: refactory each implementation to hide it internally @@ -90,6 +91,7 @@ typedef union { pktio_ops_ipc_data_t ipc; pktio_ops_loopback_data_t loopback; pktio_ops_netmap_data_t netmap; + pktio_ops_pcap_data_t pcap; } pktio_ops_data_t; /* Extract pktio ops data from pktio entry structure */ diff --git a/platform/linux-generic/pktio/pcap.c b/platform/linux-generic/pktio/pcap.c index 98f81089..b54501ed 100644 --- a/platform/linux-generic/pktio/pcap.c +++ b/platform/linux-generic/pktio/pcap.c @@ -51,7 +51,8 @@ static const char pcap_mac[] = {0x02, 0xe9, 0x34, 0x80, 0x73, 0x04}; static int pcapif_stats_reset(pktio_entry_t *pktio_entry); -static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) +static int _pcapif_parse_devname( + pktio_ops_pcap_data_t *pcap, const char *devname) { char *tok; char in[PKTIO_NAME_LEN]; @@ -80,7 +81,7 @@ static int _pcapif_parse_devname(pkt_pcap_t *pcap, const char *devname) return 0; } -static int _pcapif_init_rx(pkt_pcap_t *pcap) +static int _pcapif_init_rx(pktio_ops_pcap_data_t *pcap) { char errbuf[PCAP_ERRBUF_SIZE]; int linktype; @@ -101,7 +102,7 @@ static int _pcapif_init_rx(pkt_pcap_t *pcap) return 0; } -static int _pcapif_init_tx(pkt_pcap_t *pcap) +static int _pcapif_init_tx(pktio_ops_pcap_data_t *pcap) { pcap_t *tx = pcap->rx; @@ -136,10 +137,11 @@ static int _pcapif_init_tx(pkt_pcap_t *pcap) static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); int ret; - memset(pcap, 0, sizeof(pkt_pcap_t)); + memset(pcap, 0, sizeof(pktio_ops_pcap_data_t)); pcap->loop_cnt = 1; pcap->loops = 1; pcap->pool = pool; @@ -163,7 +165,8 @@ static int pcapif_init(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, static int pcapif_close(pktio_entry_t *pktio_entry) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); if (pcap->tx_dump) pcap_dump_close(pcap->tx_dump); @@ -181,7 +184,7 @@ static int pcapif_close(pktio_entry_t *pktio_entry) return 0; } -static int _pcapif_reopen(pkt_pcap_t *pcap) +static int _pcapif_reopen(pktio_ops_pcap_data_t *pcap) { char errbuf[PCAP_ERRBUF_SIZE]; @@ -210,7 +213,8 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, odp_packet_t pkt; odp_packet_hdr_t *pkt_hdr; uint32_t pkt_len; - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); odp_time_t ts_val; odp_time_t *ts = NULL; @@ -270,7 +274,7 @@ static int pcapif_recv_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, return i; } -static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) +static int _pcapif_dump_pkt(pktio_ops_pcap_data_t *pcap, odp_packet_t pkt) { struct pcap_pkthdr hdr; @@ -293,7 +297,8 @@ static int _pcapif_dump_pkt(pkt_pcap_t *pcap, odp_packet_t pkt) static int pcapif_send_pkt(pktio_entry_t *pktio_entry, int index ODP_UNUSED, const odp_packet_t pkts[], int len) { - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); int i; odp_ticketlock_lock(&pktio_entry->s.txl); @@ -361,7 +366,8 @@ static int pcapif_promisc_mode_set(pktio_entry_t *pktio_entry, { char filter_exp[64] = {0}; struct bpf_program bpf; - pkt_pcap_t *pcap = &pktio_entry->s.pkt_pcap; + pktio_ops_pcap_data_t *pcap = + &pktio_entry->ops_data(pcap); if (!pcap->rx) { pcap->promisc = enable; @@ -401,7 +407,7 @@ static int pcapif_promisc_mode_set(pktio_entry_t *pktio_entry, static int pcapif_promisc_mode_get(pktio_entry_t *pktio_entry) { - return pktio_entry->s.pkt_pcap.promisc; + return pktio_entry->ops_data(pcap).promisc; } static int pcapif_stats_reset(pktio_entry_t *pktio_entry)