iPXE
Data Structures | Defines | 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...

Defines

#define VLAN_TAG(tci)   ( (tci) & 0x0fff )
 Extract VLAN tag from tag control information.
#define VLAN_PRIORITY(tci)   ( (tci) >> 13 )
 Extract VLAN priority from tag control information.
#define VLAN_TCI(tag, priority)   ( ( (priority) << 13 ) | (tag) )
 Construct VLAN tag control information.
#define VLAN_TAG_IS_VALID(tag)   ( (tag) < 0xfff )
 Check VLAN tag is valid.
#define VLAN_PRIORITY_IS_VALID(priority)   ( (priority) <= 7 )
 Check VLAN priority is valid.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
unsigned int vlan_tag (struct net_device *netdev)
 Get the VLAN tag.
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_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.


Define Documentation

#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.

Referenced by intelxl_poll_rx(), and vlan_rx().

#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.

#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.

Referenced by vlan_transmit().

#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.

Referenced by vlan_create().

#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.

Referenced by vlan_create().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

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

                                                    {
        struct vlan_device *vlan;

        if ( netdev->op == &vlan_operations ) {
                vlan = netdev->priv;
                return vlan->tag;
        } else {
                return 0;
        }
}
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.

References ETH_ALEN, ll_protocol::ll_addr_len, net_device::ll_protocol, and net_device::op.

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

                                                   {

        return ( ( trunk->ll_protocol->ll_addr_len == ETH_ALEN ) &&
                 ( trunk->op != &vlan_operations ) );
}
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.

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(), vlan_device::tag, tag, vlan_device::trunk, unregister_netdev(), vlan_can_be_trunk(), vlan_find(), VLAN_PRIORITY_IS_VALID, vlan_sync(), and VLAN_TAG_IS_VALID.

Referenced by fcoe_fip_rx_vlan(), and vcreate_exec().

                                          {
        struct net_device *netdev;
        struct vlan_device *vlan;
        int rc;

        /* If VLAN already exists, just update the priority */
        if ( ( netdev = vlan_find ( trunk, tag ) ) != NULL ) {
                vlan = netdev->priv;
                if ( priority != vlan->priority ) {
                        DBGC ( netdev, "VLAN %s priority changed from %d to "
                               "%d\n", netdev->name, vlan->priority, priority );
                }
                vlan->priority = priority;
                return 0;
        }

        /* Sanity checks */
        if ( ! vlan_can_be_trunk ( trunk ) ) {
                DBGC ( trunk, "VLAN %s cannot create VLAN on non-trunk "
                       "device\n", trunk->name );
                rc = -ENOTTY;
                goto err_sanity;
        }
        if ( ! VLAN_TAG_IS_VALID ( tag ) ) {
                DBGC ( trunk, "VLAN %s cannot create VLAN with invalid tag "
                       "%d\n", trunk->name, tag );
                rc = -EINVAL;
                goto err_sanity;
        }
        if ( ! VLAN_PRIORITY_IS_VALID ( priority ) ) {
                DBGC ( trunk, "VLAN %s cannot create VLAN with invalid "
                       "priority %d\n", trunk->name, priority );
                rc = -EINVAL;
                goto err_sanity;
        }

        /* Allocate and initialise structure */
        netdev = alloc_etherdev ( sizeof ( *vlan ) );
        if ( ! netdev ) {
                rc = -ENOMEM;
                goto err_alloc_etherdev;
        }
        netdev_init ( netdev, &vlan_operations );
        netdev->dev = trunk->dev;
        memcpy ( netdev->hw_addr, trunk->ll_addr, ETH_ALEN );
        vlan = netdev->priv;
        vlan->trunk = netdev_get ( trunk );
        vlan->tag = tag;
        vlan->priority = priority;

        /* Construct VLAN device name */
        snprintf ( netdev->name, sizeof ( netdev->name ), "%s-%d",
                   trunk->name, vlan->tag );

        /* Mark device as not supporting interrupts, if applicable */
        if ( ! netdev_irq_supported ( trunk ) )
                netdev->state |= NETDEV_IRQ_UNSUPPORTED;

        /* Register VLAN device */
        if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
                DBGC ( netdev, "VLAN %s could not register: %s\n",
                       netdev->name, strerror ( rc ) );
                goto err_register;
        }

        /* Synchronise with trunk device */
        vlan_sync ( netdev );

        DBGC ( netdev, "VLAN %s created with tag %d and priority %d\n",
               netdev->name, vlan->tag, vlan->priority );

        return 0;

        unregister_netdev ( netdev );
 err_register:
        netdev_nullify ( netdev );
        netdev_put ( netdev );
        netdev_put ( trunk );
 err_alloc_etherdev:
 err_sanity:
        return rc;
}
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.

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

Referenced by vdestroy_exec(), and vlan_remove_first().

                                               {
        struct vlan_device *vlan = netdev->priv;
        struct net_device *trunk;

        /* Sanity check */
        if ( netdev->op != &vlan_operations ) {
                DBGC ( netdev, "VLAN %s cannot destroy non-VLAN device\n",
                       netdev->name );
                return -ENOTTY;
        }

        DBGC ( netdev, "VLAN %s destroyed\n", netdev->name );

        /* Remove VLAN device */
        unregister_netdev ( netdev );
        trunk = vlan->trunk;
        netdev_nullify ( netdev );
        netdev_put ( netdev );
        netdev_put ( trunk );

        return 0;
}
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.

References ENODEV, netdev_rx(), netdev_rx_err(), NULL, and vlan_find().

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().

                                                       {

        if ( tag == 0 ) {
                netdev_rx ( netdev, iobuf );
        } else {
                netdev_rx_err ( netdev, iobuf, -ENODEV );
        }
}
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.

References netdev_rx_err(), NULL, and vlan_find().

Referenced by hermon_eth_complete_recv(), and intelxl_poll_rx().

                                                                   {

        netdev_rx_err ( netdev, iobuf, rc );
}