net/vlan: add some macro for vlan

Refer:
https://github.com/torvalds/linux/blob/v6.8/include/linux/if_vlan.h#L73-L76

Signed-off-by: gaohedong <gaohedong@xiaomi.com>
This commit is contained in:
gaohedong
2024-11-20 09:03:21 +08:00
committed by Xiang Xiao
parent 3f553999da
commit 44bc5ed635
2 changed files with 88 additions and 1 deletions
@@ -13,5 +13,81 @@ Vlan Device Drivers
- Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN. - Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN.
- We add default PCP because some of our apps may not want to set - We add default PCP because some of our apps may not want to set
PCP manually PCP manually
- ``include/nuttx/net/ethernet.h``. Some definitions for 802.1Q VLAN
.. code-block:: c
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
#define VLAN_PRIO_SHIFT 13
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
#define VLAN_N_VID 4096
- **Driver**: ``drivers/net/vlan.c`` - **Driver**: ``drivers/net/vlan.c``
Configuration Options
=====================
``CONFIG_NET_VLAN``
Enable 802.1Q VLAN interface support.
``CONFIG_NET_VLAN_COUNT``
Maximum number of VLAN interfaces per physical Ethernet interface.
Usage
=====
.. code-block:: c
#include <nuttx/net/vlan.h>
#include "netutils/netlib.h"
/* Create a VLAN interface (eth0.100, VLAN ID 100) */
FAR const char *ifname = "eth0";
uint16_t vlanid = 100;
uint8_t priority = 0; /* Default PCP */
int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
if (sockfd >= 0)
{
struct vlan_ioctl_args ifv;
strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1));
ifv.u.VID = vlanid;
ifv.vlan_qos = priority;
ifv.cmd = ADD_VLAN_CMD;
if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0)
{
/* Handle error */
}
close(sockfd);
}
/* Enable the VLAN interface */
netdev_ifup("eth0.100");
.. code-block:: c
#include <nuttx/net/vlan.h>
#include "netutils/netlib.h"
/* Delete a VLAN interface (eth0.100, VLAN ID 100) */
FAR const char *ifname = "eth0.100";
int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
if (sockfd >= 0)
{
struct vlan_ioctl_args ifv;
strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1));
ifv.cmd = DEL_VLAN_CMD;
if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0)
{
/* Handle error */
}
close(sockfd);
}
+12 -1
View File
@@ -2,7 +2,8 @@
* include/nuttx/net/ethernet.h * include/nuttx/net/ethernet.h
* *
* SPDX-License-Identifier: BSD-3-Clause * SPDX-License-Identifier: BSD-3-Clause
* SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved. * SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights
* reserved.
* SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved. * SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved.
* SPDX-FileContributor: Gregory Nutt <gnutt@nuttx.org> * SPDX-FileContributor: Gregory Nutt <gnutt@nuttx.org>
* SPDX-FileContributor: Adam Dunkels <adam@dunkels.com> * SPDX-FileContributor: Adam Dunkels <adam@dunkels.com>
@@ -63,6 +64,16 @@
#define TPID_8021QVLAN ETHERTYPE_VLAN #define TPID_8021QVLAN ETHERTYPE_VLAN
/* These are some control information associated with QVLAN tagged
* Ethernet packets.
*/
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
#define VLAN_PRIO_SHIFT 13
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
#define VLAN_N_VID 4096
/* These are some of the types associated with QVLAN tagged /* These are some of the types associated with QVLAN tagged
* Ethernet packets. * Ethernet packets.
*/ */