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.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /*
  2. * Copyright (C) 2007 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 <stdint.h>
  22. #include <stdlib.h>
  23. #include <stdio.h>
  24. #include <errno.h>
  25. #include <stddef.h>
  26. #include <string.h>
  27. #include <assert.h>
  28. #include <getopt.h>
  29. #include <ipxe/netdevice.h>
  30. #include <ipxe/in.h>
  31. #include <ipxe/command.h>
  32. #include <ipxe/parseopt.h>
  33. #include <usr/dhcpmgmt.h>
  34. #include <hci/ifmgmt_cmd.h>
  35. /** @file
  36. *
  37. * DHCP management commands
  38. *
  39. */
  40. /** "dhcp" options */
  41. struct dhcp_options {};
  42. /** "dhcp" option list */
  43. static struct option_descriptor dhcp_opts[] = {};
  44. /**
  45. * Execute "dhcp" command for a network device
  46. *
  47. * @v netdev Network device
  48. * @v opts Command options
  49. * @ret rc Return status code
  50. */
  51. static int dhcp_payload ( struct net_device *netdev,
  52. struct dhcp_options *opts __unused ) {
  53. int rc;
  54. if ( ( rc = dhcp ( netdev ) ) != 0 ) {
  55. printf ( "Could not configure %s: %s\n",
  56. netdev->name, strerror ( rc ) );
  57. /* Close device on failure, to avoid memory exhaustion */
  58. netdev_close ( netdev );
  59. return rc;
  60. }
  61. return 0;
  62. }
  63. /** "dhcp" command descriptor */
  64. static struct ifcommon_command_descriptor dhcp_cmd =
  65. IFCOMMON_COMMAND_DESC ( struct dhcp_options, dhcp_opts,
  66. 0, MAX_ARGUMENTS, "[<interface>...]",
  67. dhcp_payload, 1 );
  68. /**
  69. * The "dhcp" command
  70. *
  71. * @v argc Argument count
  72. * @v argv Argument list
  73. * @ret rc Return status code
  74. */
  75. static int dhcp_exec ( int argc, char **argv ) {
  76. return ifcommon_exec ( argc, argv, &dhcp_cmd );
  77. }
  78. /** "pxebs" options */
  79. struct pxebs_options {};
  80. /** "pxebs" option list */
  81. static struct option_descriptor pxebs_opts[] = {};
  82. /** "pxebs" command descriptor */
  83. static struct command_descriptor pxebs_cmd =
  84. COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2,
  85. "<interface> <server type>" );
  86. /**
  87. * The "pxebs" command
  88. *
  89. * @v argc Argument count
  90. * @v argv Argument list
  91. * @ret rc Return status code
  92. */
  93. static int pxebs_exec ( int argc, char **argv ) {
  94. struct pxebs_options opts;
  95. struct net_device *netdev;
  96. unsigned int pxe_type;
  97. int rc;
  98. /* Parse options */
  99. if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
  100. return rc;
  101. /* Parse net device name */
  102. if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
  103. return rc;
  104. /* Parse boot server type */
  105. if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
  106. return rc;
  107. /* Perform Boot Server Discovery */
  108. if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
  109. printf ( "Could not discover boot server on %s: %s\n",
  110. netdev->name, strerror ( rc ) );
  111. return rc;
  112. }
  113. return 0;
  114. }
  115. /** DHCP management commands */
  116. struct command dhcp_commands[] __command = {
  117. {
  118. .name = "dhcp",
  119. .exec = dhcp_exec,
  120. },
  121. {
  122. .name = "pxebs",
  123. .exec = pxebs_exec,
  124. },
  125. };