From patchwork Mon Dec 1 16:15:29 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41789 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-lb0-f198.google.com (mail-lb0-f198.google.com [209.85.217.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id DC4C720672 for ; Mon, 1 Dec 2014 16:16:19 +0000 (UTC) Received: by mail-lb0-f198.google.com with SMTP id p9sf6827206lbv.1 for ; Mon, 01 Dec 2014 08:16:18 -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=JJq9RWOGkHhyelY7KIrPFs/5dQ4zwgBHc0Hj4YGY6no=; b=LNwLNFQqjFbAxQelUfW7KdUXo8iMKSYkqA4AQ3Tbh3d6ENccg+fJcH2SlwrNIwLO03 b8y2ZkZJpTLfigtzIEJn6cDBDygR9vbCu0OWnwEjgMYMn4H9j1XLbMYRIGWPi6uFThZL gVJQo7A5Yqw06h/qvFGiIlsF68rfLsA3+Qy7DMpi7NdB9tgeD5toqPpnIvcw+FuwvX7x B85wZz1pe+aBePq1QGg+1+lLs0n8ShI1xhdmnkgmvEQnUwp4CDQenoeszzUHtFeI2+B3 ob7PLWUsuFOBDlNkPG6oQKtvEKjt33GNBeVP2s1O19jl3UKh+sPlAF//TSoHtdsuWPYS FX8A== X-Gm-Message-State: ALoCoQkJocJZsxvrFnEIZbB51OsiEkm6cDVQvQGpJkV73mRwt7MiGkcfUoDGFewV1giRVIYWq5PC X-Received: by 10.180.8.9 with SMTP id n9mr13932596wia.6.1417450578801; Mon, 01 Dec 2014 08:16:18 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.134 with SMTP id t6ls229059lag.78.gmail; Mon, 01 Dec 2014 08:16:18 -0800 (PST) X-Received: by 10.112.62.166 with SMTP id z6mr56268717lbr.74.1417450578456; Mon, 01 Dec 2014 08:16:18 -0800 (PST) Received: from mail-lb0-f170.google.com (mail-lb0-f170.google.com. [209.85.217.170]) by mx.google.com with ESMTPS id pn4si3438469lbc.33.2014.12.01.08.16.18 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:16:18 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.170 as permitted sender) client-ip=209.85.217.170; Received: by mail-lb0-f170.google.com with SMTP id w7so8952505lbi.29 for ; Mon, 01 Dec 2014 08:16:18 -0800 (PST) X-Received: by 10.112.62.166 with SMTP id z6mr56268703lbr.74.1417450578294; Mon, 01 Dec 2014 08:16:18 -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 ew9csp319910lbc; Mon, 1 Dec 2014 08:16:17 -0800 (PST) X-Received: by 10.140.36.168 with SMTP id p37mr85207353qgp.101.1417450576924; Mon, 01 Dec 2014 08:16:16 -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 y1si20970972qcq.39.2014.12.01.08.16.15 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:16:16 -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 1XvTe2-0007C1-Hr; Mon, 01 Dec 2014 16:16:14 +0000 Received: from mail-lb0-f176.google.com ([209.85.217.176]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XvTdk-0007AI-CR for lng-odp@lists.linaro.org; Mon, 01 Dec 2014 16:15:56 +0000 Received: by mail-lb0-f176.google.com with SMTP id p9so9061796lbv.35 for ; Mon, 01 Dec 2014 08:15:50 -0800 (PST) X-Received: by 10.112.198.1 with SMTP id iy1mr34309676lbc.13.1417450550837; Mon, 01 Dec 2014 08:15:50 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id ar4sm4819466lbc.48.2014.12.01.08.15.48 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Dec 2014 08:15:49 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Mon, 1 Dec 2014 19:15:29 +0300 Message-Id: <1417450537-7640-4-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 In-Reply-To: <1417450537-7640-1-git-send-email-maxim.uvarov@linaro.org> References: <1417450537-7640-1-git-send-email-maxim.uvarov@linaro.org> X-Topics: patch Subject: [lng-odp] [PATCHv4 03/11] 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.217.170 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 | 25 ++++++++ platform/linux-generic/include/api/odp_std_types.h | 2 + platform/linux-generic/odp_packet_io.c | 74 ++++++++++++++++++++++ 3 files changed, 101 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index c7d1e40..65adbe5 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -173,6 +173,31 @@ int odp_pktio_promisc_set(odp_pktio_t id, odp_bool_t enable); int odp_pktio_promisc_enabled(odp_pktio_t id); /** + * Set the default MAC address of a packet IO interface. + * + * @param[in] id ODP packet IO handle. + * @param[in] mac_addr MAC address to be assigned to the interface. + * @param[in] addr_size Size of the address in bytes. + * + * @return 0 on success, -ERROR on error. + */ +int odp_pktio_mac_addr_set(odp_pktio_t id, const unsigned char *mac_addr, + size_t addr_size); + +/** + * 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 Address size written. + * @retval -ERROR on error. + */ +ssize_t odp_pktio_mac_addr(odp_pktio_t id, unsigned char *mac_addr, + size_t addr_size); + +/** * @} */ diff --git a/platform/linux-generic/include/api/odp_std_types.h b/platform/linux-generic/include/api/odp_std_types.h index 61255a6..01c0377 100644 --- a/platform/linux-generic/include/api/odp_std_types.h +++ b/platform/linux-generic/include/api/odp_std_types.h @@ -26,6 +26,8 @@ extern "C" { #include #include #include +#include +#include /** Use odp boolean type to have it well-defined and known size, * regardless which compiler is used as this facilities interoperability diff --git a/platform/linux-generic/odp_packet_io.c b/platform/linux-generic/odp_packet_io.c index d97910f..d9c2425 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]; @@ -619,3 +620,76 @@ int odp_pktio_promisc_enabled(odp_pktio_t id) else return 0; } + +int odp_pktio_mac_addr_set(odp_pktio_t id, const 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 -ENOMEM; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -ENOENT; + } + + 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; + memcpy(ifr.ifr_hwaddr.sa_data, mac_addr, addr_size); + ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; + + ret = ioctl(sockfd, SIOCSIFHWADDR, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCSIFHWADDR error\n"); + return ret; + } + + return 0; +} + +ssize_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 -ENOMEM; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -ENOENT; + } + + 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 ret; + } + + memcpy(mac_addr, (unsigned char *)ifr.ifr_ifru.ifru_hwaddr.sa_data, + ETH_ALEN); + + return ETH_ALEN; +}