From patchwork Tue Dec 26 10:36:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 122745 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp785560qgn; Tue, 26 Dec 2017 02:37:57 -0800 (PST) X-Google-Smtp-Source: ACJfBouSuEyvhGGT0/JbGjQ0yuo+s6pwr1Mo6mSFYxWYfQlNmPMGdTNsYmsiUlVfP6ierZv5x3/q X-Received: by 10.28.224.4 with SMTP id x4mr19874640wmg.118.1514284676988; Tue, 26 Dec 2017 02:37:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514284676; cv=none; d=google.com; s=arc-20160816; b=w/2xZ+vgpmRO1+19wKz0lGPymZGDD1T2OCjVpbRs60z45hYOygpuer3KmtFBn82XFi L2oxbSphoNSpSLmII3xIvRFnFpyWMDbDCIgu9mg2K29Y+BuqUWDV3Bz3Xl75djszNv9n xeBbRyx7Awm0aqD62oYNAa6F91YmnMDauXXTw9NFhcE3DA5ndITWSuheGsxTv9OOhpVF qRSI5R1ETcjVk926ZkUPJBFuz2c3RBmYE2w2WngKWnWlBTNErHfJvz/ABUm2GJ69Ti9g z4/wlksdROJkV9+sFk+l2opvAmLBLHIl78CJU1rjdVqfj/lgVW0CADABaReTMdipKVw9 Eutw== 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=Ln0EYuBkbpKyWjO+Fei0C0mzF/8a24PLlrnWIMbP2Uc=; b=MTZUMAQLKg9qw5w5klTUnpqL10rZFfeZklnIRNV8f1XAT/XMKxLDLLzSamomQTqBGk 4VcEXm0bliN4dUDyAfsJIi3k/TDMB80Czk4fkhyW3y8yACJoXBAMBMWCkLa2eJq9t8Ie OZCegUw5Zson0Ob3zeFGTe9qloc2oa1MKfMwoBMc8uZR/t/wagQQ1/+O8lXcLOd8kHs+ 0lb5zVX67oxsRSgjNE0fNTBigHEGAkMgKwKobfN9gdnYw9Msl8IrHQeXvU20PH/BCx3n YoH2rouU2NtcDoAbzLskm46bksbnggE2+9yjy2yEn2fd7akFvEUSjMaOOJsYIQQPfiY1 ZI6Q== 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 n188si11628334wma.203.2017.12.26.02.37.56; Tue, 26 Dec 2017 02:37:56 -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 E75321B257; Tue, 26 Dec 2017 11:37:55 +0100 (CET) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0056.outbound.protection.outlook.com [104.47.40.56]) by dpdk.org (Postfix) with ESMTP id 316DF1B243 for ; Tue, 26 Dec 2017 11:37:54 +0100 (CET) Received: from CY1PR03CA0002.namprd03.prod.outlook.com (2603:10b6:600::12) by SN2PR03MB2367.namprd03.prod.outlook.com (2603:10b6:804:e::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.366.8; Tue, 26 Dec 2017 10:37:52 +0000 Received: from BN1AFFO11FD028.protection.gbl (2a01:111:f400:7c10::163) by CY1PR03CA0002.outlook.office365.com (2603:10b6:600::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.366.8 via Frontend Transport; Tue, 26 Dec 2017 10:37:52 +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 BN1AFFO11FD028.mail.protection.outlook.com (10.58.52.88) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.302.6 via Frontend Transport; Tue, 26 Dec 2017 10:37:33 +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 vBQAbmDx009888; Tue, 26 Dec 2017 03:37:49 -0700 From: Hemant Agrawal To: CC: Date: Tue, 26 Dec 2017 16:06:46 +0530 Message-ID: <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1512042367-6361-1-git-send-email-hemant.agrawal@nxp.com> References: <1512042367-6361-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131587582533542605; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(336005)(346002)(376002)(39380400002)(39860400002)(396003)(2980300002)(1109001)(1110001)(3190300001)(339900001)(189003)(199004)(104016004)(2906002)(16586007)(316002)(6666003)(4326008)(53936002)(77096006)(86362001)(47776003)(85426001)(105606002)(50466002)(305945005)(356003)(48376002)(51416003)(2950100002)(6916009)(76176011)(498600001)(50226002)(68736007)(8936002)(97736004)(36756003)(106466001)(2351001)(81166006)(59450400001)(5660300001)(81156014)(8676002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR03MB2367; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD028; 1:CSN+FeXLWuLb+e/jElYk54ehAleqexufnTigWPmmOfAP1qEw8NL/qPuo6zD9UvJWfAw29MMz/WQn5r/yAcU1yJaWOmXvoFRoQ1FAj60ECnIpEGuc6LPPTyBf++Xs5a6X MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 15ccfc9e-d1ec-4909-a2cd-08d54c4cac3a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4628075)(201703131517081)(5600026)(4604075)(2017052603307); SRVR:SN2PR03MB2367; X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2367; 3:FoBFRJnEBMo12tnZDFTunm8ODyZ8Nd5FCmg7sLWIbIDpZZ/WT37CQzIsT+Bcqs4otIObTzQ1IWX5YWjyxvV9mvcKe4s5n1DhtKtcruZeuL5wdD/YoD+1CS+ThtXYwbNGpIkEZItwBG9nB6JWvjIkS8p7Y9gi/aYcSoWPZ5BkW3f4SSfb/IynSQFxEUXwsOr/+IDNG4a9MfC6OpVM+1dTrpxJLF83a6XZdG7iHoOnqXPyDfttkOlaGN98EuigCInH5lUG8u0Jtac6N6wIyWCPram4PefzJTd1E9s7ZUrj9jFrFhQR/xlfm59I7cO+PKRql3w1/pB6iNHhKR1QzCYNnmOCSr5O5ycHhiKNSj9e6k8=; 25:tvwYrCKPU37+Gtg2goLv660dPTjxYNolKv2+BO8UYlSaJws6CEnBBRUq6h5eDnTUPOHT+rmgLxgiahXSSQ8iFVDS36HWnZm6CN6Hz0ZtiP8ZjQ1Jl2zsV+EJHGw1Oc6q6xW6zaFS6TN/ItGhOnph9SU4yJ9F/qjOvHr8PzUeuXBLbhX0WmNWwBQJ4wuNFnqu6QCUNo6VyIw92Z2yjW7P5b14SUOEi71mNTBqwZnuz/RIbLIJYcnrPePTtamTKfX6JoghjDVu3k014NfFopX4keI1aGQkg2x6Tm1rRNOkoBEnnN0Hx2iaqrVCGxqDGiQhsericLriS3fAYZzLnCGBjA== X-MS-TrafficTypeDiagnostic: SN2PR03MB2367: X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2367; 31:Yl7tt096qxsKndJysRSEI96+VWhLUQkwiEQ3aWIZyS6wMQwKE8+GIQrv64xX5UpfJECYQek8bnX0Ab5c7YZ5GjQOrWr4yArf2jAtAD0fMb8yPbj9ZoaDBQyE4inVZTpBwZP2TOlCZAkuJ3ZttRcjCcqo79DtPiGAUMxyZP8O/BAVYIsD0qi2tJd6n3e8cp1ase7OPHD+hjUZWJmHsYSMm3nmbduwrVuI2LkkwZBUvPQ=; 4:jQ1fOxinDI9nVyJ2fwFbP90WnmZNhgbvY3TuxM/0EBSL9T3qJ0MsVOfxmVbyTFDP4XfoTfXiZl8jLcf33lRlQB2S11buBgVy6RNUj0FpScNSIrwCRMVvXTC3uX+QjR70rE+4zLfLU3M/U4kMV7jnf928I3lpq7B4J8J3AtDkYc/wWUOcPM/vkMSQWHO6wDftbNae0d5b+A6hIlbOOhGLYcMulC+hFOpFBAUHkai+bAyi6MsW6ow9Cx/SUbD9VM3JtrEvij4J1NfEOtL0jg2cQwZStPPgS2X5yR1ptfAQ7ROgLV5+A1zpQtGIXTWN5xJO 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)(944510075)(944921075)(946801075)(946901075)(10201501046)(6055026)(6096035)(20161123563025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123559100)(20161123561025)(20161123556025)(20161123565025)(201708071742011); SRVR:SN2PR03MB2367; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:SN2PR03MB2367; X-Forefront-PRVS: 053315510E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB2367; 23:z6JH476MVvLkA4M1TujehYqR3N6SEI5XC8fw3d9ar?= kKfq+J58ISR1+yhzHfqlZu1N5yupa/ab8c0KifGglPzYH8rnpkF1Rf3BOdDa6YUEgkwIOeap4t1/E5SEGns3+4FXknaun9Tl5+fw3I88SiqnHROf+VpW4STZMd3sAEkxh5miIB3cqRmcMLgPw5k3Q0SfFjNbFE2C/ccpYrfB8HAbQ89OTMWwqL8/XigA36JalzJuhfG4/r8mHGYh8YNZziyqb+f95hDwurk8FUNv/1zlMhI1kSW6Te98kvXYm3ghYg/flIMqTHgJPODAiKdn/0ZVZzIWf0TemRLFmvT/T0PP3GRlP7qIJeeH9iSNJSHePDyExJrWGzJJPqhhp5YqLzyXDDMubGAJNkZIPsSED6ZIEs1CWYVdM7vgdEFnnAaGCrJzkzaDSuD7qbwyvWyc4AaWrjD1jR1kxCa68CgRfdMZIKVjr8x1PIs4/62olgaiSTvn1svRr+hjXuD853aWt6CKcc/wSoaKIhFQBuiTxRA59NQD2BPTscLXbz7qX1KmgNCuzmpihXCx+e8nbi5KsGxGhCWYdkTcw7ug7MGnq64eBsfiY0ejzsQeDKMbFJ12e974BCM3QCNKiUrQXBkErMoQDFvSZ3vWpM5LQuk3m0ImIrtAzKeLuY0segWvuGMzoFx5XOj7q77h11x3IybIQMi1skqbDhyjh+EEVlXJ39h4fMBXPHGukfqRpbmbTAg9RAzoR7I6CB2uwMgJpW9Vdxalcw5/Wcr9ZEUqpuMjiaPlp+yVlfMUhYDvjnUQ6Gu4D/Tq26ZKjRRrq5TMBsvEw3zkWPijPkrQKUB2vVcoqNH9nX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q5dWpmvylzTtClgF5B2zXhz6zTanm8NY5c1oRQ0YMIgzMzqZ/DtjmFfxEnVxA0TUwxdTO83yQ+zEp0TO9/2005NTHQNTB2FDjf7ySDsb4DJDFGiflP+cSDqD/gqH SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2017 10:37:33.1982 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 15ccfc9e-d1ec-4909-a2cd-08d54c4cac3a 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: SN2PR03MB2367 Subject: [dpdk-dev] [PATCH v2 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 --- v2: * fix ABI breakage * reducing the code in documentation. * initialize ops.portid to UNIT16_MAX for vdev case 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 diff --git a/doc/guides/sample_app_ug/kernel_nic_interface.rst b/doc/guides/sample_app_ug/kernel_nic_interface.rst index e1ac415..2c143da 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 3f17385..1c251c2 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -163,6 +163,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); @@ -766,6 +767,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) { @@ -809,11 +841,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 2ac879f..1a760de 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 @@ -80,6 +80,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, }; @@ -92,6 +93,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__)); @@ -168,6 +170,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 7590f1f..b524d30 100644 --- a/lib/librte_eal/linuxapp/kni/kni_misc.c +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c @@ -458,12 +458,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 db9f489..3e02ea1 100644 --- a/lib/librte_eal/linuxapp/kni/kni_net.c +++ b/lib/librte_eal/linuxapp/kni/kni_net.c @@ -668,12 +668,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 8eca8c0..a5ee210 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -356,6 +356,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; @@ -368,6 +370,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); @@ -528,6 +532,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) { @@ -559,6 +585,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 != UNIT16_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; @@ -707,7 +741,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 ((NULL == ops->change_mtu) + && (NULL == ops->config_network_if) + && (NULL == ops->config_mac_address)) return KNI_REQ_NO_REGISTER; return KNI_REQ_REGISTERED; @@ -746,8 +782,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 d43b5b2..9bdc9f3 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -49,6 +49,7 @@ #include #include #include +#include #include @@ -70,6 +71,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[]); }; /** @@ -90,6 +94,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 b956727..06448c9 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -103,6 +103,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; @@ -260,6 +261,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 Tue Dec 26 10:36:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 122746 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp785684qgn; Tue, 26 Dec 2017 02:38:04 -0800 (PST) X-Google-Smtp-Source: ACJfBovuDCS83ERA5toX7nzFjjUMYYZVwm68s1ajE9uOOfUmeq5dEQeKJK97qbuJY1S2t/yT80Rg X-Received: by 10.223.163.141 with SMTP id l13mr24470761wrb.136.1514284684546; Tue, 26 Dec 2017 02:38:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514284684; cv=none; d=google.com; s=arc-20160816; b=KucmoZRa9GQ0t+MsH7vOKrbFtGUrczImKocXzyR2HW9g8p6Aer1rYDVEdcSaAUECl8 vnpKx5pzllvJ73J8QRWrV4ZRKt+2fvDti4qZLyzatPK0NS71YGTIf4B/pyoPHUC4A6WZ KkXu+Z8sWgcmUp46NUYqttnuZCtjjHSpdIeWnySGhZMYFxJAuId+oRiC0+Pf7mPIIYNZ pjZuPidRY3n25O8BrHdFOY0MM5K34DKBZa/ZfpN0hqdqcipuzLAybieq8+0Z8pDkmuwz QUT5QXmox2Ri+qJWR6xYl5B2828mO2B5DBXClAEF+7nGebBrMO6W2T6i9VB8aQPI1z/j 07ZA== 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=Ues18tjveMP8WIWF4pzUTzb+YlDqZtBYTViz1+A4Iww=; b=CpFbzdrZMPZ6FE+w94p1Ait+lut9rwV8im8Pg490L79OiVPFxKCJBEN513COreaTrM kKjbozOaChovgRyZaDipl7MCmChgJKpO+Jwx0+WHzWk8IQIFFO+YNjJDeBUIUKqex7zO Wf1HCAvghTp7f65LNNs5Kc1MEnEX6vKkO5+lYbjEwgYMXih13E92omhONVCLan/mShwX 1f/b7dQGqqGh+GdYN7msRpyfGq2PimMTnDewDiiRWxmXWkg5jYDJbCSNSFObEpyXEqsd gexg7YhfLqXYuGwxW4qWBUdaTo1xlaN3NUrfzA64kvSMCWEaP7PpGldCqbuuFwNBwk9K sn2g== 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 b18si8865684wrh.491.2017.12.26.02.38.04; Tue, 26 Dec 2017 02:38:04 -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 6C79A1B2D6; Tue, 26 Dec 2017 11:37:59 +0100 (CET) Received: from NAM02-CY1-obe.outbound.protection.outlook.com (mail-cys01nam02on0074.outbound.protection.outlook.com [104.47.37.74]) by dpdk.org (Postfix) with ESMTP id B13F71B243 for ; Tue, 26 Dec 2017 11:37:55 +0100 (CET) Received: from MWHPR03CA0026.namprd03.prod.outlook.com (10.174.173.143) by DM5PR03MB2699.namprd03.prod.outlook.com (10.168.197.137) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.323.15; Tue, 26 Dec 2017 10:37:54 +0000 Received: from BN1AFFO11FD019.protection.gbl (2a01:111:f400:7c10::146) by MWHPR03CA0026.outlook.office365.com (2603:10b6:301:3b::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.366.8 via Frontend Transport; Tue, 26 Dec 2017 10:37:53 +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 BN1AFFO11FD019.mail.protection.outlook.com (10.58.52.79) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Tue, 26 Dec 2017 10:37:34 +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 vBQAbmE0009888; Tue, 26 Dec 2017 03:37:51 -0700 From: Hemant Agrawal To: CC: Date: Tue, 26 Dec 2017 16:06:47 +0530 Message-ID: <1514284608-9263-2-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: <1512042367-6361-1-git-send-email-hemant.agrawal@nxp.com> <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131587582548182740; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(336005)(376002)(396003)(39860400002)(346002)(39380400002)(2980300002)(1109001)(1110001)(339900001)(3190300001)(189003)(199004)(68736007)(85426001)(51416003)(4326008)(498600001)(76176011)(5660300001)(2351001)(106466001)(2906002)(305945005)(59450400001)(8676002)(8936002)(50226002)(81156014)(81166006)(6916009)(6666003)(86362001)(53936002)(97736004)(36756003)(50466002)(104016004)(77096006)(105606002)(356003)(47776003)(2950100002)(48376002)(316002)(16586007); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2699; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD019; 1:WvMpxNLdngyGqz26x8wmWIYaXGizpTOJoaNPHUrTRaiAdW8qcb3opaHE74nHvdezwayCkygJzPd6hCo5LdEYdaUg3WnHc7ToZ9vgdU0oHahv3qFkUcKthPUsB265pY2d MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f234bbf2-8f3b-4693-06d4-08d54c4cad1a X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(5600026)(4604075)(4534020)(4628075)(201703131517081)(2017052603307); SRVR:DM5PR03MB2699; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2699; 3:8BJtrvxBrdFA5mf3azDpcAf9qX/Lu5GMSIhv/3TIMhUiT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uYZ4JeF0vn5+4yW41leAuL4uZ4Eyon9hWZlo9nb2e47gOtI/6SfdEiH7JTJ5h2vgXuXkjtiMckU4gEae/N9zIJRP9+4Rjg4x59kxegg6bAA+T7jFUrm2hV+fQRiHHCCC4verXlWG8FwtHv54fCfXAAx7AIn1sIaASlGK0IFcBYCOeqDrJ9msD60Ao+BalNx97XAHvHZy6MzQGz6W/SCRRgr 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)(10201501046)(3002001)(3231023)(944510075)(944921075)(946801075)(946901075)(6055026)(6096035)(20161123556025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123559100)(20161123561025)(20161123563025)(20161123565025)(201708071742011); SRVR:DM5PR03MB2699; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:DM5PR03MB2699; X-Forefront-PRVS: 053315510E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM5PR03MB2699; 23:LF9RLDaaDW+wq+2GYXh+msdp5NOmicTiVqAo2dY2G?= ZvQgs+61UDj14dztE7FLNfIM7+METvUNE6cTR/eTRJzYzAeo7lZGZlkJ2TPiCw+767JNSQrwG5fScogHbuwh8BkAbK6rF7Dk2flXQuq+4SxT6Jj3QcD0WqeXH+33weA+XxXWAhsazIWGMs9jXHdjzU6k4BAU6C2spqIjtmELEBAb/gpHFXkvgPKYdO3e+Id3rH+7sHbKw9O8JWfiJ1Zs16bJQtyK+FNEbyXTxnWZdwrxOgWjEjTG2Nl37ac9sEOZGuNRH7b/TCseSJiIeo0jUAwnlJQ+FVQJxdTLhp+ZOfJgkB3wENuCAmC1ggtqNbixOGZqWwQMifmA4LsGiSz9uAOtUobP/kDbOk3Avfs458UynLVyEX3pL7CSswfdc6EGDz7ggUIiD48a+4nBBE65qi2YhggKn6sZpS4zVxwWyWV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vTubAwU5X3k10/rzORU3xjGKtzQ6JaOFAdT+Z3LnXy2H03yNaXYEPVJN/OjiK29G9pyJb5sLBtaRAj6u2pBM7yBSCaLUCC7hCAcnfve64MLrYRZtHJtRKmgkKTCcPfWnklMGuSpqDj7mSAlBY4I=; 24:QMJ+49CIzXg4AKVmCaxE/ccvPCMdJvOQUa9bipSs+X6W5+6j3QcjlRKIF7xV5L2neToswaGBWNYJtHaqOOAPALalEMVjeSleYxjPwORnnCs=; 7:phInhy4drfbp2jVwf+9n4t0s9Qui1vLpPZGMhBjZFopb+8lyFilmEDWaVzj1AAw/BM3I9BhKRNfPp54TUdRrsebPtRrBJIILL4Ko4k76KIYxrK6I6TKzxR7DP5r3ZlQdMDBpOzsNvwmapxiqUJ2rBLlXf70qMWTldriqvCSmPsGQz91s8YzMfRIKDDdvYr3VHovVNoB3GJSSnEweBnltvMhGwd+8rcXGfFGqk7u4y6woimT+PkpI52i4k5C7qZEO SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2017 10:37:34.6466 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f234bbf2-8f3b-4693-06d4-08d54c4cad1a 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: DM5PR03MB2699 Subject: [dpdk-dev] [PATCH v2 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 --- v2: * fix ABI breakage * check for ops.port_id for vdev case 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 2c143da..4dd1f82 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 1a760de..b519db5 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 @@ -81,6 +81,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, }; @@ -94,6 +95,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 3e02ea1..e261c58 100644 --- a/lib/librte_eal/linuxapp/kni/kni_net.c +++ b/lib/librte_eal/linuxapp/kni/kni_net.c @@ -603,6 +603,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 */ @@ -712,6 +728,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 a5ee210..bed3f20 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -554,6 +554,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) { @@ -593,6 +613,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 != UNIT16_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; @@ -743,7 +771,8 @@ kni_check_request_register(struct rte_kni_ops *ops) if ((NULL == ops->change_mtu) && (NULL == ops->config_network_if) - && (NULL == ops->config_mac_address)) + && (NULL == ops->config_mac_address) + && (NULL == ops->config_promiscusity)) 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 9bdc9f3..4530bdd 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -74,6 +74,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 06448c9..56a7f3b 100644 --- a/test/test/test_kni.c +++ b/test/test/test_kni.c @@ -104,6 +104,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; @@ -262,6 +263,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 Tue Dec 26 10:36:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 122747 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp785853qgn; Tue, 26 Dec 2017 02:38:14 -0800 (PST) X-Google-Smtp-Source: ACJfBoudj53jQ4aCcSQ9Nf4oBwKVf5W/bkO4U8lps7TlgfOx8v1n0Jo3hF/Trs5JlcRrHauvnYbm X-Received: by 10.28.202.26 with SMTP id a26mr20070408wmg.130.1514284694764; Tue, 26 Dec 2017 02:38:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1514284694; cv=none; d=google.com; s=arc-20160816; b=beSztVzsB/bpvmJ8rynsRBS6icSpOnaHPJgoJ+I+j2OLdHh0gHpl3jlJw0HHBEIcUY ociYM/ITd5TwIYTwlJKQW2D/37ZLq6Js5m0NiuIIgYVeRyQeTZ8dCCBttSFtDx8O37R0 P6TAeWHL7IltQkgQBMaXRQkIBSozJ7doQpdonL/j7LEzsInzFAA96rAO8x86SV9CGbbr 12dhcvff4ou9GSQmevuWQjv0E0Y52CtKlFg602wi1GjOiop8V8+9i+QL+2wv36CbbaKe tTZKk6fhhQZI+opOaa32Z2TwNzfOogsCFrMDoWGPg9GegviR3QlBwYmMI/xT6eo3sPkX sXTQ== 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=uL/iKMdQllqvJsobTwZLNUpemkB5Ga2S9MxLChwnr34=; b=LTXHU5yHspM55IIbWL3k3F+bL4KsaAj+h1zDbqocTY9U1AqMXTq4zfXzpG6vW+9VPL 5bA7+IvUxW1caTuicl8ByG6BzTbm3D9E8Bc1uTzqL/LWjqBI/vmZal+4irlsWcjNRf/O YHOm+1Y+DHJbU0R05H4Fp/HtbNGz26pfg3Okg/CsnpawiV6kB9TLQe5kFDd+knhYzbD9 HC9v58Wy8OeXy4ZZqbBIOc0LQAwYyuNHo/TkAemdtPCG+zIWkVQTpP6ymI/BWgXPtBBK 9cqW+mroD+sBUne81gbo/NgQsGuwC2e0LTxlU8eysP71/IhDLOvGIcRjF4213s3q9YaP V1Lw== 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 x4si11698234wme.69.2017.12.26.02.38.14; Tue, 26 Dec 2017 02:38:14 -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 71CBD1B64D; Tue, 26 Dec 2017 11:38:00 +0100 (CET) Received: from NAM03-CO1-obe.outbound.protection.outlook.com (mail-co1nam03on0082.outbound.protection.outlook.com [104.47.40.82]) by dpdk.org (Postfix) with ESMTP id 195D81B2D6 for ; Tue, 26 Dec 2017 11:37:56 +0100 (CET) Received: from MWHPR03CA0041.namprd03.prod.outlook.com (10.174.173.158) by CY1PR03MB2361.namprd03.prod.outlook.com (10.166.207.148) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.345.14; Tue, 26 Dec 2017 10:37:55 +0000 Received: from BY2FFO11FD030.protection.gbl (2a01:111:f400:7c0c::176) by MWHPR03CA0041.outlook.office365.com (2603:10b6:301:3b::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.366.8 via Frontend Transport; Tue, 26 Dec 2017 10:37:55 +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 BY2FFO11FD030.mail.protection.outlook.com (10.1.14.211) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.345.12 via Frontend Transport; Tue, 26 Dec 2017 10:37:36 +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 vBQAbmE1009888; Tue, 26 Dec 2017 03:37:52 -0700 From: Hemant Agrawal To: CC: Date: Tue, 26 Dec 2017 16:06:48 +0530 Message-ID: <1514284608-9263-3-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: <1512042367-6361-1-git-send-email-hemant.agrawal@nxp.com> <1514284608-9263-1-git-send-email-hemant.agrawal@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131587582564932805; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(336005)(346002)(39380400002)(396003)(376002)(39860400002)(2980300002)(1109001)(1110001)(3190300001)(339900001)(189003)(199004)(498600001)(5660300001)(305945005)(356003)(6916009)(2950100002)(2906002)(68736007)(85426001)(8936002)(8676002)(81156014)(86362001)(53936002)(50226002)(6666003)(47776003)(76176011)(51416003)(81166006)(104016004)(105606002)(316002)(106466001)(16586007)(77096006)(48376002)(50466002)(2351001)(4326008)(97736004)(36756003); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR03MB2361; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD030; 1:cjBgMaMVABqAJ4HatY0upU2tdaRa5weojUX3914s8hmDQEHmZS8YIcCNJB+9LJxIbsw6okDKha37PlU361L4BanNjQ6ohs5ydAoPXd4DiM70z+CEXZkNC0iDHRMJrobC MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d0b178f3-b534-42fa-9cc5-08d54c4cae19 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4628075)(201703131517081)(5600026)(4604075)(2017052603307); SRVR:CY1PR03MB2361; X-Microsoft-Exchange-Diagnostics: 1; CY1PR03MB2361; 3:wuBn9twUO7AMzYXeotzOpKj1BQrQmQXldycPPuFK/pbR4vTXT7pEs3SnU+tNk5EZdeFbZGGX7ZUPlSbHgclcsY4jgDv76Pgrh/oqtbwrLYRZ/VLaHJavkKo1KPLLkmkNR8XBkmyM78dM/xmRnZ6MJhYhSAISUX6aXKH+Aa2WtdoJDd696bCUrn1gzg3r29GEvFMqm9f+tSg3TiMQubcfA8i6K88DFRotOoQAg900D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kJAD48Ozj01GMei+PEzgp4tpjjRR3ClWTQRImmc5rHrygOOb3EioR2r 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)(3231023)(944510075)(944921075)(946801075)(946901075)(10201501046)(3002001)(6055026)(6096035)(20161123563025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123559100)(20161123561025)(20161123556025)(20161123565025)(201708071742011); SRVR:CY1PR03MB2361; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:CY1PR03MB2361; X-Forefront-PRVS: 053315510E X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CY1PR03MB2361; 23:8/8Ka37PYCBpB4cGbNRbYm3D+CR4JsLQBrhj5ZCCb?= bOo/AsSTJTNA/+xRynvgXlzBfQI+Jt4fdOEupnwYKgH0R3T+kDHiF0O2VUCaxkHUhG3jBTzM94VvAWhYC1zexWCzP/O+xQSdDa56WqaBqongk8RVI61YjrnO9CFAQyJn6MdHyQU0pKDC1a9GrPUSYA6KHUAqqvc3nP62t+Pbav/KYXL5rjC6/tIs78UBFv72ENQNZavbIzQathW9G6tNPhTC46GG58acZukOQYHkI65i5S/uld+NNY7zstb11sLisviTsrohUEoPQuzXn5Vm6lLk1XpUgNABSZGiWy+nO2wmwmFXeSRyUV9w9/JQbzLSeHFkzm4CpgkJSzA2n3+qylLWjS2ar935li5bkE6KH1MQH2DwgBBEGjWuoaEK0MLIuy5W7w5kWx4kmULzx3JRYvEP+/LZPKPbqv7qBdq5O5rFbVY3Us9fameyi/mI8O/g2hrOyWUp7pY548ZQpl8CNmwCafVkpKOmXNWiYomYZCAhE+47f16yy7ZZ9ohGo/Y0+WpNs+5fVgKcr4sNd9kbpN4Z+JCg4OMN376Gtkhxq1j7zLkkJroxZMien73qwcf+Tf5jXaZWwc1dLxHDQ/v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IVO0mKOfAk/N6p6/FNC5gY2fQMhqf8OauKX68qVjiUI6iJiaZFtdD3O7JA4vkBB9If18Dzp6xcZwmRgaQCgc=; 7:fw96HJhTOBSpEqWEi5IkSNuSHQ56QAEkQtYecfHDAEimq+0ekR+HTSqbVmj+3oPCrq6c+PNT3RBolBz73kaP8hWvWdeOXw3WPK0bTnUGx2xCUC3FyKaM8L7WtZX9+fP7s0OmMcwOFYkdtVhfkQH5xhvfz9JIyF9wF4XUJE72Vx31XQgGz/L37XAswYy6NXPPu8E2dtkWi11vlqFpR+Eem7Qc215k/4JOrZXbMjKU5QYUeKooXhAUeKoqdgg08xET SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Dec 2017 10:37:36.3060 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d0b178f3-b534-42fa-9cc5-08d54c4cae19 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: CY1PR03MB2361 Subject: [dpdk-dev] [PATCH v2 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 --- v2: fix ABI breakage 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 1c251c2..d9c9fa5 100644 --- a/examples/kni/main.c +++ b/examples/kni/main.c @@ -845,6 +845,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 b519db5..2e393c0 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 @@ -172,6 +172,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 b524d30..0ccd227 100644 --- a/lib/librte_eal/linuxapp/kni/kni_misc.c +++ b/lib/librte_eal/linuxapp/kni/kni_misc.c @@ -470,6 +470,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 bed3f20..2461b47 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -369,6 +369,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 4530bdd..cbf3188 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -98,6 +98,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; }; /**