iPXE
Data Structures | Defines | Functions | Variables
vlan.h File Reference

Virtual LANs. More...

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)
struct vlan_header __attribute__ ((packed))
struct net_devicevlan_find (struct net_device *trunk, unsigned int tag)
 Identify VLAN device.
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.

Variables

uint16_t tci
 Tag control information.
uint16_t net_proto
 Encapsulated protocol.

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 27 of file vlan.h.

Referenced by 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 35 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 44 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 52 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 60 of file vlan.h.

Referenced by vlan_create().


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
struct vlan_header __attribute__ ( (packed)  )
struct net_device* vlan_find ( struct net_device trunk,
unsigned int  tag 
) [read]

Identify VLAN device.

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

Definition at line 202 of file vlan.c.

References for_each_netdev, netdev, NULL, net_device::op, net_device::priv, vlan_device::tag, and vlan_device::trunk.

                                                                             {
        struct net_device *netdev;
        struct vlan_device *vlan;

        for_each_netdev ( netdev ) {
                if ( netdev->op != &vlan_operations )
                        continue;
                vlan = netdev->priv;
                if ( ( vlan->trunk == trunk ) && ( vlan->tag == tag ) )
                        return netdev;
        }
        return NULL;
}
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 295 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 323 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 337 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 427 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;
}

Variable Documentation

Tag control information.

Definition at line 21 of file vlan.h.

Encapsulated protocol.

Definition at line 23 of file vlan.h.

Referenced by eth_push(), ipoib_complete_recv(), ipoib_transmit(), net80211_ll_push(), net_poll(), pxenv_undi_isr(), undinet_transmit(), and vlan_transmit().