2 * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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., 675 Mass Ave, Cambridge, MA 02139, USA.
28 #include <gpxe/netdevice.h>
30 #include <gpxe/command.h>
31 #include <usr/dhcpmgmt.h>
35 * DHCP management commands
40 * "dhcp" command syntax message
42 * @v argv Argument list
44 static void dhcp_syntax ( char **argv ) {
48 "Configure a network interface using DHCP\n",
55 * @v argc Argument count
56 * @v argv Argument list
59 static int dhcp_exec ( int argc, char **argv ) {
60 static struct option longopts[] = {
61 { "help", 0, NULL, 'h' },
64 const char *netdev_txt;
65 struct net_device *netdev;
70 while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
73 /* Display help text */
75 /* Unrecognised/invalid option */
81 /* Need exactly one interface name remaining after the options */
82 if ( optind != ( argc - 1 ) ) {
86 netdev_txt = argv[optind];
89 netdev = find_netdev ( netdev_txt );
91 printf ( "No such interface: %s\n", netdev_txt );
96 if ( ( rc = dhcp ( netdev ) ) != 0 ) {
97 printf ( "Could not configure %s: %s\n", netdev->name,
106 * "pxebs" command syntax message
108 * @v argv Argument list
110 static void pxebs_syntax ( char **argv ) {
112 " %s <interface> <server_type>\n"
114 "Perform PXE Boot Server discovery\n",
119 * The "pxebs" command
121 * @v argc Argument count
122 * @v argv Argument list
125 static int pxebs_exec ( int argc, char **argv ) {
126 static struct option longopts[] = {
127 { "help", 0, NULL, 'h' },
128 { NULL, 0, NULL, 0 },
130 const char *netdev_txt;
131 const char *pxe_type_txt;
132 struct net_device *netdev;
133 unsigned int pxe_type;
139 while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
142 /* Display help text */
144 /* Unrecognised/invalid option */
145 pxebs_syntax ( argv );
149 if ( optind != ( argc - 2 ) ) {
150 pxebs_syntax ( argv );
153 netdev_txt = argv[optind];
154 pxe_type_txt = argv[ optind + 1 ];
156 /* Parse arguments */
157 netdev = find_netdev ( netdev_txt );
159 printf ( "No such interface: %s\n", netdev_txt );
162 pxe_type = strtoul ( pxe_type_txt, &end, 0 );
164 printf ( "Bad server type: %s\n", pxe_type_txt );
168 /* Perform Boot Server Discovery */
169 if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
170 printf ( "Could not discover boot server on %s: %s\n",
171 netdev->name, strerror ( rc ) );
178 /** DHCP management commands */
179 struct command dhcp_commands[] __command = {