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> <discovery_ip> <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_server_txt;
132 const char *pxe_type_txt;
133 struct net_device *netdev;
134 struct in_addr pxe_server;
135 unsigned int pxe_type;
141 while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
144 /* Display help text */
146 /* Unrecognised/invalid option */
147 pxebs_syntax ( argv );
152 /* Need exactly one interface name remaining after the options */
153 if ( optind != ( argc - 3 ) ) {
154 pxebs_syntax ( argv );
157 netdev_txt = argv[optind];
158 pxe_server_txt = argv[ optind + 1 ];
159 pxe_type_txt = argv[ optind + 2 ];
161 /* Parse arguments */
162 netdev = find_netdev ( netdev_txt );
164 printf ( "No such interface: %s\n", netdev_txt );
167 if ( inet_aton ( pxe_server_txt, &pxe_server ) == 0 ) {
168 printf ( "Bad discovery IP address: %s\n", pxe_server_txt );
171 pxe_type = strtoul ( pxe_type_txt, &end, 0 );
173 printf ( "Bad server type: %s\n", pxe_type_txt );
177 /* Perform Boot Server Discovery */
178 if ( ( rc = pxebs ( netdev, pxe_server, pxe_type ) ) != 0 ) {
179 printf ( "Could not discover boot server on %s: %s\n",
180 netdev->name, strerror ( rc ) );
187 /** DHCP management commands */
188 struct command dhcp_commands[] __command = {