iPXE
vlan.h File Reference

Virtual LANs. More...

#include <ipxe/netdevice.h>

Go to the source code of this file.

Data Structures

struct  vlan_header
 A VLAN header. More...

Macros

#define VLAN_TAG(tci)
 Extract VLAN tag from tag control information.
#define VLAN_PRIORITY(tci)
 Extract VLAN priority from tag control information.
#define VLAN_TCI(tag, priority)
 Construct VLAN tag control information.
#define VLAN_TAG_IS_VALID(tag)
 Check VLAN tag is valid.
#define VLAN_PRIORITY_IS_VALID(priority)
 Check VLAN priority is valid.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
unsigned int vlan_tci (struct net_device *netdev)
 Get the VLAN tag control information.
static unsigned int vlan_tag (struct net_device *netdev)
 Get the VLAN tag.
struct net_devicevlan_find (struct net_device *trunk, unsigned int tag)
 Identify VLAN device.
int vlan_can_be_trunk (struct net_device *trunk)
 Check if network device can be used as a VLAN trunk device.
int vlan_create (struct net_device *trunk, unsigned int tag, unsigned int priority)
 Create VLAN device.
int vlan_destroy (struct net_device *netdev)
 Destroy VLAN device.
void vlan_auto (const void *ll_addr, unsigned int tag)
 Configure automatic VLAN device.
void vlan_netdev_rx (struct net_device *netdev, unsigned int tag, struct io_buffer *iobuf)
 Add VLAN tag-stripped packet to queue (when VLAN support is not present).
void vlan_netdev_rx_err (struct net_device *netdev, unsigned int tag, struct io_buffer *iobuf, int rc)
 Discard received VLAN tag-stripped packet (when VLAN support is not present).

Detailed Description

Virtual LANs.

Definition in file vlan.h.

Macro Definition Documentation

◆ VLAN_TAG

#define VLAN_TAG ( tci)
Value:
( (tci) & 0x0fff )

Extract VLAN tag from tag control information.

Parameters
tciTag control information
Return values
tagVLAN tag

Definition at line 30 of file vlan.h.

Referenced by efi_snp_probe(), efi_vlan_find(), intelxl_poll_rx(), vlan_rx(), and vlan_tag().

◆ VLAN_PRIORITY

#define VLAN_PRIORITY ( tci)
Value:
( (tci) >> 13 )

Extract VLAN priority from tag control information.

Parameters
tciTag control information
Return values
priorityPriority

Definition at line 38 of file vlan.h.

Referenced by efi_vlan_find().

◆ VLAN_TCI

#define VLAN_TCI ( tag,
priority )
Value:
( ( (priority) << 13 ) | (tag) )
uint64_t tag
Identity tag.
Definition edd.h:1
uint16_t priority
Priotity.
Definition stp.h:1

Construct VLAN tag control information.

Parameters
tagVLAN tag
priorityPriority
Return values
tciTag control information

Definition at line 47 of file vlan.h.

Referenced by vlan_tci(), and vlan_transmit().

◆ VLAN_TAG_IS_VALID

#define VLAN_TAG_IS_VALID ( tag)
Value:
( (tag) < 0xfff )

Check VLAN tag is valid.

Parameters
tagVLAN tag
Return values
is_validVLAN tag is valid

Definition at line 55 of file vlan.h.

Referenced by efi_vlan_find(), and vlan_create().

◆ VLAN_PRIORITY_IS_VALID

#define VLAN_PRIORITY_IS_VALID ( priority)
Value:
( (priority) <= 7 )

Check VLAN priority is valid.

Parameters
priorityVLAN priority
Return values
is_validVLAN priority is valid

Definition at line 63 of file vlan.h.

Referenced by vlan_create().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

◆ vlan_tci()

unsigned int vlan_tci ( struct net_device * netdev)
extern

Get the VLAN tag control information.

Parameters
netdevNetwork device
Return values
tciVLAN tag control information, or 0 if not a VLAN device

Definition at line 303 of file vlan.c.

303 {
304 struct vlan_device *vlan;
305
306 if ( netdev->op == &vlan_operations ) {
307 vlan = netdev->priv;
308 return ( VLAN_TCI ( vlan->tag, vlan->priority ) );
309 } else {
310 return 0;
311 }
312}
static struct net_device * netdev
Definition gdbudp.c:53
VLAN device private data.
Definition vlan.c:50
unsigned int priority
Default priority.
Definition vlan.c:56
unsigned int tag
VLAN tag.
Definition vlan.c:54
static struct net_device_operations vlan_operations
VLAN device operations.
Definition vlan.c:171
#define VLAN_TCI(tag, priority)
Construct VLAN tag control information.
Definition vlan.h:47

References netdev, vlan_device::priority, vlan_device::tag, vlan_operations, and VLAN_TCI.

◆ vlan_tag()

unsigned int vlan_tag ( struct net_device * netdev)
inlinestatic

Get the VLAN tag.

Parameters
netdevNetwork device
Return values
tagVLAN tag, or 0 if device is not a VLAN device

Definition at line 74 of file vlan.h.

74 {
75 return VLAN_TAG ( vlan_tci ( netdev ) );
76}
__weak unsigned int vlan_tci(struct net_device *netdev __unused)
Get the VLAN tag control information (when VLAN support is not present).
Definition netdevice.c:1203
#define VLAN_TAG(tci)
Extract VLAN tag from tag control information.
Definition vlan.h:30

References netdev, VLAN_TAG, and vlan_tci().

Referenced by cachedhcp_apply(), eapol_probe(), efi_netdev_path(), efi_path_net_probe(), ibft_fill_nic(), and is_autoboot_ll_addr().

◆ vlan_find()

struct net_device * vlan_find ( struct net_device * trunk,
unsigned int tag )
extern

Identify VLAN device.

Parameters
trunkTrunk network device
tagVLAN tag
Return values
netdevVLAN device, if any

Definition at line 209 of file vlan.c.

209 {
210 struct net_device *netdev;
211 struct vlan_device *vlan;
212
214 if ( netdev->op != &vlan_operations )
215 continue;
216 vlan = netdev->priv;
217 if ( ( vlan->trunk == trunk ) && ( vlan->tag == tag ) )
218 return netdev;
219 }
220 return NULL;
221}
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition netdevice.h:550
A network device.
Definition netdevice.h:353
struct net_device * trunk
Trunk network device.
Definition vlan.c:52

References for_each_netdev, netdev, NULL, tag, vlan_device::tag, vlan_device::trunk, and vlan_operations.

Referenced by efi_vlan_find(), efi_vlan_remove(), vlan_create(), vlan_netdev_rx(), vlan_netdev_rx_err(), and vlan_rx().

◆ vlan_can_be_trunk()

int vlan_can_be_trunk ( struct net_device * trunk)
extern

Check if network device can be used as a VLAN trunk device.

Parameters
trunkTrunk network device
Return values
is_okTrunk network device is usable

VLAN devices will be created as Ethernet devices. (We cannot simply clone the link layer of the trunk network device, because this link layer may expect the network device structure to contain some link-layer-private data.) The trunk network device must therefore have a link layer that is in some sense 'compatible' with Ethernet; specifically, it must have link-layer addresses that are the same length as Ethernet link-layer addresses.

As an additional check, and primarily to assist with the sanity of the FCoE code, we refuse to allow nested VLANs.

Definition at line 331 of file vlan.c.

331 {
332
333 return ( ( trunk->ll_protocol->ll_addr_len == ETH_ALEN ) &&
334 ( trunk->op != &vlan_operations ) );
335}
#define ETH_ALEN
Definition if_ether.h:9
uint8_t ll_addr_len
Link-layer address length.
Definition netdevice.h:199
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition netdevice.h:373
struct net_device_operations * op
Network device operations.
Definition netdevice.h:370

References ETH_ALEN, ll_protocol::ll_addr_len, net_device::ll_protocol, net_device::op, vlan_device::trunk, and vlan_operations.

Referenced by fcoe_expired(), fcoe_reset(), vlan_create(), and vlan_probe().

◆ vlan_create()

int vlan_create ( struct net_device * trunk,
unsigned int tag,
unsigned int priority )
extern

Create VLAN device.

Parameters
trunkTrunk network device
tagVLAN tag
priorityDefault VLAN priority
Return values
rcReturn status code

Definition at line 345 of file vlan.c.

346 {
347 struct net_device *netdev;
348 struct vlan_device *vlan;
349 int rc;
350
351 /* If VLAN already exists, just update the priority */
352 if ( ( netdev = vlan_find ( trunk, tag ) ) != NULL ) {
353 vlan = netdev->priv;
354 if ( priority != vlan->priority ) {
355 DBGC ( netdev, "VLAN %s priority changed from %d to "
356 "%d\n", netdev->name, vlan->priority, priority );
357 }
358 vlan->priority = priority;
359 return 0;
360 }
361
362 /* Sanity checks */
363 if ( ! vlan_can_be_trunk ( trunk ) ) {
364 DBGC ( trunk, "VLAN %s cannot create VLAN on non-trunk "
365 "device\n", trunk->name );
366 rc = -ENOTTY;
367 goto err_sanity;
368 }
369 if ( ! VLAN_TAG_IS_VALID ( tag ) ) {
370 DBGC ( trunk, "VLAN %s cannot create VLAN with invalid tag "
371 "%d\n", trunk->name, tag );
372 rc = -EINVAL;
373 goto err_sanity;
374 }
375 if ( ! VLAN_PRIORITY_IS_VALID ( priority ) ) {
376 DBGC ( trunk, "VLAN %s cannot create VLAN with invalid "
377 "priority %d\n", trunk->name, priority );
378 rc = -EINVAL;
379 goto err_sanity;
380 }
381
382 /* Allocate and initialise structure */
383 netdev = alloc_etherdev ( sizeof ( *vlan ) );
384 if ( ! netdev ) {
385 rc = -ENOMEM;
386 goto err_alloc_etherdev;
387 }
389 netdev->dev = trunk->dev;
390 memcpy ( netdev->hw_addr, trunk->ll_addr, ETH_ALEN );
391 vlan = netdev->priv;
392 vlan->trunk = netdev_get ( trunk );
393 vlan->tag = tag;
394 vlan->priority = priority;
395
396 /* Construct VLAN device name */
397 snprintf ( netdev->name, sizeof ( netdev->name ), "%s-%d",
398 trunk->name, vlan->tag );
399
400 /* Mark device as not supporting interrupts, if applicable */
401 if ( ! netdev_irq_supported ( trunk ) )
403
404 /* Register VLAN device */
405 if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
406 DBGC ( netdev, "VLAN %s could not register: %s\n",
407 netdev->name, strerror ( rc ) );
408 goto err_register;
409 }
410
411 /* Synchronise with trunk device */
412 vlan_sync ( netdev );
413
414 DBGC ( netdev, "VLAN %s created with tag %d and priority %d\n",
415 netdev->name, vlan->tag, vlan->priority );
416
417 return 0;
418
420 err_register:
422 netdev_put ( netdev );
423 netdev_put ( trunk );
424 err_alloc_etherdev:
425 err_sanity:
426 return rc;
427}
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition ethernet.c:266
#define DBGC(...)
Definition compiler.h:530
#define EINVAL
Invalid argument.
Definition errno.h:472
#define ENOMEM
Not enough space.
Definition errno.h:578
#define ENOTTY
Inappropriate I/O control operation.
Definition errno.h:638
void * memcpy(void *dest, const void *src, size_t len) __nonnull
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition netdevice.c:946
int register_netdev(struct net_device *netdev)
Register network device.
Definition netdevice.c:760
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition netdevice.h:568
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition netdevice.h:676
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition netdevice.h:522
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition netdevice.h:535
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition netdevice.h:453
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition netdevice.h:579
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition netdevice.h:363
struct device * dev
Underlying hardware device.
Definition netdevice.h:365
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition netdevice.h:388
int vlan_can_be_trunk(struct net_device *trunk)
Check if network device can be used as a VLAN trunk device.
Definition vlan.c:331
struct net_device * vlan_find(struct net_device *trunk, unsigned int tag)
Identify VLAN device.
Definition vlan.c:209
static void vlan_sync(struct net_device *netdev)
Synchronise VLAN device.
Definition vlan.c:184
#define VLAN_TAG_IS_VALID(tag)
Check VLAN tag is valid.
Definition vlan.h:55
#define VLAN_PRIORITY_IS_VALID(priority)
Check VLAN priority is valid.
Definition vlan.h:63
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References alloc_etherdev(), DBGC, net_device::dev, EINVAL, ENOMEM, ENOTTY, ETH_ALEN, net_device::ll_addr, memcpy(), net_device::name, netdev, netdev_get(), netdev_init(), netdev_irq_supported(), NETDEV_IRQ_UNSUPPORTED, netdev_nullify(), netdev_put(), NULL, priority, vlan_device::priority, rc, register_netdev(), snprintf(), strerror(), tag, vlan_device::tag, vlan_device::trunk, unregister_netdev(), vlan_can_be_trunk(), vlan_find(), vlan_operations, VLAN_PRIORITY_IS_VALID, vlan_sync(), and VLAN_TAG_IS_VALID.

Referenced by efi_vlan_set(), fcoe_fip_rx_vlan(), vcreate_exec(), and vlan_probe().

◆ vlan_destroy()

int vlan_destroy ( struct net_device * netdev)
extern

Destroy VLAN device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 435 of file vlan.c.

435 {
436 struct vlan_device *vlan = netdev->priv;
437 struct net_device *trunk;
438
439 /* Sanity check */
440 if ( netdev->op != &vlan_operations ) {
441 DBGC ( netdev, "VLAN %s cannot destroy non-VLAN device\n",
442 netdev->name );
443 return -ENOTTY;
444 }
445
446 DBGC ( netdev, "VLAN %s destroyed\n", netdev->name );
447
448 /* Remove VLAN device */
450 trunk = vlan->trunk;
452 netdev_put ( netdev );
453 netdev_put ( trunk );
454
455 return 0;
456}

References DBGC, ENOTTY, netdev, netdev_nullify(), netdev_put(), vlan_device::trunk, unregister_netdev(), and vlan_operations.

Referenced by efi_vlan_remove(), vdestroy_exec(), and vlan_remove_first().

◆ vlan_auto()

void vlan_auto ( const void * ll_addr,
unsigned int tag )
extern

Configure automatic VLAN device.

Parameters
ll_addrLink-layer address
tagVLAN tag

Definition at line 464 of file vlan.c.

464 {
465
466 /* Record link-layer address and VLAN tag */
467 memcpy ( vlan_auto_ll_addr, ll_addr, ETH_ALEN );
469}
static uint8_t vlan_auto_ll_addr[ETH_ALEN]
Automatic VLAN device link-layer address.
Definition vlan.c:60
static unsigned int vlan_auto_tag
Automatic VLAN tag.
Definition vlan.c:63

References ETH_ALEN, net_device::ll_addr, memcpy(), tag, vlan_auto_ll_addr, and vlan_auto_tag.

Referenced by efi_set_autoboot_ll_addr().

◆ vlan_netdev_rx()

void vlan_netdev_rx ( struct net_device * netdev,
unsigned int tag,
struct io_buffer * iobuf )
extern

Add VLAN tag-stripped packet to queue (when VLAN support is not present).

Parameters
netdevNetwork device
tagVLAN tag, or zero
iobufI/O buffer

Add VLAN tag-stripped packet to queue (when VLAN support is not present).

Parameters
netdevNetwork device
tagVLAN tag, or zero
iobufI/O buffer

Definition at line 1214 of file netdevice.c.

1215 {
1216
1217 if ( tag == 0 ) {
1218 netdev_rx ( netdev, iobuf );
1219 } else {
1220 netdev_rx_err ( netdev, iobuf, -ENODEV );
1221 }
1222}
#define ENODEV
No such device.
Definition errno.h:553
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition netdevice.c:549
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition netdevice.c:587

References __weak, ENODEV, netdev, netdev_rx(), netdev_rx_err(), NULL, tag, and vlan_find().

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().

◆ vlan_netdev_rx_err()

void vlan_netdev_rx_err ( struct net_device * netdev,
unsigned int tag ,
struct io_buffer * iobuf,
int rc )
extern

Discard received VLAN tag-stripped packet (when VLAN support is not present).

Parameters
netdevNetwork device
tagVLAN tag, or zero
iobufI/O buffer, or NULL
rcPacket status code

Discard received VLAN tag-stripped packet (when VLAN support is not present).

Parameters
netdevNetwork device
tagVLAN tag, or zero
iobufI/O buffer, or NULL
rcPacket status code

Definition at line 1232 of file netdevice.c.

1234 {
1235
1236 netdev_rx_err ( netdev, iobuf, rc );
1237}

References __unused, __weak, netdev, netdev_rx_err(), NULL, rc, tag, and vlan_find().

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().