From patchwork Tue Nov 25 14:05:27 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 41464 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-la0-f72.google.com (mail-la0-f72.google.com [209.85.215.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5B807246DF for ; Tue, 25 Nov 2014 14:05:57 +0000 (UTC) Received: by mail-la0-f72.google.com with SMTP id gq15sf457873lab.7 for ; Tue, 25 Nov 2014 06:05:56 -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: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=JsfIrWGUXWKkANlYmb9txHAbiPgN9XJ/d8FtyqSUUz0=; b=No7ZeRfET/Q4GHnaGTytlbMwUft8N34sOnZ9RxmiuO6NroqvQiRWk7UE1xC0yb4TpW gBQKCxpDTHccfLRntNUGOtvPUD3Pwsb1Y9vtzpAe24YDpNqVPI63g3TYAoCpLeIKvvvk 6P+KlQR/GunLupJblA8/j6RX0f9Omx8gFGnwd/x1KF/ZC37yjX6PBqSeD6M6LhwxBe8K CdSTuJ6J/L7KwZaD4Jke9eippTIBOVxhtMrjCWbCrKDA9WLrrPFN7Yb9Ndef96qtX9wK G9sCviZE/CAmPAzwDjwjFV5Egi20SRYz04J2zObgESXfw0YGn3USO/M6WC2XCZnsV8HV d4ew== X-Gm-Message-State: ALoCoQmJ4OluPEdR/qmr90vCYRF8jQ1dQl2F9GenH1hh98G2Qxp6SWhhaqVZhHvNRX+5kUrlv89s X-Received: by 10.152.8.67 with SMTP id p3mr7695260laa.4.1416924356283; Tue, 25 Nov 2014 06:05:56 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.27.129 with SMTP id t1ls614279lag.53.gmail; Tue, 25 Nov 2014 06:05:56 -0800 (PST) X-Received: by 10.112.159.129 with SMTP id xc1mr27379599lbb.24.1416924356010; Tue, 25 Nov 2014 06:05:56 -0800 (PST) Received: from mail-la0-f45.google.com (mail-la0-f45.google.com. [209.85.215.45]) by mx.google.com with ESMTPS id j15si1483739lbg.30.2014.11.25.06.05.55 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Nov 2014 06:05:55 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.215.45 as permitted sender) client-ip=209.85.215.45; Received: by mail-la0-f45.google.com with SMTP id gq15so588242lab.32 for ; Tue, 25 Nov 2014 06:05:55 -0800 (PST) X-Received: by 10.112.38.4 with SMTP id c4mr11398696lbk.46.1416924355793; Tue, 25 Nov 2014 06:05:55 -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 ew9csp438983lbc; Tue, 25 Nov 2014 06:05:54 -0800 (PST) X-Received: by 10.52.92.79 with SMTP id ck15mr12199765vdb.63.1416924353577; Tue, 25 Nov 2014 06:05:53 -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 qi9si397924vcb.54.2014.11.25.06.05.52 for (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 25 Nov 2014 06:05:53 -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 1XtGkX-0005WA-Bi; Tue, 25 Nov 2014 14:05:49 +0000 Received: from mail-lb0-f175.google.com ([209.85.217.175]) by ip-10-35-177-41.ec2.internal with esmtp (Exim 4.76) (envelope-from ) id 1XtGkR-0005W0-1m for lng-odp@lists.linaro.org; Tue, 25 Nov 2014 14:05:43 +0000 Received: by mail-lb0-f175.google.com with SMTP id u10so584916lbd.34 for ; Tue, 25 Nov 2014 06:05:37 -0800 (PST) X-Received: by 10.152.216.167 with SMTP id or7mr25834733lac.93.1416924337062; Tue, 25 Nov 2014 06:05:37 -0800 (PST) Received: from localhost.localdomain ([188.92.105.210]) by mx.google.com with ESMTPSA id x1sm369331laa.20.2014.11.25.06.05.35 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 25 Nov 2014 06:05:36 -0800 (PST) From: Maxim Uvarov To: lng-odp@lists.linaro.org Date: Tue, 25 Nov 2014 17:05:27 +0300 Message-Id: <1416924328-17663-1-git-send-email-maxim.uvarov@linaro.org> X-Mailer: git-send-email 1.8.5.1.163.gd7aced9 X-Topics: patch Subject: [lng-odp] [PATCH 1/2] 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.45 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 Signed-off-by: Maxim Uvarov --- Implement mac function according to pktio log: https://docs.google.com/document/d/1EHU54p3Kaa-hGUG-W7xquDfQb3aSWF3fEtwmcv5Bts8/edit#heading=h.b8vg8t31zjwt platform/linux-generic/include/api/odp_packet_io.h | 24 ++++++++ platform/linux-generic/odp_packet_io.c | 66 ++++++++++++++++++++++ 2 files changed, 90 insertions(+) diff --git a/platform/linux-generic/include/api/odp_packet_io.h b/platform/linux-generic/include/api/odp_packet_io.h index c9b0889..d6a6067 100644 --- a/platform/linux-generic/include/api/odp_packet_io.h +++ b/platform/linux-generic/include/api/odp_packet_io.h @@ -183,6 +183,30 @@ int odp_pktio_promisc_disable(odp_pktio_t id); int odp_pktio_promisc_get_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, -1 on error. + */ +int odp_pktio_set_mac_addr(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[out] addr_size Size of the MAC address. + * + * @return 0 on success, -1 on error. + */ +int odp_pktio_get_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 937f7f0..909cd32 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]; @@ -650,3 +651,68 @@ int odp_pktio_promisc_get_enabled(odp_pktio_t id) else return 0; } + +int odp_pktio_set_mac_addr(odp_pktio_t id, const unsigned char *mac_addr, + size_t addr_size) +{ + pktio_entry_t *entry; + int sockfd; + struct ifreq ifr; + int ret; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + 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 -1; + } + + return 0; +} + +int odp_pktio_get_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; + + entry = get_entry(id); + if (entry == NULL) { + ODP_DBG("pktio entry %d does not exist\n", id); + return -1; + } + + if (entry->s.pkt_sock_mmap.sockfd) + sockfd = entry->s.pkt_sock_mmap.sockfd; + else + sockfd = entry->s.pkt_sock.sockfd; + + strncpy(ifr.ifr_name, entry->s.name, IFNAMSIZ); + + ret = ioctl(sockfd, SIOCGIFHWADDR, &ifr); + if (ret < 0) { + ODP_DBG("ioctl SIOCGIFHWADDR error\n"); + return -1; + } + + *addr_size = ETH_ALEN; + memcpy(mac_addr, (unsigned char *)ifr.ifr_ifru.ifru_hwaddr.sa_data, + ETH_ALEN); + return 0; +}