From patchwork Fri Dec 25 13:48:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 58999 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp323493lbb; Fri, 25 Dec 2015 05:49:27 -0800 (PST) X-Received: by 10.140.179.68 with SMTP id z65mr58720610qhz.70.1451051367223; Fri, 25 Dec 2015 05:49:27 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id f30si16577656qga.65.2015.12.25.05.49.26; Fri, 25 Dec 2015 05:49:27 -0800 (PST) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dkim=neutral (body hash did not verify) header.i=@linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 85FDA6164B; Fri, 25 Dec 2015 13:49:26 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=NZqlBKi6; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, T_DKIM_INVALID, URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 4BA3A61665; Fri, 25 Dec 2015 13:48:56 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 1A5876165F; Fri, 25 Dec 2015 13:48:51 +0000 (UTC) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by lists.linaro.org (Postfix) with ESMTPS id C27CC6165B for ; Fri, 25 Dec 2015 13:48:49 +0000 (UTC) Received: by mail-lb0-f181.google.com with SMTP id bc4so69728567lbc.2 for ; Fri, 25 Dec 2015 05:48:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=bu4roSiZxTtA0yNqZH8Dlv76ARkJK4/9AlE3jL8F9T8=; b=NZqlBKi61YEGXhSltHXjBWQTczgrGqfS9BMe/mLRUBk/QYb+c4u9JXmcDxjnmiyxFE r1RJ+aTiuImRVD7ta6TOSB4CLj5LM/9B0iPY1wlWubOv92iKjg2BbUiqXl0G5Lmu2n1+ w0Rc0awO6v41qCUCk5kRJscZpsY7G0QPs7IgU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bu4roSiZxTtA0yNqZH8Dlv76ARkJK4/9AlE3jL8F9T8=; b=mQUHTF4WNpBUvJRobl+v3781UnOMJEI3yVrFGuoaPAPRFcKtzyNEQwt5Ar/mX6NHZw ErVnYmu37xUnspfs0NkY3YK9obDKV0vpIS3lgJDo43/+Gf6th0CQoS4t2ZL/i8gLl7WV bs3BQipeRqw3ZnSulpfanSc9H57xscDSgyYT5bTS9I93M2qbHH7rUEWhkd5hSjt3dAin ZFbtQM+3AE5kJWhVaL3otFvejpj8U0V0dBFdBcZPe/vuJYHWkernnr4yzxOMD1DnNzEJ lYextyAMapMvWAgR08amebkf+Z/b1LMixp0+x9DwkP6WcFdeobXHydocA6019yQL0WWb oIMg== X-Gm-Message-State: ALoCoQmFsIOtPKMN1zPSnqNGN7x5AbMXM5VM7y4m2bTevjscuOZsHMHqKdpleh+TxY2NJVtsGeiBD4Y6Q7IArKQSJOrRZj5tqA== X-Received: by 10.112.131.105 with SMTP id ol9mr14579428lbb.45.1451051328647; Fri, 25 Dec 2015 05:48:48 -0800 (PST) Received: from localhost.localdomain (ppp91-76-173-134.pppoe.mtu-net.ru. [91.76.173.134]) by smtp.gmail.com with ESMTPSA id r2sm8128881lfe.28.2015.12.25.05.48.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 25 Dec 2015 05:48:47 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Fri, 25 Dec 2015 16:48:37 +0300 Message-Id: <1451051319-22073-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451051319-22073-1-git-send-email-maxim.uvarov@linaro.org> References: <1451051319-22073-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCH 1/3] linux-generic: pktio: implement odp_pktio_link_status() X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" 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" Signed-off-by: Maxim Uvarov --- .../linux-generic/include/odp_packet_io_internal.h | 1 + platform/linux-generic/include/odp_packet_socket.h | 5 +++++ platform/linux-generic/odp_packet_io.c | 26 ++++++++++++++++++++++ platform/linux-generic/pktio/socket.c | 24 ++++++++++++++++++++ platform/linux-generic/pktio/socket_mmap.c | 7 ++++++ 5 files changed, 63 insertions(+) diff --git a/platform/linux-generic/include/odp_packet_io_internal.h b/platform/linux-generic/include/odp_packet_io_internal.h index e15c6af..4fd3c87 100644 --- a/platform/linux-generic/include/odp_packet_io_internal.h +++ b/platform/linux-generic/include/odp_packet_io_internal.h @@ -137,6 +137,7 @@ typedef struct pktio_if_ops { int (*promisc_mode_set)(pktio_entry_t *pktio_entry, int enable); int (*promisc_mode_get)(pktio_entry_t *pktio_entry); int (*mac_get)(pktio_entry_t *pktio_entry, void *mac_addr); + int (*link_status)(pktio_entry_t *pktio_entry); int (*capability)(pktio_entry_t *pktio_entry, odp_pktio_capability_t *capa); int (*input_queues_config)(pktio_entry_t *pktio_entry, diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index 66c258f..ec202db 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -118,6 +118,11 @@ int promisc_mode_set_fd(int fd, const char *name, int enable); int promisc_mode_get_fd(int fd, const char *name); /** + * Return link status of a packet socket (up/down) + */ +int link_status_fd(int fd, const char *name); + +/** * Get enabled RSS hash protocols of a packet socket * * @param fd Socket file descriptor diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index a235798..95b8904 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -821,6 +821,32 @@ int odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, int addr_size) return ret; } +int odp_pktio_link_status(odp_pktio_t id) +{ + pktio_entry_t *entry; + int ret = -1; + + entry = get_pktio_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + lock_entry(entry); + + if (odp_unlikely(is_free(entry))) { + unlock_entry(entry); + ODP_DBG("already freed pktio\n"); + return -1; + } + + if (entry->s.ops->link_status) + ret = entry->s.ops->link_status(entry); + unlock_entry(entry); + + return ret; +} + void odp_pktio_param_init(odp_pktio_param_t *params) { memset(params, 0, sizeof(odp_pktio_param_t)); diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index ae5a2d6..343f89e 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -195,6 +195,23 @@ int promisc_mode_get_fd(int fd, const char *name) return !!(ifr.ifr_flags & IFF_PROMISC); } +int link_status_fd(int fd, const char *name) +{ + struct ifreq ifr; + int ret; + + snprintf(ifr.ifr_name, IF_NAMESIZE, "%s", name); + ret = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (ret < 0) { + __odp_errno = errno; + ODP_DBG("ioctl(SIOCGIFFLAGS): %s: \"%s\".\n", strerror(errno), + ifr.ifr_name); + return -1; + } + + return !!(ifr.ifr_flags & IFF_RUNNING); +} + /** * Get enabled hash options of a packet socket * @@ -767,6 +784,12 @@ static int sock_promisc_mode_get(pktio_entry_t *pktio_entry) pktio_entry->s.name); } +static int sock_link_status(pktio_entry_t *pktio_entry) +{ + return link_status_fd(pktio_entry->s.pkt_sock.sockfd, + pktio_entry->s.name); +} + const pktio_if_ops_t sock_mmsg_pktio_ops = { .name = "socket", .init = NULL, @@ -781,6 +804,7 @@ const pktio_if_ops_t sock_mmsg_pktio_ops = { .promisc_mode_set = sock_promisc_mode_set, .promisc_mode_get = sock_promisc_mode_get, .mac_get = sock_mac_addr_get, + .link_status = sock_link_status, .capability = NULL, .input_queues_config = NULL, .output_queues_config = NULL, diff --git a/platform/linux-generic/pktio/socket_mmap.c b/platform/linux-generic/pktio/socket_mmap.c index 628848a..b8f2665 100644 --- a/platform/linux-generic/pktio/socket_mmap.c +++ b/platform/linux-generic/pktio/socket_mmap.c @@ -554,6 +554,12 @@ static int sock_mmap_promisc_mode_get(pktio_entry_t *pktio_entry) pktio_entry->s.name); } +static int sock_mmap_link_status(pktio_entry_t *pktio_entry) +{ + return link_status_fd(pktio_entry->s.pkt_sock_mmap.sockfd, + pktio_entry->s.name); +} + const pktio_if_ops_t sock_mmap_pktio_ops = { .name = "socket_mmap", .init = NULL, @@ -568,6 +574,7 @@ const pktio_if_ops_t sock_mmap_pktio_ops = { .promisc_mode_set = sock_mmap_promisc_mode_set, .promisc_mode_get = sock_mmap_promisc_mode_get, .mac_get = sock_mmap_mac_addr_get, + .link_status = sock_mmap_link_status, .capability = NULL, .input_queues_config = NULL, .output_queues_config = NULL,