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 <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng
2024-07-23 16:47:31 +08:00
committed by Alan Carvalho de Assis
parent 33ddf1a297
commit 90c0acce05
2 changed files with 19 additions and 0 deletions
+18
View File
@@ -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;
}
+1
View File
@@ -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 ************************************************************/