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., 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. "<sending interface> <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. };