From patchwork Mon Dec 1 16:15:28 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41788 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f200.google.com (mail-lb0-f200.google.com [209.85.217.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C936D20672 for ; Mon, 1 Dec 2014 16:16:13 +0000 (UTC) Received: by mail-lb0-f200.google.com with SMTP id f15sf6923024lbj.3 for ; Mon, 01 Dec 2014 08:16:12 -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=is7wZW3eq58YkbU2YEcFwu1I6UIyACy2KpqJC2JSjAo=; b=Ts+RIvraU+ytt4uaRBsmxsTfHyyc3LK1ZJuX7FrKgjAVNBg9veM5rlY6zz2heXVVd5 j/ChNZOJyTVqempV0cpqp4Wo1e+tyGN3H8xRKfueH3ZkJ6dxSEXNuuEfnsb1NbCOffxe yQVmMyYDowmdMfo7whTBEt6UF/N0ytI7Dw1BmUM2GKK8nSYDXKX2BxakfpHTnrc3uRVy qxF4lXNCTmQSe1lcGCGrYjtUxxDekbwZKWlKhclU1ypZaWoA9BwWn1ueh2BaEVrjpiFS xbE1egBFpt9etY6kDCt/lhM8nPj6fHAsTlpmYSuMlTq2SOFSOS/tNYtlsFaw4IdC11Wx EUuA== X-Gm-Message-State: ALoCoQlpRUCkhHYoYzqAaIE57OrTNgxGyTukJdBmc5176vAAfo8jlcHpUmfLzjFg8c3zfZtAyZid X-Received: by 10.152.18.136 with SMTP id w8mr2019162lad.5.1417450572750; Mon, 01 Dec 2014 08:16:12 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.21.225 with SMTP id y1ls674999lae.25.gmail; Mon, 01 Dec 2014 08:16:12 -0800 (PST) X-Received: by 10.153.11.133 with SMTP id ei5mr58064600lad.75.1417450572426; Mon, 01 Dec 2014 08:16:12 -0800 (PST) Received: from mail-lb0-f172.google.com (mail-lb0-f172.google.com. [209.85.217.172]) by mx.google.com with ESMTPS id xk6si18128001lbb.22.2014.12.01.08.16.12 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:16:12 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.172 as permitted sender) client-ip=209.85.217.172; Received: by mail-lb0-f172.google.com with SMTP id u10so8963681lbd.17 for ; Mon, 01 Dec 2014 08:16:12 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr56797710lbo.32.1417450572336; Mon, 01 Dec 2014 08:16:12 -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 ew9csp319889lbc; Mon, 1 Dec 2014 08:16:11 -0800 (PST) X-Received: by 10.224.164.195 with SMTP id f3mr1870484qay.55.1417450570897; Mon, 01 Dec 2014 08:16:10 -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 104si3564732qgp.70.2014.12.01.08.16.10 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:16:10 -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 1XvTdw-0007BW-NF; Mon, 01 Dec 2014 16:16:08 +0000 Received: from mail-la0-f46.google.com ([209.85.215.46]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XvTdi-0007AH-NT for lng-odp@lists.linaro.org; Mon, 01 Dec 2014 16:15:54 +0000 Received: by mail-la0-f46.google.com with SMTP id q1so4215127lam.33 for ; Mon, 01 Dec 2014 08:15:48 -0800 (PST) X-Received: by 10.152.36.232 with SMTP id t8mr52399907laj.6.1417450548742; Mon, 01 Dec 2014 08:15:48 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id ar4sm4819466lbc.48.2014.12.01.08.15.47 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:15:47 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 1 Dec 2014 19:15:28 +0300 Message-Id: <1417450537-7640-3-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417450537-7640-1-git-send-email-maxim.uvarov@linaro.org> References: <1417450537-7640-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 02/11] 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.217.172 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 | 74 ++++++++++++++++++++++ 2 files changed, 98 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..c7d1e40 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -149,6 +149,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_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_enabled(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index acc03bb..d97910f 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -545,3 +545,77 @@ int odp_pktio_mtu(odp_pktio_t id) return ifr.ifr_mtu; } + +int odp_pktio_promisc_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; + } + + if (entry->s.pkt_sock_mmap.sockfd > -1) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + 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"); + return -1; + } + + if (enable) + ifr.ifr_flags |= IFF_PROMISC; + else + 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_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 > -1) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + 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"); + return -1; + } + + if (ifr.ifr_flags & IFF_PROMISC) + return 1; + else + return 0; +}