This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 90c0acce05 net/tun: Support changing carrier state of TUN/TAP
90c0acce05 is described below

commit 90c0acce058895cfba7bb87d6cfdd521b18b929a
Author: Zhe Weng <weng...@xiaomi.com>
AuthorDate: Tue Jul 23 16:47:31 2024 +0800

    net/tun: Support changing carrier state of TUN/TAP
    
    Add TUNSETCARRIER ioctl, then we may change the carrier state of TUN 
dynamically. Note that we don't need an ioctl for getting carrier, it can be 
done by SIOCGIFFLAGS already.
    
    Ref: 
https://github.com/torvalds/linux/blob/v6.10/drivers/net/tun.c#L3374-L3380
    
    Signed-off-by: Zhe Weng <weng...@xiaomi.com>
---
 drivers/net/tun.c         | 18 ++++++++++++++++++
 include/nuttx/net/ioctl.h |  1 +
 2 files changed, 19 insertions(+)

diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index 9d84b959da..515de58d6d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1268,6 +1268,24 @@ static int tun_ioctl(FAR struct file *filep, int cmd, 
unsigned long arg)
 
       return OK;
     }
+  else if (cmd == TUNSETCARRIER)
+    {
+      if (priv == NULL || arg == 0)
+        {
+          return -EINVAL;
+        }
+
+      if (*(FAR int *)((uintptr_t)arg))
+        {
+          netdev_carrier_on(&priv->dev);
+        }
+      else
+        {
+          netdev_carrier_off(&priv->dev);
+        }
+
+      return OK;
+    }
 
   return -ENOTTY;
 }
diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h
index fc59d0e485..c795307463 100644
--- a/include/nuttx/net/ioctl.h
+++ b/include/nuttx/net/ioctl.h
@@ -107,6 +107,7 @@
 
 #define TUNSETIFF        _SIOC(0x0028)  /* Set TUN/TAP interface */
 #define TUNGETIFF        _SIOC(0x0035)  /* Get TUN/TAP interface */
+#define TUNSETCARRIER    _SIOC(0x0040)  /* Set TUN/TAP carrier state */
 
 /* Telnet driver ************************************************************/
 

Reply via email to