From patchwork Wed Dec 3 15:05:54 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41852 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-wi0-f198.google.com (mail-wi0-f198.google.com [209.85.212.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7EA3C25E66 for ; Wed, 3 Dec 2014 15:06:41 +0000 (UTC) Received: by mail-wi0-f198.google.com with SMTP id r20sf9841244wiv.9 for ; Wed, 03 Dec 2014 07:06:40 -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=Wz/te2zingy7SYlwZcLobmjlrW/oUJYjdEGr34Lyz5I=; b=T+6uu3BU3vlrxDL0nrwkYWZx9VaqYI8RyGbaw1qHwFlYAC63xQH/0aXNRG6rV1pomf b7uQwyW6Fr1BGJZhE+9ivSFZBSIXtiVCm5D04sWCUi9NMGaFsZc06/zbRTTKOwgxZtAx 6RLzY51PuRufGQP2mMPqj/oa7MrkSTpMEP0OvfDG7KktwVVPK6eXpJiZsllKTsAtI+T3 K/f/Psl6Y+JWL7Y87HOk8rsGCMaa2L8d3tKVOjZ5e09TrUZOHIMnR707C2nF+Xfn1gNb mOKo9bU5vePULw/8ovYb+xQXKne1Ws5FyD80qWB6UBW7oP7/1WoaSOPg8CcyLSc6IeO1 E0TQ== X-Gm-Message-State: ALoCoQlyuLfsvTMpxoA3H9+ZO2Cvp9zNmjhYqodNC/RwuDgEXSAuNejv5tIlgQrTt8+/jn5u/pcl X-Received: by 10.112.142.36 with SMTP id rt4mr1173985lbb.3.1417619200818; Wed, 03 Dec 2014 07:06:40 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.36.169 with SMTP id r9ls134964laj.57.gmail; Wed, 03 Dec 2014 07:06:40 -0800 (PST) X-Received: by 10.112.16.39 with SMTP id c7mr4627059lbd.19.1417619200666; Wed, 03 Dec 2014 07:06:40 -0800 (PST) Received: from mail-la0-f44.google.com (mail-la0-f44.google.com. [209.85.215.44]) by mx.google.com with ESMTPS id pm1si9411454lbb.52.2014.12.03.07.06.40 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:06:40 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.44 as permitted sender) client-ip=209.85.215.44; Received: by mail-la0-f44.google.com with SMTP id ge10so12769503lab.3 for ; Wed, 03 Dec 2014 07:06:40 -0800 (PST) X-Received: by 10.112.173.202 with SMTP id bm10mr4595990lbc.74.1417619200594; Wed, 03 Dec 2014 07:06:40 -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 ew9csp680287lbc; Wed, 3 Dec 2014 07:06:39 -0800 (PST) X-Received: by 10.170.54.76 with SMTP id 73mr7690608ykw.0.1417619198903; Wed, 03 Dec 2014 07:06:38 -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 t9si5668641yke.138.2014.12.03.07.06.38 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:06:38 -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 1XwBVk-0005JB-Tf; Wed, 03 Dec 2014 15:06:36 +0000 Received: from mail-lb0-f170.google.com ([209.85.217.170]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XwBVS-0005Hd-FX for lng-odp@lists.linaro.org; Wed, 03 Dec 2014 15:06:18 +0000 Received: by mail-lb0-f170.google.com with SMTP id w7so12484036lbi.29 for ; Wed, 03 Dec 2014 07:06:12 -0800 (PST) X-Received: by 10.152.1.193 with SMTP id 1mr4698892lao.45.1417619172891; Wed, 03 Dec 2014 07:06:12 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id r4sm6449679lar.3.2014.12.03.07.06.11 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Dec 2014 07:06:12 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Wed, 3 Dec 2014 18:05:54 +0300 Message-Id: <1417619157-13690-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417619157-13690-1-git-send-email-maxim.uvarov@linaro.org> References: <1417619157-13690-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 3/6] API: pktio: mac addr functions 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.44 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 for mac address change and implement linux-generic version. Signed-off-by: Maxim Uvarov --- 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 df2b138..152d23b 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -177,6 +177,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[in] id ODP packet IO handle. + * @param[out] mac_addr Storage for MAC address of the packet IO interface. + * @param[in] 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, unsigned char *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 8286728..595ba56 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]; @@ -623,3 +624,40 @@ int odp_pktio_promisc_mode(odp_pktio_t id) else return 0; } + +size_t odp_pktio_mac_addr(odp_pktio_t id, unsigned char *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; + } + + if (entry->s.pkt_sock_mmap.sockfd > -1) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ - 1); + ifr.ifr_name[IFNAMSIZ - 1] = 0; + + ret = ioctl(sockfd, SIOCGIFHWADDR, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFHWADDR error\n"); + return 0; + } + + memcpy(mac_addr, (unsigned char *)ifr.ifr_ifru.ifru_hwaddr.sa_data, + ETH_ALEN); + + return ETH_ALEN; +}