mirror of
https://github.com/apache/nuttx.git
synced 2026-06-01 16:59:28 +08:00
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:
@@ -13,5 +13,81 @@ Vlan Device Drivers
|
||||
- Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN.
|
||||
- We add default PCP because some of our apps may not want to set
|
||||
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``
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -2,7 +2,8 @@
|
||||
* include/nuttx/net/ethernet.h
|
||||
*
|
||||
* 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-FileContributor: Gregory Nutt <gnutt@nuttx.org>
|
||||
* SPDX-FileContributor: Adam Dunkels <adam@dunkels.com>
|
||||
@@ -63,6 +64,16 @@
|
||||
|
||||
#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
|
||||
* Ethernet packets.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user