iPXE
vlan.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of the
7  * License, or any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <stdint.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <byteswap.h>
31 #include <ipxe/features.h>
32 #include <ipxe/if_ether.h>
33 #include <ipxe/ethernet.h>
34 #include <ipxe/netdevice.h>
35 #include <ipxe/iobuf.h>
36 #include <ipxe/vlan.h>
37 
38 /** @file
39  *
40  * Virtual LANs
41  *
42  */
43 
45 
46 struct net_protocol vlan_protocol __net_protocol;
47 
48 /** VLAN device private data */
49 struct vlan_device {
50  /** Trunk network device */
51  struct net_device *trunk;
52  /** VLAN tag */
53  unsigned int tag;
54  /** Default priority */
55  unsigned int priority;
56 };
57 
58 /**
59  * Open VLAN device
60  *
61  * @v netdev Network device
62  * @ret rc Return status code
63  */
64 static int vlan_open ( struct net_device *netdev ) {
65  struct vlan_device *vlan = netdev->priv;
66 
67  return netdev_open ( vlan->trunk );
68 }
69 
70 /**
71  * Close VLAN device
72  *
73  * @v netdev Network device
74  */
75 static void vlan_close ( struct net_device *netdev ) {
76  struct vlan_device *vlan = netdev->priv;
77 
78  netdev_close ( vlan->trunk );
79 }
80 
81 /**
82  * Transmit packet on VLAN device
83  *
84  * @v netdev Network device
85  * @v iobuf I/O buffer
86  * @ret rc Return status code
87  */
88 static int vlan_transmit ( struct net_device *netdev,
89  struct io_buffer *iobuf ) {
90  struct vlan_device *vlan = netdev->priv;
91  struct net_device *trunk = vlan->trunk;
92  struct ll_protocol *ll_protocol;
93  struct vlan_header *vlanhdr;
94  uint8_t ll_dest_copy[ETH_ALEN];
95  uint8_t ll_source_copy[ETH_ALEN];
96  const void *ll_dest;
97  const void *ll_source;
99  unsigned int flags;
100  int rc;
101 
102  /* Strip link-layer header and preserve link-layer header fields */
104  if ( ( rc = ll_protocol->pull ( netdev, iobuf, &ll_dest, &ll_source,
105  &net_proto, &flags ) ) != 0 ) {
106  DBGC ( netdev, "VLAN %s could not parse link-layer header: "
107  "%s\n", netdev->name, strerror ( rc ) );
108  return rc;
109  }
110  memcpy ( ll_dest_copy, ll_dest, ETH_ALEN );
111  memcpy ( ll_source_copy, ll_source, ETH_ALEN );
112 
113  /* Construct VLAN header */
114  vlanhdr = iob_push ( iobuf, sizeof ( *vlanhdr ) );
115  vlanhdr->tci = htons ( VLAN_TCI ( vlan->tag, vlan->priority ) );
116  vlanhdr->net_proto = net_proto;
117 
118  /* Reclaim I/O buffer from VLAN device's TX queue */
119  list_del ( &iobuf->list );
120 
121  /* Transmit packet on trunk device */
122  if ( ( rc = net_tx ( iob_disown ( iobuf ), trunk, &vlan_protocol,
123  ll_dest_copy, ll_source_copy ) ) != 0 ) {
124  DBGC ( netdev, "VLAN %s could not transmit: %s\n",
125  netdev->name, strerror ( rc ) );
126  /* Cannot return an error status, since that would
127  * cause the I/O buffer to be double-freed.
128  */
129  return 0;
130  }
131 
132  return 0;
133 }
134 
135 /**
136  * Poll VLAN device
137  *
138  * @v netdev Network device
139  */
140 static void vlan_poll ( struct net_device *netdev ) {
141  struct vlan_device *vlan = netdev->priv;
142 
143  /* Poll trunk device */
144  netdev_poll ( vlan->trunk );
145 }
146 
147 /**
148  * Enable/disable interrupts on VLAN device
149  *
150  * @v netdev Network device
151  * @v enable Interrupts should be enabled
152  */
153 static void vlan_irq ( struct net_device *netdev, int enable ) {
154  struct vlan_device *vlan = netdev->priv;
155 
156  /* Enable/disable interrupts on trunk device. This is not at
157  * all robust, but there is no sensible course of action
158  * available.
159  */
160  netdev_irq ( vlan->trunk, enable );
161 }
162 
163 /** VLAN device operations */
165  .open = vlan_open,
166  .close = vlan_close,
167  .transmit = vlan_transmit,
168  .poll = vlan_poll,
169  .irq = vlan_irq,
170 };
171 
172 /**
173  * Synchronise VLAN device
174  *
175  * @v netdev Network device
176  */
177 static void vlan_sync ( struct net_device *netdev ) {
178  struct vlan_device *vlan = netdev->priv;
179  struct net_device *trunk = vlan->trunk;
180 
181  /* Synchronise link status */
182  if ( netdev->link_rc != trunk->link_rc )
183  netdev_link_err ( netdev, trunk->link_rc );
184 
185  /* Synchronise open/closed status */
186  if ( netdev_is_open ( trunk ) ) {
187  if ( ! netdev_is_open ( netdev ) )
188  netdev_open ( netdev );
189  } else {
190  if ( netdev_is_open ( netdev ) )
191  netdev_close ( netdev );
192  }
193 }
194 
195 /**
196  * Identify VLAN device
197  *
198  * @v trunk Trunk network device
199  * @v tag VLAN tag
200  * @ret netdev VLAN device, if any
201  */
202 static struct net_device * vlan_find ( struct net_device *trunk,
203  unsigned int tag ) {
204  struct net_device *netdev;
205  struct vlan_device *vlan;
206 
207  for_each_netdev ( netdev ) {
208  if ( netdev->op != &vlan_operations )
209  continue;
210  vlan = netdev->priv;
211  if ( ( vlan->trunk == trunk ) && ( vlan->tag == tag ) )
212  return netdev;
213  }
214  return NULL;
215 }
216 
217 /**
218  * Process incoming VLAN packet
219  *
220  * @v iobuf I/O buffer
221  * @v trunk Trunk network device
222  * @v ll_dest Link-layer destination address
223  * @v ll_source Link-layer source address
224  * @v flags Packet flags
225  * @ret rc Return status code
226  */
227 static int vlan_rx ( struct io_buffer *iobuf, struct net_device *trunk,
228  const void *ll_dest, const void *ll_source,
229  unsigned int flags __unused ) {
230  struct vlan_header *vlanhdr = iobuf->data;
231  struct net_device *netdev;
232  struct ll_protocol *ll_protocol;
233  uint8_t ll_dest_copy[ETH_ALEN];
234  uint8_t ll_source_copy[ETH_ALEN];
235  uint16_t tag;
236  int rc;
237 
238  /* Sanity check */
239  if ( iob_len ( iobuf ) < sizeof ( *vlanhdr ) ) {
240  DBGC ( trunk, "VLAN %s received underlength packet (%zd "
241  "bytes)\n", trunk->name, iob_len ( iobuf ) );
242  rc = -EINVAL;
243  goto err_sanity;
244  }
245 
246  /* Identify VLAN device */
247  tag = VLAN_TAG ( ntohs ( vlanhdr->tci ) );
248  netdev = vlan_find ( trunk, tag );
249  if ( ! netdev ) {
250  DBGC2 ( trunk, "VLAN %s received packet for unknown VLAN "
251  "%d\n", trunk->name, tag );
252  rc = -EPIPE;
253  goto err_no_vlan;
254  }
255 
256  /* Strip VLAN header and preserve original link-layer header fields */
257  iob_pull ( iobuf, sizeof ( *vlanhdr ) );
258  ll_protocol = trunk->ll_protocol;
259  memcpy ( ll_dest_copy, ll_dest, ETH_ALEN );
260  memcpy ( ll_source_copy, ll_source, ETH_ALEN );
261 
262  /* Reconstruct link-layer header for VLAN device */
264  if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest_copy,
265  ll_source_copy,
266  vlanhdr->net_proto ) ) != 0 ) {
267  DBGC ( netdev, "VLAN %s could not reconstruct link-layer "
268  "header: %s\n", netdev->name, strerror ( rc ) );
269  goto err_ll_push;
270  }
271 
272  /* Enqueue packet on VLAN device */
273  netdev_rx ( netdev, iob_disown ( iobuf ) );
274  return 0;
275 
276  err_ll_push:
277  err_no_vlan:
278  err_sanity:
279  free_iob ( iobuf );
280  return rc;
281 }
282 
283 /** VLAN protocol */
284 struct net_protocol vlan_protocol __net_protocol = {
285  .name = "VLAN",
286  .net_proto = htons ( ETH_P_8021Q ),
287  .rx = vlan_rx,
288 };
289 
290 /**
291  * Get the VLAN tag
292  *
293  * @v netdev Network device
294  * @ret tag VLAN tag, or 0 if device is not a VLAN device
295  */
296 unsigned int vlan_tag ( struct net_device *netdev ) {
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 }
306 
307 /**
308  * Check if network device can be used as a VLAN trunk device
309  *
310  * @v trunk Trunk network device
311  * @ret is_ok Trunk network device is usable
312  *
313  * VLAN devices will be created as Ethernet devices. (We cannot
314  * simply clone the link layer of the trunk network device, because
315  * this link layer may expect the network device structure to contain
316  * some link-layer-private data.) The trunk network device must
317  * therefore have a link layer that is in some sense 'compatible' with
318  * Ethernet; specifically, it must have link-layer addresses that are
319  * the same length as Ethernet link-layer addresses.
320  *
321  * As an additional check, and primarily to assist with the sanity of
322  * the FCoE code, we refuse to allow nested VLANs.
323  */
325 
326  return ( ( trunk->ll_protocol->ll_addr_len == ETH_ALEN ) &&
327  ( trunk->op != &vlan_operations ) );
328 }
329 
330 /**
331  * Create VLAN device
332  *
333  * @v trunk Trunk network device
334  * @v tag VLAN tag
335  * @v priority Default VLAN priority
336  * @ret rc Return status code
337  */
338 int vlan_create ( struct net_device *trunk, unsigned int tag,
339  unsigned int priority ) {
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 }
421 
422 /**
423  * Destroy VLAN device
424  *
425  * @v netdev Network device
426  * @ret rc Return status code
427  */
428 int vlan_destroy ( struct net_device *netdev ) {
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 }
450 
451 /**
452  * Handle trunk network device link state change
453  *
454  * @v trunk Trunk network device
455  */
456 static void vlan_notify ( struct net_device *trunk ) {
457  struct net_device *netdev;
458  struct vlan_device *vlan;
459 
460  for_each_netdev ( netdev ) {
461  if ( netdev->op != &vlan_operations )
462  continue;
463  vlan = netdev->priv;
464  if ( vlan->trunk == trunk )
465  vlan_sync ( netdev );
466  }
467 }
468 
469 /**
470  * Destroy first VLAN device for a given trunk
471  *
472  * @v trunk Trunk network device
473  * @ret found A VLAN device was found
474  */
475 static int vlan_remove_first ( struct net_device *trunk ) {
476  struct net_device *netdev;
477  struct vlan_device *vlan;
478 
479  for_each_netdev ( netdev ) {
480  if ( netdev->op != &vlan_operations )
481  continue;
482  vlan = netdev->priv;
483  if ( vlan->trunk == trunk ) {
484  vlan_destroy ( netdev );
485  return 1;
486  }
487  }
488  return 0;
489 }
490 
491 /**
492  * Destroy all VLAN devices for a given trunk
493  *
494  * @v trunk Trunk network device
495  */
496 static void vlan_remove ( struct net_device *trunk ) {
497 
498  /* Remove all VLAN devices attached to this trunk, safe
499  * against arbitrary net device removal.
500  */
501  while ( vlan_remove_first ( trunk ) ) {}
502 }
503 
504 /** VLAN driver */
505 struct net_driver vlan_driver __net_driver = {
506  .name = "VLAN",
507  .notify = vlan_notify,
508  .remove = vlan_remove,
509 };
510 
511 /**
512  * Add VLAN tag-stripped packet to receive queue
513  *
514  * @v netdev Network device
515  * @v tag VLAN tag, or zero
516  * @v iobuf I/O buffer
517  */
518 void vlan_netdev_rx ( struct net_device *netdev, unsigned int tag,
519  struct io_buffer *iobuf ) {
520  struct net_device *vlan;
521 
522  /* Identify VLAN device, if applicable */
523  if ( tag ) {
524  if ( ( vlan = vlan_find ( netdev, tag ) ) == NULL ) {
525  netdev_rx_err ( netdev, iobuf, -ENODEV );
526  return;
527  }
528  netdev = vlan;
529  }
530 
531  /* Hand off to network device */
532  netdev_rx ( netdev, iobuf );
533 }
534 
535 /**
536  * Discard received VLAN tag-stripped packet
537  *
538  * @v netdev Network device
539  * @v tag VLAN tag, or zero
540  * @v iobuf I/O buffer, or NULL
541  * @v rc Packet status code
542  */
543 void vlan_netdev_rx_err ( struct net_device *netdev, unsigned int tag,
544  struct io_buffer *iobuf, int rc ) {
545  struct net_device *vlan;
546 
547  /* Identify VLAN device, if applicable */
548  if ( tag && ( ( vlan = vlan_find ( netdev, tag ) ) != NULL ) )
549  netdev = vlan;
550 
551  /* Hand off to network device */
552  netdev_rx_err ( netdev, iobuf, rc );
553 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:98
#define VLAN_TAG(tci)
Extract VLAN tag from tag control information.
Definition: vlan.h:29
#define EINVAL
Invalid argument.
Definition: errno.h:428
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
unsigned short uint16_t
Definition: stdint.h:11
const char * name
Protocol name.
Definition: netdevice.h:66
uint16_t tci
Tag control information.
Definition: vlan.h:18
void netdev_rx_err(struct net_device *netdev, struct io_buffer *iobuf, int rc)
Discard received packet.
Definition: netdevice.c:501
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
#define FEATURE_PROTOCOL
Network protocols.
Definition: features.h:21
int(* open)(struct net_device *netdev)
Open network device.
Definition: netdevice.h:222
#define VLAN_TCI(tag, priority)
Construct VLAN tag control information.
Definition: vlan.h:46
void vlan_netdev_rx_err(struct net_device *netdev, unsigned int tag, struct io_buffer *iobuf, int rc)
Discard received VLAN tag-stripped packet.
Definition: vlan.c:543
struct net_protocol vlan_protocol __net_protocol
VLAN protocol.
Definition: vlan.c:46
uint16_t net_proto
Encapsulated protocol.
Definition: vlan.h:20
Error codes.
#define iob_push(iobuf, len)
Definition: iobuf.h:80
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:145
#define EPIPE
Broken pipe.
Definition: errno.h:619
static void vlan_notify(struct net_device *trunk)
Handle trunk network device link state change.
Definition: vlan.c:456
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 ntohs(value)
Definition: byteswap.h:136
#define VLAN_TAG_IS_VALID(tag)
Check VLAN tag is valid.
Definition: vlan.h:54
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:363
A network upper-layer driver.
Definition: netdevice.h:461
static int vlan_remove_first(struct net_device *trunk)
Destroy first VLAN device for a given trunk.
Definition: vlan.c:475
A link-layer protocol.
Definition: netdevice.h:114
int vlan_create(struct net_device *trunk, unsigned int tag, unsigned int priority)
Create VLAN device.
Definition: vlan.c:338
int(* push)(struct net_device *netdev, struct io_buffer *iobuf, const void *ll_dest, const void *ll_source, uint16_t net_proto)
Add link-layer header.
Definition: netdevice.h:127
static void netdev_init(struct net_device *netdev, struct net_device_operations *op)
Initialise a network device.
Definition: netdevice.h:498
static int vlan_rx(struct io_buffer *iobuf, struct net_device *trunk, const void *ll_dest, const void *ll_source, unsigned int flags __unused)
Process incoming VLAN packet.
Definition: vlan.c:227
#define list_del(list)
Delete an entry from a list.
Definition: list.h:119
#define ENOMEM
Not enough space.
Definition: errno.h:534
#define iob_disown(iobuf)
Disown an I/O buffer.
Definition: iobuf.h:208
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * name
Name.
Definition: netdevice.h:463
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:652
A VLAN header.
Definition: vlan.h:16
int link_rc
Link status code.
Definition: netdevice.h:395
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:555
Ethernet protocol.
#define VLAN_PRIORITY_IS_VALID(priority)
Check VLAN priority is valid.
Definition: vlan.h:62
static void vlan_poll(struct net_device *netdev)
Poll VLAN device.
Definition: vlan.c:140
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
Feature list.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:844
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition: netdevice.c:523
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void vlan_close(struct net_device *netdev)
Close VLAN device.
Definition: vlan.c:75
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:526
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:667
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:151
FEATURE(FEATURE_PROTOCOL, "VLAN", DHCP_EB_FEATURE_VLAN, 1)
void netdev_irq(struct net_device *netdev, int enable)
Enable or disable interrupts.
Definition: netdevice.c:875
A network device.
Definition: netdevice.h:348
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:163
#define ENODEV
No such device.
Definition: errno.h:509
static void netdev_nullify(struct net_device *netdev)
Stop using a network device.
Definition: netdevice.h:511
unsigned char uint8_t
Definition: stdint.h:10
static struct net_device * vlan_find(struct net_device *trunk, unsigned int tag)
Identify VLAN device.
Definition: vlan.c:202
static void vlan_remove(struct net_device *trunk)
Destroy all VLAN devices for a given trunk.
Definition: vlan.c:496
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
int vlan_destroy(struct net_device *netdev)
Destroy VLAN device.
Definition: vlan.c:428
Network device operations.
Definition: netdevice.h:213
void netdev_rx(struct net_device *netdev, struct io_buffer *iobuf)
Add packet to receive queue.
Definition: netdevice.c:470
struct device * dev
Underlying hardware device.
Definition: netdevice.h:360
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:801
A network-layer protocol.
Definition: netdevice.h:64
Network device management.
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
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
int(* pull)(struct net_device *netdev, struct io_buffer *iobuf, const void **ll_dest, const void **ll_source, uint16_t *net_proto, unsigned int *flags)
Remove link-layer header.
Definition: netdevice.h:141
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:39
int net_tx(struct io_buffer *iobuf, struct net_device *netdev, struct net_protocol *net_protocol, const void *ll_dest, const void *ll_source)
Transmit network-layer packet.
Definition: netdevice.c:999
#define DBGC2(...)
Definition: compiler.h:522
#define ENOTTY
Inappropriate I/O control operation.
Definition: errno.h:594
static void vlan_irq(struct net_device *netdev, int enable)
Enable/disable interrupts on VLAN device.
Definition: vlan.c:153
uint16_t priority
Priotity.
Definition: stp.h:12
struct net_driver vlan_driver __net_driver
VLAN driver.
Definition: vlan.c:505
void * data
Start of data.
Definition: iobuf.h:44
static int vlan_open(struct net_device *netdev)
Open VLAN device.
Definition: vlan.c:64
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
Virtual LANs.
void vlan_netdev_rx(struct net_device *netdev, unsigned int tag, struct io_buffer *iobuf)
Add VLAN tag-stripped packet to receive queue.
Definition: vlan.c:518
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
static int vlan_transmit(struct net_device *netdev, struct io_buffer *iobuf)
Transmit packet on VLAN device.
Definition: vlan.c:88
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition: netdevice.h:446
#define DHCP_EB_FEATURE_VLAN
VLAN support.
Definition: features.h:54
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:375
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
String functions.
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition: netdevice.h:663
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:767
#define htons(value)
Definition: byteswap.h:135
#define ETH_P_8021Q
Definition: if_ether.h:21
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:366
A persistent I/O buffer.
Definition: iobuf.h:32
uint8_t flags
Flags.
Definition: ena.h:18
unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.c:296