From patchwork Mon Dec 8 14:58:30 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 42015 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wg0-f71.google.com (mail-wg0-f71.google.com [74.125.82.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 2F2A8244AC for ; Mon, 8 Dec 2014 14:59:22 +0000 (UTC) Received: by mail-wg0-f71.google.com with SMTP id l18sf2843793wgh.2 for ; Mon, 08 Dec 2014 06:59:21 -0800 (PST) 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:in-reply-to :references:subject:precedence:list-id:list-unsubscribe:list-archive :list-post:list-help:list-subscribe:mime-version:content-type :content-transfer-encoding:errors-to:sender:x-original-sender :x-original-authentication-results:mailing-list; bh=Xtx/xW8htNa4D7RpWZqFqdfInHlhBe6v+Q+wa4yniew=; b=e8YeszPr0c6IBPUGXkq89mNTeQCw8F/Wb+IRwHtFkwgscRUE1VKtborPBemxhUKrCr WC+yelJJDP4QYN2Lo/zROj6whysEkpmInl3JoJXKPR8z+TJKEsLwp7m7+3vb2t+mdL2B VF5T6O6YZEVtuyRaUlqKZ1L2Sm3MlzVNMQUi8IcJJfq8FLNo2sdAzre6a8V+Avzh15Ay PXqUq3vIX63N4CXYDReH411mlnyJHY1f2XyOpLvINuobJkvjoCEcRvYBSl4VCF68fEcE B08/HHXjvRC9ZYToKZzhcehcrhOIUpIPPp5pjB67e34Q+uI+GB9pKJ3LmaXxiQPZjbnf DxtQ== X-Gm-Message-State: ALoCoQnDl40YKJ0Dh6gVLoz4ls9B6TWtImPFhnM7/M7jH5zTdPMjd3B19P/TFgXSrRLSbt89P1Xt X-Received: by 10.112.166.102 with SMTP id zf6mr417648lbb.12.1418050761379; Mon, 08 Dec 2014 06:59:21 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.43.1 with SMTP id s1ls646181lal.23.gmail; Mon, 08 Dec 2014 06:59:21 -0800 (PST) X-Received: by 10.112.168.97 with SMTP id zv1mr16993106lbb.6.1418050761232; Mon, 08 Dec 2014 06:59:21 -0800 (PST) Received: from mail-la0-f52.google.com (mail-la0-f52.google.com. [209.85.215.52]) by mx.google.com with ESMTPS id vu2si24702442lbb.38.2014.12.08.06.59.21 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:59:21 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.52 as permitted sender) client-ip=209.85.215.52; Received: by mail-la0-f52.google.com with SMTP id hs14so4018845lab.39 for ; Mon, 08 Dec 2014 06:59:21 -0800 (PST) X-Received: by 10.152.21.66 with SMTP id t2mr16441859lae.27.1418050761136; Mon, 08 Dec 2014 06:59:21 -0800 (PST) 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.184.201 with SMTP id ew9csp617393lbc; Mon, 8 Dec 2014 06:59:20 -0800 (PST) X-Received: by 10.229.235.194 with SMTP id kh2mr53245323qcb.10.1418050759283; Mon, 08 Dec 2014 06:59:19 -0800 (PST) Received: from ip-10-35-177-41.ec2.internal (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTPS id y9si43520737qad.90.2014.12.08.06.59.17 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:59:19 -0800 (PST) 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 1XxzmN-0006Mr-TQ; Mon, 08 Dec 2014 14:59:15 +0000 Received: from mail-la0-f41.google.com ([209.85.215.41]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1Xxzm1-0006H4-6i for lng-odp@lists.linaro.org; Mon, 08 Dec 2014 14:58:53 +0000 Received: by mail-la0-f41.google.com with SMTP id hv19so4039024lab.14 for ; Mon, 08 Dec 2014 06:58:47 -0800 (PST) X-Received: by 10.112.235.135 with SMTP id um7mr16997429lbc.96.1418050727280; Mon, 08 Dec 2014 06:58:47 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id xs6sm10869631lbb.13.2014.12.08.06.58.45 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 08 Dec 2014 06:58:46 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 8 Dec 2014 17:58:30 +0300 Message-Id: <1418050713-29694-5-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1418050713-29694-1-git-send-email-maxim.uvarov@linaro.org> References: <1418050713-29694-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv7 3/6] API: pktio: mac addr get function 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: maxim.uvarov@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.52 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 Define API to get MAC address for specific packet i/o and implement linux-generic version. Signed-off-by: Maxim Uvarov Reviewed-by: Petri Savolainen --- platform/linux-generic/include/api/odp_packet_io.h | 12 +++++++ platform/linux-generic/odp_packet_io.c | 38 ++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index 742ea59..63c047c 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -175,6 +175,18 @@ int odp_pktio_promisc_mode_set(odp_pktio_t id, odp_bool_t enable); int odp_pktio_promisc_mode(odp_pktio_t id); /** + * Get the default MAC address of a packet IO interface. + * + * @param id ODP packet IO handle. + * @param[out] mac_addr Storage for MAC address of the packet IO interface. + * @param addr_size Storage size for the address + * + * @retval Number of bytes written on success, 0 on failure. + */ +size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, + size_t addr_size); + +/** * @} */ diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index 7d2d2a4..e8815cd 100644 --- a/platform/linux-generic/odp_packet_io.c +++ b/platform/linux-generic/odp_packet_io.c @@ -21,6 +21,7 @@ #include #include +#include typedef struct { pktio_entry_t entries[ODP_CONFIG_PKTIO_ENTRIES]; @@ -633,3 +634,40 @@ int odp_pktio_promisc_mode(odp_pktio_t id) else return 0; } + +size_t odp_pktio_mac_addr(odp_pktio_t id, void *mac_addr, + size_t addr_size) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + if (addr_size < ETH_ALEN) + return 0; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return 0; + } + + lock_entry(entry); + + sockfd = sockfd_from_pktio_entry(entry); + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + ret = ioctl(sockfd, SIOCGIFHWADDR, &ifr); + if (ret < 0) { + unlock_entry(entry); + ODP_DBG("ioctl SIOCGIFHWADDR error\n"); + return 0; + } + + memcpy(mac_addr, (unsigned char *)ifr.ifr_ifru.ifru_hwaddr.sa_data, + ETH_ALEN); + unlock_entry(entry); + + return ETH_ALEN; +}