From patchwork Mon Oct 6 10:22:59 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balasubramanian Manoharan X-Patchwork-Id: 38363 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f199.google.com (mail-wi0-f199.google.com [209.85.212.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 57E0D202E7 for ; Mon, 6 Oct 2014 10:24:25 +0000 (UTC) Received: by mail-wi0-f199.google.com with SMTP id d1sf1383769wiv.10 for ; Mon, 06 Oct 2014 03:24:24 -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=ihevRqZGtEZuL4xcKtT6HN1A6aD5laZ6BvN3PTF9oMM=; b=NhMPXLAmQzwIvtWt3onXpeOeFsZTjTSPcu8d2fsrA+hcTHFBP76iXG+f4YAbbw9viU UPPRTm8SNU24B/guORAmUcC8/l98EoHMGRpmOIbK2KMT4cSdKp1+YZZADsopQBQMwW8o i+VQo1ZVK7/Ygok80C9LeQrVOBWBk+pveuediDLLXNtAJt4OD5dxyj2ntxpD8y/bdUw7 54mCmgEVHP1bEZK+zVcLlywXDLazi1YlktLtMMvYiNLy6z40/vN2HBwB5APKRttvZ8YZ 3KRcYs+H655D0g0PhqZVzYZt6c3GiR5GBuiVdNMT8WYSiaiAd2qcjEaO3VItC62NkIgv ZpVQ== X-Gm-Message-State: ALoCoQnRpDnQnd6dUqf+Umy9vZyySerz2lAXZ/IJkIRhu2jC+qXzCFo92Fh/Mq7bevFitvkcSQG9 X-Received: by 10.180.89.243 with SMTP id br19mr2383340wib.7.1412591064492; Mon, 06 Oct 2014 03:24:24 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.26.72 with SMTP id j8ls71463lag.105.gmail; Mon, 06 Oct 2014 03:24:24 -0700 (PDT) X-Received: by 10.112.9.234 with SMTP id d10mr1834715lbb.98.1412591064265; Mon, 06 Oct 2014 03:24:24 -0700 (PDT) Received: from mail-la0-f47.google.com (mail-la0-f47.google.com [209.85.215.47]) by mx.google.com with ESMTPS id o1si1099085lal.39.2014.10.06.03.24.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Oct 2014 03:24:24 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.47 as permitted sender) client-ip=209.85.215.47; Received: by mail-la0-f47.google.com with SMTP id pv20so4108483lab.34 for ; Mon, 06 Oct 2014 03:24:24 -0700 (PDT) X-Received: by 10.152.22.137 with SMTP id d9mr24033027laf.29.1412591064171; Mon, 06 Oct 2014 03:24:24 -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 of9csp157277lbb; Mon, 6 Oct 2014 03:24:23 -0700 (PDT) X-Received: by 10.224.103.66 with SMTP id j2mr29072956qao.13.1412591062901; Mon, 06 Oct 2014 03:24:22 -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 y104si5582765qgd.126.2014.10.06.03.24.22 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 06 Oct 2014 03:24:22 -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 1Xb5Sn-0004xk-H7; Mon, 06 Oct 2014 10:24:21 +0000 Received: from mail-yh0-f42.google.com ([209.85.213.42]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xb5Sg-0004wY-SV for lng-odp@lists.linaro.org; Mon, 06 Oct 2014 10:24:14 +0000 Received: by mail-yh0-f42.google.com with SMTP id t59so1901238yho.29 for ; Mon, 06 Oct 2014 03:24:09 -0700 (PDT) X-Received: by 10.236.133.112 with SMTP id p76mr52505yhi.151.1412591049609; Mon, 06 Oct 2014 03:24:09 -0700 (PDT) Received: from bala-PowerEdge-T110-II.caveonetworks.com ([111.93.218.67]) by mx.google.com with ESMTPSA id b59sm6874418yha.33.2014.10.06.03.24.07 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 06 Oct 2014 03:24:09 -0700 (PDT) From: Balasubramanian Manoharan To: lng-odp@lists.linaro.org Date: Mon, 6 Oct 2014 15:52:59 +0530 Message-Id: <1412590979-32584-1-git-send-email-bala.manoharan@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Topics: patch Subject: [lng-odp] [ODP/PATCH v5] 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.47 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 using odp_pktio_t handle. This patch incorporates the changes after the removal of netmap from linux generic repo. Signed-off-by: Balasubramanian Manoharan --- example/ipsec/odp_ipsec.c | 9 ++++++-- platform/linux-generic/include/api/odp_packet_io.h | 17 +++++++++++++++ platform/linux-generic/odp_packet_io.c | 24 ++++++++++++++++++++++ platform/linux-generic/odp_packet_socket.c | 14 +++++++++---- 4 files changed, 58 insertions(+), 6 deletions(-) diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c index ec6c87a..9a46a0c 100644 --- a/example/ipsec/odp_ipsec.c +++ b/example/ipsec/odp_ipsec.c @@ -549,7 +549,8 @@ void initialize_intf(char *intf) char inq_name[ODP_QUEUE_NAME_LEN]; odp_queue_param_t qparam; int ret; - uint8_t src_mac[ODPH_ETHADDR_LEN]; + uint8_t src_mac[ODP_MAC_ADDR_MAX_LENGTH]; + size_t mac_addr_size; char src_mac_str[MAX_STRING]; /* @@ -587,8 +588,12 @@ void initialize_intf(char *intf) /* 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_ABORT("Ethernet mac address length not supported"); + } #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 29fd105..2086316 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -125,6 +125,23 @@ void odp_pktio_set_input(odp_packet_t pkt, odp_pktio_t id); */ odp_pktio_t odp_pktio_get_input(odp_packet_t pkt); +/** + * Defines the maximum length of mac address supported by this platform + */ +#define ODP_MAC_ADDR_MAX_LENGTH ETH_ALEN + +/** + * Get mac address of the interface + * + * @param id ODP packet IO handle + * @param mac_addr Storage for Mac address of the packet IO interface + * Storage provided by the caller should be equal + * to ODP_MAC_ADDR_MAX_LENGTH (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 0c30f0f..c982ec8 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -476,3 +476,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.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.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 006d7bd..840987b 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; } @@ -778,7 +784,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; @@ -787,13 +793,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-1); - 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; @@ -848,7 +854,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;