You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/12/20 13:15:55 UTC
[nuttx] branch master updated: tun: add ioctl cmd TUNGETIFF implement
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang 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 ba9ef06970 tun: add ioctl cmd TUNGETIFF implement
ba9ef06970 is described below
commit ba9ef0697079a278dac9c2d59a97269de1e79395
Author: zhanghongyu <zh...@xiaomi.com>
AuthorDate: Tue Dec 20 16:32:20 2022 +0800
tun: add ioctl cmd TUNGETIFF implement
Signed-off-by: zhanghongyu <zh...@xiaomi.com>
---
drivers/net/tun.c | 16 ++++++++++++++--
include/nuttx/net/ioctl.h | 1 +
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index ecffb10b07..751efeaf2d 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -1177,13 +1177,13 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
FAR struct tun_device_s *priv = filep->f_priv;
int ret = OK;
- if (cmd == TUNSETIFF && priv == NULL)
+ if (cmd == TUNSETIFF)
{
uint8_t free_tuns;
int intf;
FAR struct ifreq *ifr = (FAR struct ifreq *)arg;
- if (ifr == NULL ||
+ if (priv != NULL || ifr == NULL ||
((ifr->ifr_flags & IFF_MASK) != IFF_TUN &&
(ifr->ifr_flags & IFF_MASK) != IFF_TAP))
{
@@ -1223,6 +1223,18 @@ static int tun_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
strlcpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ);
nxmutex_unlock(&tun->lock);
+ return OK;
+ }
+ else if (cmd == TUNGETIFF)
+ {
+ FAR struct ifreq *ifr = (FAR struct ifreq *)arg;
+ if (priv == NULL || ifr == NULL)
+ {
+ return -EINVAL;
+ }
+
+ strlcpy(ifr->ifr_name, priv->dev.d_ifname, IFNAMSIZ);
+
return OK;
}
diff --git a/include/nuttx/net/ioctl.h b/include/nuttx/net/ioctl.h
index 4e82bb440c..9ba5635ab4 100644
--- a/include/nuttx/net/ioctl.h
+++ b/include/nuttx/net/ioctl.h
@@ -106,6 +106,7 @@
/* TUN/TAP driver ***********************************************************/
#define TUNSETIFF _SIOC(0x0028) /* Set TUN/TAP interface */
+#define TUNGETIFF _SIOC(0x0035) /* Get TUN/TAP interface */
/* Telnet driver ************************************************************/