From patchwork Thu Nov 30 11:46:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 120139 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp557991qgn; Thu, 30 Nov 2017 03:47:07 -0800 (PST) X-Google-Smtp-Source: AGs4zMYpWe83b4+G1s3Tf7CA5nFW9uCSurijLHikMFPnnNkH0L3ztR3cLGjKvlkl5xQNeAXxWEz2 X-Received: by 10.28.84.19 with SMTP id i19mr1842455wmb.62.1512042426897; Thu, 30 Nov 2017 03:47:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042426; cv=none; d=google.com; s=arc-20160816; b=E3Bi2XDJQZwT59r1qc+81B9Uvp+yQ/EUejjkVViVLoWVy/mIx1QLIaNKfhJ82ER6oL s9/yVzSvbgSybM+mwt7IjdLq2Il2Z3hRbV21eeaEnOGq0bIEFgAT7kg6C+aKu/PbmK8b nKWGuF8tou6+reWm0f8kS7oHlRtoJwOZ1PgktWYzfj87SDcMLMTtGG4FLEAY2FdbqLLn HySDpX1UJBhhGB7MvRtUss0VZIpT7G17130LDVoy88ReD3yZeZHbHZgtfA2v7DrGcRxH GZF2e/6B8K/xjPK01Q6E7hbbClnh91Y7dkrFeg0sp+k1IRw3CXJMXTiPdDKB6tLiFG6Z 6TXQ== 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:message-id:date:cc:to:from :arc-authentication-results; bh=wbHs2V2RNaVNjGHUB/f8WRCabbfiud7peo/YaBsVAYo=; b=bce9w/QcjI93ZY4s1z9avHWJGk5EBYsU1ithEBp0/a8xWxBxGeIEws3D41NHamvLXb fEniLGu5boM8mjXz+DbXXSEH9M3YQ5WnvW/D+Z44I3+2tBzQ+APDthu8WJtKcyN2pDFX SaovILPaUo+SBPwVDfVNOUjARoyF+hthHQJm6ZCJJTnNbO9Rv4A7zdluiwJakQSALxWl BDjjl/HzOc4OQQi1p12SgfDFv+ond46DBnHiGXhS1LOn7el48PAAzvarufxUS6wenRdW eTKmRURKlOaPQ9+qifCPC/t21q5fXn9s4SUIzL55Zfh+Oqie83srEy4hYISBfBmIvjuL f8Mg== 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 w19si2945326wra.165.2017.11.30.03.47.06; Thu, 30 Nov 2017 03:47:06 -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 960772B9E; Thu, 30 Nov 2017 12:47:05 +0100 (CET) Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0080.outbound.protection.outlook.com [104.47.42.80]) by dpdk.org (Postfix) with ESMTP id EE21528EE for ; Thu, 30 Nov 2017 12:47:03 +0100 (CET) Received: from BN6PR03CA0024.namprd03.prod.outlook.com (10.168.230.162) 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.282.5; Thu, 30 Nov 2017 11:47:01 +0000 Received: from BN1BFFO11FD029.protection.gbl (2a01:111:f400:7c10::1:137) by BN6PR03CA0024.outlook.office365.com (2603:10b6:404:23::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.282.5 via Frontend Transport; Thu, 30 Nov 2017 11:47:01 +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 BN1BFFO11FD029.mail.protection.outlook.com (10.58.144.92) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.239.4 via Frontend Transport; Thu, 30 Nov 2017 11:47:01 +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 vAUBkx6w031415; Thu, 30 Nov 2017 04:46:59 -0700 From: Hemant Agrawal To: CC: Date: Thu, 30 Nov 2017 17:16:05 +0530 Message-ID: <1512042367-6361-1-git-send-email-hemant.agrawal@nxp.com> X-Mailer: git-send-email 2.7.4 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131565160216805358; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(39860400002)(346002)(39380400002)(376002)(2980300002)(1109001)(1110001)(339900001)(3190300001)(189002)(199003)(8936002)(8676002)(6916009)(498600001)(5660300001)(189998001)(105606002)(53936002)(106466001)(81156014)(33646002)(50986010)(77096006)(16586007)(316002)(356003)(4326008)(86362001)(36756003)(68736007)(2351001)(305945005)(50466002)(81166006)(48376002)(2906002)(51416003)(47776003)(85426001)(50226002)(6666003)(97736004)(104016004); 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; BN1BFFO11FD029; 1:Wq/xQVJz2r/zTMsCyh5iN0CS2hnH5VaSwFtw+iksl/89LoSeR+SNSKvho6aDVdUps3GgHbbAr43Fpvegu8UzYbVuFRKDb+GBNIYZNq/U7Qpq5rwLzcwnzE357rLLwbR0 MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a8be16d4-7b85-4383-de8f-08d537e811fe X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4628075)(201703131517081)(5600026)(4604075)(2017052603285); SRVR:BN6PR03MB2691; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2691; 3:H/OqliQ2LJQnYbBqJ5c93IvXWjLDw0zdrC1Qk7ouIixu1Gcx9tnpE2/0lcSZqC0bu/DVh2bw6h8zOjDQb3gqRqXRdEumtO0xepGEVxYsiI9FLaz830fJ555QVWO+ZKcYwGQccYNsFmbCaf7K6IgbeiDA5D+iPeUGRMEz3g/3of7X5YLc6WwnuBTeBHwf/slvScDUhWlW8id6ZINAOT4QltkD3d+RxSZH14vjfOwHK7cqlvupovMjE51racJVoDZNHYS7P5ZSCgoyMHI77SCb0mgXfDnAHpnyU3MhPhU+/WXP0aiODadl3q/Y3681YsIVOGkL3T253PBbuvcnavefGHz3Jz7CnWBfEPPpTjxx+Jg=; 25:5Ugx6QKnSIjDCAkX4/6mT4Ap/Nm6AS2AucFU0B6PbfNH43fEf2Ogz2gV7f6LfikeAHacy4TZOlnknx2xj2/ZDpGXGnRNLZ59EZBSaQs7su4fQvT82ygQN7aak/S0fn7Wb2jr9AM90zATwLcmtcUa/qxLX8eiOdCirqG2hN40/zwaucFyroY1n98OTbDa4x0Jgo2T/yRAIzZId1u8/fARo2MScZc7McIeKPbRPmmzodQj3PsTsV9rzwaXibAwINBObsa5MVlGLzDyIbxtTIhRBeDTzjsNCAcmrJU16MB++uxNc95iM5hh0MHhDWddDzVCXeIzL/pV4VFkO1ZGF0DsKmOYQIyM9qR0Y96DAcpW8Gk= X-MS-TrafficTypeDiagnostic: BN6PR03MB2691: X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2691; 31:wIzF/Clj1E/ktTQcuAD/LByZEQlkjWCaX8l7QKZpq8Buge94I/aMSVRNemuDNn/rYQCxl33LVueYmbpzy6M3V1oQxvvyBtJaVLZ9RdRGMbVIhwGxFWYaz6Zz76BajJ2R799l0Y8XnEUv9xWRiYQSG/4xnYe0IFpQaaB8v9KRnmFiYI/ZJCIEjLwE5pDwCHjJQTaXx8uaVBKu1/8+3RuxKli+ya1ymVoM16nNgDWC8mo=; 4:fSj0QRy8tWSbSNG75FmY56VDPpbwdIAXzup/+bY4JhOWMgdHaqqd8oir5I0Z7tyQLC1ZgjJAPC4fQeukuP5B/OrUFJDRP7VlxXMQQtriusgxGWimhTxzOTlCKv/tFEopLhftZvyTiCviz+pP4VdkUcM+jTywouUDxU6y4qvuWhJFiskYtrm/wW0idZzy2QeqsYuwOBFsXFWovPnW+IAsVRYQbV9rPHoqmBx2lj45MQKt3Ke1aLoXCi13AWuBhS+BvrnNpa7vMAxVR/pS1zrcFIROJwEEHvnHo75VsAxeQVsZ3BT1a2M9UK1j1dq8Uluo 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)(3231022)(3002001)(93006095)(93001095)(6055026)(6096035)(20161123561025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123563025)(20161123565025)(20161123559100)(20161123556025)(201708071742011); SRVR:BN6PR03MB2691; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:BN6PR03MB2691; X-Forefront-PRVS: 05079D8470 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2691; 23:WjEVaBuMnaH8RUa7zVaw1c26dmh6hnbcN6GsWj+Ma?= STdduoK+WJMNs3fIRCXL3YKuAvYoEYMaSN0ctMTMNzTZMDnxnVhkWxyikWws+DeyqQ5cgfPaczthxfETvE7Tzc5uHgrAyPS0kj9qaIuIeXwv3VKuBgptmcgfyPVtYxpecLDlC6OjXNxatTow37rys0lJcnScArp8rmdxq/K64jrB9lJBYYYQwz93YBX+SNs2T7GyWLvC7Z4QoNNQ2ChMpRPKvJbPdPR9/FsuW7g4BSw8mdjStOW0qOfbaKXUezKnFijxUvREqlBPLgaEqNbjTk9a4/3r11xrHr325newYszaw00128rbaPIbABt53nEcxOM8Ok7gva6VDlsdvFOOumjwtuy9xktVIJcX7PIIfqZLTytbuVRoSWbDoDAv5oVgQK8dMkQzjYT1mzWsZ5HBR9pNLUSEQpF9htapqhcFryrboG1YPEwUGuIMw9GA5CGLBiJauHgXNQcpO0qoWKIJsM53EK/HjNpoM8+6RhCl9b2Zhcc9OX71uHDEwT3q1pbuy8bJRqkzLHBh0jtjhPVqXJTz5jOfbld4I2DTGEl7EcswZtkIW4uReweefxqStXma8rS7RPt0Jmxc00/i/HuovpM29draprBkEnkXXjiUhLL8lZSRGg0Hgllv/LA/RO4RIrtIi50QlAPKhgvIO3pmfhidSvbZ7VwtwTZ2ovgBk6/9aMzWbuixe+8T5Sy/O2Db4sVrm7NLimlhU3iQbnRcp82tKOmW8bL2yfb8weC3GvLJoTbOiQwS1C8FS0Fqr9nZ9XLAj7jjBmAkuvYq8HtdJg3Z+017WSJDToNsKKKXlaPy7x2XFU5U7zIXwIM6qM5ayakGT71ZhKRjk916N45PjOmjx6gDJFkduogwKl8mZ2Bp2+OCZfEX8D/jscJYHCSEkAQ58xPtmHE3I2HMLXf47mr856xyHjSfQnKSTzbH+dD4ZI5cznQR9i+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:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2017 11:47:01.4933 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a8be16d4-7b85-4383-de8f-08d537e811fe 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 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 --- doc/guides/sample_app_ug/kernel_nic_interface.rst | 41 +++++++++++++++++++++- 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 | 40 +++++++++++++++++++-- lib/librte_kni/rte_kni.h | 5 +++ test/test/test_kni.c | 2 ++ 8 files changed, 147 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..d9d8e4a 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,26 @@ 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[]) + { + 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); + /* Configure network interface mac address */ + 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; + } 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..04db3df 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -368,6 +368,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 +530,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 +583,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 + 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 +739,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 +780,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..a53329b 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[]); }; /** @@ -87,6 +91,7 @@ struct rte_kni_conf { unsigned mbuf_size; /* mbuf size */ struct rte_pci_addr addr; struct rte_pci_id id; + char mac_addr[ETHER_ADDR_LEN]; /* MAC address assigned to KNI */ __extension__ uint8_t force_bind : 1; /* Flag to bind kernel thread */ 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 Thu Nov 30 11:46:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 120140 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558109qgn; Thu, 30 Nov 2017 03:47:14 -0800 (PST) X-Google-Smtp-Source: AGs4zMYQASjeylsB67bLZpm8y3KHSRjNhxty5YsxciHJ1mZTBnKRkaphum6JR4eAjU5s6kduqGuC X-Received: by 10.223.190.135 with SMTP id i7mr1732596wrh.91.1512042434829; Thu, 30 Nov 2017 03:47:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042434; cv=none; d=google.com; s=arc-20160816; b=FMXr1IF9tfQ7li2QADgty05xtRCCj+Z3n9jkuQuNOQ9R6hpqEEUhQl2Zzuxj4E09mv 7yB18Ub3fP+r2NfP7XhFKdXG9BzcLe8o9rKI6dtCKGbcP+kKG6ScVhTZm9gQ8E7CJbis teEQiRQjEw5pBkrXLtRSjd6xIgfTMls4AUcN13UaMdUfAxP+B6zbIkALxJ95ZvYR3rxK FTkfrDZfKrvg9krAgajK/zfAduuDrzWju22M+iushmfWhiq85CUEiwZZfvgXb//BkKQD azg+41uBT1eR4D0PcIoQW9aHz3BnbHM48/xnsom2Zw1kgEoc55kJlf6VIxQTjcSyIrCQ MDFg== 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=AQ68SVuBj/T9OyZVfYmF0DwCXiHShsMXW0twxBec6+Q=; b=S7cByQwlZsp35SaiK5YV0M4CN9cmre0tQzxuaO7I5APBH6A1B7+h2++7HMp7vAMa/C 1XL790fyExgpoIveWHzJVFi0ZIL0+wcer2Lnf1YndB4Gs1wcX624213YuPpfHVYkas4H 4hsMjFUP+sZuYOnYqOZgwn93Uw3ua2vpCEaYR+hsEducvDBkGJqUBBXNzjr6f4sjCyim eA3+9WbAQ332FZ5vf0vLBHKwI9ROgbJBLlny1V7HMRjUAjdj43EmzYa28gNxJL7CjxZx W25BJYYLQeYC/sbTXbgiDfSHkkgfxyDfHIKNq3ZIThrJpOCC4HyU9I29V33XfRHljcVy 46SA== 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 q124si3010528wma.132.2017.11.30.03.47.14; Thu, 30 Nov 2017 03:47: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 CDDB5324B; Thu, 30 Nov 2017 12:47:08 +0100 (CET) Received: from NAM01-BY2-obe.outbound.protection.outlook.com (mail-by2nam01on0085.outbound.protection.outlook.com [104.47.34.85]) by dpdk.org (Postfix) with ESMTP id C41EC2C54 for ; Thu, 30 Nov 2017 12:47:05 +0100 (CET) Received: from BN3PR03CA0116.namprd03.prod.outlook.com (10.174.66.34) by CO2PR03MB2359.namprd03.prod.outlook.com (10.166.93.19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Thu, 30 Nov 2017 11:47:04 +0000 Received: from BY2FFO11OLC014.protection.gbl (2a01:111:f400:7c0c::106) by BN3PR03CA0116.outlook.office365.com (2603:10b6:400:4::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.282.5 via Frontend Transport; Thu, 30 Nov 2017 11:47:03 +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 BY2FFO11OLC014.mail.protection.outlook.com (10.1.15.48) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.239.4 via Frontend Transport; Thu, 30 Nov 2017 11:47:03 +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 vAUBkx6x031415; Thu, 30 Nov 2017 04:47:01 -0700 From: Hemant Agrawal To: CC: Date: Thu, 30 Nov 2017 17:16:06 +0530 Message-ID: <1512042367-6361-2-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: 131565160235032277; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7966004)(336005)(39860400002)(376002)(39380400002)(346002)(2980300002)(1109001)(1110001)(339900001)(3190300001)(199003)(189002)(189998001)(316002)(85426001)(81156014)(356003)(2351001)(50466002)(81166006)(104016004)(86362001)(50986010)(51416003)(76176010)(305945005)(97736004)(53936002)(36756003)(68736007)(48376002)(105606002)(8676002)(50226002)(33646002)(8936002)(4326008)(16586007)(2906002)(77096006)(47776003)(106466001)(2950100002)(498600001)(5660300001)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR03MB2359; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11OLC014; 1:is9365HyaLtYomalCCBD86vGqRIcz3QH7hTknQIhSZTDseYbl5mdDy9wwlWtlmptoR9EAkUdhU4i7Y3NiSyx2rY1fyd8DUhem4LCFFiXuHW+1UdmOHIlt6k2GgpAei+8 MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 173c9e8b-13d6-421e-911f-08d537e812ff X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4628075)(201703131517081)(5600026)(4604075)(2017052603285); SRVR:CO2PR03MB2359; X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2359; 3:qGfM32/I6soczFyzVO2FKiJ59e70fxhVgVZBiDhrpcL0Y+tvVac3a2nBejXmvUVOjV9nfYfjfZK/ngyYNXES8tsPSfG2Xlo1QBB5M+jURxuksBoKAyUahPyNCPwUM9SBI4dBLNuZBBLVAMtcdtG1t09eCohRqajqx+qNks7gwOaLEaCXKNnkBKzmALV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C6KgPvmioPIaAHPEWnRL2qg7ITUCPWDTkO1YIr5uqx1VQL2PEBR3udGmEqrOlLQrGBQacExCw8 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)(3231022)(10201501046)(3002001)(93006095)(93001095)(6055026)(6096035)(20161123559100)(20161123561025)(201703131430075)(201703131433075)(201703131441075)(201703131448075)(201703161259150)(20161123556025)(20161123563025)(20161123565025)(201708071742011); SRVR:CO2PR03MB2359; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:CO2PR03MB2359; X-Forefront-PRVS: 05079D8470 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR03MB2359; 23:IrmeVR6SR1EJmOdzN+gMGbphLvBz5ov2t+sabF1TH?= RnceiTafp+WAFRLFI08vjJXDYOniHTTKiMeouMHVbBho2HYE/TEVeTIBuBOwqrrL/63rcxLxsYcITpoG6geIW6r4g3UKR+DX1DXfQS9bq2Oww5mMKX69DM8qNiMvHcB4OmBK0EL7kfqYwrq7iICKtI7fjeTKtpYcK5NPS9jnJb+DOqRP+yR7clux1T7mPcM/Lmj0kYoGnvXAG+X7Wn4HXle3Vr9J6F1u9cVLZOrR4cKwS2LAkt+vtmiCIpcz89HqD7Q/7j/IYq+nPHHoTUxs3KJO5m/w7Fl0x5wfPLOYVXYWSMj/79B+NIOH/H/Nf1MjT/tmi6K6MXPFhdgOrDGv+HgBsKcf5LFcC0W9LxP0O9GW6U8xsZjC+AzoeLOpS4rniR4GqwChXGG7V7ySH2bEwmSYhXThZ8cvoQI7/9OXh4FNJ0RO5aqI26epe2fBvluRUQ91MRnXngG5Ob4Tow3abpIxKOhvgKuVHBts310rtTbofgBfQho8jAtOhfePQ7ZyRVhpa+eDbXwWM+4Wg20Jy+2aP+GC4jCN06sWegGpera7ISjk1XiDs7bdV8/Es0cwdZMIXU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SDlBechfkjQst4h2DEWJAPJiGyE=; 24:FAMqAMDmiV4ANF9S0i6on88W4fIj/0vjbwdxHKHCbOC6P46v1qnKuHDGlMKr5EN9uPJ38p3Z6fxgxMW5VvkniP1qmaPgPDIs83jEnLE+QKU=; 7:cSJ0Z59XY2J6viYyIhh+YbJdl5y+jFMhR7gx9z7CFIVelFdqng6OCQw+0tsqOgvYGjoO7rozZTzJYwKtvT3KFSA6pue4G8JoTVuzOS3mm/NKS/s2YcezqRatIlt1H0ub+6Nr55XWdfreYPrgdWGQyXP2k7Q/3I80/kHqqTuz1qUVqAO9e6m8t22siuMJIVfSyp3LbsGXIFSHoVWBN9wKobp/JT45Ui3gr2QbiBm+ZpmZnDU4Qz3G6XIkrHHnKiIg SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2017 11:47:03.1600 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 173c9e8b-13d6-421e-911f-08d537e812ff 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: CO2PR03MB2359 Subject: [dpdk-dev] [PATCH 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 --- doc/guides/sample_app_ug/kernel_nic_interface.rst | 29 +++++++++++++++++--- .../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, 80 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 d9d8e4a..9cb8463 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 */ @@ -626,3 +627,25 @@ may choose to not implement follwoing callbacks: return ret; } + + /* 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; + } + 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..f2ef48e 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_PROMISC, RTE_KNI_REQ_CHANGE_MAC_ADDR, 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 04db3df..e8cd297 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -552,6 +552,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) { @@ -591,6 +611,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 + 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; @@ -741,7 +769,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 a53329b..bc5ead7 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -72,6 +72,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 promiscuous mode */ + int (*config_promiscusity)(uint16_t port_id, uint8_t to_on); + /* Pointer to function of configuring mac address */ int (*config_mac_address)(uint16_t port_id, uint8_t mac_addr[]); }; 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 Thu Nov 30 11:46:07 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hemant Agrawal X-Patchwork-Id: 120141 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp558280qgn; Thu, 30 Nov 2017 03:47:27 -0800 (PST) X-Google-Smtp-Source: AGs4zMbug07l3yP2lrkXSb+8ulat1lh1I9JeXZlFmz6fVSGMLR23c88Dksiy1o4ADXUBY7aXxkRc X-Received: by 10.223.135.121 with SMTP id 54mr1757927wrz.160.1512042447054; Thu, 30 Nov 2017 03:47:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512042447; cv=none; d=google.com; s=arc-20160816; b=De4Z+D4PuEdy7g69AJu6jeIV4+f5Bq+U4DRuXodkgXY939ASohkHLornz75p7tRt1p aKuc596QOZwRlRPdAHsVOYABwaqxixJrhPaImrUWN4PIJmzxoTRuVkRwa0kUKIKt1m6r ruiPbpvNC2Q+XMSd83SxbgWSUvWUUnMniEbecLOZIcWONcEU36pj0lO66uDw1x2ADFUn CGr6XgePPeffySGgcdsXCMLvvuW2czV8mOtdMR3TLsd4sImQa3fv7iUF/do5NmcbWtRy aeCKkitqwv/NmIYVqZcQUv6w492rTDkb/k+ZTJJkeUlfG6wDNl0M95R6k947PRhCCiHo QUQQ== 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=kmNRwIbjO1nd2iLZgWSxUoEwQ1SKBAI+pHdtgym6R9o=; b=W5d+6yul90ZnQ/C+xgZjQrF685rRQ684RpCv8GZp7aywbyYZo2wTzTCWZrJoeafCw3 fmF/VrsJg4NttoC3I4OqnFWD1UI5xoZWuxfZT3N6fgzaWaNrx0eZ3sXp4YCiG1/lFXzv pZnubAFqn0+64SekZ3aS9sNMCiU/3hW3Q6rdi5rIsEnEPlWbbAfbeMhaoGN5RbyQVb5q ucxEEKdRr76eGVpDxTmEPjTlxKPLqpHou00W6ikeo7TIz9eLNp2GH4yEA1GXsU5emP/T 0lDBoiz594psn85c2J4CLhnr+NVsuam7okcAZmiywrnRNWfWAqzGQFSG6oVyvHuhhGEn w93w== 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 v3si3270199wre.426.2017.11.30.03.47.26; Thu, 30 Nov 2017 03:47:27 -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 E38B63258; Thu, 30 Nov 2017 12:47:09 +0100 (CET) Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0059.outbound.protection.outlook.com [104.47.32.59]) by dpdk.org (Postfix) with ESMTP id E0CD6324A for ; Thu, 30 Nov 2017 12:47:06 +0100 (CET) Received: from CY4PR03CA0083.namprd03.prod.outlook.com (10.171.242.152) by BN6PR03MB2690.namprd03.prod.outlook.com (10.173.144.9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.282.5; Thu, 30 Nov 2017 11:47:05 +0000 Received: from BN1BFFO11FD007.protection.gbl (2a01:111:f400:7c10::1:167) by CY4PR03CA0083.outlook.office365.com (2603:10b6:910:4d::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.282.5 via Frontend Transport; Thu, 30 Nov 2017 11:47:04 +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 BN1BFFO11FD007.mail.protection.outlook.com (10.58.144.70) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.20.239.4 via Frontend Transport; Thu, 30 Nov 2017 11:47:04 +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 vAUBkx70031415; Thu, 30 Nov 2017 04:47:03 -0700 From: Hemant Agrawal To: CC: Date: Thu, 30 Nov 2017 17:16:07 +0530 Message-ID: <1512042367-6361-3-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: 131565160247832456; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(336005)(346002)(376002)(39380400002)(39860400002)(2980300002)(1110001)(1109001)(339900001)(3190300001)(189002)(199003)(4326008)(77096006)(33646002)(50226002)(316002)(189998001)(16586007)(85426001)(47776003)(305945005)(36756003)(5660300001)(68736007)(104016004)(97736004)(48376002)(2351001)(50466002)(356003)(106466001)(50986010)(76176010)(51416003)(81156014)(81166006)(8676002)(498600001)(8936002)(53936002)(86362001)(105606002)(2906002)(2950100002)(6916009); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR03MB2690; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1BFFO11FD007; 1:XP71NgWOsEuAbTR2/lx5dvYEQ17pwT/DNJxxN/mjN3IoL/s+Vj3TJEbxacVBbb1K9ApaLeXAIkiCKSIsXPcUyc91foa78IvwZFZLo69iWh0l3qMjtw/JyhzHgDnNE0Lj MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9adf6e4e-3930-4d2d-4e28-08d537e813d8 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(4534020)(4628075)(201703131517081)(5600026)(4604075)(2017052603285); SRVR:BN6PR03MB2690; X-Microsoft-Exchange-Diagnostics: 1; BN6PR03MB2690; 3:XmUB6yDWtbb6uH0KJ72zppFtV8TM7DTWK2eNKnSzLywOUBvH/I5+oAoTVYzXNp9mXLyk0KuAHts4KnZhxZpj5AHiKhkMzkwxeuqb4AIixHH54TpFfE03RpaoUpYhTcQ89d4A7BD/0wYGUxJEtT3cxvR93ZVc6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HD6I/DdW8qzQ78bPjBf3Zzh6/L0JVzfTtOEMDG4zwwwh4NoJ9nGuYnZGXjlyx2wBqKBKTdn9TT43DT7A/3l+0QWLXRvwSY48KFtroaX 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)(3231022)(10201501046)(3002001)(93006095)(93001095)(6055026)(6096035)(20161123561025)(20161123563025)(20161123559100)(20161123565025)(201703131430075)(201703131433075)(201703131448075)(201703161259150)(201703151042153)(20161123556025)(201708071742011); SRVR:BN6PR03MB2690; BCL:0; PCL:0; RULEID:(100000803101)(100110400095)(400006); SRVR:BN6PR03MB2690; X-Forefront-PRVS: 05079D8470 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR03MB2690; 23:9H0k0dXh0+CupfIr2mbY5X2gJrvX/LWbyU7+UvWdV?= LC2ONCXV6cig5ra0YUz4T7WKYBLzXcmovRpnIb7QgZpFTbpb3TKyatQrTTIDo7r4RaVdCbwlGTEbmtbCTv45bQxa10Z+GUJC6qwBUy6BOPoRD+KNw9qcoos9GaVyEvNGrMXvZb83sCAfBm1Vf2tiSz4R5jGpi2NZscCeVyEaqvJtdPPjBmxhsiXE34R+omuEcofdftuK1PsmIQ7uff+k9XWBxTN1u3jgQr8w5nmPFmhoydxm9v5PwwFoU0h3/a7t5f1bL54X/r/Q6/tfJbuSLDAK10DEijo4oo2TW8v6cfsmTcmf8q+SEw/b0+TODpcTj93yPXHiBvZlEmqkz5O/UNfMX4slz5JCEdbyVok7HQ8DcRhEIK+jdmxPqUOs920KHtJt2aX7l37KM+iCunRDSNKm9sQJhbwZufzx1TPw5tDhej3CU4f+4iyiXHXWNUC/QaJQBF0BGfiEX0MpxLbSBAOYeEy440U6Fyx30qRxMKRLLgsN0gg309taaHLbB6ZAyg6m9pUEJlbNr//3ARqocLvg6ji7g+TlvXqfxOwi50uOq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E/hBzeiIPyQDsW6adhaGiZJfc2hydGUpFyyEZg4zAbA=; 24:ZClbXTgIhYuB8BEkTf9vRAiXw/rKGIkXXd1N4zDY3c1+D2Ft1qc/VjMXNtjxIXpVLNofYIikDxa26jGXHg0XcezBdysW7U3mXGTHDAyMqJ8=; 7:nEaonCAETqgXdDk5nefHXiM409+3I90P2ePkV7B7viQ/LSDMxa34NVZVlAJlI/sSXg9RaYMFVFgNvvhdxZA9SRvg+npFBy1lp4QwST7c21dqinIkzmfVDshaC4o3ZXIgm0SKOPWRbtOZ9oXM79PDYZbY3dx5ski8h+5tv15tGsK6TyXI3ULHAaCgOfJdKlNFV0BvYzSLkRrbLcs7P+Ev4foB7z20BQoe985d+aN0k829dGzMx1+ImDffnx6neHgG SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2017 11:47:04.5960 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 9adf6e4e-3930-4d2d-4e28-08d537e813d8 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: BN6PR03MB2690 Subject: [dpdk-dev] [PATCH 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 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 f2ef48e..9fdaed9 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 e8cd297..8b31747 100644 --- a/lib/librte_kni/rte_kni.c +++ b/lib/librte_kni/rte_kni.c @@ -367,6 +367,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 bc5ead7..37dded6 100644 --- a/lib/librte_kni/rte_kni.h +++ b/lib/librte_kni/rte_kni.h @@ -95,6 +95,7 @@ struct rte_kni_conf { struct rte_pci_addr addr; struct rte_pci_id id; char mac_addr[ETHER_ADDR_LEN]; /* MAC address assigned to KNI */ + uint16_t mtu; __extension__ uint8_t force_bind : 1; /* Flag to bind kernel thread */