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 /** Automatic VLAN device link-layer address */
60 
61 /** Automatic VLAN tag */
62 static unsigned int vlan_auto_tag;
63 
64 /**
65  * Open VLAN device
66  *
67  * @v netdev Network device
68  * @ret rc Return status code
69  */
70 static int vlan_open ( struct net_device *netdev ) {
71  struct vlan_device *vlan = netdev->priv;
72 
73  return netdev_open ( vlan->trunk );
74 }
75 
76 /**
77  * Close VLAN device
78  *
79  * @v netdev Network device
80  */
81 static void vlan_close ( struct net_device *netdev ) {
82  struct vlan_device *vlan = netdev->priv;
83 
84  netdev_close ( vlan->trunk );
85 }
86 
87 /**
88  * Transmit packet on VLAN device
89  *
90  * @v netdev Network device
91  * @v iobuf I/O buffer
92  * @ret rc Return status code
93  */
94 static int vlan_transmit ( struct net_device *netdev,
95  struct io_buffer *iobuf ) {
96  struct vlan_device *vlan = netdev->priv;
97  struct net_device *trunk = vlan->trunk;
98  struct ll_protocol *ll_protocol;
99  struct vlan_header *vlanhdr;
100  uint8_t ll_dest_copy[ETH_ALEN];
101  uint8_t ll_source_copy[ETH_ALEN];
102  const void *ll_dest;
103  const void *ll_source;
105  unsigned int flags;
106  int rc;
107 
108  /* Strip link-layer header and preserve link-layer header fields */
110  if ( ( rc = ll_protocol->pull ( netdev, iobuf, &ll_dest, &ll_source,
111  &net_proto, &flags ) ) != 0 ) {
112  DBGC ( netdev, "VLAN %s could not parse link-layer header: "
113  "%s\n", netdev->name, strerror ( rc ) );
114  return rc;
115  }
116  memcpy ( ll_dest_copy, ll_dest, ETH_ALEN );
117  memcpy ( ll_source_copy, ll_source, ETH_ALEN );
118 
119  /* Construct VLAN header */
120  vlanhdr = iob_push ( iobuf, sizeof ( *vlanhdr ) );
121  vlanhdr->tci = htons ( VLAN_TCI ( vlan->tag, vlan->priority ) );
122  vlanhdr->net_proto = net_proto;
123 
124  /* Reclaim I/O buffer from VLAN device's TX queue */
125  list_del ( &iobuf->list );
126 
127  /* Transmit packet on trunk device */
128  if ( ( rc = net_tx ( iob_disown ( iobuf ), trunk, &vlan_protocol,
129  ll_dest_copy, ll_source_copy ) ) != 0 ) {
130  DBGC ( netdev, "VLAN %s could not transmit: %s\n",
131  netdev->name, strerror ( rc ) );
132  /* Cannot return an error status, since that would
133  * cause the I/O buffer to be double-freed.
134  */
135  return 0;
136  }
137 
138  return 0;
139 }
140 
141 /**
142  * Poll VLAN device
143  *
144  * @v netdev Network device
145  */
146 static void vlan_poll ( struct net_device *netdev ) {
147  struct vlan_device *vlan = netdev->priv;
148 
149  /* Poll trunk device */
150  netdev_poll ( vlan->trunk );
151 }
152 
153 /**
154  * Enable/disable interrupts on VLAN device
155  *
156  * @v netdev Network device
157  * @v enable Interrupts should be enabled
158  */
159 static void vlan_irq ( struct net_device *netdev, int enable ) {
160  struct vlan_device *vlan = netdev->priv;
161 
162  /* Enable/disable interrupts on trunk device. This is not at
163  * all robust, but there is no sensible course of action
164  * available.
165  */
166  netdev_irq ( vlan->trunk, enable );
167 }
168 
169 /** VLAN device operations */
171  .open = vlan_open,
172  .close = vlan_close,
173  .transmit = vlan_transmit,
174  .poll = vlan_poll,
175  .irq = vlan_irq,
176 };
177 
178 /**
179  * Synchronise VLAN device
180  *
181  * @v netdev Network device
182  */
183 static void vlan_sync ( struct net_device *netdev ) {
184  struct vlan_device *vlan = netdev->priv;
185  struct net_device *trunk = vlan->trunk;
186 
187  /* Synchronise link status */
188  if ( netdev->link_rc != trunk->link_rc )
189  netdev_link_err ( netdev, trunk->link_rc );
190 
191  /* Synchronise open/closed status */
192  if ( netdev_is_open ( trunk ) ) {
193  if ( ! netdev_is_open ( netdev ) )
194  netdev_open ( netdev );
195  } else {
196  if ( netdev_is_open ( netdev ) )
197  netdev_close ( netdev );
198  }
199 }
200 
201 /**
202  * Identify VLAN device
203  *
204  * @v trunk Trunk network device
205  * @v tag VLAN tag
206  * @ret netdev VLAN device, if any
207  */
208 struct net_device * vlan_find ( struct net_device *trunk, unsigned int tag ) {
209  struct net_device *netdev;
210  struct vlan_device *vlan;
211 
212  for_each_netdev ( netdev ) {
213  if ( netdev->op != &vlan_operations )
214  continue;
215  vlan = netdev->priv;
216  if ( ( vlan->trunk == trunk ) && ( vlan->tag == tag ) )
217  return netdev;
218  }
219  return NULL;
220 }
221 
222 /**
223  * Process incoming VLAN packet
224  *
225  * @v iobuf I/O buffer
226  * @v trunk Trunk network device
227  * @v ll_dest Link-layer destination address
228  * @v ll_source Link-layer source address
229  * @v flags Packet flags
230  * @ret rc Return status code
231  */
232 static int vlan_rx ( struct io_buffer *iobuf, struct net_device *trunk,
233  const void *ll_dest, const void *ll_source,
234  unsigned int flags __unused ) {
235  struct vlan_header *vlanhdr = iobuf->data;
236  struct net_device *netdev;
237  struct ll_protocol *ll_protocol;
238  uint8_t ll_dest_copy[ETH_ALEN];
239  uint8_t ll_source_copy[ETH_ALEN];
240  uint16_t tag;
241  int rc;
242 
243  /* Sanity check */
244  if ( iob_len ( iobuf ) < sizeof ( *vlanhdr ) ) {
245  DBGC ( trunk, "VLAN %s received underlength packet (%zd "
246  "bytes)\n", trunk->name, iob_len ( iobuf ) );
247  rc = -EINVAL;
248  goto err_sanity;
249  }
250 
251  /* Identify VLAN device */
252  tag = VLAN_TAG ( ntohs ( vlanhdr->tci ) );
253  netdev = vlan_find ( trunk, tag );
254  if ( ! netdev ) {
255  DBGC2 ( trunk, "VLAN %s received packet for unknown VLAN "
256  "%d\n", trunk->name, tag );
257  rc = -EPIPE;
258  goto err_no_vlan;
259  }
260 
261  /* Strip VLAN header and preserve original link-layer header fields */
262  iob_pull ( iobuf, sizeof ( *vlanhdr ) );
263  ll_protocol = trunk->ll_protocol;
264  memcpy ( ll_dest_copy, ll_dest, ETH_ALEN );
265  memcpy ( ll_source_copy, ll_source, ETH_ALEN );
266 
267  /* Reconstruct link-layer header for VLAN device */
269  if ( ( rc = ll_protocol->push ( netdev, iobuf, ll_dest_copy,
270  ll_source_copy,
271  vlanhdr->net_proto ) ) != 0 ) {
272  DBGC ( netdev, "VLAN %s could not reconstruct link-layer "
273  "header: %s\n", netdev->name, strerror ( rc ) );
274  goto err_ll_push;
275  }
276 
277  /* Enqueue packet on VLAN device */
278  netdev_rx ( netdev, iob_disown ( iobuf ) );
279  return 0;
280 
281  err_ll_push:
282  err_no_vlan:
283  err_sanity:
284  free_iob ( iobuf );
285  return rc;
286 }
287 
288 /** VLAN protocol */
289 struct net_protocol vlan_protocol __net_protocol = {
290  .name = "VLAN",
291  .net_proto = htons ( ETH_P_8021Q ),
292  .rx = vlan_rx,
293 };
294 
295 /**
296  * Get the VLAN tag control information
297  *
298  * @v netdev Network device
299  * @ret tci VLAN tag control information, or 0 if not a VLAN device
300  */
301 unsigned int vlan_tci ( struct net_device *netdev ) {
302  struct vlan_device *vlan;
303 
304  if ( netdev->op == &vlan_operations ) {
305  vlan = netdev->priv;
306  return ( VLAN_TCI ( vlan->tag, vlan->priority ) );
307  } else {
308  return 0;
309  }
310 }
311 
312 /**
313  * Check if network device can be used as a VLAN trunk device
314  *
315  * @v trunk Trunk network device
316  * @ret is_ok Trunk network device is usable
317  *
318  * VLAN devices will be created as Ethernet devices. (We cannot
319  * simply clone the link layer of the trunk network device, because
320  * this link layer may expect the network device structure to contain
321  * some link-layer-private data.) The trunk network device must
322  * therefore have a link layer that is in some sense 'compatible' with
323  * Ethernet; specifically, it must have link-layer addresses that are
324  * the same length as Ethernet link-layer addresses.
325  *
326  * As an additional check, and primarily to assist with the sanity of
327  * the FCoE code, we refuse to allow nested VLANs.
328  */
330 
331  return ( ( trunk->ll_protocol->ll_addr_len == ETH_ALEN ) &&
332  ( trunk->op != &vlan_operations ) );
333 }
334 
335 /**
336  * Create VLAN device
337  *
338  * @v trunk Trunk network device
339  * @v tag VLAN tag
340  * @v priority Default VLAN priority
341  * @ret rc Return status code
342  */
343 int vlan_create ( struct net_device *trunk, unsigned int tag,
344  unsigned int priority ) {
345  struct net_device *netdev;
346  struct vlan_device *vlan;
347  int rc;
348 
349  /* If VLAN already exists, just update the priority */
350  if ( ( netdev = vlan_find ( trunk, tag ) ) != NULL ) {
351  vlan = netdev->priv;
352  if ( priority != vlan->priority ) {
353  DBGC ( netdev, "VLAN %s priority changed from %d to "
354  "%d\n", netdev->name, vlan->priority, priority );
355  }
356  vlan->priority = priority;
357  return 0;
358  }
359 
360  /* Sanity checks */
361  if ( ! vlan_can_be_trunk ( trunk ) ) {
362  DBGC ( trunk, "VLAN %s cannot create VLAN on non-trunk "
363  "device\n", trunk->name );
364  rc = -ENOTTY;
365  goto err_sanity;
366  }
367  if ( ! VLAN_TAG_IS_VALID ( tag ) ) {
368  DBGC ( trunk, "VLAN %s cannot create VLAN with invalid tag "
369  "%d\n", trunk->name, tag );
370  rc = -EINVAL;
371  goto err_sanity;
372  }
373  if ( ! VLAN_PRIORITY_IS_VALID ( priority ) ) {
374  DBGC ( trunk, "VLAN %s cannot create VLAN with invalid "
375  "priority %d\n", trunk->name, priority );
376  rc = -EINVAL;
377  goto err_sanity;
378  }
379 
380  /* Allocate and initialise structure */
381  netdev = alloc_etherdev ( sizeof ( *vlan ) );
382  if ( ! netdev ) {
383  rc = -ENOMEM;
384  goto err_alloc_etherdev;
385  }
387  netdev->dev = trunk->dev;
389  vlan = netdev->priv;
390  vlan->trunk = netdev_get ( trunk );
391  vlan->tag = tag;
392  vlan->priority = priority;
393 
394  /* Construct VLAN device name */
395  snprintf ( netdev->name, sizeof ( netdev->name ), "%s-%d",
396  trunk->name, vlan->tag );
397 
398  /* Mark device as not supporting interrupts, if applicable */
399  if ( ! netdev_irq_supported ( trunk ) )
401 
402  /* Register VLAN device */
403  if ( ( rc = register_netdev ( netdev ) ) != 0 ) {
404  DBGC ( netdev, "VLAN %s could not register: %s\n",
405  netdev->name, strerror ( rc ) );
406  goto err_register;
407  }
408 
409  /* Synchronise with trunk device */
410  vlan_sync ( netdev );
411 
412  DBGC ( netdev, "VLAN %s created with tag %d and priority %d\n",
413  netdev->name, vlan->tag, vlan->priority );
414 
415  return 0;
416 
418  err_register:
420  netdev_put ( netdev );
421  netdev_put ( trunk );
422  err_alloc_etherdev:
423  err_sanity:
424  return rc;
425 }
426 
427 /**
428  * Destroy VLAN device
429  *
430  * @v netdev Network device
431  * @ret rc Return status code
432  */
433 int vlan_destroy ( struct net_device *netdev ) {
434  struct vlan_device *vlan = netdev->priv;
435  struct net_device *trunk;
436 
437  /* Sanity check */
438  if ( netdev->op != &vlan_operations ) {
439  DBGC ( netdev, "VLAN %s cannot destroy non-VLAN device\n",
440  netdev->name );
441  return -ENOTTY;
442  }
443 
444  DBGC ( netdev, "VLAN %s destroyed\n", netdev->name );
445 
446  /* Remove VLAN device */
448  trunk = vlan->trunk;
450  netdev_put ( netdev );
451  netdev_put ( trunk );
452 
453  return 0;
454 }
455 
456 /**
457  * Configure automatic VLAN device
458  *
459  * @v ll_addr Link-layer address
460  * @v tag VLAN tag
461  */
462 void vlan_auto ( const void *ll_addr, unsigned int tag ) {
463 
464  /* Record link-layer address and VLAN tag */
466  vlan_auto_tag = tag;
467 }
468 
469 /**
470  * Create automatic VLAN device
471  *
472  * @v trunk Trunk network device
473  * @v priv Private data
474  * @ret rc Return status code
475  */
476 static int vlan_probe ( struct net_device *trunk, void *priv __unused ) {
477  int rc;
478 
479  /* Do nothing unless an automatic VLAN exists */
480  if ( ! vlan_auto_tag )
481  return 0;
482 
483  /* Ignore non-trunk devices */
484  if ( ! vlan_can_be_trunk ( trunk ) )
485  return 0;
486 
487  /* Ignore non-matching link-layer addresses */
488  if ( memcmp ( trunk->ll_addr, vlan_auto_ll_addr, ETH_ALEN ) != 0 )
489  return 0;
490 
491  /* Create automatic VLAN device */
492  if ( ( rc = vlan_create ( trunk, vlan_auto_tag, 0 ) ) != 0 )
493  return rc;
494 
495  return 0;
496 }
497 
498 /**
499  * Handle trunk network device link state change
500  *
501  * @v trunk Trunk network device
502  * @v priv Private data
503  */
504 static void vlan_notify ( struct net_device *trunk, void *priv __unused ) {
505  struct net_device *netdev;
506  struct vlan_device *vlan;
507 
508  for_each_netdev ( netdev ) {
509  if ( netdev->op != &vlan_operations )
510  continue;
511  vlan = netdev->priv;
512  if ( vlan->trunk == trunk )
513  vlan_sync ( netdev );
514  }
515 }
516 
517 /**
518  * Destroy first VLAN device for a given trunk
519  *
520  * @v trunk Trunk network device
521  * @ret found A VLAN device was found
522  */
523 static int vlan_remove_first ( struct net_device *trunk ) {
524  struct net_device *netdev;
525  struct vlan_device *vlan;
526 
527  for_each_netdev ( netdev ) {
528  if ( netdev->op != &vlan_operations )
529  continue;
530  vlan = netdev->priv;
531  if ( vlan->trunk == trunk ) {
532  vlan_destroy ( netdev );
533  return 1;
534  }
535  }
536  return 0;
537 }
538 
539 /**
540  * Destroy all VLAN devices for a given trunk
541  *
542  * @v trunk Trunk network device
543  * @v priv Private data
544  */
545 static void vlan_remove ( struct net_device *trunk, void *priv __unused ) {
546 
547  /* Remove all VLAN devices attached to this trunk, safe
548  * against arbitrary net device removal.
549  */
550  while ( vlan_remove_first ( trunk ) ) {}
551 }
552 
553 /** VLAN driver */
554 struct net_driver vlan_driver __net_driver = {
555  .name = "VLAN",
556  .probe = vlan_probe,
557  .notify = vlan_notify,
558  .remove = vlan_remove,
559 };
560 
561 /**
562  * Add VLAN tag-stripped packet to receive queue
563  *
564  * @v netdev Network device
565  * @v tag VLAN tag, or zero
566  * @v iobuf I/O buffer
567  */
568 void vlan_netdev_rx ( struct net_device *netdev, unsigned int tag,
569  struct io_buffer *iobuf ) {
570  struct net_device *vlan;
571 
572  /* Identify VLAN device, if applicable */
573  if ( tag ) {
574  if ( ( vlan = vlan_find ( netdev, tag ) ) == NULL ) {
575  netdev_rx_err ( netdev, iobuf, -ENODEV );
576  return;
577  }
578  netdev = vlan;
579  }
580 
581  /* Hand off to network device */
582  netdev_rx ( netdev, iobuf );
583 }
584 
585 /**
586  * Discard received VLAN tag-stripped packet
587  *
588  * @v netdev Network device
589  * @v tag VLAN tag, or zero
590  * @v iobuf I/O buffer, or NULL
591  * @v rc Packet status code
592  */
593 void vlan_netdev_rx_err ( struct net_device *netdev, unsigned int tag,
594  struct io_buffer *iobuf, int rc ) {
595  struct net_device *vlan;
596 
597  /* Identify VLAN device, if applicable */
598  if ( tag && ( ( vlan = vlan_find ( netdev, tag ) ) != NULL ) )
599  netdev = vlan;
600 
601  /* Hand off to network device */
602  netdev_rx_err ( netdev, iobuf, rc );
603 }
#define iob_pull(iobuf, len)
Definition: iobuf.h:102
#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:586
unsigned int vlan_tci(struct net_device *netdev)
Get the VLAN tag control information.
Definition: vlan.c:301
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:170
#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:593
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:84
I/O buffers.
void free_iob(struct io_buffer *iobuf)
Free I/O buffer.
Definition: iobuf.c:146
#define EPIPE
Broken pipe.
Definition: errno.h:619
VLAN device private data.
Definition: vlan.c:49
#define DBGC(...)
Definition: compiler.h:505
unsigned int state
Current device state.
Definition: netdevice.h:395
#define ntohs(value)
Definition: byteswap.h:136
#define VLAN_TAG_IS_VALID(tag)
Check VLAN tag is valid.
Definition: vlan.h:54
static void vlan_notify(struct net_device *trunk, void *priv __unused)
Handle trunk network device link state change.
Definition: vlan.c:504
struct net_device_operations * op
Network device operations.
Definition: netdevice.h:369
A network upper-layer driver.
Definition: netdevice.h:473
static int vlan_remove_first(struct net_device *trunk)
Destroy first VLAN device for a given trunk.
Definition: vlan.c:523
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:343
struct net_device * vlan_find(struct net_device *trunk, unsigned int tag)
Identify VLAN device.
Definition: vlan.c:208
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:515
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:232
#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:212
void * memcpy(void *dest, const void *src, size_t len) __nonnull
const char * name
Name.
Definition: netdevice.h:475
static int netdev_is_open(struct net_device *netdev)
Check whether or not network device is open.
Definition: netdevice.h:658
void vlan_auto(const void *ll_addr, unsigned int tag)
Configure automatic VLAN device.
Definition: vlan.c:462
A VLAN header.
Definition: vlan.h:16
int link_rc
Link status code.
Definition: netdevice.h:401
static void netdev_put(struct net_device *netdev)
Drop reference to network device.
Definition: netdevice.h:572
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:146
void * priv
Driver private data.
Definition: netdevice.h:431
static int vlan_probe(struct net_device *trunk, void *priv __unused)
Create automatic VLAN device.
Definition: vlan.c:476
static void vlan_sync(struct net_device *netdev)
Synchronise VLAN device.
Definition: vlan.c:183
static struct net_device * netdev
Definition: gdbudp.c:52
Feature list.
void unregister_netdev(struct net_device *netdev)
Unregister network device.
Definition: netdevice.c:941
void netdev_poll(struct net_device *netdev)
Poll for completed and received packets on network device.
Definition: netdevice.c:612
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:81
static uint8_t vlan_auto_ll_addr[ETH_ALEN]
Automatic VLAN device link-layer address.
Definition: vlan.c:59
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:543
int register_netdev(struct net_device *netdev)
Register network device.
Definition: netdevice.c:759
static size_t iob_len(struct io_buffer *iobuf)
Calculate length of data in an I/O buffer.
Definition: iobuf.h:155
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:970
A network device.
Definition: netdevice.h:352
void netdev_link_err(struct net_device *netdev, int rc)
Mark network device as having a specific link state.
Definition: netdevice.c:207
#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:528
unsigned char uint8_t
Definition: stdint.h:10
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition: netdevice.h:561
#define ETH_ALEN
Definition: if_ether.h:8
int vlan_destroy(struct net_device *netdev)
Destroy VLAN device.
Definition: vlan.c:433
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:548
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:895
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:329
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:362
struct list_head list
List of which this buffer is a member.
Definition: iobuf.h:40
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:1073
#define DBGC2(...)
Definition: compiler.h:522
static struct tlan_private * priv
Definition: tlan.c:224
#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:159
uint16_t priority
Priotity.
Definition: stp.h:12
struct net_driver vlan_driver __net_driver
VLAN driver.
Definition: vlan.c:554
void * data
Start of data.
Definition: iobuf.h:48
static int vlan_open(struct net_device *netdev)
Open VLAN device.
Definition: vlan.c:70
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
struct net_device * alloc_etherdev(size_t priv_size)
Allocate Ethernet device.
Definition: ethernet.c:264
static void vlan_remove(struct net_device *trunk, void *priv __unused)
Destroy all VLAN devices for a given trunk.
Definition: vlan.c:545
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:568
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:387
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:94
uint64_t tag
Identity tag.
Definition: edd.h:30
#define NETDEV_IRQ_UNSUPPORTED
Network device interrupts are unsupported.
Definition: netdevice.h:452
#define DHCP_EB_FEATURE_VLAN
VLAN support.
Definition: features.h:54
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
uint8_t hw_addr[MAX_HW_ADDR_LEN]
Hardware address.
Definition: netdevice.h:381
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
static unsigned int vlan_auto_tag
Automatic VLAN tag.
Definition: vlan.c:62
String functions.
static int netdev_irq_supported(struct net_device *netdev)
Check whether or not network device supports interrupts.
Definition: netdevice.h:669
int netdev_open(struct net_device *netdev)
Open network device.
Definition: netdevice.c:861
#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:372
A persistent I/O buffer.
Definition: iobuf.h:33
uint8_t flags
Flags.
Definition: ena.h:18