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

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