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.

lotest_cmd.c 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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/if_ether.h>
  32. #include <usr/lotest.h>
  33. /** @file
  34. *
  35. * Loopback testing commands
  36. *
  37. */
  38. /** "lotest" options */
  39. struct lotest_options {
  40. /** MTU */
  41. unsigned int mtu;
  42. /** Broadcast */
  43. int broadcast;
  44. };
  45. /** "lotest" option list */
  46. static struct option_descriptor lotest_opts[] = {
  47. OPTION_DESC ( "mtu", 'm', required_argument,
  48. struct lotest_options, mtu, parse_integer ),
  49. OPTION_DESC ( "broadcast", 'b', no_argument,
  50. struct lotest_options, broadcast, parse_flag ),
  51. };
  52. /** "lotest" command descriptor */
  53. static struct command_descriptor lotest_cmd =
  54. COMMAND_DESC ( struct lotest_options, lotest_opts, 2, 2,
  55. "<sending interface> <receiving interface>" );
  56. /**
  57. * "lotest" command
  58. *
  59. * @v argc Argument count
  60. * @v argv Argument list
  61. * @ret rc Return status code
  62. */
  63. static int lotest_exec ( int argc, char **argv ) {
  64. struct lotest_options opts;
  65. struct net_device *sender;
  66. struct net_device *receiver;
  67. int rc;
  68. /* Parse options */
  69. if ( ( rc = parse_options ( argc, argv, &lotest_cmd, &opts ) ) != 0 )
  70. return rc;
  71. /* Parse sending interface name */
  72. if ( ( rc = parse_netdev ( argv[optind], &sender ) ) != 0 )
  73. return rc;
  74. /* Parse receiving interface name */
  75. if ( ( rc = parse_netdev ( argv[ optind + 1 ], &receiver ) ) != 0 )
  76. return rc;
  77. /* Use default MTU if none specified */
  78. if ( ! opts.mtu )
  79. opts.mtu = ETH_MAX_MTU;
  80. /* Perform loopback test */
  81. if ( ( rc = loopback_test ( sender, receiver, opts.mtu,
  82. opts.broadcast ) ) != 0 ) {
  83. printf ( "Test failed: %s\n", strerror ( rc ) );
  84. return rc;
  85. }
  86. return 0;
  87. }
  88. /** Loopback testing commands */
  89. struct command lotest_command __command = {
  90. .name = "lotest",
  91. .exec = lotest_exec,
  92. };