From patchwork Fri Dec 5 16:20:22 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41981 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f197.google.com (mail-lb0-f197.google.com [209.85.217.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 189EE240F7 for ; Fri, 5 Dec 2014 16:21:16 +0000 (UTC) Received: by mail-lb0-f197.google.com with SMTP id n15sf658045lbi.8 for ; Fri, 05 Dec 2014 08:21:14 -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=gXZzCExHTMAyybPsPSSf7F2kmp9PCipaYYlVe/5CATM=; b=h/xBkx4mRcO7YI9Nj80yxPJ+GYmCtiRVx8UqjaRJN3vY5+HjUZHo79aiyu1XCctckm R6BKsANzNql843vNrPIQ4jZ/CF7xjZNzcqVZu21T3fqDVaHW7TkjLba+rC9mAvEkOe9p FqFCajjL8LF5bup5fM6MoUFh8BSrX8PyetHxcHt0nfpNikVNk6NDMcCr078vTYlhT91h ZL+9Q0yd6f+cbtjrYrLP3gsxvsM6/14TY1iGtEMpCQLCIlXLxQMzdx9Idk5OI/SSF/bG zt4++omV1TGc1hMCvH2HbJDc6oJQpLPYruBoXzeTRvMO3jEW5knKHMMUxAE0AxNlr2j1 njzQ== X-Gm-Message-State: ALoCoQlJg9hFdsktFlpNOTAhCYkh6A2GiHRSXiyZNMQCw0FVqVHzpEOVEWyyjNz92UYTtNCaqjMy X-Received: by 10.180.98.165 with SMTP id ej5mr841025wib.1.1417796474941; Fri, 05 Dec 2014 08:21:14 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.30.42 with SMTP id p10ls322199lah.98.gmail; Fri, 05 Dec 2014 08:21:14 -0800 (PST) X-Received: by 10.152.170.170 with SMTP id an10mr3707819lac.46.1417796474387; Fri, 05 Dec 2014 08:21:14 -0800 (PST) Received: from mail-la0-f42.google.com (mail-la0-f42.google.com. [209.85.215.42]) by mx.google.com with ESMTPS id ay3si29416559lbc.4.2014.12.05.08.21.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Dec 2014 08:21:14 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.42 as permitted sender) client-ip=209.85.215.42; Received: by mail-la0-f42.google.com with SMTP id gd6so940331lab.29 for ; Fri, 05 Dec 2014 08:21:14 -0800 (PST) X-Received: by 10.152.43.103 with SMTP id v7mr3669850lal.29.1417796474314; Fri, 05 Dec 2014 08:21:14 -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 ew9csp239433lbc; Fri, 5 Dec 2014 08:21:13 -0800 (PST) X-Received: by 10.224.55.145 with SMTP id u17mr27154725qag.12.1417796472833; Fri, 05 Dec 2014 08:21:12 -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 x109si35245091qge.89.2014.12.05.08.21.11 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 05 Dec 2014 08:21:12 -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 1Xwvd0-0001yp-K8; Fri, 05 Dec 2014 16:21:10 +0000 Received: from mail-lb0-f180.google.com ([209.85.217.180]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xwvca-0001t3-C5 for lng-odp@lists.linaro.org; Fri, 05 Dec 2014 16:20:44 +0000 Received: by mail-lb0-f180.google.com with SMTP id l4so788530lbv.39 for ; Fri, 05 Dec 2014 08:20:38 -0800 (PST) X-Received: by 10.152.5.198 with SMTP id u6mr3823210lau.42.1417796438842; Fri, 05 Dec 2014 08:20:38 -0800 (PST) Received: from localhost.localdomain (ppp91-76-163-205.pppoe.mtu-net.ru. [91.76.163.205]) by mx.google.com with ESMTPSA id pr9sm8455263lbc.12.2014.12.05.08.20.36 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 05 Dec 2014 08:20:37 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 5 Dec 2014 19:20:22 +0300 Message-Id: <1417796424-9909-5-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417796424-9909-1-git-send-email-maxim.uvarov@linaro.org> References: <1417796424-9909-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv6 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.42 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: lo0 can not be used. Instead of it we walking though all devices and select one that can be used for cunit testing. Filter criteria is: device has to support mac, promisc and mtu changes. Device has to be wireless device. Also hint 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 | 64 ++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index e8815cd..993f2ab 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]; @@ -154,12 +155,75 @@ static int free_pktio_entry(odp_pktio_t id) return 0; } +static int find_loop_dev(char loop[IFNAMSIZ]) +{ + struct ifaddrs *ifap, *ifa; + + getifaddrs(&ifap); + + for (ifa = ifap; ifa; ifa = ifa->ifa_next) { + if (ifa->ifa_addr && + ifa->ifa_addr->sa_family == AF_INET) { + if ((ifa->ifa_flags & (IFF_LOOPBACK | + IFF_POINTOPOINT | + IFF_NOARP)) || + (!memcmp(ifa->ifa_name, "lxcbr", 5)) || + (!memcmp(ifa->ifa_name, "wlan", 4)) || + (!memcmp(ifa->ifa_name, "veth", 4)) || + (!memcmp(ifa->ifa_name, "virbr", 5))) + continue; + memcpy(loop, ifa->ifa_name, IFNAMSIZ); + freeifaddrs(ifap); + return 0; + } + } + + freeifaddrs(ifap); + return -1; +} + odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool) { odp_pktio_t id; 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)) { + 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); + } else { + if (!find_loop_dev(loop)) { + ODP_DBG("pktio rename loop to %s\n", loop); + dev = loop; + } else { + ODP_DBG("pktio: No suitable netdev.\n"); + return ODP_PKTIO_INVALID; + } + } + } id = alloc_lock_pktio_entry(); if (id == ODP_PKTIO_INVALID) {