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.5KB

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