選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

lotest_cmd.c 2.7KB

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