From patchwork Thu Oct 19 08:00:10 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: 116339 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp204930qgn; Thu, 19 Oct 2017 01:01:08 -0700 (PDT) X-Google-Smtp-Source: ABhQp+SJ8l6YgVFYybqUFfm4rEqpggtA4J+4TzDX+Z5Ndhpa1jlwpXer3K6XkXbJ4hCU9mFEhOHF X-Received: by 10.55.209.27 with SMTP id s27mr892496qki.4.1508400068548; Thu, 19 Oct 2017 01:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508400068; cv=none; d=google.com; s=arc-20160816; b=SGkm+BtmEyZONFqkj6f7YEiK3lYNP5ytWbMV3PrY/wGjQAJwxRNkpSoFEYOtrNb/Je O56a5B7T3e+iBAOzfSBTJiGgmO8ighIXsq+/wbgyaTRy1fSflam7Z76fu/8mhaoj6Zs8 ytEV39Cwcem7lFbzrApIBhyCsYjhMLHoOpJYqUolqX4DGljTjnD8uYF+r8dEX3tQImN6 gS3wpYEPZ55c1JMleoMI1sicym2vQYPfwlN8qCY/le/frwYigXCP9gMzhcLI2/zvwIow WD35TsTz7EXRItFjs3Jd3gk0VMz/w4a+IUyA6Sw8Ct2KKgNJ3EpK1iB3LfolYD5Rd4sZ qsgg== 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=e3MRbXF0fK6dWKZq3pjQxXi2BQOvod0AARjIf7FSWWI=; b=Fg0LzXl01XJzeuqB5BfZC4DOS+C/WHb90ZXb3utS2jdaR48cMJE+P7Jhcatnaaulqc DlpUY7Ha2TKAj5kvZBLB2hDgxcU4EaMuC2cOR3vHhNq0cHBHrmCiYCFdU4ESk/Jwu/N1 Beu2IMRBpr0+QG+VNYeiCXwqGh7HNprGVD7Ev2TYjgtLBbAHWm8/ppqs6lRp7hjc5o9b sxlgQTbn7MWHpc4OUAhCBTKR3d5w/Y9xke4q7mRG7xD+pidE+Wz90zh9i/X2Zw5La3r7 71LWJWmFxDfMXbJv3iPJXzymTCK90ZLcrIsCQE7ZHmOgbR/ocIhV3psTLc1rV+yrApSJ b1Gw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id l192si4973728qke.459.2017.10.19.01.01.07; Thu, 19 Oct 2017 01:01:08 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 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 B402F62AD8; Thu, 19 Oct 2017 08:01:07 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 B8E576291E; Thu, 19 Oct 2017 08:00:52 +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 7EDE962AC4; Thu, 19 Oct 2017 08:00:38 +0000 (UTC) Received: from forward106o.mail.yandex.net (forward106o.mail.yandex.net [37.140.190.187]) by lists.linaro.org (Postfix) with ESMTPS id 82E6E62AE4 for ; Thu, 19 Oct 2017 08:00:18 +0000 (UTC) Received: from mxback7o.mail.yandex.net (mxback7o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::21]) by forward106o.mail.yandex.net (Yandex) with ESMTP id CBD71784429 for ; Thu, 19 Oct 2017 11:00:16 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback7o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id GrxiUKIShs-0GJiVjaS; Thu, 19 Oct 2017 11:00:16 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id OmTGLJNgIE-0GcicFiu; Thu, 19 Oct 2017 11:00:16 +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, 19 Oct 2017 11:00:10 +0300 Message-Id: <1508400012-1278-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508400012-1278-1-git-send-email-odpbot@yandex.ru> References: <1508400012-1278-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 232 Subject: [lng-odp] [PATCH API-NEXT v2 1/3] linux-gen: pktio: tap: implement start/stop operations 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: Bogdan Pricope Implement start/stop tap pktio operations. Signed-off-by: Bogdan Pricope --- /** Email created from pull request 232 (bogdanPricope:tap_set_mac_pr) ** https://github.com/Linaro/odp/pull/232 ** Patch: https://github.com/Linaro/odp/pull/232.patch ** Base sha: edca8cd1e55898826f79383b689c2c4bd2c28b3a ** Merge commit sha: 89f18d929052add128b4252f5b17907b9a354ccb **/ platform/linux-generic/pktio/tap.c | 72 +++++++++++++++++++++++++++++++------- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index ed4479445..8ddd757d9 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -134,8 +134,30 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, goto sock_err; } - /* Up interface by default. */ - if (ioctl(skfd, SIOCGIFFLAGS, &ifr) < 0) { + tap->fd = fd; + tap->skfd = skfd; + tap->mtu = mtu; + tap->pool = pool; + return 0; +sock_err: + close(skfd); +tap_err: + close(fd); + ODP_ERR("Tap device alloc failed.\n"); + return -1; +} + +static int tap_pktio_start(pktio_entry_t *pktio_entry) +{ + struct ifreq ifr; + pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + + odp_memset(&ifr, 0, sizeof(ifr)); + snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", + (char *)pktio_entry->s.name + 4); + + /* Up interface by default. */ + if (ioctl(tap->skfd, SIOCGIFFLAGS, &ifr) < 0) { __odp_errno = errno; ODP_ERR("ioctl(SIOCGIFFLAGS) failed: %s\n", strerror(errno)); goto sock_err; @@ -144,22 +166,46 @@ static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, ifr.ifr_flags |= IFF_UP; ifr.ifr_flags |= IFF_RUNNING; - if (ioctl(skfd, SIOCSIFFLAGS, &ifr) < 0) { + if (ioctl(tap->skfd, SIOCSIFFLAGS, &ifr) < 0) { __odp_errno = errno; ODP_ERR("failed to come up: %s\n", strerror(errno)); goto sock_err; } - tap->fd = fd; - tap->skfd = skfd; - tap->mtu = mtu; - tap->pool = pool; return 0; sock_err: - close(skfd); -tap_err: - close(fd); - ODP_ERR("Tap device alloc failed.\n"); + ODP_ERR("Tap device open failed.\n"); + return -1; +} + +static int tap_pktio_stop(pktio_entry_t *pktio_entry) +{ + struct ifreq ifr; + pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + + odp_memset(&ifr, 0, sizeof(ifr)); + snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", + (char *)pktio_entry->s.name + 4); + + /* Up interface by default. */ + if (ioctl(tap->skfd, SIOCGIFFLAGS, &ifr) < 0) { + __odp_errno = errno; + ODP_ERR("ioctl(SIOCGIFFLAGS) failed: %s\n", strerror(errno)); + goto sock_err; + } + + ifr.ifr_flags &= ~IFF_UP; + ifr.ifr_flags &= ~IFF_RUNNING; + + if (ioctl(tap->skfd, SIOCSIFFLAGS, &ifr) < 0) { + __odp_errno = errno; + ODP_ERR("failed to come up: %s\n", strerror(errno)); + goto sock_err; + } + + return 0; +sock_err: + ODP_ERR("Tap device open failed.\n"); return -1; } @@ -383,8 +429,8 @@ const pktio_if_ops_t tap_pktio_ops = { .term = NULL, .open = tap_pktio_open, .close = tap_pktio_close, - .start = NULL, - .stop = NULL, + .start = tap_pktio_start, + .stop = tap_pktio_stop, .recv = tap_pktio_recv, .send = tap_pktio_send, .mtu_get = tap_mtu_get,