From patchwork Mon Dec 8 14:58:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 42016 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 37E08244AC for ; Mon, 8 Dec 2014 14:59:24 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf1876038wib.2 for ; Mon, 08 Dec 2014 06:59:23 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=u9+7Y/PmZBAyRbaoOIgWY9QcFcmBYOpczJrvm2D6YaQ=; b=D0XbRpkqh0OXZ7mE6nez+UCYxk6NPj4R0eO3mxFJKGHqEwaF0dfj03ispXme6hjpMk EWbMiLITxZpckjEAoXmeTijEgV3jiTwWquL+bX7LN4ujHm1CWDT778wHxtoZjHztbtSH C39frDWAGIBHzbZIAo0SyZnR5zesRXSc0uguEd9pvhhJn0cJGdYBu0hTfNK44KfdymZT 9UjDOuNqpX8sFcck93k/JZz7dnoc/fTpiiAW1o2EqXb+ezpST6duFyfEYS2rNpXlS7t4 gVcWCXY2mZjOYH+5I94BjeZUYDpEnkE4Ccui7mUwmw+Cl4kKZoFusZTrOUNydKvvGdXJ m4GQ== X-Gm-Message-State: ALoCoQm4FBTEhMXkYw7+MeZoIwE+IQ8n+ZeJKytG0xfKEQJ/aSNMwlObdzZHi5RumkF9Uc0A3Kov X-Received: by 10.112.171.167 with SMTP id av7mr177095lbc.2.1418050763470; Mon, 08 Dec 2014 06:59:23 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.88.77 with SMTP id be13ls666999lab.40.gmail; Mon, 08 Dec 2014 06:59:23 -0800 (PST) X-Received: by 10.112.150.136 with SMTP id ui8mr16811560lbb.60.1418050763322; Mon, 08 Dec 2014 06:59:23 -0800 (PST) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com. [209.85.215.49]) by mx.google.com with ESMTPS id vr4si37175186lbb.110.2014.12.08.06.59.23 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:59:23 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id hs14so4011225lab.22 for ; Mon, 08 Dec 2014 06:59:23 -0800 (PST) X-Received: by 10.152.43.12 with SMTP id s12mr16424085lal.67.1418050763240; Mon, 08 Dec 2014 06:59:23 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.112.184.201 with SMTP id ew9csp617400lbc; Mon, 8 Dec 2014 06:59:22 -0800 (PST) X-Received: by 10.140.88.177 with SMTP id t46mr51856028qgd.36.1418050761708; Mon, 08 Dec 2014 06:59:21 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id n16si26209843qar.14.2014.12.08.06.59.20 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:59:21 -0800 (PST) Received-SPF: none (google.com: lng-odp-bounces@lists.linaro.org does not designate permitted sender hosts) client-ip=54.225.227.206; Received: from localhost ([127.0.0.1] helo=ip-10-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XxzmR-0006NS-6W; Mon, 08 Dec 2014 14:59:19 +0000 Received: from mail-lb0-f179.google.com ([209.85.217.179]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xxzm2-0006H5-4I for lng-odp@lists.linaro.org; Mon, 08 Dec 2014 14:58:54 +0000 Received: by mail-lb0-f179.google.com with SMTP id z11so3828413lbi.38 for ; Mon, 08 Dec 2014 06:58:48 -0800 (PST) X-Received: by 10.112.151.104 with SMTP id up8mr16401678lbb.21.1418050728633; Mon, 08 Dec 2014 06:58:48 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id xs6sm10869631lbb.13.2014.12.08.06.58.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:58:47 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 8 Dec 2014 17:58:31 +0300 Message-Id: <1418050713-29694-6-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1418050713-29694-1-git-send-email-maxim.uvarov@linaro.org> References: <1418050713-29694-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv7 4/6] linux-generic: odp_pktio_open loop support X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , MIME-Version: 1.0 Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: maxim.uvarov@linaro.org X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Implement pktio device loop device suitable for testing. Note: sometimes lo0 can not be used in case if you need change / get mac, promisc, mtu for specific device. Environment variable is added to bind loop to specific device, example: export ODP_PKTIO_LOOPDEV=eth0 Signed-off-by: Maxim Uvarov --- platform/linux-generic/odp_packet_io.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index e8815cd..8a86421 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -22,6 +22,7 @@ #include #include #include +#include typedef struct { pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; @@ -160,6 +161,37 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) pktio_entry_t *pktio_entry; int res; int fanout = 1; + char loop[IFNAMSIZ] = {0}; + char *loop_hint; + + if (strlen(dev) >= IFNAMSIZ) { + /* ioctl names limitation */ + ODP_ERR("pktio name %s is too big, limit is %d bytes\n", + dev, IFNAMSIZ); + return ODP_PKTIO_INVALID; + } + + /* If hint with ODP_PKTIO_LOOPDEV is provided, use hint, + * if not try to find usable device. + */ + loop_hint = getenv("ODP_PKTIO_LOOPDEV"); + if (!strcmp(dev, "loop")) { + if (!loop_hint || (strlen(loop_hint) == 0)) { + ODP_ERR("Set loop with ODP_PKTIO_LOOPDEV=ethX\n"); + return ODP_PKTIO_INVALID; + } + + if (strlen(loop_hint) >= IFNAMSIZ) { + ODP_ERR("pktio name %s is too big, limit is %d bytes\n", + loop_hint, IFNAMSIZ); + return ODP_PKTIO_INVALID; + } + + memset(loop, 0, IFNAMSIZ); + memcpy(loop, loop_hint, strlen(loop_hint)); + dev = loop; + ODP_DBG("pktio using %s as loopback device\n", loop_hint); + } id = alloc_lock_pktio_entry(); if (id == ODP_PKTIO_INVALID) {