iPXE
Data Structures | Macros | Functions
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)   ( (tci) & 0x0fff )
 Extract VLAN tag from tag control information. More...
 
#define VLAN_PRIORITY(tci)   ( (tci) >> 13 )
 Extract VLAN priority from tag control information. More...
 
#define VLAN_TCI(tag, priority)   ( ( (priority) << 13 ) | (tag) )
 Construct VLAN tag control information. More...
 
#define VLAN_TAG_IS_VALID(tag)   ( (tag) < 0xfff )
 Check VLAN tag is valid. More...
 
#define VLAN_PRIORITY_IS_VALID(priority)   ( (priority) <= 7 )
 Check VLAN priority is valid. More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
unsigned int vlan_tag (struct net_device *netdev)
 Get the VLAN tag. More...
 
int vlan_can_be_trunk (struct net_device *trunk)
 Check if network device can be used as a VLAN trunk device. More...
 
int vlan_create (struct net_device *trunk, unsigned int tag, unsigned int priority)
 Create VLAN device. More...
 
int vlan_destroy (struct net_device *netdev)
 Destroy VLAN device. More...
 
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) More...
 
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) More...
 

Detailed Description

Virtual LANs.

Definition in file vlan.h.

Macro Definition Documentation

◆ VLAN_TAG

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

Extract VLAN tag from tag control information.

Parameters
tciTag control information
Return values
tagVLAN tag

Definition at line 29 of file vlan.h.

◆ VLAN_PRIORITY

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

Extract VLAN priority from tag control information.

Parameters
tciTag control information
Return values
priorityPriority

Definition at line 37 of file vlan.h.

◆ VLAN_TCI

#define VLAN_TCI (   tag,
  priority 
)    ( ( (priority) << 13 ) | (tag) )

Construct VLAN tag control information.

Parameters
tagVLAN tag
priorityPriority
Return values
tciTag control information

Definition at line 46 of file vlan.h.

◆ VLAN_TAG_IS_VALID

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

Check VLAN tag is valid.

Parameters
tagVLAN tag
Return values
is_validVLAN tag is valid

Definition at line 54 of file vlan.h.

◆ VLAN_PRIORITY_IS_VALID

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

Check VLAN priority is valid.

Parameters
priorityVLAN priority
Return values
is_validVLAN priority is valid

Definition at line 62 of file vlan.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ vlan_tag()

unsigned int vlan_tag ( struct net_device netdev)

Get the VLAN tag.

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

Definition at line 296 of file vlan.c.

296  {
297  struct vlan_device *vlan;
298 
299  if ( netdev->op == &vlan_operations ) {
300  vlan = netdev->priv;
301  return vlan->tag;
302  } else {
303  return 0;
304  }
305 }
static struct net_device_operations vlan_operations
VLAN device operations.
Definition: vlan.c:164
VLAN device private data.
Definition: vlan.c:49
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
unsigned int tag
VLAN tag.
Definition: vlan.c:53

References netdev, net_device::op, net_device::priv, vlan_device::tag, and vlan_operations.

◆ vlan_can_be_trunk()

int vlan_can_be_trunk ( struct net_device trunk)

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 324 of file vlan.c.

324  {
325 
326  return ( ( trunk->ll_protocol->ll_addr_len == ETH_ALEN ) &&
327  ( trunk->op != &vlan_operations ) );
328 }
struct net_device * trunk
Trunk network device.
Definition: vlan.c:51
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
static struct net_device_operations vlan_operations
VLAN device operations.
Definition: vlan.c:164
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
#define ETH_ALEN
Definition: if_ether.h:8
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366

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(), and vlan_create().

◆ vlan_create()

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

Create VLAN device.

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

Definition at line 338 of file vlan.c.

339  {
340  struct net_device *netdev;
341  struct vlan_device *vlan;
342  int rc;
343 
344  /* If VLAN already exists, just update the priority */
345  if ( ( netdev = vlan_find ( trunk, tag ) ) != NULL ) {
346  vlan = netdev->priv;
347  if ( priority != vlan->priority ) {
348  DBGC ( netdev, "VLAN %s priority changed from %d to "
349  "%d\n", netdev->name, vlan->priority, priority );
350  }
351  vlan->priority = priority;
352  return 0;
353  }
354 
355  /* Sanity checks */
356  if ( ! vlan_can_be_trunk ( trunk ) ) {
357  DBGC ( trunk, "VLAN %s cannot create VLAN on non-trunk "
358  "device\n", trunk->name );
359  rc = -ENOTTY;
360  goto err_sanity;
361  }
362  if ( ! VLAN_TAG_IS_VALID ( tag ) ) {
363  DBGC ( trunk, "VLAN %s cannot create VLAN with invalid tag "
364  "%d\n", trunk->name, tag );
365  rc = -EINVAL;
366  goto err_sanity;
367  }
368  if ( ! VLAN_PRIORITY_IS_VALID ( priority ) ) {
369  DBGC ( trunk, "VLAN %s cannot create VLAN with invalid "
370  "priority %d\n", trunk->name, priority );
371  rc = -EINVAL;
372  goto err_sanity;
373  }
374 
375  /* Allocate and initialise structure */
376  netdev = alloc_etherdev ( sizeof ( *vlan ) );
377  if ( ! netdev ) {
378  rc = -ENOMEM;
379  goto err_alloc_etherdev;
380  }
382  netdev->dev = trunk->dev;
384  vlan = netdev->priv;
385  vlan->trunk = netdev_get ( trunk );
386  vlan->tag = tag;
387  vlan->priority = priority;
388 
389  /* Construct VLAN device name */
390  snprintf ( netdev->name, sizeof ( netdev->name ), "%s-%d",
391  trunk->name, vlan->tag );
392 
393  /* Mark device as not supporting interrupts, if applicable */
394  if ( ! netdev_irq_supported ( trunk ) )
396 
397  /* Register VLAN device */
398  if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
399  DBGC ( netdev, "VLAN %s could not register: %s\n",
400  netdev->name, strerror ( rc ) );
401  goto err_register;
402  }
403 
404  /* Synchronise with trunk device */
405  vlan_sync ( netdev );
406 
407  DBGC ( netdev, "VLAN %s created with tag %d and priority %d\n",
408  netdev->name, vlan->tag, vlan->priority );
409 
410  return 0;
411 
413  err_register:
415  netdev_put ( netdev );
416  netdev_put ( trunk );
417  err_alloc_etherdev:
418  err_sanity:
419  return rc;
420 }
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
struct net_device * trunk
Trunk network device.
Definition: vlan.c:51
static struct net_device_operations vlan_operations
VLAN device operations.
Definition: vlan.c:164
VLAN device private data.
Definition: vlan.c:49
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:389
#define VLAN_TAG_IS_VALID(tag)
Check VLAN tag is valid.
Definition: vlan.h:54
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
#define ENOMEM
Not enough space.
Definition: errno.h:534
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
#define VLAN_PRIORITY_IS_VALID(priority)
Check VLAN priority is valid.
Definition: vlan.h:62
void * priv
Driver private data.
Definition: netdevice.h:425
static void vlan_sync(struct net_device *netdev)
Synchronise VLAN device.
Definition: vlan.c:177
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
static struct net_device * vlan_find(struct net_device *trunk, unsigned int tag)
Identify VLAN device.
Definition: vlan.c:202
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:544
#define ETH_ALEN
Definition: if_ether.h:8
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
unsigned int tag
VLAN tag.
Definition: vlan.c:53
int vlan_can_be_trunk(struct net_device *trunk)
Check if network device can be used as a VLAN trunk device.
Definition: vlan.c:324
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
uint16_t priority
Priotity.
Definition: stp.h:12
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:381
unsigned int priority
Default priority.
Definition: vlan.c:55
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition: netdevice.h:446
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition: netdevice.h:663

References alloc_etherdev(), DBGC, net_device::dev, EINVAL, ENOMEM, ENOTTY, ETH_ALEN, net_device::hw_addr, 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, net_device::priv, rc, register_netdev(), snprintf(), net_device::state, 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 fcoe_fip_rx_vlan(), and vcreate_exec().

◆ vlan_destroy()

int vlan_destroy ( struct net_device netdev)

Destroy VLAN device.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 428 of file vlan.c.

428  {
429  struct vlan_device *vlan = netdev->priv;
430  struct net_device *trunk;
431 
432  /* Sanity check */
433  if ( netdev->op != &vlan_operations ) {
434  DBGC ( netdev, "VLAN %s cannot destroy non-VLAN device\n",
435  netdev->name );
436  return -ENOTTY;
437  }
438 
439  DBGC ( netdev, "VLAN %s destroyed\n", netdev->name );
440 
441  /* Remove VLAN device */
443  trunk = vlan->trunk;
445  netdev_put ( netdev );
446  netdev_put ( trunk );
447 
448  return 0;
449 }
struct net_device * trunk
Trunk network device.
Definition: vlan.c:51
static struct net_device_operations vlan_operations
VLAN device operations.
Definition: vlan.c:164
VLAN device private data.
Definition: vlan.c:49
#define DBGC(...)
Definition: compiler.h:505
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
void * priv
Driver private data.
Definition: netdevice.h:425
static struct net_device * netdev
Definition: gdbudp.c:52
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
A network device.
Definition: netdevice.h:348
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594

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

Referenced by vdestroy_exec(), and vlan_remove_first().

◆ vlan_netdev_rx()

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)

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 1135 of file netdevice.c.

1136  {
1137 
1138  if ( tag == 0 ) {
1139  netdev_rx ( netdev, iobuf );
1140  } else {
1141  netdev_rx_err ( netdev, iobuf, -ENODEV );
1142  }
1143 }
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
static struct net_device * netdev
Definition: gdbudp.c:52
#define ENODEV
No such device.
Definition: errno.h:509
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
uint64_t tag
Identity tag.
Definition: edd.h:30

References 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 
)

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 1153 of file netdevice.c.

1155  {
1156 
1157  netdev_rx_err ( netdev, iobuf, rc );
1158 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
static struct net_device * netdev
Definition: gdbudp.c:52

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

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().