You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vlan_cmd.c 3.4KB

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