From patchwork Thu Dec 4 12:00:35 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41932 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 2922C2486D for ; Thu, 4 Dec 2014 12:01:17 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id bs8sf10968445wib.6 for ; Thu, 04 Dec 2014 04:01:16 -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=amTAec0zbflh/q4Z/x5ozVt186xSIz1klZ+F86iQvRg=; b=banj7iQkFUly2l3w/JSuMcTjr0W9Y+VfCUaXRmAcTaThxsKe3bGbT6WXYHbN2IsToM fhP04FrcYzGh/hs0qy/EBx7LQXljKvpElqFiRXQHZC4G+Xm/w2k8iqhkP+HhAhxsmFRk CC5P2oPUqTwg79Ot3fdJwQR+erkxB74vnN1jsdQCKi6eQ3FPIvSbDo+byxjs4MJGNfDZ P4lZy7/0SaXL0G8YFQtlaxiN1AIX2iLKWIYJZk70ANqltH88oZBLVEhXnwN3IC/Fexoz 8U+dCngRO+MGxlH1Z3ngAjeL/gnTiGb1JsepuEbt5V//n/rdp9RHH1muOW85kcSqsgeU QL7w== X-Gm-Message-State: ALoCoQlf5zG6NUPyl9yeb0ywngeAPoN2mDgQXCPsTsyLrqFT7WACa2ZfA3o+YYp05aHiXN1J7mz8 X-Received: by 10.180.108.101 with SMTP id hj5mr3218014wib.3.1417694476359; Thu, 04 Dec 2014 04:01:16 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.4.40 with SMTP id h8ls274493lah.12.gmail; Thu, 04 Dec 2014 04:01:16 -0800 (PST) X-Received: by 10.152.234.140 with SMTP id ue12mr8957375lac.78.1417694476106; Thu, 04 Dec 2014 04:01:16 -0800 (PST) Received: from mail-la0-f41.google.com (mail-la0-f41.google.com. [209.85.215.41]) by mx.google.com with ESMTPS id pd10si25645079lbc.128.2014.12.04.04.01.16 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Dec 2014 04:01:16 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.41 as permitted sender) client-ip=209.85.215.41; Received: by mail-la0-f41.google.com with SMTP id hv19so9646248lab.28 for ; Thu, 04 Dec 2014 04:01:16 -0800 (PST) X-Received: by 10.112.38.4 with SMTP id c4mr9160833lbk.46.1417694476014; Thu, 04 Dec 2014 04:01:16 -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 ew9csp21553lbc; Thu, 4 Dec 2014 04:01:14 -0800 (PST) X-Received: by 10.236.209.229 with SMTP id s65mr12398209yho.128.1417694474355; Thu, 04 Dec 2014 04:01:14 -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 t102si31069157qgd.127.2014.12.04.04.01.13 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Thu, 04 Dec 2014 04:01:14 -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 1XwV5r-00078s-Fd; Thu, 04 Dec 2014 12:01:11 +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 1XwV5d-00075X-K1 for lng-odp@lists.linaro.org; Thu, 04 Dec 2014 12:00:57 +0000 Received: by mail-lb0-f180.google.com with SMTP id l4so13565249lbv.25 for ; Thu, 04 Dec 2014 04:00:51 -0800 (PST) X-Received: by 10.112.12.102 with SMTP id x6mr2310352lbb.29.1417694451696; Thu, 04 Dec 2014 04:00:51 -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 f7sm7172882lam.26.2014.12.04.04.00.50 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 04 Dec 2014 04:00:50 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Thu, 4 Dec 2014 15:00:35 +0300 Message-Id: <1417694439-13861-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417694439-13861-1-git-send-email-maxim.uvarov@linaro.org> References: <1417694439-13861-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv5 2/6] API: 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.41 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 for linux-generic. Signed-off-by: Maxim Uvarov --- platform/linux-generic/include/api/odp_packet_io.h | 24 +++++++ platform/linux-generic/odp_packet_io.c | 84 ++++++++++++++++++++++ 2 files changed, 108 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 5f7ba7c..df2b138 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -153,6 +153,30 @@ 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. + * @param[in] enable 1 enabled, 0 disabled. + * + * @retval 0 on success. + * @retval -1 on a bad pktio id + * @retval -1 any other error + */ +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable); + +/** + * 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_mode(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index faa197f..b0c00c0 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -486,6 +486,15 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) return nbr; } +/** function should be called with locked entry */ +static int sockfd_from_pktio_entry(pktio_entry_t *entry) +{ + if (entry->s.pkt_sock_mmap.sockfd > -1) + return entry->s.pkt_sock_mmap.sockfd; + else + return entry->s.pkt_sock.sockfd; +} + int odp_pktio_set_mtu(odp_pktio_t id, int mtu) { pktio_entry_t *entry; @@ -549,3 +558,78 @@ int odp_pktio_mtu(odp_pktio_t id) return ifr.ifr_mtu; } + +int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable) +{ + 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; + } + + lock_entry(entry); + + sockfd = sockfd_from_pktio_entry(entry); + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + unlock_entry(entry); + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + return -1; + } + + if (enable) + ifr.ifr_flags |= IFF_PROMISC; + else + ifr.ifr_flags &= ~(IFF_PROMISC); + + ret = ioctl(sockfd, SIOCSIFFLAGS, &ifr); + if (ret < 0) { + unlock_entry(entry); + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); + return -1; + } + + unlock_entry(entry); + return 0; +} + +int odp_pktio_promisc_mode(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; + } + + lock_entry(entry); + + sockfd = sockfd_from_pktio_entry(entry); + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + ret = ioctl(sockfd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + unlock_entry(entry); + return -1; + } + unlock_entry(entry); + + if (ifr.ifr_flags & IFF_PROMISC) + return 1; + else + return 0; +}