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

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