From patchwork Mon Dec 28 16:40:10 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 59024 Delivered-To: patch@linaro.org Received: by 10.112.130.2 with SMTP id oa2csp1806446lbb; Mon, 28 Dec 2015 08:41:02 -0800 (PST) X-Received: by 10.55.80.194 with SMTP id e185mr70547312qkb.68.1451320861308; Mon, 28 Dec 2015 08:41:01 -0800 (PST) Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id b76si14437938qkb.51.2015.12.28.08.41.00; Mon, 28 Dec 2015 08:41:01 -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 E8D3761706; Mon, 28 Dec 2015 16:40:59 +0000 (UTC) Authentication-Results: lists.linaro.org; dkim=fail reason="verification failed; unprotected key" header.d=linaro.org header.i=@linaro.org header.b=V2ew0VcT; 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 F3CC9616F0; Mon, 28 Dec 2015 16:40:29 +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 F22FB616F0; Mon, 28 Dec 2015 16:40:21 +0000 (UTC) Received: from mail-lb0-f177.google.com (mail-lb0-f177.google.com [209.85.217.177]) by lists.linaro.org (Postfix) with ESMTPS id 684EF616EC for ; Mon, 28 Dec 2015 16:40:20 +0000 (UTC) Received: by mail-lb0-f177.google.com with SMTP id bc4so93353691lbc.2 for ; Mon, 28 Dec 2015 08:40:20 -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=V2ew0VcTXrMK8V56S38LMx7k7Doh9HCsLcEevNRpI95hwzlVbt83uGyH/QB2wuaNnH 1jozkFCzoC6tu2CodVCpa6cxW/4qaLu5C/QJI+ACyb9TOQJWSdNVEcR0S9EvNbomxKh7 CGlzrXx9gCEP/9tl5VQHcnuQS0iY2x/PoMvLc= 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=YHAcFqPHTiXuToo+YaKCu1RLOya/Urwi4gg728+B04j6RXaT55pIom6/6S2w1BBoTW DuUrhehQYThFH81gZunQokH7HHVHfIY1OVzgrVnDDQJRcR4d1IGwxOTPl/c7vkDzV7gS C3FftLw7ETnQDepz+68mXJ9E6Of9ymxj706vm0rj/sfwAnDyroVwvn1gI4WPw+0wIeBI qXNbQHESXI/PgbTvgLDLQHnXIMy2snG7Douk3STwsusAG478u3cU+X7vurdw9IlVD34X bndYguL0vhwJxb/C+B+pHrvgFXW7p3XKLXsEVq7Zo6so7SQdY6x6EhjEblAayrBwMqji MisQ== X-Gm-Message-State: ALoCoQklR26ixrwdkTQCdD0imncwquQ/hsRkxCMTHcTyeNKvzqX2ApYu5+SFj7IW8noFxzj+W3V59I7GoQLUT3ZcET89GP2uLw== X-Received: by 10.112.132.66 with SMTP id os2mr6945062lbb.111.1451320819241; Mon, 28 Dec 2015 08:40:19 -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 kz5sm9252745lbc.7.2015.12.28.08.40.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 28 Dec 2015 08:40:18 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 28 Dec 2015 19:40:10 +0300 Message-Id: <1451320813-9428-2-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1451320813-9428-1-git-send-email-maxim.uvarov@linaro.org> References: <1451320813-9428-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [API-NEXT PATCHv2 1/4] 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,