[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT PATCH v5 09/11] lib/uknetdev: Promiscuous mode interfaces



From: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>

Add interfaces to query, enable, and disable promiscuous mode for a
netdev. The getter is a mandatory interface to implement by drivers.

Signed-off-by: Simon Kuenzer <simon.kuenzer@xxxxxxxxx>
Signed-off-by: Razvan Cojocaru <razvan.cojocaru93@xxxxxxxxx>
---
 lib/uknetdev/exportsyms.uk            |  2 ++
 lib/uknetdev/include/uk/netdev.h      | 26 ++++++++++++++++++++++++++
 lib/uknetdev/include/uk/netdev_core.h | 10 ++++++++++
 lib/uknetdev/netdev.c                 | 35 +++++++++++++++++++++++++++++++++++
 4 files changed, 73 insertions(+)

diff --git a/lib/uknetdev/exportsyms.uk b/lib/uknetdev/exportsyms.uk
index f989934..b0775cb 100644
--- a/lib/uknetdev/exportsyms.uk
+++ b/lib/uknetdev/exportsyms.uk
@@ -23,3 +23,5 @@ uk_netdev_txq_configure
 uk_netdev_start
 uk_netdev_hwaddr_set
 uk_netdev_hwaddr_get
+uk_netdev_promiscuous_get
+uk_netdev_promiscuous_set
diff --git a/lib/uknetdev/include/uk/netdev.h b/lib/uknetdev/include/uk/netdev.h
index 022fe28..b618140 100644
--- a/lib/uknetdev/include/uk/netdev.h
+++ b/lib/uknetdev/include/uk/netdev.h
@@ -309,6 +309,32 @@ const struct uk_hwaddr *uk_netdev_hwaddr_get(struct 
uk_netdev *dev);
  */
 int uk_netdev_hwaddr_set(struct uk_netdev *dev, const struct uk_hwaddr 
*hwaddr);
 
+/**
+ * Returns if promiscuous mode is enabled for an Unikraft network device.
+ *
+ * @param dev
+ *   The Unikraft Network Device.
+ * @return
+ *   - (>0): if promiscuous is enabled
+ *   - (0): if promiscuous is disabled.
+ */
+unsigned uk_netdev_promiscuous_get(struct uk_netdev *dev);
+
+/**
+ * Enables or disables promiscuous mode for an Unikraft network device.
+ *
+ * @param dev
+ *   The Unikraft Network Device.
+ * @param mode
+ *   - (0): disable promiscuous mode
+ *   - (1): enable promiscuous mode
+ * @return
+ *   - (0): if successful.
+ *   - (-ENOTSUP): if operation is not supported.
+ *   - (<0): on error returned by driver
+ */
+int uk_netdev_promiscuous_set(struct uk_netdev *dev, unsigned mode);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/uknetdev/include/uk/netdev_core.h 
b/lib/uknetdev/include/uk/netdev_core.h
index f1001b1..4174862 100644
--- a/lib/uknetdev/include/uk/netdev_core.h
+++ b/lib/uknetdev/include/uk/netdev_core.h
@@ -241,6 +241,12 @@ typedef const struct uk_hwaddr *(*uk_netdev_hwaddr_get_t)(
 typedef int (*uk_netdev_hwaddr_set_t)(struct uk_netdev *dev,
                                      const struct uk_hwaddr *hwaddr);
 
+/** Driver callback type to get the current promiscuous mode */
+typedef unsigned (*uk_netdev_promiscuous_get_t)(struct uk_netdev *dev);
+
+/** Driver callback type to enable or disable promiscuous mode */
+typedef int (*uk_netdev_promiscuous_set_t)(struct uk_netdev *dev,
+                                          unsigned mode);
 
 /**
  * A structure containing the functions exported by a driver.
@@ -250,6 +256,10 @@ struct uk_netdev_ops {
        uk_netdev_hwaddr_get_t          hwaddr_get;       /* recommended */
        uk_netdev_hwaddr_set_t          hwaddr_set;       /* optional */
 
+       /** Promiscuous mode. */
+       uk_netdev_promiscuous_set_t     promiscuous_set;  /* optional */
+       uk_netdev_promiscuous_get_t     promiscuous_get;
+
        /** Device/driver capabilities and info. */
        uk_netdev_info_get_t            info_get;
        uk_netdev_txq_info_get_t        txq_info_get;
diff --git a/lib/uknetdev/netdev.c b/lib/uknetdev/netdev.c
index 8507ba1..e2246dc 100644
--- a/lib/uknetdev/netdev.c
+++ b/lib/uknetdev/netdev.c
@@ -78,6 +78,7 @@ int uk_netdev_drv_register(struct uk_netdev *dev, struct 
uk_alloc *a,
        UK_ASSERT(dev->ops->txq_info_get);
        UK_ASSERT(dev->ops->txq_configure);
        UK_ASSERT(dev->ops->start);
+       UK_ASSERT(dev->ops->promiscuous_get);
 
        dev->_data = _alloc_data(a, netdev_count,  drv_name);
        if (!dev->_data)
@@ -449,3 +450,37 @@ const struct uk_hwaddr *uk_netdev_hwaddr_get(struct 
uk_netdev *dev)
 
        return dev->ops->hwaddr_get(dev);
 }
+
+unsigned uk_netdev_promiscuous_get(struct uk_netdev *dev)
+{
+       UK_ASSERT(dev);
+       UK_ASSERT(dev->_data);
+       UK_ASSERT(dev->ops);
+       UK_ASSERT(dev->ops->promiscuous_get);
+
+       /* We do support retrieving of promiscuous mode
+        * only when device was configured
+        */
+       UK_ASSERT(dev->_data->state == UK_NETDEV_CONFIGURED ||
+                 dev->_data->state == UK_NETDEV_RUNNING);
+
+       return dev->ops->promiscuous_get(dev);
+}
+
+int uk_netdev_promiscuous_set(struct uk_netdev *dev, unsigned mode)
+{
+       UK_ASSERT(dev);
+       UK_ASSERT(dev->_data);
+       UK_ASSERT(dev->ops);
+
+       /* We do support setting of promiscuous mode
+        * only when device was configured
+        */
+       UK_ASSERT(dev->_data->state == UK_NETDEV_CONFIGURED
+                 || dev->_data->state == UK_NETDEV_RUNNING);
+
+       if (unlikely(!dev->ops->promiscuous_set))
+               return -ENOTSUP;
+
+       return dev->ops->promiscuous_set(dev, mode ? 1 : 0);
+}
-- 
2.7.4


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.