[dpdk-dev] [RFC PATCH 2/5] kni: add support for promisc mode set

Hemant Agrawal hemant.agrawal at nxp.com
Wed May 3 13:21:09 CEST 2017


message to userspace on promisc mode change

Signed-off-by: Hemant Agrawal <hemant.agrawal at nxp.com>
---
 .../linuxapp/eal/include/exec-env/rte_kni_common.h   |  2 ++
 lib/librte_eal/linuxapp/kni/kni_net.c                | 20 ++++++++++++++++++++
 lib/librte_kni/rte_kni.c                             |  5 +++++
 lib/librte_kni/rte_kni.h                             |  3 +++
 4 files changed, 30 insertions(+)

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 e9fdc73..c04fefd 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 866cbdd..e4a3296 100644
--- a/lib/librte_eal/linuxapp/kni/kni_net.c
+++ b/lib/librte_eal/linuxapp/kni/kni_net.c
@@ -44,6 +44,9 @@
 
 #define WD_TIMEOUT 5 /*jiffies */
 
+#define PROMISC_ENABLE 1
+#define PROMISC_DISABLE 0
+
 #define KNI_WAIT_RESPONSE_TIMEOUT 300 /* 3 seconds */
 
 /* typedef for rx function */
@@ -603,6 +606,22 @@
 	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 = PROMISC_ENABLE;
+	else
+		req.promiscusity= PROMISC_DISABLE;
+	kni_net_process_request(kni, &req);
+}
+
 /*
  * Checks if the user space application provided the resp message
  */
@@ -711,6 +730,7 @@
 	.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 d5a717b..8ae632f 100644
--- a/lib/librte_kni/rte_kni.c
+++ b/lib/librte_kni/rte_kni.c
@@ -552,6 +552,11 @@ struct rte_kni *
 			req->result = kni->ops.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);
+		break;
 	default:
 		RTE_LOG(ERR, KNI, "Unknown request id %u\n", req->req_id);
 		req->result = -EINVAL;
diff --git a/lib/librte_kni/rte_kni.h b/lib/librte_kni/rte_kni.h
index 5d2a233..488db4b 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 network interface */
 	int (*config_network_if)(uint8_t port_id, uint8_t if_up);
+	
+	/* Pointer to function of configuring promiscuous mode */
+	int (*config_promiscusity)(uint8_t port_id, uint8_t to_on);
 
 	/* Pointer to function of configuring mac address */
 	int (*config_mac_address)(uint8_t port_id, uint8_t mac_addr[6]);
-- 
1.9.1



More information about the dev mailing list