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.

dhcp_cmd.c 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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. * 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 <stdint.h>
  26. #include <stdlib.h>
  27. #include <stdio.h>
  28. #include <errno.h>
  29. #include <stddef.h>
  30. #include <string.h>
  31. #include <assert.h>
  32. #include <getopt.h>
  33. #include <ipxe/netdevice.h>
  34. #include <ipxe/in.h>
  35. #include <ipxe/command.h>
  36. #include <ipxe/parseopt.h>
  37. #include <usr/dhcpmgmt.h>
  38. #include <hci/ifmgmt_cmd.h>
  39. /** @file
  40. *
  41. * DHCP management commands
  42. *
  43. */
  44. /** "pxebs" options */
  45. struct pxebs_options {};
  46. /** "pxebs" option list */
  47. static struct option_descriptor pxebs_opts[] = {};
  48. /** "pxebs" command descriptor */
  49. static struct command_descriptor pxebs_cmd =
  50. COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2,
  51. "<interface> <server type>" );
  52. /**
  53. * The "pxebs" command
  54. *
  55. * @v argc Argument count
  56. * @v argv Argument list
  57. * @ret rc Return status code
  58. */
  59. static int pxebs_exec ( int argc, char **argv ) {
  60. struct pxebs_options opts;
  61. struct net_device *netdev;
  62. unsigned int pxe_type;
  63. int rc;
  64. /* Parse options */
  65. if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
  66. return rc;
  67. /* Parse net device name */
  68. if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
  69. return rc;
  70. /* Parse boot server type */
  71. if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
  72. return rc;
  73. /* Perform Boot Server Discovery */
  74. if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
  75. printf ( "Could not discover boot server on %s: %s\n",
  76. netdev->name, strerror ( rc ) );
  77. return rc;
  78. }
  79. return 0;
  80. }
  81. /** DHCP management commands */
  82. struct command dhcp_commands[] __command = {
  83. {
  84. .name = "dhcp",
  85. .exec = ifconf_exec, /* synonym for "ifconf" */
  86. },
  87. {
  88. .name = "pxebs",
  89. .exec = pxebs_exec,
  90. },
  91. };