From patchwork Mon Dec 8 14:58:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 42014 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f197.google.com (mail-wi0-f197.google.com [209.85.212.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 78C5F244AC for ; Mon, 8 Dec 2014 14:59:15 +0000 (UTC) Received: by mail-wi0-f197.google.com with SMTP id l15sf1870333wiw.8 for ; Mon, 08 Dec 2014 06:59:14 -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=SMgiiCxuOdVSF4QuDIUIVU/dGFC4apOoGb/7qo9vGTM=; b=DIjFfWEfWwnJQP82F8lZTIxMfXoP5Qzp2gyqM/DAu/H3XtN1aSEVxbZj7ILoOUfpuT OTh40epauY27S9eXWNeG3TPNY29KMlzzp9ELjUyhSPm6FMEs2MwSxNKOcr2yfIvBrxPO id36epl/rwS5X02HpJ0gwKKoXWJ4BgafMZqhKQb/S/2K6Q2LUmfGWqNofi3DQeFUpwOH TB4z157iRaZIgrZz/Rhk7yShjxtyQTikX9doDvu2nwYtV1THCYFM1QNsdEuAVqfdBg3H 8r6UH0V1qybYsR+44nO/PTwfbhZu0HXsRkarC3kc9sym0ObxlCSQJidbjL2s9FF7GJl/ 5v+g== X-Gm-Message-State: ALoCoQlE8ZPJpZHs2cWXTPP5n4WwUV8l/y2HiF3KcpNlsWpi8PWI4YJThrBHK8NEmYXuZK+SaCHC X-Received: by 10.180.24.131 with SMTP id u3mr3530467wif.4.1418050754695; Mon, 08 Dec 2014 06:59:14 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.226 with SMTP id z2ls643814lal.5.gmail; Mon, 08 Dec 2014 06:59:14 -0800 (PST) X-Received: by 10.112.142.197 with SMTP id ry5mr17022026lbb.26.1418050754526; Mon, 08 Dec 2014 06:59:14 -0800 (PST) Received: from mail-lb0-f171.google.com (mail-lb0-f171.google.com. [209.85.217.171]) by mx.google.com with ESMTPS id x8si37194414lbb.86.2014.12.08.06.59.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:59:14 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.171 as permitted sender) client-ip=209.85.217.171; Received: by mail-lb0-f171.google.com with SMTP id n15so3916647lbi.30 for ; Mon, 08 Dec 2014 06:59:14 -0800 (PST) X-Received: by 10.112.14.69 with SMTP id n5mr16791946lbc.34.1418050754409; Mon, 08 Dec 2014 06:59:14 -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 ew9csp617370lbc; Mon, 8 Dec 2014 06:59:13 -0800 (PST) X-Received: by 10.140.22.201 with SMTP id 67mr51255051qgn.16.1418050752640; Mon, 08 Dec 2014 06:59:12 -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 n16si26209394qar.14.2014.12.08.06.59.11 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:59:12 -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 1XxzmI-0006KH-Bv; Mon, 08 Dec 2014 14:59:10 +0000 Received: from mail-la0-f48.google.com ([209.85.215.48]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xxzlz-0006Gz-4u for lng-odp@lists.linaro.org; Mon, 08 Dec 2014 14:58:51 +0000 Received: by mail-la0-f48.google.com with SMTP id gf13so4145848lab.35 for ; Mon, 08 Dec 2014 06:58:45 -0800 (PST) X-Received: by 10.112.52.37 with SMTP id q5mr16501501lbo.32.1418050725611; Mon, 08 Dec 2014 06:58:45 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id xs6sm10869631lbb.13.2014.12.08.06.58.44 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:58:44 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 8 Dec 2014 17:58:29 +0300 Message-Id: <1418050713-29694-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1418050713-29694-1-git-send-email-maxim.uvarov@linaro.org> References: <1418050713-29694-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv7 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.217.171 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 Reviewed-by: Petri Savolainen --- platform/linux-generic/include/api/odp_packet_io.h | 22 ++++++ platform/linux-generic/odp_packet_io.c | 84 ++++++++++++++++++++++ 2 files changed, 106 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..742ea59 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -153,6 +153,28 @@ int odp_pktio_set_mtu(odp_pktio_t id, int mtu); int odp_pktio_mtu(odp_pktio_t id); /** + * Enable/Disable promiscuous mode on a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * @param[in] enable 1 to enable, 0 to disable. + * + * @retval 0 on success. + * @retval non-zero on any 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 any 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..7d2d2a4 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 >= 0) + 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; +}