From patchwork Mon Oct 16 12:00:07 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: 115905 Delivered-To: patch@linaro.org Received: by 10.140.22.163 with SMTP id 32csp3598608qgn; Mon, 16 Oct 2017 05:03:15 -0700 (PDT) X-Google-Smtp-Source: AOwi7QB8IvB+oa8l42Fa2pk2Afj2QUcophKg1kjjHhq3XLiXApt2uH22b0VC/Xh62p1Dm0yvESLM X-Received: by 10.107.3.193 with SMTP id e62mr12493457ioi.88.1508155395458; Mon, 16 Oct 2017 05:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1508155395; cv=none; d=google.com; s=arc-20160816; b=aOeI+Zd8YyjWD/9hEZjWtXYy8GgioHeowqbzhe4eW0BxRE0dC2kepywmg17pCn8p5t XYiaQs8UR4V+zAUT9KEnSUNm3rjpB7He9ZYT2pjbhBSdT0C+PRS7fhhW73LwlCoN1TKh jCTGaoqKBlr6cWYZsKbFxWkRgY0r+D1Z3lqAVqSMBWDVpewQTXvyC+DN/OZH2we2HW8k a2wW44QL37PH+T4qO51m8tBcJfTe3+eMZz0kT7vyM39wv6S9V1+4uyrRWyluxjyUTyLs WGroU4YOAdngrbjQauxXJ+EqeEHeuXK5j11SBxLZ/DVJpHBd8pFfzYA48QZEfYO0Zgxm er5A== 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=eneTyJxLPSdvYsahgU5B1pnqAtJn9vs3ueXmP5aWBPk=; b=oyOL0bsCfu0N96fr71aJpxo5edwMa1rtAc3TA6TMORuzI6lVrV4h4NLs4mFIyEcDfs w45kDcggjThggBQsUV3Un0ongER9A8333WXEg4JC6HtP1HYoFxStczJYQ+0fDtJn4nw2 VBqlnkSvzSoSA/kM/X6jmLcjiIwCjSG+Cu3jAh49FWr7q9fEYPSgJAFBTltZEz5Odl1F QPGgAMXd2IwKoZOBC63h7n6ddlmtoQ/dE5LuAE1q4aVs+j45ev1RH20NljEY5f9Qou3Q hCFOWM4ynV7t/MrlHf0D9gRJ0YvelworJZMOY9jv3JOM0fz5cpuhyD4HPXFyX8/+huRv Vx4w== 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 p10si1981612iti.94.2017.10.16.05.03.15; Mon, 16 Oct 2017 05:03:15 -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 066CE60ABA; Mon, 16 Oct 2017 12:03:15 +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=-2.6 required=5.0 tests=BAYES_00,FREEMAIL_FROM, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,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 96109608B6; Mon, 16 Oct 2017 12:02:23 +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 73198609DB; Mon, 16 Oct 2017 12:02:11 +0000 (UTC) Received: from forward105p.mail.yandex.net (forward105p.mail.yandex.net [77.88.28.108]) by lists.linaro.org (Postfix) with ESMTPS id 56FB160A51 for ; Mon, 16 Oct 2017 12:00:16 +0000 (UTC) Received: from mxback2g.mail.yandex.net (mxback2g.mail.yandex.net [IPv6:2a02:6b8:0:1472:2741:0:8b7:163]) by forward105p.mail.yandex.net (Yandex) with ESMTP id E33AB4080FC6 for ; Mon, 16 Oct 2017 15:00:14 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback2g.mail.yandex.net (nwsmtp/Yandex) with ESMTP id awfZ0xW0yB-0E5uh8UK; Mon, 16 Oct 2017 15:00:14 +0300 Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id KcD5G1a8yg-0E1W9sTZ; Mon, 16 Oct 2017 15:00:14 +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: Mon, 16 Oct 2017 15:00:07 +0300 Message-Id: <1508155207-5041-4-git-send-email-odpbot@yandex.ru> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1508155207-5041-1-git-send-email-odpbot@yandex.ru> References: <1508155207-5041-1-git-send-email-odpbot@yandex.ru> Github-pr-num: 232 Subject: [lng-odp] [PATCH API-NEXT v1 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: afeda4d14bb6f449cb269680cdbd56b26726eedf ** Merge commit sha: 8726d6c7a814c3380aacd18250194eae85ababb3 **/ platform/linux-generic/include/odp_packet_socket.h | 5 +++++ platform/linux-generic/pktio/socket.c | 25 ++++++++++++++++++++++ platform/linux-generic/pktio/tap.c | 13 ++++++++++- 3 files changed, 42 insertions(+), 1 deletion(-) diff --git a/platform/linux-generic/include/odp_packet_socket.h b/platform/linux-generic/include/odp_packet_socket.h index 0e61f6f0c..a05629ba5 100644 --- a/platform/linux-generic/include/odp_packet_socket.h +++ b/platform/linux-generic/include/odp_packet_socket.h @@ -99,6 +99,11 @@ ethaddrs_equal(unsigned char mac_a[], unsigned char mac_b[]) int mac_addr_get_fd(int fd, const char *name, unsigned char mac_dst[]); /** + * Write the MAC address for a packet socket + */ +int mac_addr_set_fd(int fd, const char *name, const unsigned char mac_dst[]); + +/** * Read the MTU from a packet socket */ uint32_t mtu_get_fd(int fd, const char *name); diff --git a/platform/linux-generic/pktio/socket.c b/platform/linux-generic/pktio/socket.c index 0a80035f5..447b02b20 100644 --- a/platform/linux-generic/pktio/socket.c +++ b/platform/linux-generic/pktio/socket.c @@ -125,6 +125,31 @@ int mac_addr_get_fd(int fd, const char *name, unsigned char mac_dst[]) return 0; } +/** + * ODP_PACKET_TAP: + */ +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; +} + /* * ODP_PACKET_SOCKET_MMSG: * ODP_PACKET_SOCKET_MMAP: diff --git a/platform/linux-generic/pktio/tap.c b/platform/linux-generic/pktio/tap.c index 2fda0b814..841631d9b 100644 --- a/platform/linux-generic/pktio/tap.c +++ b/platform/linux-generic/pktio/tap.c @@ -412,6 +412,16 @@ static int tap_link_status(pktio_entry_t *pktio_entry) pktio_entry->s.name + 4); } +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_capability(pktio_entry_t *pktio_entry ODP_UNUSED, odp_pktio_capability_t *capa) { @@ -420,6 +430,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 +454,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,