Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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. FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
  24. #include <stdio.h>
  25. #include <stdlib.h>
  26. #include <string.h>
  27. #include <getopt.h>
  28. #include <ipxe/netdevice.h>
  29. #include <ipxe/command.h>
  30. #include <ipxe/parseopt.h>
  31. #include <ipxe/vlan.h>
  32. /** @file
  33. *
  34. * VLAN commands
  35. *
  36. */
  37. /** "vcreate" options */
  38. struct vcreate_options {
  39. /** VLAN tag */
  40. unsigned int tag;
  41. /** VLAN default priority */
  42. unsigned int priority;
  43. };
  44. /** "vcreate" option list */
  45. static struct option_descriptor vcreate_opts[] = {
  46. OPTION_DESC ( "tag", 't', required_argument,
  47. struct vcreate_options, tag, parse_integer ),
  48. OPTION_DESC ( "priority", 'p', required_argument,
  49. struct vcreate_options, priority, parse_integer ),
  50. };
  51. /** "vcreate" command descriptor */
  52. static struct command_descriptor vcreate_cmd =
  53. COMMAND_DESC ( struct vcreate_options, vcreate_opts, 1, 1,
  54. "<trunk interface>" );
  55. /**
  56. * "vcreate" command
  57. *
  58. * @v argc Argument count
  59. * @v argv Argument list
  60. * @ret rc Return status code
  61. */
  62. static int vcreate_exec ( int argc, char **argv ) {
  63. struct vcreate_options opts;
  64. struct net_device *trunk;
  65. int rc;
  66. /* Parse options */
  67. if ( ( rc = parse_options ( argc, argv, &vcreate_cmd, &opts ) ) != 0 )
  68. return rc;
  69. /* Parse trunk interface */
  70. if ( ( rc = parse_netdev ( argv[optind], &trunk ) ) != 0 )
  71. return rc;
  72. /* Create VLAN device */
  73. if ( ( rc = vlan_create ( trunk, opts.tag, opts.priority ) ) != 0 ) {
  74. printf ( "Could not create VLAN device: %s\n",
  75. strerror ( rc ) );
  76. return rc;
  77. }
  78. return 0;
  79. }
  80. /** "vdestroy" options */
  81. struct vdestroy_options {};
  82. /** "vdestroy" option list */
  83. static struct option_descriptor vdestroy_opts[] = {};
  84. /** "vdestroy" command descriptor */
  85. static struct command_descriptor vdestroy_cmd =
  86. COMMAND_DESC ( struct vdestroy_options, vdestroy_opts, 1, 1,
  87. "<VLAN interface>" );
  88. /**
  89. * "vdestroy" command
  90. *
  91. * @v argc Argument count
  92. * @v argv Argument list
  93. * @ret rc Return status code
  94. */
  95. static int vdestroy_exec ( int argc, char **argv ) {
  96. struct vdestroy_options opts;
  97. struct net_device *netdev;
  98. int rc;
  99. /* Parse options */
  100. if ( ( rc = parse_options ( argc, argv, &vdestroy_cmd, &opts ) ) != 0 )
  101. return rc;
  102. /* Parse trunk interface */
  103. if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
  104. return rc;
  105. /* Destroy VLAN device */
  106. if ( ( rc = vlan_destroy ( netdev ) ) != 0 ) {
  107. printf ( "Could not destroy VLAN device: %s\n",
  108. strerror ( rc ) );
  109. return rc;
  110. }
  111. return 0;
  112. }
  113. /** VLAN commands */
  114. struct command vlan_commands[] __command = {
  115. {
  116. .name = "vcreate",
  117. .exec = vcreate_exec,
  118. },
  119. {
  120. .name = "vdestroy",
  121. .exec = vdestroy_exec,
  122. },
  123. };