From patchwork Fri Nov 14 09:30:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 40804 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f200.google.com (mail-wi0-f200.google.com [209.85.212.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 54C33240ED for ; Fri, 14 Nov 2014 09:31:46 +0000 (UTC) Received: by mail-wi0-f200.google.com with SMTP id ex7sf746638wid.11 for ; Fri, 14 Nov 2014 01:31:45 -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:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=TXETWHK5U6/E8cdom1EcWYTZ9RjAOFzKGQZpWEa8xWc=; b=RaoFlABUwLdYXyt4NcL9nT1FYnxLEfCTA31QruK75+LwnCU/yNM4bA8yZZY9s0UG92 t3ZDzRLZSL41Bvkz6zSlvclbJsP0V9YHNDR4tCX/E6hetm9SNVlDPA3evkllrIcQ61yL 6c0lQ3qf4HIXQzE4DXyRDgF2hA0KVE+7Rm1n4NHo6le+ex6WlhuY8Ff+soUriS1lw65a ZV5tRn9qclDLH7caZWHYJ1w7GcZg+RyKXHDY15fZKxrj/XXdei9UGYL6v/AdtOLP5TFt 9j+UrJ06/J1s46ZYrX8A5l92Ok3d5UYThvJlRJwO0CQNSz+YXY9L2k4pIu4kFKLc6NWf XRsQ== X-Gm-Message-State: ALoCoQl/hxybgACFCjmsBAKr8EVgJF1PH9/ydoSwTvb8wsUWCuOVI1GBr0NRI4Gb1s8Oinv77Cs5 X-Received: by 10.112.62.226 with SMTP id b2mr272743lbs.11.1415957505595; Fri, 14 Nov 2014 01:31:45 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.19.1 with SMTP id a1ls657509lae.19.gmail; Fri, 14 Nov 2014 01:31:45 -0800 (PST) X-Received: by 10.152.21.135 with SMTP id v7mr7328361lae.65.1415957505113; Fri, 14 Nov 2014 01:31:45 -0800 (PST) Received: from mail-la0-f51.google.com (mail-la0-f51.google.com. [209.85.215.51]) by mx.google.com with ESMTPS id z3si41136777lad.17.2014.11.14.01.31.45 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 01:31:45 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.51 as permitted sender) client-ip=209.85.215.51; Received: by mail-la0-f51.google.com with SMTP id q1so14614472lam.24 for ; Fri, 14 Nov 2014 01:31:45 -0800 (PST) X-Received: by 10.112.62.166 with SMTP id z6mr1689333lbr.74.1415957505020; Fri, 14 Nov 2014 01:31:45 -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 ew9csp736029lbc; Fri, 14 Nov 2014 01:31:44 -0800 (PST) X-Received: by 10.140.29.226 with SMTP id b89mr9939801qgb.94.1415957502122; Fri, 14 Nov 2014 01:31:42 -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 g38si50261582qgd.63.2014.11.14.01.31.39 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Fri, 14 Nov 2014 01:31:42 -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 1XpDEA-0003o6-5N; Fri, 14 Nov 2014 09:31:38 +0000 Received: from mail-lb0-f175.google.com ([209.85.217.175]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XpDDr-0003mh-0M for lng-odp@lists.linaro.org; Fri, 14 Nov 2014 09:31:19 +0000 Received: by mail-lb0-f175.google.com with SMTP id n15so12714325lbi.34 for ; Fri, 14 Nov 2014 01:31:13 -0800 (PST) X-Received: by 10.112.185.68 with SMTP id fa4mr986909lbc.84.1415957473165; Fri, 14 Nov 2014 01:31:13 -0800 (PST) Received: from localhost.localdomain (broadband-46-188-125-121.2com.net. [46.188.125.121]) by mx.google.com with ESMTPSA id x3sm1676435laj.34.2014.11.14.01.31.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 14 Nov 2014 01:31:12 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 14 Nov 2014 12:30:59 +0300 Message-Id: <1415957459-11458-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1415957459-11458-1-git-send-email-maxim.uvarov@linaro.org> References: <1415957459-11458-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 3/3] 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.51 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_set_promisc() odp_pktio_promisc() Signed-off-by: Maxim Uvarov --- platform/linux-generic/include/api/odp_packet_io.h | 25 +++++++ platform/linux-generic/odp_packet_io.c | 77 ++++++++++++++++++++++ 2 files changed, 102 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index e5cf320..87589ce 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -159,6 +159,31 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); int odp_pktio_mtu(odp_pktio_t id); /** + * Set promiscuous mode on a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * @param[in] enable 1 to enable promiscuous mode, 0 to disable + * + * @retval 0 on success. + * @retval -1 on a bad pktio id + * @retval -1 ilegal enable value + * @retval -1 any other error + */ +int odp_pktio_set_promisc(odp_pktio_t id, int 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(odp_pktio_t id); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index f0e361a..403804c 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -542,3 +542,80 @@ int odp_pktio_mtu(odp_pktio_t id) return ifr.ifr_mtu; } + +int odp_pktio_set_promisc(odp_pktio_t id, int enable) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + if (enable < 0 || enable > 1) { + ODP_DBG("illegal enable value %d\n", enable); + return -1; + } + + 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) { + 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) { + ODP_DBG("ioctl SIOCSIFFLAGS error\n"); + return -1; + } + + return 0; +} + +int odp_pktio_promisc(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) { + ODP_DBG("ioctl SIOCGIFFLAGS error\n"); + return -1; + } + + if (ifr.ifr_flags & IFF_PROMISC) + return 1; + else + return 0; +}