From patchwork Mon Nov 24 09:53:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41397 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f69.google.com (mail-wg0-f69.google.com [74.125.82.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 8264424524 for ; Mon, 24 Nov 2014 09:53:30 +0000 (UTC) Received: by mail-wg0-f69.google.com with SMTP id k14sf4987953wgh.4 for ; Mon, 24 Nov 2014 01:53:29 -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: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=qOTczFhDBjdM2TsaE00em8nM5KHVS2qb1ZwxUmAcfUs=; b=muiHdDJ9NOwqu/3lhJwPBEqC+ZOm3kh+y7p67zCJlWgtz6duuMN+0OPUDKJQ2ZW8dm KlaKZn77EHnZ87G/EWWHicziSds9vIFcLXoBwBgHRqeeNhVx6Y9f/9DK5l5Ee+yDq4Oo LjyZHXXwajAkBoLJf+1Yo4EgNiACiy4dLCd9Ra7jMMhhpa29lA5G7HFy3tzcykLLjnig L8J3j6hwY8n93UZ0fgJHbSDpsUfocvJpY+vJDFs7l+MXh+4rUqrM5Jld6nrX1QO/eMg7 lF6q850JoYIFb/AhZ4CkNbg1dVjCpcOWPNdVHPX7xADAJekL9Bd3+cGdFKbdEvgEFzn8 yvQw== X-Gm-Message-State: ALoCoQmjFxLyZPoQq79heGq88+NVYKz5YIygOYMRf+EGWFU8t2pbX4nnVipAf5Z/cCr7GvU/WnV1 X-Received: by 10.180.101.170 with SMTP id fh10mr3817536wib.4.1416822809736; Mon, 24 Nov 2014 01:53:29 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.120.4 with SMTP id ky4ls430188lab.23.gmail; Mon, 24 Nov 2014 01:53:29 -0800 (PST) X-Received: by 10.152.36.232 with SMTP id t8mr14331099laj.6.1416822809478; Mon, 24 Nov 2014 01:53:29 -0800 (PST) Received: from mail-la0-f53.google.com (mail-la0-f53.google.com. [209.85.215.53]) by mx.google.com with ESMTPS id iz2si14583499lbc.92.2014.11.24.01.53.29 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 01:53:29 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.53 as permitted sender) client-ip=209.85.215.53; Received: by mail-la0-f53.google.com with SMTP id gm9so4218703lab.26 for ; Mon, 24 Nov 2014 01:53:29 -0800 (PST) X-Received: by 10.152.9.7 with SMTP id v7mr19549341laa.40.1416822809372; Mon, 24 Nov 2014 01:53:29 -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 ew9csp224960lbc; Mon, 24 Nov 2014 01:53:28 -0800 (PST) X-Received: by 10.140.100.199 with SMTP id s65mr27328510qge.44.1416822807942; Mon, 24 Nov 2014 01:53:27 -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 w81si15095080qge.81.2014.11.24.01.53.27 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 24 Nov 2014 01:53:27 -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 1XsqKj-0006eH-BS; Mon, 24 Nov 2014 09:53:25 +0000 Received: from mail-la0-f51.google.com ([209.85.215.51]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XsqKb-0006dw-RD for lng-odp@lists.linaro.org; Mon, 24 Nov 2014 09:53:17 +0000 Received: by mail-la0-f51.google.com with SMTP id mc6so7189921lab.24 for ; Mon, 24 Nov 2014 01:53:12 -0800 (PST) X-Received: by 10.112.199.227 with SMTP id jn3mr19329729lbc.86.1416822792008; Mon, 24 Nov 2014 01:53:12 -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 eg2sm3420195lbb.29.2014.11.24.01.53.10 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Nov 2014 01:53:10 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 24 Nov 2014 12:53:02 +0300 Message-Id: <1416822783-16612-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 X-Topics: patch Subject: [lng-odp] [PATCH 1/2] promisc mode manipulation functions 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.53 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 Define API and implement promisc functions: odp_pktio_promisc_get_enabled() odp_pktio_promisc_enable() odp_pktio_promisc_disable() Signed-off-by: Maxim Uvarov --- platform/linux-generic/include/api/odp_packet_io.h | 34 +++++++ platform/linux-generic/odp_packet_io.c | 108 +++++++++++++++++++++ 2 files changed, 142 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 667395c..c9b0889 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -149,6 +149,40 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); int odp_pktio_mtu(odp_pktio_t id); /** + * Enable promiscuous mode on a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * + * @retval 0 on success. + * @retval -1 on a bad pktio id + * @retval -1 any other error + */ +int odp_pktio_promisc_enable(odp_pktio_t id); + +/** + * Disable promiscuous mode on a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * + * @retval 0 on success. + * @retval -1 on a bad pktio id + * @retval -1 any other error + */ +int odp_pktio_promisc_disable(odp_pktio_t id); + +/** + * Determine if promiscuous mode is enabled for a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * + * @retval 1 if promiscuous mode is enabled. + * @retval 0 if promiscuous mode is disabled. + * @retval -1 on a bad pktio id + * @retval -1 any other error +*/ +int odp_pktio_promisc_get_enabled(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index c523350..937f7f0 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -542,3 +542,111 @@ int odp_pktio_mtu(odp_pktio_t id) return ifr.ifr_mtu; } + +int odp_pktio_promisc_enable(odp_pktio_t id) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + ifr.ifr_name[IFNAMSIZ] = 0; + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + return -1; + } + + ifr.ifr_flags |= IFF_PROMISC; + + ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); + return -1; + } + + return 0; +} + +int odp_pktio_promisc_disable(odp_pktio_t id) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + ifr.ifr_name[IFNAMSIZ] = 0; + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + return -1; + } + + ifr.ifr_flags &= ~(IFF_PROMISC); + + ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); + return -1; + } + + return 0; +} + +int odp_pktio_promisc_get_enabled(odp_pktio_t id) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + return -1; + } + + if (ifr.ifr_flags & IFF_PROMISC) + return 1; + else + return 0; +}