From patchwork Wed Dec 30 13:13:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 59076 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp2839681lbb; Wed, 30 Dec 2015 05:13:42 -0800 (PST) X-Received: by 10.140.40.37 with SMTP id w34mr11452805qgw.85.1451481222890; Wed, 30 Dec 2015 05:13:42 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t23si65461701qki.112.2015.12.30.05.13.42; Wed, 30 Dec 2015 05:13:42 -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 027436179C; Wed, 30 Dec 2015 13:13:41 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=j86TMfV9; 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 CB97961794; Wed, 30 Dec 2015 13:13:37 +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 88A9F61796; Wed, 30 Dec 2015 13:13:35 +0000 (UTC) Received: from mail-lf0-f48.google.com (mail-lf0-f48.google.com [209.85.215.48]) by lists.linaro.org (Postfix) with ESMTPS id 52B096178E for ; Wed, 30 Dec 2015 13:13:34 +0000 (UTC) Received: by mail-lf0-f48.google.com with SMTP id y184so225939476lfc.1 for ; Wed, 30 Dec 2015 05:13:34 -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=j86TMfV9ahDk/2VawsSUKt65U6vS1HgHor5bcg7GgBlqioudbKTZlve8k195e3hLjP glhIm8PjJairPMcKIIQ4h3I+hFHhxPSPDyLrHcbNcIcaDpWITyFXGVSQGVUlTGSmP0WU oKGKreWkTzcSZQc10iIEODyiWw3A0BmvQwqY4= 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=d3sUAFbXp6jE3z8Hn9XpV4Hn0+LaJctl8gElGJ8jAto5PZC1gYrh7EIrkfb5ZIsITL QUi61TCJziGyWIQQbEPonhZN8lvUfcNvSw1eZpUGTza4iPv2fIRseH7eVDpBPsk98r3M SkyblYF6TfDyOOBJ4mK+g8o1kMIEVz4sYKMLDvgr9uguNqw85v4SoRswXchSprNHwgXY K0i2QshTyiQXhVa4BIfBSn61XKNwilxDtThku/6rUmG0SyNN+EyX0rsw0Ii6Tc7yCilp 2GHs0bL4ImY454hltZUCezczdQH6h4/OR1s/tism8zcPSaIOH4tINpq4T/vW1e1dR6f5 dTYA== X-Gm-Message-State: ALoCoQm7Rm5tCEdJvdga6RFJwUfGZc6CWPfJw2d0RHApi6OYUs4rjWeUL+zIB/kK443nhNGJiU3JT0k0AbIHfXNNZQ33ZyX8og== X-Received: by 10.25.18.231 with SMTP id 100mr22964535lfs.25.1451481213161; Wed, 30 Dec 2015 05:13:33 -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 b74sm6568598lfb.32.2015.12.30.05.13.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 30 Dec 2015 05:13:32 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 30 Dec 2015 16:13:24 +0300 Message-Id: <1451481205-20606-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451481205-20606-1-git-send-email-maxim.uvarov@linaro.org> References: <1451481205-20606-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv4 1/2] 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,