This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit f932574af7296265607211311c2722c154f3669c Author: wangjinjing1 <[email protected]> AuthorDate: Wed Feb 4 16:40:42 2026 +0800 net/upperhalf: vlan device support rxtype setting from ioctl Allow the rxtype of a VLAN device to be configured through ioctl so the VLAN receive mode can be changed at runtime, independently of the real device. Also copy the MTU from the real device when the VLAN device is created. Signed-off-by: wangjinjing1 <[email protected]> --- drivers/net/netdev_upperhalf.c | 3 ++- drivers/net/vlan.c | 26 ++++++++++++++++++++------ include/nuttx/net/netdev_lowerhalf.h | 9 +++++---- include/nuttx/net/vlan.h | 7 ++++++- 4 files changed, 33 insertions(+), 12 deletions(-) diff --git a/drivers/net/netdev_upperhalf.c b/drivers/net/netdev_upperhalf.c index e3f085e19fc..9bef3d33b25 100644 --- a/drivers/net/netdev_upperhalf.c +++ b/drivers/net/netdev_upperhalf.c @@ -1230,7 +1230,8 @@ int netdev_upper_vlan_ioctl(FAR struct netdev_lowerhalf_s *lower, switch (args->cmd) { case ADD_VLAN_CMD: - return vlan_register(lower, args->u.VID, args->vlan_qos); + return vlan_register(lower, args->u.VID, args->vlan_qos, + args->rx_type, args->rx_priority); case DEL_VLAN_CMD: vlan_unregister(lower); diff --git a/drivers/net/vlan.c b/drivers/net/vlan.c index 9221877d5c0..d2290224291 100644 --- a/drivers/net/vlan.c +++ b/drivers/net/vlan.c @@ -40,7 +40,7 @@ * Pre-processor Definitions ****************************************************************************/ -#define VLAN_DEV_NAME_FMT "%s.%i" +#define VLAN_DEV_NAME_FMT "%.*s.%u" /**************************************************************************** * Private Types @@ -311,10 +311,9 @@ static void vlan_txpoll(FAR struct netdev_lowerhalf_s *dev) ****************************************************************************/ int vlan_register(FAR struct netdev_lowerhalf_s *real, uint16_t vid, - uint16_t prio) + uint16_t prio, uint8_t rx_type, uint8_t rx_priority) { FAR struct vlan_device_s *vlan; - char vlanifname[IFNAMSIZ + 8]; int ret; if (real == NULL || real->netdev.d_lltype != NET_LL_ETHERNET) @@ -329,6 +328,12 @@ int vlan_register(FAR struct netdev_lowerhalf_s *real, uint16_t vid, return -EINVAL; } + if (rx_type > NETDEV_RX_DEFAULT) + { + nerr("ERROR: Invalid vlan rx_type %d\n", rx_type); + return -EINVAL; + } + /* Create a new VLAN device */ vlan = kmm_zalloc(sizeof(struct vlan_device_s)); @@ -348,11 +353,14 @@ int vlan_register(FAR struct netdev_lowerhalf_s *real, uint16_t vid, vlan->dev.priority = real->priority; vlan->dev.ops = &g_vlan_ops; + /* Copy MTU from the real device */ + + vlan->dev.netdev.d_pktsize = real->netdev.d_pktsize; + /* Set the VLAN device name, use a buffer to make compiler happy */ - snprintf(vlanifname, sizeof(vlanifname), VLAN_DEV_NAME_FMT, - real->netdev.d_ifname, vid); - strlcpy(vlan->dev.netdev.d_ifname, vlanifname, IFNAMSIZ); + snprintf(vlan->dev.netdev.d_ifname, IFNAMSIZ, VLAN_DEV_NAME_FMT, + IFNAMSIZ - 6, real->netdev.d_ifname, vid); /* Copy the MAC address from the real device */ @@ -368,6 +376,12 @@ int vlan_register(FAR struct netdev_lowerhalf_s *real, uint16_t vid, goto errout; } + if (rx_type != NETDEV_RX_DEFAULT) + { + vlan->dev.rxtype = rx_type; + vlan->dev.priority = rx_priority; + } + ret = netdev_lower_register(&vlan->dev, NET_LL_ETHERNET); if (ret < 0) { diff --git a/include/nuttx/net/netdev_lowerhalf.h b/include/nuttx/net/netdev_lowerhalf.h index 7bd1631a6c3..1cea1133422 100644 --- a/include/nuttx/net/netdev_lowerhalf.h +++ b/include/nuttx/net/netdev_lowerhalf.h @@ -90,10 +90,11 @@ enum netpkt_type_e enum netdev_rx_e { - NETDEV_RX_WORK, /* Use work queue thread */ - NETDEV_RX_DIRECT, /* Directly based on the current thread */ - NETDEV_RX_THREAD, /* Upper half dedicated thread */ - NETDEV_RX_THREAD_RSS /* RSS mode, upper half thread */ + NETDEV_RX_WORK, /* Use work queue thread */ + NETDEV_RX_DIRECT, /* Directly based on the current thread */ + NETDEV_RX_THREAD, /* Upper half dedicated thread */ + NETDEV_RX_THREAD_RSS, /* RSS mode, upper half thread */ + NETDEV_RX_DEFAULT /* Inherit real device rxtype for vlan */ }; /* This structure is the generic form of state structure used by lower half diff --git a/include/nuttx/net/vlan.h b/include/nuttx/net/vlan.h index a8d2b2e8b76..ba8a93b6098 100644 --- a/include/nuttx/net/vlan.h +++ b/include/nuttx/net/vlan.h @@ -76,6 +76,11 @@ struct vlan_ioctl_args } u; int16_t vlan_qos; + + /* Rx mode setting for vlan device */ + + uint8_t rx_type; /* Value defined in enum netdev_rx_e */ + uint8_t rx_priority; /* Rx thread priority when rxtype == NETDEV_RX_THREAD */ }; /**************************************************************************** @@ -108,7 +113,7 @@ extern "C" ****************************************************************************/ int vlan_register(FAR struct netdev_lowerhalf_s *real, uint16_t vid, - uint16_t prio); + uint16_t prio, uint8_t rx_type, uint8_t rx_priority); /**************************************************************************** * Name: vlan_unregister
