From patchwork Wed Oct 1 13:24:00 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 38234 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f70.google.com (mail-wg0-f70.google.com [74.125.82.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id E2CBE20549 for ; Wed, 1 Oct 2014 13:25:15 +0000 (UTC) Received: by mail-wg0-f70.google.com with SMTP id a1sf605667wgh.5 for ; Wed, 01 Oct 2014 06:25:15 -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:date:message-id:subject :precedence:list-id:list-unsubscribe:list-archive:list-post :list-help:list-subscribe:mime-version:errors-to:sender :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=uXeHqDcHbIWupORYrIWzo/l5sPY+Ctf/tD7bDYUhLU8=; b=mHti6JjJz7EA+ASiNYPeBxi6h6h1trGLsJe58MrUGq7hoNd6zKln/6y6GW1cBPeKT/ rQkQv1qc3e5DQh89x+RG0e0g6aMseDmQebVGshqBEbK5dXvqXZaVEohcVYTvw8xC06vI ZOMI+s1C50gDafTXQbjTxmu+qo9XIohDWhflKwup0LXbQxWarvNNn8twW+5BOgOtT6HU iZoXaJ2rt98BvPdUndllljcjeWgwpX4v7dVol+Dsn+VIvEkwbxsV1bpLXP+T/QaGvTzv LFEm/Vmq2o76bLtswoEwIafY7sSHD//DoizO2rgfa+fpcn1L+Wc5t6bi8PJRYPFLBhlz klhQ== X-Gm-Message-State: ALoCoQng8gF66n69xsjnuZ+qsObIGSqfKXtbcwF6BHLuvOeb01+nPAyxS36lzzRvAwUl1e8G+LxC X-Received: by 10.112.137.230 with SMTP id ql6mr409914lbb.13.1412169915089; Wed, 01 Oct 2014 06:25:15 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.87.132 with SMTP id ay4ls160069lab.46.gmail; Wed, 01 Oct 2014 06:25:14 -0700 (PDT) X-Received: by 10.152.4.194 with SMTP id m2mr56156029lam.63.1412169914823; Wed, 01 Oct 2014 06:25:14 -0700 (PDT) Received: from mail-la0-f49.google.com (mail-la0-f49.google.com [209.85.215.49]) by mx.google.com with ESMTPS id y4si1589688laa.107.2014.10.01.06.25.14 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 01 Oct 2014 06:25:14 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.49 as permitted sender) client-ip=209.85.215.49; Received: by mail-la0-f49.google.com with SMTP id q1so323880lam.22 for ; Wed, 01 Oct 2014 06:25:14 -0700 (PDT) X-Received: by 10.112.75.233 with SMTP id f9mr17821122lbw.102.1412169914691; Wed, 01 Oct 2014 06:25:14 -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.112.130.169 with SMTP id of9csp528395lbb; Wed, 1 Oct 2014 06:25:13 -0700 (PDT) X-Received: by 10.140.97.136 with SMTP id m8mr25178223qge.95.1412169913188; Wed, 01 Oct 2014 06:25:13 -0700 (PDT) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id e9si1542658qae.77.2014.10.01.06.25.12 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 01 Oct 2014 06:25:13 -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-35-177-41.ec2.internal) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XZJu3-00030d-Ev; Wed, 01 Oct 2014 13:25:11 +0000 Received: from mail-yh0-f52.google.com ([209.85.213.52]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XZJtx-0002zZ-6e for lng-odp@lists.linaro.org; Wed, 01 Oct 2014 13:25:05 +0000 Received: by mail-yh0-f52.google.com with SMTP id 29so115403yhl.25 for ; Wed, 01 Oct 2014 06:25:00 -0700 (PDT) X-Received: by 10.236.209.198 with SMTP id s46mr4653670yho.175.1412169899889; Wed, 01 Oct 2014 06:24:59 -0700 (PDT) Received: from bala-PowerEdge-T110-II.caveonetworks.com ([111.93.218.67]) by mx.google.com with ESMTPSA id s92sm396841yhp.46.2014.10.01.06.24.58 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 01 Oct 2014 06:24:59 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Wed, 1 Oct 2014 18:54:00 +0530 Message-Id: <1412169840-28033-1-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [PATCH v4] 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: , 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: bala.manoharan@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.215.49 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 This patch provides API support for querying mac address of an interface using odp_pktio_t handle. This patch incorporates the review comments from the previous patch. Signed-off-by: Balasubramanian Manoharan --- example/ipsec/odp_ipsec.c | 8 ++++++- platform/linux-generic/include/api/odp_packet_io.h | 10 +++++++++ platform/linux-generic/odp_packet_io.c | 25 ++++++++++++++++++++++ platform/linux-generic/odp_packet_socket.c | 14 ++++++++---- 4 files changed, 52 insertions(+), 5 deletions(-) diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index a9bba24..e5da314 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -555,6 +555,7 @@ void initialize_intf(char *intf, int type, int fanout) odp_pktio_params_t params; socket_params_t *sock_params = ¶ms.sock_params; uint8_t src_mac[ODPH_ETHADDR_LEN]; + size_t mac_addr_size; char src_mac_str[MAX_STRING]; /* @@ -594,8 +595,13 @@ void initialize_intf(char *intf, int type, int fanout) /* Read the source MAC address for this interface */ #if USE_MAC_ADDR_HACK ret = query_mac_address(intf, src_mac); + (void)mac_addr_size; #else - ret = odp_pktio_get_mac_addr(pktio, src_mac); + ret = odp_pktio_get_mac_addr(pktio, src_mac, &mac_addr_size); + if (mac_addr_size != ODPH_ETHADDR_LEN) { + ODP_ERR("Error: Ethernet mac address length not supported"); + exit(EXIT_FAILURE); + } #endif if (ret) { ODP_ERR("Error: failed during MAC address get for %s\n", intf); diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index cfefac0..e2372b6 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -129,6 +129,16 @@ 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) + * @param addr_size Size of the Mac address (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, + size_t *addr_size); #ifdef __cplusplus } #endif diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index c06653f..feb157b 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -226,6 +226,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; } @@ -499,3 +500,27 @@ 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 id, unsigned char *mac_addr, + size_t *addr_size) +{ + pktio_entry_t *pktio_entry = get_entry(id); + 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; + default: + ODP_ERR("Invalid pktio type: %02x\n", + pktio_entry->s.params.type); + return ODP_PKTIO_INVALID; + } + *addr_size = ETH_ALEN; + return 0; +} diff --git a/platform/linux-generic/odp_packet_socket.c b/platform/linux-generic/odp_packet_socket.c index 279a0cb..7f5953b 100644 --- a/platform/linux-generic/odp_packet_socket.c +++ b/platform/linux-generic/odp_packet_socket.c @@ -89,6 +89,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. @@ -206,6 +208,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; } @@ -777,7 +783,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; @@ -786,13 +792,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; @@ -847,7 +853,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;