Skip to content

Commit 44bc5ed

Browse files
HedongGaoxiaoxiang781216
authored andcommitted
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 <[email protected]>
1 parent 3f55399 commit 44bc5ed

File tree

2 files changed

+88
-1
lines changed

2 files changed

+88
-1
lines changed

Documentation/components/drivers/special/net/vlan.rst

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,81 @@ Vlan Device Drivers
1313
- Supporting ADD_VLAN_CMD and DEL_VLAN_CMD of SIOCSIFVLAN.
1414
- We add default PCP because some of our apps may not want to set
1515
PCP manually
16+
- ``include/nuttx/net/ethernet.h``. Some definitions for 802.1Q VLAN
17+
18+
.. code-block:: c
19+
20+
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
21+
#define VLAN_PRIO_SHIFT 13
22+
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
23+
#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
24+
#define VLAN_N_VID 4096
1625
1726
- **Driver**: ``drivers/net/vlan.c``
27+
28+
Configuration Options
29+
=====================
30+
31+
``CONFIG_NET_VLAN``
32+
Enable 802.1Q VLAN interface support.
33+
``CONFIG_NET_VLAN_COUNT``
34+
Maximum number of VLAN interfaces per physical Ethernet interface.
35+
36+
Usage
37+
=====
38+
39+
.. code-block:: c
40+
41+
#include <nuttx/net/vlan.h>
42+
#include "netutils/netlib.h"
43+
44+
/* Create a VLAN interface (eth0.100, VLAN ID 100) */
45+
46+
FAR const char *ifname = "eth0";
47+
uint16_t vlanid = 100;
48+
uint8_t priority = 0; /* Default PCP */
49+
50+
int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
51+
52+
if (sockfd >= 0)
53+
{
54+
struct vlan_ioctl_args ifv;
55+
56+
strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1));
57+
ifv.u.VID = vlanid;
58+
ifv.vlan_qos = priority;
59+
ifv.cmd = ADD_VLAN_CMD;
60+
if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0)
61+
{
62+
/* Handle error */
63+
}
64+
close(sockfd);
65+
}
66+
67+
/* Enable the VLAN interface */
68+
69+
netdev_ifup("eth0.100");
70+
71+
.. code-block:: c
72+
73+
#include <nuttx/net/vlan.h>
74+
#include "netutils/netlib.h"
75+
76+
/* Delete a VLAN interface (eth0.100, VLAN ID 100) */
77+
78+
FAR const char *ifname = "eth0.100";
79+
80+
int sockfd = socket(NET_SOCK_FAMILY, NET_SOCK_TYPE, NET_SOCK_PROTOCOL);
81+
82+
if (sockfd >= 0)
83+
{
84+
struct vlan_ioctl_args ifv;
85+
86+
strncpy(ifv.vlan_devname, ifname, sizeof(ifv.device1));
87+
ifv.cmd = DEL_VLAN_CMD;
88+
if (ioctl(sockfd, SIOCSIFVLAN, (unsigned long)&ifv) < 0)
89+
{
90+
/* Handle error */
91+
}
92+
close(sockfd);
93+
}

include/nuttx/net/ethernet.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
* include/nuttx/net/ethernet.h
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
5-
* SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights reserved.
5+
* SPDX-FileCopyrightText: 2007, 2009-2012, 2015 Gregory Nutt. All rights
6+
* reserved.
67
* SPDX-FileCopyrightText: 2001-2003, Adam Dunkels. All rights reserved.
78
* SPDX-FileContributor: Gregory Nutt <[email protected]>
89
* SPDX-FileContributor: Adam Dunkels <[email protected]>
@@ -63,6 +64,16 @@
6364

6465
#define TPID_8021QVLAN ETHERTYPE_VLAN
6566

67+
/* These are some control information associated with QVLAN tagged
68+
* Ethernet packets.
69+
*/
70+
71+
#define VLAN_PRIO_MASK 0xe000 /* Priority Code Point */
72+
#define VLAN_PRIO_SHIFT 13
73+
#define VLAN_CFI_MASK 0x1000 /* Canonical Format Indicator / Drop Eligible Indicator */
74+
#define VLAN_VID_MASK 0x0fff /* VLAN Identifier */
75+
#define VLAN_N_VID 4096
76+
6677
/* These are some of the types associated with QVLAN tagged
6778
* Ethernet packets.
6879
*/

0 commit comments

Comments
 (0)