From patchwork Thu Jan 18 06:12:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 124921 Delivered-To: patch@linaro.org Received: by 10.80.140.226 with SMTP id r31csp3134889edr; Wed, 17 Jan 2018 22:14:33 -0800 (PST) X-Google-Smtp-Source: ACJfBovIo6A0P97vABbD/t1U+8c6xqGBcgAyL63GEsZ59DQOcPa8PsW6xJhWON+3QJxkmMAiNhp2 X-Received: by 10.223.208.201 with SMTP id z9mr4813223wrh.194.1516256073546; Wed, 17 Jan 2018 22:14:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516256073; cv=none; d=google.com; s=arc-20160816; b=AtVs5sncriMEJbAurokpqsecso41SM+8v1f4iJzyrHtL8bLymFaQbpOotU/ilX3INL yUKfymbqmzxX7R2j0WKtzLq8oUsXRbNF/2s7uGe5Lvh8weZD/wywiCsFajsRUpeMv1Mf XKfzkDjtri0g+BqYpsqYA3PwrsXfhZctMoNagi55tR7t69qa9TLskF/Z39FhkxA9vW4k wS0Fp7mkIPFIdl93lo6/CHef3nBJkwhzLYkbkfmcLNyG+b3EGZgzKxY1fAQPw0Cu7oRm dMndo4Zw0USfswvOAfS3J9UJvSUCYDfYfsdsyxPQBeybpY7bjwfQFvylosKak2RVEvOs ttXw== 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:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=tWzisFevGjL3KzJMpGlBzbSPzslBsxIS0jJXVCiBGvY=; b=NlHdJR0fxD6DRSMWQl7kOrcES5Ms/dcHHmq+kXzQx1kFprrfFEmFGdHFjOcTEYaRjK RBM2jn/+YiSdFAgR1RlyOsqpKOrtvI8p5nseSmmH4OkItoCvID6us8df88VlOcPBWJRf JA15ABduWsXt8KN6LuYnqRTGsLLyPfWHuzv35VNS9W9sfE1sx8FL0sEIeQeXQ5tqd5uY maNy7J2NggYuFMmcF01V3M0tSLdDZE/uRHJ6pUig4zDySD+/4k6By1aL0c/sdLKjkkjC uoMwLHu0pYwst7vNHw6K3Ko8wS77xdUQ6y6Y9zEV0NQOY4NO1WZFf9A3m8rzCqr7WVTf 5KIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id n188si5048387wmd.49.2018.01.17.22.14.33; Wed, 17 Jan 2018 22:14:33 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id C517B1B1BF; Thu, 18 Jan 2018 07:14:20 +0100 (CET) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0086.outbound.protection.outlook.com [104.47.34.86]) by dpdk.org (Postfix) with ESMTP id 7EA981B1BF for ; Thu, 18 Jan 2018 07:14:18 +0100 (CET) Received: from BN3PR03CA0061.namprd03.prod.outlook.com (10.167.1.149) by CY1PR03MB2362.namprd03.prod.outlook.com (10.166.207.149) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 06:14:17 +0000 Received: from BN1AFFO11FD038.protection.gbl (2a01:111:f400:7c10::164) by BN3PR03CA0061.outlook.office365.com (2a01:111:e400:7a4d::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.407.7 via Frontend Transport; Thu, 18 Jan 2018 06:14:11 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; intel.com; dkim=none (message not signed) header.d=none; intel.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD038.mail.protection.outlook.com (10.58.52.242) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Thu, 18 Jan 2018 06:14:09 +0000 Received: from bf-netperf1.ap.freescale.net (bf-netperf1.ap.freescale.net [10.232.134.28]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0I6E6h9024428; Wed, 17 Jan 2018 23:14:07 -0700 From: Hemant Agrawal To: CC: Date: Thu, 18 Jan 2018 11:42:58 +0530 Message-ID: <1516255980-25092-1-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> References: <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131607296502617006; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(7966004)(396003)(39380400002)(39860400002)(376002)(346002)(2980300002)(1110001)(1109001)(339900001)(3190300001)(189003)(199004)(5660300001)(26005)(2351001)(50226002)(6916009)(47776003)(8676002)(105606002)(316002)(8936002)(508600001)(81166006)(51416003)(76176011)(106466001)(356003)(16586007)(81156014)(68736007)(53936002)(6666003)(305945005)(50466002)(2906002)(2950100002)(59450400001)(97736004)(4326008)(48376002)(36756003)(85426001)(104016004)(77096007)(86362001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2362; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD038; 1:+3umuX3kOLwRHcuFSLs1OKNYWSsQcK7sWnmcxklX7Z+23Ohf43pe8JVrPZjOOqvNBgVp4CO1q9Y06kpP6Q1UPWxYzB1jz/Kf0eon3HXUpkTvIVTEHNB1yTEfsaz2hVRd MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 23f07744-8691-47af-53ae-08d55e3ab05a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(5600026)(4604075)(2017052603307); SRVR:CY1PR03MB2362; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2362; 3:wGwn0n0mZUs9e4SvOrgSIIxNwZZDteuwPqTHwGv7LDbzKKcZFEO7BwsknCtBEjDEgOp6ShRfm4SGu/H/8keBQdyDYcylateIc/7/fqCy/Zlu6W2yvO9Cr7JR9WEpytWoDxp7m23mw9Af3LkDXEphE0XsIxKQrzkajPImh85aR5LPfFz54kGu668nUtX7a7RPafshBTEBzd2nCZVPqi8hGmMOBY2FKsY4CX+Sp0MmUUKHCgAO0WzDgQ6/5QQ/G29eb2Magt3hMFNhD6QaXFMmID8n1fyw5nYRL2cL+lr/JOYdcDT0/E8OCnUpQ4XZZfMqzOI/N/GpAh959aTingK61mIDq8Wk2YY5hm7s5YewHGA=; 25:YDmtARqDECmSCFSnYvZVGBUt3w6CDxZIlNRxSWJa/VWPHvtOan3wI/RFLDSOoUKkqhk/NsDpF4ZY7RsalsZeEjdGExKapso0nr1D4WXuENYMjoEl+2vFX/hQPxgy6nhMHwIdGZaLkTYO2vot+NfisNuzTaP/8wbs+mqTh43vB4nDAVImnXzquh7m+yv4Ke6Ozbh40kjEyhLCqI3BPdQ2+x4T04gvWUL9PuXBlipAYpAM9x6Rlqd07ROQlD14X1f+GYMdK2WlHOGoHT3BQrxyiou+0oE5/KZhbYgqumqpA5o1t75HKWS/EOohpmENpo8rrLLwHrp7edglaoSunZinHQ== X-MS-TrafficTypeDiagnostic: CY1PR03MB2362: X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2362; 31:H2RGBFDuMcPnQAG+wTdKD/8/n3jAoiZUTBhyPva5jNWn6I023AkF7Tphh3T+V3gdcIr1HS2DKzuxH74+RCD9YsBrzmikTb/91G0JQuHGmP91wlpIdiwbJptJc+aYHOXG6PjWwk0H2tvqu4+FhzSDos1XX1wIyu100N06hdse1PZehOgUFpc3mTlKf906mLAa/V0F5VgHRyEOMBx0+756WXE4FHtnr8Ap1hSvpPlUzh0=; 4:CLiZvJPKVofRji1Qqgqlk46mE6TG21V5XwinZhcseJERv6qvJkH96UtqfnKX0r8zfs4gt8CEYOxQ00soQ5lMWnWANPTz4h6W/IZquVNUL545E+0yQuoD9bP8R73/2zkM4Y8VaQAVTkSV5xkyQH6Zg/dLfyMzhxllnYIk9k8mj5mvpqHA1Ajw2eT6zQp6U27ZVKccPo6tQX1c11b1QkFNh9onermohP9rjOMFMWrmb/jr/wga76bDbvyspUAq7KGUaUssWLP5MRyNnnoQ8D/CXagBF+4rENH335gTLEdOV5Qq6r7lHF9Pu8KHZ1hz1uFj X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(5005006)(8121501046)(93006095)(93001095)(3002001)(10201501046)(3231023)(2400057)(944501161)(6055026)(6096035)(20161123565025)(20161123559100)(20161123556025)(20161123563025)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(20161123561025)(201708071742011); SRVR:CY1PR03MB2362; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:CY1PR03MB2362; X-Forefront-PRVS: 05568D1FF7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB2362; 23:U2exHVi6VVlodrfI4MPtWjr/LusVgpZSysLO8VOue?= Nkr+nstRM1zC9Z06/xFtsb9K+Uyu1pvwvqLKQ/Az4nnkYY6eVdBNUaaYexKUYuZgiCmu4BME1+LjVz+683IpwvJQivg0bDpmCX9aa0snM8FcG3XB3KdgeKpZX7cMPjmUy0x0OdXB+BATIucbGCoAg8IFltXMHytAW9NQ7rFfHvEFLwFKOLlFOfL/yNA4b9ym1HthJX3baiZC0CItgbWu7UgyUjgfSHsp8aNPL5fCZj9BId/eszOny+ON0pRcm4iK+nMXxjhfvBi1Kn3v0vGBdj2ASUhNw3y5QldPbtsTR5Fy7zFfOmrFkRKDxTGfXkFHWGyPB35sVnzV+qthib+lkG1iyjMHy4GmfUO+1P9WKd/0+w18FNA/NDpSIwUAxjHP4nN6HxIzA85ku/UDQcI6HQoxQnN+exPlEgglr87wX3SaeQaGrOZpsxD3TdHCvQTDLaqafA9d+kMVeKqZrwVHTYLlUrCWfCOgQs7Ug81NQQ1HQmjriooQiZg1N/x/lNe4eAviXIuwwGD4t1scw8pSaXP/MOHKKanFzbF3pGEq4su9+UU1uDbh1t0jyovXX3cffRSHUIUWM8o5KgrzAKvnYj6nGSMujNZDr3lQXiBLlRQcsoYFAqGZAtKu1aFYeB+Tkelzp04potX56cGSGDkJuEz2ZXK7vxZq099P/CR0o592xstFB9q5EKyHEX+rIRI0FpaPsF2cHEewivYSTkmSLBvmX3L0dlkTYv4eRiH4vdMgJoauLD4JZatiS/vC3/VK6nqxkvOYv2chSj/0/rV5r2IN2wLEyHwdzTcpFWUAOzb2IMjLRAa1qWPOBEmOYK0OmIpAUSR7duY9fxSAlQZ6sw50TSrrEV2XSfxb3dTWF8VN63LVBFgXlbfVVh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eSkRzJXx7Y2uohSKOySVbsJfqvQch3b++SiIzKgrHxQRd1gFavFcLX2f8CLPW7MpZXLTizj70EIRv9 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 06:14:09.4348 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 23f07744-8691-47af-53ae-08d55e3ab05a X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR03MB2362 Subject: [dpdk-dev] [PATCH v3 1/3] kni: support for MAC addr change X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch adds following: 1. Option to configure the mac address during create. Generate random address only if the user has not provided any valid address. 2. Inform usespace, if mac address is being changed in linux. 3. Implement default handling of mac address change in the corresponding ethernet device. Signed-off-by: Hemant Agrawal --- v3: fix compilation err and checkpatch warnings doc/guides/sample_app_ug/kernel_nic_interface.rst | 26 +++++++++++++- examples/kni/main.c | 36 +++++++++++++++++++ .../linuxapp/eal/include/exec-env/rte_kni_common.h | 3 ++ lib/librte_eal/linuxapp/kni/kni_misc.c | 17 +++++---- lib/librte_eal/linuxapp/kni/kni_net.c | 14 +++++++- lib/librte_kni/rte_kni.c | 42 ++++++++++++++++++++-- lib/librte_kni/rte_kni.h | 5 +++ test/test/test_kni.c | 2 ++ 8 files changed, 134 insertions(+), 11 deletions(-) -- 2.7.4 Acked-by: Ferruh Yigit diff --git a/doc/guides/sample_app_ug/kernel_nic_interface.rst b/doc/guides/sample_app_ug/kernel_nic_interface.rst index 67f2140..d7989bf 100644 --- a/doc/guides/sample_app_ug/kernel_nic_interface.rst +++ b/doc/guides/sample_app_ug/kernel_nic_interface.rst @@ -209,6 +209,12 @@ Dumping the network traffic: #tcpdump -i vEth0_0 +Change the MAC address: + +.. code-block:: console + + #ifconfig vEth0_0 hw ether 0C:01:02:03:04:08 + When the DPDK userspace application is closed, all the KNI devices are deleted from Linux*. Explanation @@ -269,11 +275,15 @@ The code for allocating the kernel NIC interfaces for a specific port is as foll conf.addr = dev_info.pci_dev->addr; conf.id = dev_info.pci_dev->id; + /* Get the interface default mac address */ + rte_eth_macaddr_get(port_id, (struct ether_addr *)&conf.mac_addr); + memset(&ops, 0, sizeof(ops)); ops.port_id = port_id; ops.change_mtu = kni_change_mtu; ops.config_network_if = kni_config_network_interface; + ops.config_mac_address = kni_config_mac_address; kni = rte_kni_alloc(pktmbuf_pool, &conf, &ops); } else @@ -502,13 +512,19 @@ Callbacks for Kernel Requests To execute specific PMD operations in user space requested by some Linux* commands, callbacks must be implemented and filled in the struct rte_kni_ops structure. -Currently, setting a new MTU and configuring the network interface (up/ down) are supported. +Currently, setting a new MTU, change in mac address and configuring the network interface(up/ down) +are supported. +Default implementation for following is available in rte_kni library. Application +may choose to not implement follwoing callbacks: + ``config_mac_address`` + .. code-block:: c static struct rte_kni_ops kni_ops = { .change_mtu = kni_change_mtu, .config_network_if = kni_config_network_interface, + .config_mac_address = kni_config_mac_address, }; /* Callback for request of changing MTU */ @@ -587,3 +603,11 @@ Currently, setting a new MTU and configuring the network interface (up/ down) ar RTE_LOG(ERR, APP, "Failed to start port %d\n", port_id); return ret; } + + /* Callback for request of configuring device mac address */ + + static int + kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]) + { + ..... + } diff --git a/examples/kni/main.c b/examples/kni/main.c index 5700740..ebec433 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -131,6 +131,7 @@ static struct kni_interface_stats kni_stats[RTE_MAX_ETHPORTS]; static int kni_change_mtu(uint16_t port_id, unsigned int new_mtu); static int kni_config_network_interface(uint16_t port_id, uint8_t if_up); +static int kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]); static rte_atomic32_t kni_stop = RTE_ATOMIC32_INIT(0); @@ -767,6 +768,37 @@ kni_config_network_interface(uint16_t port_id, uint8_t if_up) return ret; } +static void +print_ethaddr(const char *name, struct ether_addr *mac_addr) +{ + char buf[ETHER_ADDR_FMT_SIZE]; + ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, mac_addr); + RTE_LOG(INFO, APP, "\t%s%s\n", name, buf); +} + +/* Callback for request of configuring mac address */ +static int +kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]) +{ + int ret = 0; + + if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) { + RTE_LOG(ERR, APP, "Invalid port id %d\n", port_id); + return -EINVAL; + } + + RTE_LOG(INFO, APP, "Configure mac address of %d\n", port_id); + print_ethaddr("Address:", (struct ether_addr *)mac_addr); + + ret = rte_eth_dev_default_mac_addr_set(port_id, + (struct ether_addr *)mac_addr); + if (ret < 0) + RTE_LOG(ERR, APP, "Failed to config mac_addr for port %d\n", + port_id); + + return ret; +} + static int kni_alloc(uint16_t port_id) { @@ -810,11 +842,15 @@ kni_alloc(uint16_t port_id) conf.addr = dev_info.pci_dev->addr; conf.id = dev_info.pci_dev->id; } + /* Get the interface default mac address */ + rte_eth_macaddr_get(port_id, + (struct ether_addr *)&conf.mac_addr); memset(&ops, 0, sizeof(ops)); ops.port_id = port_id; ops.change_mtu = kni_change_mtu; ops.config_network_if = kni_config_network_interface; + ops.config_mac_address = kni_config_mac_address; kni = rte_kni_alloc(pktmbuf_pool, &conf, &ops); } else diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h index 61ace6f..62b4a05 100644 --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h @@ -28,6 +28,7 @@ enum rte_kni_req_id { RTE_KNI_REQ_UNKNOWN = 0, RTE_KNI_REQ_CHANGE_MTU, RTE_KNI_REQ_CFG_NETWORK_IF, + RTE_KNI_REQ_CHANGE_MAC_ADDR, RTE_KNI_REQ_MAX, }; @@ -40,6 +41,7 @@ struct rte_kni_request { union { uint32_t new_mtu; /**< New MTU */ uint8_t if_up; /**< 1: interface up, 0: interface down */ + uint8_t mac_addr[6]; /**< MAC address for interface */ }; int32_t result; /**< Result for processing request */ } __attribute__((__packed__)); @@ -116,6 +118,7 @@ struct rte_kni_device_info { /* mbuf size */ unsigned mbuf_size; + char mac_addr[6]; }; #define KNI_DEVICE "kni" diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c index def4f1e..83649ce 100644 --- a/lib/librte_eal/linuxapp/kni/kni_misc.c +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c @@ -439,12 +439,17 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num, if (kni->lad_dev) ether_addr_copy(net_dev->dev_addr, kni->lad_dev->dev_addr); - else - /* - * Generate random mac address. eth_random_addr() is the newer - * version of generating mac address in linux kernel. - */ - random_ether_addr(net_dev->dev_addr); + else { + /* if user has provided a valid mac address */ + if (is_valid_ether_addr((unsigned char *)(dev_info.mac_addr))) + memcpy(net_dev->dev_addr, dev_info.mac_addr, ETH_ALEN); + else + /* + * Generate random mac address. eth_random_addr() is the + * newer version of generating mac address in kernel. + */ + random_ether_addr(net_dev->dev_addr); + } ret = register_netdev(net_dev); if (ret) { diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c index 07d6fdb..3e35008 100644 --- a/lib/librte_eal/linuxapp/kni/kni_net.c +++ b/lib/librte_eal/linuxapp/kni/kni_net.c @@ -649,12 +649,24 @@ kni_net_rebuild_header(struct sk_buff *skb) static int kni_net_set_mac(struct net_device *netdev, void *p) { + int ret; + struct rte_kni_request req; + struct kni_dev *kni; struct sockaddr *addr = p; + memset(&req, 0, sizeof(req)); + req.req_id = RTE_KNI_REQ_CHANGE_MAC_ADDR; + if (!is_valid_ether_addr((unsigned char *)(addr->sa_data))) return -EADDRNOTAVAIL; + + memcpy(req.mac_addr, addr->sa_data, netdev->addr_len); memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); - return 0; + + kni = netdev_priv(netdev); + ret = kni_net_process_request(kni, &req); + + return (ret == 0 ? req.result : ret); } #ifdef HAVE_CHANGE_CARRIER_CB diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index f4fa994..a140dfc 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -327,6 +327,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool, memset(ctx, 0, sizeof(struct rte_kni)); if (ops) memcpy(&ctx->ops, ops, sizeof(struct rte_kni_ops)); + else + ctx->ops.port_id = UINT16_MAX; memset(&dev_info, 0, sizeof(dev_info)); dev_info.bus = conf->addr.bus; @@ -339,6 +341,8 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool, dev_info.group_id = conf->group_id; dev_info.mbuf_size = conf->mbuf_size; + memcpy(dev_info.mac_addr, conf->mac_addr, ETHER_ADDR_LEN); + snprintf(ctx->name, RTE_KNI_NAMESIZE, "%s", intf_name); snprintf(dev_info.name, RTE_KNI_NAMESIZE, "%s", intf_name); @@ -499,6 +503,28 @@ rte_kni_release(struct rte_kni *kni) return 0; } +/* default callback for request of configuring device mac address */ +static int +kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]) +{ + int ret = 0; + + if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) { + RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id); + return -EINVAL; + } + + RTE_LOG(INFO, KNI, "Configure mac address of %d", port_id); + + ret = rte_eth_dev_default_mac_addr_set(port_id, + (struct ether_addr *)mac_addr); + if (ret < 0) + RTE_LOG(ERR, KNI, "Failed to config mac_addr for port %d\n", + port_id); + + return ret; +} + int rte_kni_handle_request(struct rte_kni *kni) { @@ -530,6 +556,14 @@ rte_kni_handle_request(struct rte_kni *kni) req->result = kni->ops.config_network_if(\ kni->ops.port_id, req->if_up); break; + case RTE_KNI_REQ_CHANGE_MAC_ADDR: /* Change MAC Address */ + if (kni->ops.config_mac_address) + req->result = kni->ops.config_mac_address( + kni->ops.port_id, req->mac_addr); + else if (kni->ops.port_id != UINT16_MAX) + req->result = kni_config_mac_address( + kni->ops.port_id, req->mac_addr); + break; default: RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id); req->result = -EINVAL; @@ -678,7 +712,9 @@ kni_check_request_register(struct rte_kni_ops *ops) if( NULL == ops ) return KNI_REQ_NO_REGISTER; - if((NULL == ops->change_mtu) && (NULL == ops->config_network_if)) + if ((ops->change_mtu == NULL) + && (ops->config_network_if == NULL) + && (ops->config_mac_address == NULL)) return KNI_REQ_NO_REGISTER; return KNI_REQ_REGISTERED; @@ -717,8 +753,8 @@ rte_kni_unregister_handlers(struct rte_kni *kni) return -1; } - kni->ops.change_mtu = NULL; - kni->ops.config_network_if = NULL; + memset(&kni->ops, 0, sizeof(struct rte_kni_ops)); + return 0; } void diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index c4dcfff..370b02a 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -41,6 +42,9 @@ struct rte_kni_ops { /* Pointer to function of configuring network interface */ int (*config_network_if)(uint16_t port_id, uint8_t if_up); + + /* Pointer to function of configuring mac address */ + int (*config_mac_address)(uint16_t port_id, uint8_t mac_addr[]); }; /** @@ -61,6 +65,7 @@ struct rte_kni_conf { __extension__ uint8_t force_bind : 1; /* Flag to bind kernel thread */ + char mac_addr[ETHER_ADDR_LEN]; /* MAC address assigned to KNI */ }; /** diff --git a/test/test/test_kni.c b/test/test/test_kni.c index 539d231..4513de1 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -74,6 +74,7 @@ static const struct rte_eth_conf port_conf = { static struct rte_kni_ops kni_ops = { .change_mtu = NULL, .config_network_if = NULL, + .config_mac_address = NULL, }; static unsigned lcore_master, lcore_ingress, lcore_egress; @@ -231,6 +232,7 @@ test_kni_register_handler_mp(void) struct rte_kni_ops ops = { .change_mtu = kni_change_mtu, .config_network_if = NULL, + .config_mac_address = NULL, }; if (!kni) { From patchwork Thu Jan 18 06:12:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 124919 Delivered-To: patch@linaro.org Received: by 10.46.3.10 with SMTP id 10csp1752297ljd; Wed, 17 Jan 2018 22:14:20 -0800 (PST) X-Google-Smtp-Source: ACJfBoukcAa0TEi1JxvnceJ9OchWwiv+MSPvl1V2458SJNmQSyPx0XrIYBMe8ye4Sf2I6DNNsjbD X-Received: by 10.28.109.10 with SMTP id i10mr278578wmc.107.1516256060519; Wed, 17 Jan 2018 22:14:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516256060; cv=none; d=google.com; s=arc-20160816; b=cTFGjkYQwJTBXyyhWkVthOa+Fr/pfyXgmlYRAVzBkyI6ibXx11EX4cqU+6/gyex9Dp W3QgX6/qCsogoq2YsPU5SHIiUr9fzjCRuC2nyxdXWeZHSOGYovcdHfgmm+UKARoDrxvZ XAb+2COBFwQRM3FR08F+NsBrEzN6cLMYo+VYB6qgsIMjyntVrIbSicLwfbOraXM48/5r Xw+9gouzq8leBsfjvtg53roSH5iVDTQJRr9j9+mROPt+b/9cksicnhx/agOdSPER+q4w Nd1YPjtLkQyyakOAfSM4o+nLly8j4sayirGaPWycIUlugJux5L9eTOespscK8Z0cIfGN JxIg== 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:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=tj2KmgzyWyW4aGv2hJrK5PY3UR9cpVWBwJX3v+8ecgM=; b=u1MM+MpyNknE4cafFrx6djPyd7AHiQD1GTVY3PWPGR8VVPdUQqp43JiQqzTJl3p6fg AeBQuYSQb+hNMe32Pod7fNa1uXJDTgfcuNEBwfHgEUfsu4+MuNseF2k2kmbarc38R20g n/HeX8wT5zIFN00os2+S4nYLKlgw4BnGYr8Kb6lX7DrKiUUTKyS15JSkRcoyuCqgOhT6 C0qLD9AlE2Cir8D53cXWmbZKxA/9SFr8ykW3exENpLSRDwZGdyzxUA+TflFeKoF2OFxJ g7vAGNj8B+1pljJ1+ZWw41YQ9C6gs1WB/+18jEp8tU5IB5/Og72ZdMWrvgdmKr55bgoS toxg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id t48si5719438wrc.507.2018.01.17.22.14.14; Wed, 17 Jan 2018 22:14:20 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 081F01B16A; Thu, 18 Jan 2018 07:14:14 +0100 (CET) Received: from NAM02-BL2-obe.outbound.protection.outlook.com (mail-bl2nam02on0064.outbound.protection.outlook.com [104.47.38.64]) by dpdk.org (Postfix) with ESMTP id 231901B025 for ; Thu, 18 Jan 2018 07:14:12 +0100 (CET) Received: from BN6PR03CA0064.namprd03.prod.outlook.com (10.173.137.26) by DM5PR03MB2700.namprd03.prod.outlook.com (10.168.197.138) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.428.17; Thu, 18 Jan 2018 06:14:11 +0000 Received: from BL2FFO11FD030.protection.gbl (2a01:111:f400:7c09::104) by BN6PR03CA0064.outlook.office365.com (2603:10b6:404:4c::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.407.7 via Frontend Transport; Thu, 18 Jan 2018 06:14:11 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; intel.com; dkim=none (message not signed) header.d=none; intel.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD030.mail.protection.outlook.com (10.173.161.40) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Thu, 18 Jan 2018 06:14:10 +0000 Received: from bf-netperf1.ap.freescale.net (bf-netperf1.ap.freescale.net [10.232.134.28]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0I6E6hA024428; Wed, 17 Jan 2018 23:14:09 -0700 From: Hemant Agrawal To: CC: Date: Thu, 18 Jan 2018 11:42:59 +0530 Message-ID: <1516255980-25092-2-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516255980-25092-1-git-send-email-hemant.agrawal@nxp.com> References: <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> <1516255980-25092-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131607296508466687; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(7966004)(396003)(39860400002)(39380400002)(376002)(346002)(2980300002)(1110001)(1109001)(339900001)(3190300001)(199004)(189003)(53936002)(48376002)(97736004)(4326008)(50226002)(8676002)(8936002)(85426001)(50466002)(36756003)(81166006)(81156014)(86362001)(316002)(508600001)(51416003)(26005)(2950100002)(6916009)(6666003)(2906002)(68736007)(16586007)(2351001)(356003)(106466001)(305945005)(47776003)(76176011)(104016004)(105606002)(5660300001)(59450400001)(77096007); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2700; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD030; 1:Sxrc6A/MajNrW1ggpllnaFUO1tvgKwsLtVEEXcscawfnFJe5d6dw15LycFkwAmNYYxsBFdkMzPZ+43sMbwg0BynsdN7S2V92uMECXazphiQC6XvDDEgcj/iP3XJPRxZL MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c141373-cb81-4252-95ff-08d55e3ab0b3 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(5600026)(4604075)(2017052603307); SRVR:DM5PR03MB2700; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2700; 3:NFwhzHXovxRQVRCHr2acGtf1KdMRq1aLXNyybg0iuNkWqQ+Se0ZlIl4EfaSzyqd07RnHVy00quykTidw0XL0VmXpXDCacP+A2fRDOS6B87Ku9VpDYjURCuEpu+os7eVfI/eD0LT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1+yxl/3s15576ldZDlJ7Unp/VNVlhoYELnMqMu0pBAj3VmHmHN0zqzvHU+knawcvbNDIPUBcmCi/lxnDy2fqQHURN7Xu9STLdVqo196y1WMhELG5K3S4QriotImi5 X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(5005006)(8121501046)(10201501046)(3231023)(944501161)(3002001)(93006095)(93001095)(6055026)(6096035)(201703131430075)(201703131441075)(201703131448075)(201703131433075)(20161123561025)(20161123565025)(20161123556025)(20161123559100)(20161123563025)(201708071742011); SRVR:DM5PR03MB2700; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:DM5PR03MB2700; X-Forefront-PRVS: 05568D1FF7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2700; 23:kCVbFo/6LBShE5dOGH8LzmAVshNq+FjH+9itDwcrq?= IrceuDgQ6e1MFSdniumgr2+UhzRxo6njgXwjmZodNdbrWtz3WATC84wO2O4hasEroQVzhnOVcBDjAzBEGM57fCU3cCBm4p6eYCnEIlOwU5C8/ZjXKFA5N4hH4GvxhSiL2Sk2KVTgyCaXjmHQOqqM51YDW4XAdiFf4ohy+2GQvHJ5xlh5y426BNmEfqjEHu45nvs+ahhRux4cjXinqWWWeVTOkox6mCQ5MJKpFlEkcPa6TyxTWaRQAZvRyzyxrTFdF9QdfCPaRL5rKmL5nzN29GkkN9R6gwzIRhn8OSZFg0OzAmKPsTCGK1LwmMNd26sOrAltt6gqAVgY9gesVLqvKU9+jCGaZZU6OIHMf4jiKHHOrfi0TtsP6NaJepPLSD2QnRCF9d1oyBrtNmd/uuIi8NeCpROGlhQuad302lo0qzYXYFNnOjo9exqGPCIQshjk1gFRmFbKUokcJZlQA+Zt3ICxCrocqJlqu4DsDSXyX0cchg+JCMi0KZXtAN8OrfVOLd1sZu3VwSQeB3DUPQ9TlV+AMW27nke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dKKGErvxxejcD4nKctY9WhIKITsvN0XnRVamRDIjA718zMtNJ9UY+w=; 24:k+W2VAq9dO/LJ0ACJOhGkHV/e9EVrGyOSNKFtn3pNOvmmAhkps9Z/3bVbQzqc6o4rRELvx/tJRlDCRumzl8hJCYDlU8AISUC17WDzn4RdUo=; 7:FSbhVTweoQsfukL5daKQb5b6QZBw26etr3EAzmjvbVcs+K00y24+9Eir6CT6I6pIvaC6HIeC8ad04u8Gtc4B5p/gib4PFgDiQ8U4LSKVhHmeOlp+UeKRsxT+07cUBxPf0hXsw7ze9HTePb0uCAv2ojMWFzwilQ1WXTTuyw4Dcwz04f/93CCNRosx3HqvRVPNGkbOdzmiW/NrLQLz+qtTrYmlkwaXCSmfcmbYlyhJ/etEusQYHoAoTtuFjyV5wpfD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 06:14:10.6906 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c141373-cb81-4252-95ff-08d55e3ab0b3 X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR03MB2700 Subject: [dpdk-dev] [PATCH v3 2/3] kni: add support for promisc mode set X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Inform userspace app about promisc mode change Signed-off-by: Hemant Agrawal --- v3: fix checkpatch warning and compilation err doc/guides/sample_app_ug/kernel_nic_interface.rst | 15 ++++++++--- .../linuxapp/eal/include/exec-env/rte_kni_common.h | 2 ++ lib/librte_eal/linuxapp/kni/kni_net.c | 17 ++++++++++++ lib/librte_kni/rte_kni.c | 31 +++++++++++++++++++++- lib/librte_kni/rte_kni.h | 3 +++ test/test/test_kni.c | 2 ++ 6 files changed, 66 insertions(+), 4 deletions(-) -- 2.7.4 diff --git a/doc/guides/sample_app_ug/kernel_nic_interface.rst b/doc/guides/sample_app_ug/kernel_nic_interface.rst index d7989bf..fdd061e 100644 --- a/doc/guides/sample_app_ug/kernel_nic_interface.rst +++ b/doc/guides/sample_app_ug/kernel_nic_interface.rst @@ -512,11 +512,11 @@ Callbacks for Kernel Requests To execute specific PMD operations in user space requested by some Linux* commands, callbacks must be implemented and filled in the struct rte_kni_ops structure. -Currently, setting a new MTU, change in mac address and configuring the network interface(up/ down) -are supported. +Currently, setting a new MTU, change in mac address, configuring promiscusous mode +and configuring the network interface(up/ down) are supported. Default implementation for following is available in rte_kni library. Application may choose to not implement follwoing callbacks: - ``config_mac_address`` + ``config_mac_address`` and ``config_promiscusity`` .. code-block:: c @@ -525,6 +525,7 @@ may choose to not implement follwoing callbacks: .change_mtu = kni_change_mtu, .config_network_if = kni_config_network_interface, .config_mac_address = kni_config_mac_address, + .config_promiscusity = kni_config_promiscusity, }; /* Callback for request of changing MTU */ @@ -611,3 +612,11 @@ may choose to not implement follwoing callbacks: { ..... } + + /* Callback for request of configuring promiscuous mode */ + + static int + kni_config_promiscusity(uint16_t port_id, uint8_t to_on) + { + ..... + } diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h index 62b4a05..b186417 100644 --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h @@ -29,6 +29,7 @@ enum rte_kni_req_id { RTE_KNI_REQ_CHANGE_MTU, RTE_KNI_REQ_CFG_NETWORK_IF, RTE_KNI_REQ_CHANGE_MAC_ADDR, + RTE_KNI_REQ_CHANGE_PROMISC, RTE_KNI_REQ_MAX, }; @@ -42,6 +43,7 @@ struct rte_kni_request { uint32_t new_mtu; /**< New MTU */ uint8_t if_up; /**< 1: interface up, 0: interface down */ uint8_t mac_addr[6]; /**< MAC address for interface */ + uint8_t promiscusity;/**< 1: promisc mode enable, 0: disable */ }; int32_t result; /**< Result for processing request */ } __attribute__((__packed__)); diff --git a/lib/librte_eal/linuxapp/kni/kni_net.c b/lib/librte_eal/linuxapp/kni/kni_net.c index 3e35008..9f9b798 100644 --- a/lib/librte_eal/linuxapp/kni/kni_net.c +++ b/lib/librte_eal/linuxapp/kni/kni_net.c @@ -584,6 +584,22 @@ kni_net_change_mtu(struct net_device *dev, int new_mtu) return (ret == 0) ? req.result : ret; } +static void +kni_net_set_promiscusity(struct net_device *netdev, int flags) +{ + struct rte_kni_request req; + struct kni_dev *kni = netdev_priv(netdev); + + memset(&req, 0, sizeof(req)); + req.req_id = RTE_KNI_REQ_CHANGE_PROMISC; + + if (netdev->flags & IFF_PROMISC) + req.promiscusity = 1; + else + req.promiscusity = 0; + kni_net_process_request(kni, &req); +} + /* * Checks if the user space application provided the resp message */ @@ -693,6 +709,7 @@ static const struct net_device_ops kni_net_netdev_ops = { .ndo_open = kni_net_open, .ndo_stop = kni_net_release, .ndo_set_config = kni_net_config, + .ndo_change_rx_flags = kni_net_set_promiscusity, .ndo_start_xmit = kni_net_tx, .ndo_change_mtu = kni_net_change_mtu, .ndo_do_ioctl = kni_net_ioctl, diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index a140dfc..c089a49 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -525,6 +525,26 @@ kni_config_mac_address(uint16_t port_id, uint8_t mac_addr[]) return ret; } +/* default callback for request of configuring promiscuous mode */ +static int +kni_config_promiscusity(uint16_t port_id, uint8_t to_on) +{ + if (port_id >= rte_eth_dev_count() || port_id >= RTE_MAX_ETHPORTS) { + RTE_LOG(ERR, KNI, "Invalid port id %d\n", port_id); + return -EINVAL; + } + + RTE_LOG(INFO, KNI, "Configure promiscuous mode of %d to %d\n", + port_id, to_on); + + if (to_on) + rte_eth_promiscuous_enable(port_id); + else + rte_eth_promiscuous_disable(port_id); + + return 0; +} + int rte_kni_handle_request(struct rte_kni *kni) { @@ -564,6 +584,14 @@ rte_kni_handle_request(struct rte_kni *kni) req->result = kni_config_mac_address( kni->ops.port_id, req->mac_addr); break; + case RTE_KNI_REQ_CHANGE_PROMISC: /* Change PROMISCUOUS MODE */ + if (kni->ops.config_promiscusity) + req->result = kni->ops.config_promiscusity( + kni->ops.port_id, req->promiscusity); + else if (kni->ops.port_id != UINT16_MAX) + req->result = kni_config_promiscusity( + kni->ops.port_id, req->promiscusity); + break; default: RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id); req->result = -EINVAL; @@ -714,7 +742,8 @@ kni_check_request_register(struct rte_kni_ops *ops) if ((ops->change_mtu == NULL) && (ops->config_network_if == NULL) - && (ops->config_mac_address == NULL)) + && (ops->config_mac_address == NULL) + && (ops->config_promiscusity == NULL)) return KNI_REQ_NO_REGISTER; return KNI_REQ_REGISTERED; diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 370b02a..711c2a9 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -45,6 +45,9 @@ struct rte_kni_ops { /* Pointer to function of configuring mac address */ int (*config_mac_address)(uint16_t port_id, uint8_t mac_addr[]); + + /* Pointer to function of configuring promiscuous mode */ + int (*config_promiscusity)(uint16_t port_id, uint8_t to_on); }; /** diff --git a/test/test/test_kni.c b/test/test/test_kni.c index 4513de1..9917e8a 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -75,6 +75,7 @@ static struct rte_kni_ops kni_ops = { .change_mtu = NULL, .config_network_if = NULL, .config_mac_address = NULL, + .config_promiscusity = NULL, }; static unsigned lcore_master, lcore_ingress, lcore_egress; @@ -233,6 +234,7 @@ test_kni_register_handler_mp(void) .change_mtu = kni_change_mtu, .config_network_if = NULL, .config_mac_address = NULL, + .config_promiscusity = NULL, }; if (!kni) { From patchwork Thu Jan 18 06:13:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 124920 Delivered-To: patch@linaro.org Received: by 10.80.140.226 with SMTP id r31csp3134757edr; Wed, 17 Jan 2018 22:14:25 -0800 (PST) X-Google-Smtp-Source: ACJfBou0OTGAYJgPUtdmAJtfY7yyJjCZQA+olCDbd88DmUU5W0O39lF+6VgTw2uYqEYEuBtGVTM8 X-Received: by 10.223.138.178 with SMTP id y47mr4585989wry.257.1516256064929; Wed, 17 Jan 2018 22:14:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1516256064; cv=none; d=google.com; s=arc-20160816; b=gqmQF9uU6va5j8pJtEUYyPonivQBXgDj3qS2QN16DMup6LC0hRI2Y/HJ2INyOLSv19 Ea5FlbrtZLQfVjES8UqwG3pziyFn/t9jdZDDVsJ8J2nkBnWyELObtGufTSzLcNKQpwXu 8ciFK8FfBhsGkhJ/tle+wbtahgUy1H155wSpNj+z0C/P9jw8E2YqYGiWssYdUkAaqgfM Z6xAedUsEJriqZyXWjMJZW2mW7IJqOGDb5lpypae7aJhewM0Pewh6Q//4UX6pOsVfdlE XLV3lJIl+xIqvIXBA/E86Qkwhk2RwA0RGVehsvaoiMzPOMRn+ZYZnPIsdbcAvUfg2AbH oTYA== 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:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:references:in-reply-to:message-id :date:cc:to:from:arc-authentication-results; bh=mjRYqLyPR5ojxH8TNLj/waN1pXIwXeXSizgJT/xm/2s=; b=m1F/abaqxfRxvHsHx7Oz8NRyLwV4Nu2F6zSKfFRTUOTnr4M+fEvKshOxOrsnNF1Zv9 InUeKJisUkbvX0Cdx0xT0DsCtQYIlnB42dFF6RnFsRo5d/O4baCFb1+AEvoC6TKDsNrM L3ckQB5pTufAuzzb+MTVuoUYg8k1+LhJ9klqmLeGo9aV50yG+1rTocT3DRwP1UDimezf u6gkkJ4RsOb6XmU3x1QAACv/PvKtq9eUF9ML5J+q6PchZusIv/HO9vtW67c1nesVvGRl r47X/i6vMNcu3G3p3MCnj8qtLJl08QwmYQD2ZaRiy2ExEsF4Zzk0qI6W3CG2GzfwduY6 205Q== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from dpdk.org (dpdk.org. [92.243.14.124]) by mx.google.com with ESMTP id a21si5495011wra.286.2018.01.17.22.14.24; Wed, 17 Jan 2018 22:14:24 -0800 (PST) Received-SPF: pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) client-ip=92.243.14.124; Authentication-Results: mx.google.com; spf=pass (google.com: domain of dev-bounces@dpdk.org designates 92.243.14.124 as permitted sender) smtp.mailfrom=dev-bounces@dpdk.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 922E61B1B8; Thu, 18 Jan 2018 07:14:17 +0100 (CET) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0040.outbound.protection.outlook.com [104.47.34.40]) by dpdk.org (Postfix) with ESMTP id 8963D1B1B8 for ; Thu, 18 Jan 2018 07:14:15 +0100 (CET) Received: from CY4PR03CA0105.namprd03.prod.outlook.com (10.171.242.174) by BN6PR03MB2691.namprd03.prod.outlook.com (10.173.144.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.407.7; Thu, 18 Jan 2018 06:14:14 +0000 Received: from BL2FFO11FD005.protection.gbl (2a01:111:f400:7c09::115) by CY4PR03CA0105.outlook.office365.com (2603:10b6:910:4d::46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.428.17 via Frontend Transport; Thu, 18 Jan 2018 06:14:13 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; intel.com; dkim=none (message not signed) header.d=none; intel.com; dmarc=fail action=none header.from=nxp.com; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BL2FFO11FD005.mail.protection.outlook.com (10.173.161.1) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Thu, 18 Jan 2018 06:14:12 +0000 Received: from bf-netperf1.ap.freescale.net (bf-netperf1.ap.freescale.net [10.232.134.28]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id w0I6E6hB024428; Wed, 17 Jan 2018 23:14:10 -0700 From: Hemant Agrawal To: CC: Date: Thu, 18 Jan 2018 11:43:00 +0530 Message-ID: <1516255980-25092-3-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516255980-25092-1-git-send-email-hemant.agrawal@nxp.com> References: <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> <1516255980-25092-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131607296524784087; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(376002)(396003)(39860400002)(346002)(39380400002)(2980300002)(1109001)(1110001)(3190300001)(339900001)(189003)(199004)(48376002)(2351001)(50466002)(2906002)(6666003)(76176011)(97736004)(2950100002)(6916009)(51416003)(105606002)(498600001)(5660300001)(36756003)(47776003)(106466001)(86362001)(26005)(85426001)(316002)(8936002)(8676002)(16586007)(81166006)(81156014)(68736007)(53936002)(104016004)(4326008)(50226002)(356003)(305945005)(77096007); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2691; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BL2FFO11FD005; 1:rpibNDLXFNawJ+kn3kGq50SDiP5XuIxwmAzKVPuD6GZ0BEr0eU9I3qqKMEriEfHIGr7TZQA4t4etTyaCfqTiUJdoC3liKoKE4uqm/EctVpQTfeoRdGi+1ROAA1u76qun MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ed93190-e896-4842-91d7-08d55e3ab1ac X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(5600026)(4604075)(2017052603307); SRVR:BN6PR03MB2691; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2691; 3:66Oj0u0xlJvtnnu0/6tw7fRebuSsnXOf4UNWH2KpiqRH8jbqbQ6/4oSBMhkggj/AoShd8uz9syRrqL+GL3rMAysBoF7nYAOfmZ03m3GrZvdy6MjXTb881qyQhxtvtcGd2HzKPL+B2Z2jUI5Ngg50ZGQkqelO0J1XyHpWpLVrzKjzz0TEjgZ26Be+P4mWntMvLjc6zkIhg2pL01zoWR28NFLO5/x2UjAnN7krzXpfr1H00txGtPJXTXBoNVWFkyhNwi432ng5nYxT6/GLLJ96q9zvq4478POll5Agc7bvBPt7PqKdjUUbKFoOVP5yfr80UhzReyJvjcB5P6kEjFtquanhWuTaK3gGccsbjICH/P8=; 25:lsuGkg9cxXkAI7+c4G9FzeawdQAmE250OK/J7ty1u8Bsuxi3cP6UKyHNog0BNhd9RBlMVy6QgJRo73sjqn7rxNQcNyendzUQbvAKApGNXHjjjcE7F4ZQ5qQRw7+rvpJ3PwJmmOUjfUAndQaIMCwiTVNcFQkPezcAqbS5JZjjiGs3pQZX7U97G6kyDbk0ozWh7Z3UfdBAnHbRTOBxJb1vsYwJIWCl5b92dtvfBvaL3n6aWt6zllkcQedGoA4+ZKkf1N1Tr2XByv9F5Qzsn7Lse7gm+gmd4DGHY7MNoicgzVeF/f1tZqi/V/N5Ab8uLdLjmqx9CG9JW8G30b6uu0Z4uw== X-MS-TrafficTypeDiagnostic: BN6PR03MB2691: X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2691; 31:ZuqZe3hV1rGtLDlT4B7S3SIs97UF30m36fOhnW28m1cIixFX7dTy/jbRRNzKX4X6PbgauXgAlpUPdjWPUP1fDCs6siNt8WuTDX0TIniRBN5zZV1PBcjtDqbehB3KU+CQzMq1zhGC7eNvwu4CkSs1XvSci/NJ2ZwIHAhDiYNyHtQasdGxKy5Cj1GhcxhrDyOlvcal7LZcC9R6H5AZvR2O/AFzoUEeITcGB8Hz96tAwt8=; 4:M8RBVjLUBzRkBbH47OrclCtymPm8lzBTm/bdGipBq0SIy76rjiVVXfr4A2kOjU2cIluEaTVpx6CEdV3UAdKhk/fGiKfdyl8os9FJV6vrTseRp37esOHeKTMxcteggs7o9r9tC/g/T8UAoWcZHW7sYbtueVkmsWy7vc671xicop9XGXkDvIUm47XYDNG4WY7yNi02lqVFfA/J8YTNIuwCvVxP0L+xx3pG9qp7TzoOs9Fmm5mx28pFFoVmcKKf2ciHsc8+l28Icv1Z66SbbybdEtpaA+pLrd8GElATHZFPW7TIv8mxFS0725r+izQGTL6t X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6095135)(2401047)(8121501046)(5005006)(93006095)(93001095)(3002001)(3231023)(2400057)(944501161)(10201501046)(6055026)(6096035)(201703131430075)(201703131433075)(201703131448075)(201703151042153)(20161123559100)(20161123565025)(20161123556025)(20161123561025)(20161123563025)(201708071742011); SRVR:BN6PR03MB2691; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:BN6PR03MB2691; X-Forefront-PRVS: 05568D1FF7 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2691; 23:rM4QEnWpsnR2OeusEsI2nLQxNuOOcZZ8mkDT3uJxl?= yFZW7QKRuJcv1BP/jzYTqyXCfhbgMnj5qKTHLukT/zGv9oSut00JR3PrEh5pejJLvdz6YnDvacPTwt1kOxegF+f3/aXVr3ac/gffSlk0ryW3jOoHPUSPKgz0nuxnfAOBmTmuVT6uScOWReIn637KvoO8qDJk0rWWb6ebeKx9jSjUQ0nyJ70FOoUwx7n1zpzeeTT5F7uTu7ZvzM3o5gfbyOnqoObfVZpwF2MePe92ePSa1VrWrYQKwoEmGunZYjiyU0Lb0BbFJ7chd5kE0QQL/ErOxrB2T0kh91GYDEwwj8U3SbikurQZcjS5tVdeBjj7W3mOXqpOLsUVNSaJhGe3QFUeC47uwJNB+rfIqQlU2p6ib+AB7Rsq8Q5f8GYSOKvO2e/u0M99EDeWRA/V1EKxIP6SubJVs1FaKWBxYEpGrZRZtKi1x+Jw67N57TmfeEgLR8XenVm9yk5pbQCzNlzd1VnKJB/g0ytNiFK8RiKhiC9P1LQU2jK4LfG6ig1r4ovoQFQXwjOTaOI+PlfuWUBXMLC0APyyK4gqpKwNUkx0yIR9rUJhcj0yfZkkwOR/FLXfQz4KUxj+RfuAkdU8D+AdhzNnJJ011xahc9aC9ho341dP68h075tsQMASZaesrtxQ5vp+WKU5rFxwLt5lfJ71cQfZOMY8v7cMrAJjK1p6zvUUIxkiWhzdyfzJakuIJeJIBuPgz4xxqYcJ9iV6llITxiy50wN7t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JFxpTAqEm2lhVW5M52L5vllxOARYJEa42EFQbH7Dr2mP5YVwBe2pizjwuCFlBXoDEcZxbYbvHwz9OoS1loeC0dMc4l9hkfye0BfpSVlJ7RHUvDUvQ5hkZW1yFuT9S2MQZARekpWuKekU0Lson3A1Y+QWxWAF35LT/NKdwm4Dr1G SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Jan 2018 06:14:12.3068 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ed93190-e896-4842-91d7-08d55e3ab1ac X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR03MB2691 Subject: [dpdk-dev] [PATCH v3 3/3] kni: set initial value for MTU X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" Configure initial application provided mtu on the KNI interface. Signed-off-by: Hemant Agrawal --- examples/kni/main.c | 2 ++ lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h | 1 + lib/librte_eal/linuxapp/kni/kni_misc.c | 3 +++ lib/librte_kni/rte_kni.c | 1 + lib/librte_kni/rte_kni.h | 1 + 5 files changed, 8 insertions(+) -- 2.7.4 diff --git a/examples/kni/main.c b/examples/kni/main.c index ebec433..e5cc30e 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -846,6 +846,8 @@ kni_alloc(uint16_t port_id) rte_eth_macaddr_get(port_id, (struct ether_addr *)&conf.mac_addr); + rte_eth_dev_get_mtu(port_id, &conf.mtu); + memset(&ops, 0, sizeof(ops)); ops.port_id = port_id; ops.change_mtu = kni_change_mtu; diff --git a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h index b186417..cfa9448 100644 --- a/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h +++ b/lib/librte_eal/linuxapp/eal/include/exec-env/rte_kni_common.h @@ -120,6 +120,7 @@ struct rte_kni_device_info { /* mbuf size */ unsigned mbuf_size; + unsigned int mtu; char mac_addr[6]; }; diff --git a/lib/librte_eal/linuxapp/kni/kni_misc.c b/lib/librte_eal/linuxapp/kni/kni_misc.c index 83649ce..01574ec 100644 --- a/lib/librte_eal/linuxapp/kni/kni_misc.c +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c @@ -451,6 +451,9 @@ kni_ioctl_create(struct net *net, uint32_t ioctl_num, random_ether_addr(net_dev->dev_addr); } + if (dev_info.mtu) + net_dev->mtu = dev_info.mtu; + ret = register_netdev(net_dev); if (ret) { pr_err("error %i registering device \"%s\"\n", diff --git a/lib/librte_kni/rte_kni.c b/lib/librte_kni/rte_kni.c index c089a49..2867411 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -340,6 +340,7 @@ rte_kni_alloc(struct rte_mempool *pktmbuf_pool, dev_info.force_bind = conf->force_bind; dev_info.group_id = conf->group_id; dev_info.mbuf_size = conf->mbuf_size; + dev_info.mtu = conf->mtu; memcpy(dev_info.mac_addr, conf->mac_addr, ETHER_ADDR_LEN); diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h index 711c2a9..99055e2 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -69,6 +69,7 @@ struct rte_kni_conf { __extension__ uint8_t force_bind : 1; /* Flag to bind kernel thread */ char mac_addr[ETHER_ADDR_LEN]; /* MAC address assigned to KNI */ + uint16_t mtu; }; /**