From patchwork Thu Aug 21 02:46:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robbie King X-Patchwork-Id: 35720 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pd0-f200.google.com (mail-pd0-f200.google.com [209.85.192.200]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3750D20351 for ; Thu, 21 Aug 2014 02:47:10 +0000 (UTC) Received: by mail-pd0-f200.google.com with SMTP id w10sf69722943pde.7 for ; Wed, 20 Aug 2014 19:47:09 -0700 (PDT) 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:thread-topic:thread-index :date:message-id:references:in-reply-to:accept-language:mime-version :subject:precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list:content-language :content-type:content-transfer-encoding; bh=FFYJhqcltT9zEqhd8B/aocLBXAC+xj/vFbPWcjz9ELA=; b=jMT7d5BuLtO1cl1G8n9MExL7y5kS4N6cJlxtbW9ShJvj5MnVBeWJbgnx2q2K70peYb XgmPOd8LKB1JsLDya2k/iD/8T9F3iPoxVg0oddp362jpvKfxXIFhSHVJOQwLe1frB1Da PvdjngyM7KCDK1KTyLQIWhghOiSZxWloRsHWg/YgUKPO8hiwcLR58svAXP3SZJiMehas VGJHWg7Ta1nwA6wzE+e88bq2iTcjpvSIHdr99NBYcOcVuZ8lQ/t64yMDsJsRfF9l4wKR Mkzd/EoMWBXx79pQEue/uS0yOqU0ilk3iim04QZkWrjwkQArQc2EYV0TtxQatmXNwnyh hIUA== X-Gm-Message-State: ALoCoQkn0mLuFCK5iqekTgkynhlEg3V38O1OXlxvZIAOcnpWECGAjtiaV0EPRoS41GKMj9NAKCGW X-Received: by 10.68.190.130 with SMTP id gq2mr23611692pbc.3.1408589229247; Wed, 20 Aug 2014 19:47:09 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.38 with SMTP id i35ls563977qgf.76.gmail; Wed, 20 Aug 2014 19:47:09 -0700 (PDT) X-Received: by 10.52.0.132 with SMTP id 4mr4177375vde.10.1408589228830; Wed, 20 Aug 2014 19:47:08 -0700 (PDT) Received: from mail-vc0-x22e.google.com (mail-vc0-x22e.google.com [2607:f8b0:400c:c03::22e]) by mx.google.com with ESMTPS id t9si11890313vco.90.2014.08.20.19.47.08 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 20 Aug 2014 19:47:08 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22e as permitted sender) client-ip=2607:f8b0:400c:c03::22e; Received: by mail-vc0-f174.google.com with SMTP id la4so10112085vcb.19 for ; Wed, 20 Aug 2014 19:47:08 -0700 (PDT) X-Received: by 10.52.135.133 with SMTP id ps5mr21045300vdb.33.1408589228718; Wed, 20 Aug 2014 19:47:08 -0700 (PDT) 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.221.45.67 with SMTP id uj3csp99013vcb; Wed, 20 Aug 2014 19:47:08 -0700 (PDT) X-Received: by 10.229.206.68 with SMTP id ft4mr22554941qcb.28.1408589227791; Wed, 20 Aug 2014 19:47:07 -0700 (PDT) Received: from ip-10-141-164-156.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id u9si37022096qag.56.2014.08.20.19.47.06 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 20 Aug 2014 19:47:07 -0700 (PDT) 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-141-164-156.ec2.internal) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKIP3-0003c0-SC; Thu, 21 Aug 2014 02:47:05 +0000 Received: from alln-iport-2.cisco.com ([173.37.142.89]) by ip-10-141-164-156.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XKIOx-0003bu-Pl for lng-odp@lists.linaro.org; Thu, 21 Aug 2014 02:46:59 +0000 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AiAFAMFc9VOtJV2Z/2dsb2JhbABagmojU1cEgnjJSQqHWQEZdBZ3hAMBAQEEAQEBIAQNOhcEAgEIDgMEAQEDAgYdAwICAiUBChQBCAgCBAESCIg6AQysV5UtF4EsjVcYFiIGgnM2gR0FjxKCE4Qmg3eEWZMzg11sgQdBgQcBAQE X-IronPort-AV: E=Sophos;i="5.01,906,1400025600"; d="scan'208";a="71057365" Received: from rcdn-core-2.cisco.com ([173.37.93.153]) by alln-iport-2.cisco.com with ESMTP; 21 Aug 2014 02:46:54 +0000 Received: from xhc-aln-x04.cisco.com (xhc-aln-x04.cisco.com [173.36.12.78]) by rcdn-core-2.cisco.com (8.14.5/8.14.5) with ESMTP id s7L2ksDn018638 (version=TLSv1/SSLv3 cipher=AES128-SHA bits=128 verify=FAIL); Thu, 21 Aug 2014 02:46:54 GMT Received: from xmb-aln-x01.cisco.com ([fe80::747b:83e1:9755:d453]) by xhc-aln-x04.cisco.com ([173.36.12.78]) with mapi id 14.03.0195.001; Wed, 20 Aug 2014 21:46:53 -0500 From: "Robbie King (robking)" To: Balasubramanian Manoharan , "lng-odp@lists.linaro.org" Thread-Topic: [lng-odp] [PATCH v4 1/1] API support for querying mac address Thread-Index: AQHPvIBzwG9m8DFbkkCX6Ud4e7VthZvaWxcw Date: Thu, 21 Aug 2014 02:46:53 +0000 Message-ID: References: <1408543705-1982-1-git-send-email-bala.manoharan@linaro.org> In-Reply-To: <1408543705-1982-1-git-send-email-bala.manoharan@linaro.org> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.82.227.187] MIME-Version: 1.0 X-Topics: patch Subject: Re: [lng-odp] [PATCH v4 1/1] API support for querying mac address 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: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: lng-odp-bounces@lists.linaro.org X-Original-Sender: robking@cisco.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 2607:f8b0:400c:c03::22e as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org; dkim=neutral (body hash did not verify) header.i=@ Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Content-Language: en-US Hi Bala, I patched this in and was able to query mac address using odp_pktio_t handle. Thanks! -----Original Message----- From: lng-odp-bounces@lists.linaro.org [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of Balasubramanian Manoharan Sent: Wednesday, August 20, 2014 10:08 AM To: lng-odp@lists.linaro.org Subject: [lng-odp] [PATCH v4 1/1] API support for querying mac address This patch provides API support for querying mac address of an interface using odp_pktio_t handle. This current patch incorporates the review comments from the previous patch. The discussions are ongoing regarding adding additional API for querying mac address using device name, once it gets finalized the same will be provided as a different patch. Signed-off-by: Balasubramanian Manoharan --- include/odp_packet_io.h | 8 +++++++ platform/linux-generic/include/odp_packet_netmap.h | 1 + platform/linux-generic/odp_packet_io.c | 28 ++++++++++++++++++++++ platform/linux-generic/odp_packet_netmap.c | 2 ++ platform/linux-generic/odp_packet_socket.c | 14 +++++++---- 5 files changed, 49 insertions(+), 4 deletions(-) diff --git a/include/odp_packet_io.h b/include/odp_packet_io.h index cfefac0..86778bf 100644 --- a/include/odp_packet_io.h +++ b/include/odp_packet_io.h @@ -129,6 +129,14 @@ void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id); */ odp_pktio_t odp_pktio_get_input(odp_packet_t pkt); +/** + * Get mac address of the interface + * + * @param id ODP packet IO handle + * @param mac_addr Storage for Mac address of the packet IO interface (filled by function) + * @return 0 on success or -1 on error +**/ +int odp_pktio_get_mac_addr(odp_pktio_t id, unsigned char *mac_addr); #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/include/odp_packet_netmap.h b/platform/linux-generic/include/odp_packet_netmap.h index 57d9f2c..69174fe 100644 --- a/platform/linux-generic/include/odp_packet_netmap.h +++ b/platform/linux-generic/include/odp_packet_netmap.h @@ -40,6 +40,7 @@ typedef struct { odp_queue_t tx_access; /* Used for exclusive access to send packets */ uint32_t if_flags; char ifname[32]; + unsigned char if_mac[ETH_ALEN]; } pkt_netmap_t; /** diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 33ade10..b29cca1 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -246,6 +246,7 @@ odp_pktio_t odp_pktio_open(const char *dev, odp_buffer_pool_t pool, break; } + pktio_entry->s.params.type = params->type; unlock_entry(pktio_entry); return id; } @@ -535,3 +536,30 @@ int pktin_deq_multi(queue_entry_t *qentry, odp_buffer_hdr_t *buf_hdr[], int num) return nbr; } +int odp_pktio_get_mac_addr(odp_pktio_t pkt, unsigned char *mac_addr) +{ + pktio_entry_t *pktio_entry = get_entry(pkt); + if (!pktio_entry) { + ODP_ERR("Invalid odp_pktio_t value\n"); + return -1; + } + switch (pktio_entry->s.params.type) { + case ODP_PKTIO_TYPE_SOCKET_BASIC: + case ODP_PKTIO_TYPE_SOCKET_MMSG: + memcpy(mac_addr, pktio_entry->s.pkt_sock.if_mac, ETH_ALEN); + break; + case ODP_PKTIO_TYPE_SOCKET_MMAP: + memcpy(mac_addr, pktio_entry->s.pkt_sock_mmap.if_mac, ETH_ALEN); + break; +#ifdef ODP_HAVE_NETMAP + case ODP_PKTIO_TYPE_NETMAP: + memcpy(mac_addr, pktio_entry->s.pkt_nm.if_mac, ETH_ALEN); + break; +#endif + default: + ODP_ERR("Invalid pktio type: %02x\n", + pktio_entry->s.params.type); + return ODP_PKTIO_INVALID; + } + return 0; +} diff --git a/platform/linux-generic/odp_packet_netmap.c b/platform/linux-generic/odp_packet_netmap.c index e2215ab..9f58a6a 100644 --- a/platform/linux-generic/odp_packet_netmap.c +++ b/platform/linux-generic/odp_packet_netmap.c @@ -222,6 +222,8 @@ int setup_pkt_netmap(pkt_netmap_t * const pkt_nm, const char *netdev, ODP_ERR("Error: token creation failed\n"); return -1; } + if (socket_store_hw_addr(pkt_nm->if_mac, netdev) + return -1; odp_queue_enq(pkt_nm->tx_access, token); diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index d44c333..39aa4db 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -57,6 +57,8 @@ typedef struct { static raw_socket_t raw_sockets[MAX_RAW_SOCKETS_NETDEVS]; static odp_spinlock_t raw_sockets_lock; +static int socket_store_hw_addr(int sockfd, unsigned char *if_mac, + const char *netdev); /** Eth buffer start offset from u32-aligned address to make sure the following * header (e.g. IP) starts at a 32-bit aligned address. @@ -174,6 +176,10 @@ int setup_pkt_sock(pkt_sock_t * const pkt_sock, const char *netdev, sockfd = find_raw_fd(netdev); if (sockfd) { pkt_sock->sockfd = sockfd; + if (socket_store_hw_addr(sockfd, pkt_sock->if_mac, netdev)) { + perror("setup_pkt_sock() - socket_store_hw_addr()"); + goto error; + } odp_spinlock_unlock(&raw_sockets_lock); return sockfd; } @@ -735,7 +741,7 @@ static int mmap_bind_sock(pkt_sock_mmap_t *pkt_sock, const char *netdev) return 0; } -static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, +static int socket_store_hw_addr(int sockfd, unsigned char *if_mac, const char *netdev) { struct ifreq ethreq; @@ -744,13 +750,13 @@ static int mmap_store_hw_addr(pkt_sock_mmap_t * const pkt_sock, /* get MAC address */ memset(ðreq, 0, sizeof(ethreq)); strncpy(ethreq.ifr_name, netdev, IFNAMSIZ); - ret = ioctl(pkt_sock->sockfd, SIOCGIFHWADDR, ðreq); + ret = ioctl(sockfd, SIOCGIFHWADDR, ðreq); if (ret != 0) { perror("store_hw_addr() - ioctl(SIOCGIFHWADDR)"); return -1; } - ethaddr_copy(pkt_sock->if_mac, + ethaddr_copy(if_mac, (unsigned char *)ethreq.ifr_ifru.ifru_hwaddr.sa_data); return 0; @@ -805,7 +811,7 @@ int setup_pkt_sock_mmap(pkt_sock_mmap_t * const pkt_sock, const char *netdev, if (ret != 0) return -1; - ret = mmap_store_hw_addr(pkt_sock, netdev); + ret = socket_store_hw_addr(pkt_sock->sockfd, pkt_sock->if_mac, netdev); if (ret != 0) return -1;