netdev/ioctl: Add support for simple VLAN ioctl

Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN
Ref: https://github.com/torvalds/linux/blob/v6.12/net/8021q/vlan.c#L621

Signed-off-by: Zhe Weng <wengzhe@xiaomi.com>
This commit is contained in:
Zhe Weng
2025-01-07 17:30:59 +08:00
committed by Alan C. Assis
parent 242c253178
commit 2b34bcfcb1
4 changed files with 137 additions and 2 deletions
+58
View File
@@ -45,6 +45,7 @@
#include <nuttx/net/netdev.h>
#include <nuttx/net/radiodev.h>
#include <nuttx/net/vlan.h>
#ifdef CONFIG_NET_6LOWPAN
# include <nuttx/net/sixlowpan.h>
@@ -653,6 +654,53 @@ static int netdev_wifr_ioctl(FAR struct socket *psock, int cmd,
}
#endif
/****************************************************************************
* Name: netdev_vlan_ioctl
*
* Description:
* Perform VLAN network device specific operations.
*
* Input Parameters:
* psock Socket structure
* cmd The ioctl command
* req The argument of the ioctl cmd
*
* Returned Value:
* >=0 on success (positive non-zero values are cmd-specific)
* Negated errno returned on failure.
*
****************************************************************************/
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_VLAN)
static int netdev_vlan_ioctl(FAR struct socket *psock, int cmd,
FAR struct vlan_ioctl_args *req)
{
FAR struct net_driver_s *dev;
int ret = -ENOTTY;
/* Verify that this is a valid VLAN IOCTL command */
if (cmd == SIOCGIFVLAN || cmd == SIOCSIFVLAN)
{
/* Get the network device associated with the IOCTL command */
dev = netdev_findbyname(req->device1);
if (dev != NULL)
{
/* Just forward the IOCTL to the network driver */
ret = dev->d_ioctl(dev, cmd, (unsigned long)(uintptr_t)req);
}
else
{
ret = -ENODEV;
}
}
return ret;
}
#endif
/****************************************************************************
* Name: netdev_ifr_split_idx
*
@@ -1865,6 +1913,16 @@ int psock_vioctl(FAR struct socket *psock, int cmd, va_list ap)
}
#endif
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_VLAN)
/* Check for a VLAN command */
if (ret == -ENOTTY)
{
ret = netdev_vlan_ioctl(psock, cmd,
(FAR struct vlan_ioctl_args *)(uintptr_t)arg);
}
#endif
#ifdef HAVE_IEEE802154_IOCTL
/* Check for a IEEE802.15.4 network device IOCTL command */