From patchwork Mon Oct 16 12:00:05 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: 115904 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3597439qgn; Mon, 16 Oct 2017 05:02:24 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Scb0hMqrvcTuDrTgJLF+gRLkdULS4LBX2LZiiEwYib3iVUCFkuo7Mr4VF0NuZNW5VrJPT2 X-Received: by 10.107.232.3 with SMTP id f3mr11814413ioh.156.1508155344635; Mon, 16 Oct 2017 05:02:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508155344; cv=none; d=google.com; s=arc-20160816; b=DjLuIclR7pRevAW4a2RBdwylsAPO6m9cLrOaW6R4V9mhB/FS+VHO5FTEfdF4xFSfUA oOCy+n+jdggGy3sHjNpgut6+1Q+hjVqVf0tmop0XbVje/4inktEH07lspNzHldRlakXq kLJo/WuzhwgKOtfWJNj5c9zLgb8i5MLKjSQg6cE5qgzszLwZO1AFY3cwqEDADEkKMPYp mAczWQ0yDObtk7159Vibl1WbrnBB4VX2HnwdHje9vO/fxLMMsKJjQ8SG4OFTiqZmVVU+ 3RvW6NsARKwYTOhsjXeKe7dCopSYhqIbSd6uidA9hXBAeWeJkZ9FTsVC43WfOJuwfDR6 AuXg== 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=oVo3Hk2VDQ9UNmWFgcZIWzf1lS7+i4aFuuHHPbgtSOU=; b=w0y7dqvKF1OV5cqv7KRDgqZa/qXmMDE3ynLvManID7AC3pzIoWwhZuNpNqj/Kg7d/c AAUR1yoEnfPqdpUCS16smZX+1FOuedmxfJeJ06PnZngvWK6AyGeqO2k5yafzV4EcsD67 mFOA2UKMQoGhH+o2THIyUo3eBK6RT562rcD/Sb5sW5shSZYza7ZOVODi4ylSquusuyKp qghFxnz5gUuub78t/ru0OdH+tGcwkEHyKSJ/8YXs/FRGue9csUEqf+XtoGJJN7MpdIsA 4Ng0Og8otKgYsQsgiUIbundZxn2CVd09RovIWK5SWSLX76KLo46VI4umE+TRADeXD+tP S3RA== 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 d1si4848754itj.45.2017.10.16.05.02.24; Mon, 16 Oct 2017 05:02:24 -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 CE763609DB; Mon, 16 Oct 2017 12:02:23 +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,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 3F80560923; Mon, 16 Oct 2017 12:01:59 +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 B941E609EB; Mon, 16 Oct 2017 12:01:53 +0000 (UTC) Received: from forward106p.mail.yandex.net (forward106p.mail.yandex.net [77.88.28.109]) by lists.linaro.org (Postfix) with ESMTPS id 3E9B360609 for ; Mon, 16 Oct 2017 12:00:15 +0000 (UTC) Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward106p.mail.yandex.net (Yandex) with ESMTP id E309D2D81F53 for ; Mon, 16 Oct 2017 15:00:13 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id 9TKw4DHvvW-0DFWBxrU; Mon, 16 Oct 2017 15:00:13 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id KcD5G1a8yg-0D1KJlWV; Mon, 16 Oct 2017 15:00:13 +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: Mon, 16 Oct 2017 15:00:05 +0300 Message-Id: <1508155207-5041-2-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508155207-5041-1-git-send-email-odpbot@yandex.ru> References: <1508155207-5041-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 232 Subject: [lng-odp] [PATCH API-NEXT v1 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: afeda4d14bb6f449cb269680cdbd56b26726eedf ** Merge commit sha: 8726d6c7a814c3380aacd18250194eae85ababb3 **/ 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,