From patchwork Thu Oct 19 08:00:12 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Github ODP bot X-Patchwork-Id: 116341 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp207591qgn; Thu, 19 Oct 2017 01:04:04 -0700 (PDT) X-Google-Smtp-Source: ABhQp+TDVCcxThh59GQ50f25LXUHp5TWMgTtR8x9GhcH1r6gtXpmAMwnP6F5KFXNR4Vp0gV8ooam X-Received: by 10.200.1.136 with SMTP id x8mr951741qtf.259.1508400244333; Thu, 19 Oct 2017 01:04:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508400244; cv=none; d=google.com; s=arc-20160816; b=sr5AHdwEiqTihGDqPii5iXzQg7YX+hRbM6mJwHAUwHLTVCAO1uNDJCoCF5YFqcmn2X 9ZrwX7Oi6Y4znymLbQ28EWxSeJmICAdpyRHMF/KlXSL/d0T06Xep5eUJJGw1r0TYxyut vAx2igMTXHFLvYIQkGaM9/P9kT20UMWy+Rsci56xWOuJ1UETgDirCwu4QmruLQaGH4cr twRyCCDvUTFqaR5aJMcbMtDjcw/rFwI8s+AYMq4iOrVl7V4Se6dtBcAE98vpk3tGx9zN WYn9IdEFHnW9OwhCgDf0ZO8MmYhJlJEPTP5s38YO+1Y6eJ10TEjcJxv723Uaq4RcPCnJ Carg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:github-pr-num :references:in-reply-to:message-id:date:to:from:delivered-to :arc-authentication-results; bh=3dOjy8A7TzZUjXJevhHTCgqMTbGFSHxkv8vRagwHbDo=; b=lEzCvti0HOsnPt8FKRTNNKCgjDuvyhFfK8AUP7OM0GJ3JhbJD+u5tgl8DNrApjMBOh 0TMp0UKc6YJqECSwfmVPw635eI3Y5RTiOGVT5IL/N46ROuvL+E0T1seyZEP8oebQj7hV rPoAQm2jjqw58j2Y5NMgPLL4RSHvhAcALBAwoTXJQ6FghYggHYVN52Wg2Ov9DqC+Xv29 2AOkFmBjY6/4h3JDpDimRvTGFFQJ6Ycf7yqkB1dTRW7YL/skIbCixeuQSXnyaoV+rp7w DdiUPU5rwlsoKuK9Mby5ehE4jd34tzrKc7s2v9WMCo1rQ3co8P5Th70U/Wn8ckFt30Ba jS1A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Return-Path: Received: from lists.linaro.org (ec2-54-197-127-237.compute-1.amazonaws.com. [54.197.127.237]) by mx.google.com with ESMTP id b29si1045174qtk.59.2017.10.19.01.04.04; Thu, 19 Oct 2017 01:04:04 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) client-ip=54.197.127.237; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.197.127.237 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=yandex.ru Received: by lists.linaro.org (Postfix, from userid 109) id 00D5D62EA0; Thu, 19 Oct 2017 08:04:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id 8427A62AE4; Thu, 19 Oct 2017 08:01:10 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id D3C73629F1; Thu, 19 Oct 2017 08:00:43 +0000 (UTC) Received: from forward102j.mail.yandex.net (forward102j.mail.yandex.net [5.45.198.243]) by lists.linaro.org (Postfix) with ESMTPS id 846D66291E for ; Thu, 19 Oct 2017 08:00:19 +0000 (UTC) Received: from mxback20j.mail.yandex.net (mxback20j.mail.yandex.net [IPv6:2a02:6b8:0:1619::114]) by forward102j.mail.yandex.net (Yandex) with ESMTP id E92265605147 for ; Thu, 19 Oct 2017 11:00:17 +0300 (MSK) Received: from smtp1j.mail.yandex.net (smtp1j.mail.yandex.net [2a02:6b8:0:801::ab]) by mxback20j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id vlNZnYfdqY-0HM4AKOr; Thu, 19 Oct 2017 11:00:17 +0300 Received: by smtp1j.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id OmTGLJNgIE-0HcWjwp7; Thu, 19 Oct 2017 11:00:17 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (Client certificate not present) From: Github ODP bot To: lng-odp@lists.linaro.org Date: Thu, 19 Oct 2017 11:00:12 +0300 Message-Id: <1508400012-1278-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508400012-1278-1-git-send-email-odpbot@yandex.ru> References: <1508400012-1278-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 232 Subject: [lng-odp] [PATCH API-NEXT v2 3/3] linux-gen: pktio: tap: implement MAC address set operation X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" From: Bogdan Pricope Implement MAC address set function and set corresponding capability flag. Signed-off-by: Bogdan Pricope --- /** Email created from pull request 232 (bogdanPricope:tap_set_mac_pr) ** https://github.com/Linaro/odp/pull/232 ** Patch: https://github.com/Linaro/odp/pull/232.patch ** Base sha: edca8cd1e55898826f79383b689c2c4bd2c28b3a ** Merge commit sha: 89f18d929052add128b4252f5b17907b9a354ccb **/ platform/linux-generic/pktio/tap.c | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 2fda0b814..d8b78f3f8 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -59,6 +59,29 @@ static int gen_random_mac(unsigned char *mac) return 0; } +static int mac_addr_set_fd(int fd, const char *name, + const unsigned char mac_dst[]) +{ + struct ifreq ethreq; + int ret; + + memset(ðreq, 0, sizeof(ethreq)); + snprintf(ethreq.ifr_name, IF_NAMESIZE, "%s", name); + + ethreq.ifr_hwaddr.sa_family = AF_UNIX; + memcpy(ethreq.ifr_hwaddr.sa_data, mac_dst, ETH_ALEN); + + ret = ioctl(fd, SIOCSIFHWADDR, ðreq); + if (ret != 0) { + __odp_errno = errno; + ODP_ERR("ioctl(SIOCSIFHWADDR): %s: \"%s\".\n", strerror(errno), + ethreq.ifr_name); + return -1; + } + + return 0; +} + static int tap_pktio_open(odp_pktio_t id ODP_UNUSED, pktio_entry_t *pktio_entry, const char *devname, odp_pool_t pool) @@ -406,6 +429,16 @@ static int tap_mac_addr_get(pktio_entry_t *pktio_entry, void *mac_addr) return ETH_ALEN; } +static int tap_mac_addr_set(pktio_entry_t *pktio_entry, const void *mac_addr) +{ + pkt_tap_t *tap = &pktio_entry->s.pkt_tap; + + memcpy(tap->if_mac, mac_addr, ETH_ALEN); + + return mac_addr_set_fd(tap->fd, (char *)pktio_entry->s.name + 4, + tap->if_mac); +} + static int tap_link_status(pktio_entry_t *pktio_entry) { return link_status_fd(pktio_entry->s.pkt_tap.skfd, @@ -420,6 +453,7 @@ static int tap_capability(pktio_entry_t *pktio_entry ODP_UNUSED, capa->max_input_queues = 1; capa->max_output_queues = 1; capa->set_op.op.promisc_mode = 1; + capa->set_op.op.mac_addr = 1; odp_pktio_config_init(&capa->config); capa->config.pktin.bit.ts_all = 1; @@ -443,7 +477,7 @@ const pktio_if_ops_t tap_pktio_ops = { .promisc_mode_set = tap_promisc_mode_set, .promisc_mode_get = tap_promisc_mode_get, .mac_get = tap_mac_addr_get, - .mac_set = NULL, + .mac_set = tap_mac_addr_set, .link_status = tap_link_status, .capability = tap_capability, .pktin_ts_res = NULL,