2007-01-12 10:53:28 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation; either version 2 of the
|
|
|
|
* License, or any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2009-05-01 16:41:06 +02:00
|
|
|
FILE_LICENCE ( GPL2_OR_LATER );
|
|
|
|
|
2007-07-03 19:20:22 +02:00
|
|
|
#include <stdio.h>
|
2007-01-12 10:53:28 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
2007-01-19 02:13:12 +01:00
|
|
|
#include <stdio.h>
|
2007-07-03 19:20:22 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <stddef.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2007-01-12 10:53:28 +01:00
|
|
|
#include <getopt.h>
|
2010-04-19 21:16:01 +02:00
|
|
|
#include <ipxe/netdevice.h>
|
|
|
|
#include <ipxe/in.h>
|
|
|
|
#include <ipxe/command.h>
|
2010-11-21 19:18:01 +01:00
|
|
|
#include <ipxe/parseopt.h>
|
2007-01-12 10:53:28 +01:00
|
|
|
#include <usr/dhcpmgmt.h>
|
2010-11-21 19:18:01 +01:00
|
|
|
#include <hci/ifmgmt_cmd.h>
|
2007-01-12 10:53:28 +01:00
|
|
|
|
|
|
|
/** @file
|
|
|
|
*
|
|
|
|
* DHCP management commands
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-11-21 19:18:01 +01:00
|
|
|
/** "dhcp" command descriptor */
|
|
|
|
static struct command_descriptor dhcp_cmd =
|
|
|
|
COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
|
|
|
|
"[<interface>] [<interface>...]",
|
|
|
|
"Configure network interface(s) using DHCP" );
|
2007-01-12 10:53:28 +01:00
|
|
|
|
2010-07-31 10:20:41 +02:00
|
|
|
/**
|
|
|
|
* Execute "dhcp" command for a network device
|
|
|
|
*
|
|
|
|
* @v netdev Network device
|
2010-11-21 19:18:01 +01:00
|
|
|
* @ret rc Return status code
|
2010-07-31 10:20:41 +02:00
|
|
|
*/
|
2010-11-21 19:18:01 +01:00
|
|
|
static int dhcp_payload ( struct net_device *netdev ) {
|
2010-07-31 10:20:41 +02:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
if ( ( rc = dhcp ( netdev ) ) != 0 ) {
|
|
|
|
printf ( "Could not configure %s: %s\n",
|
|
|
|
netdev->name, strerror ( rc ) );
|
|
|
|
|
|
|
|
/* Close device on failure, to avoid memory exhaustion */
|
|
|
|
netdev_close ( netdev );
|
|
|
|
|
2010-11-21 19:18:01 +01:00
|
|
|
return rc;
|
2010-07-31 10:20:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-12 10:53:28 +01:00
|
|
|
/**
|
|
|
|
* The "dhcp" command
|
|
|
|
*
|
|
|
|
* @v argc Argument count
|
|
|
|
* @v argv Argument list
|
2010-11-21 19:18:01 +01:00
|
|
|
* @ret rc Return status code
|
2007-01-12 10:53:28 +01:00
|
|
|
*/
|
|
|
|
static int dhcp_exec ( int argc, char **argv ) {
|
2010-11-21 19:18:01 +01:00
|
|
|
return ifcommon_exec ( argc, argv, &dhcp_cmd, dhcp_payload, 1 );
|
|
|
|
}
|
2007-01-12 10:53:28 +01:00
|
|
|
|
2010-11-21 19:18:01 +01:00
|
|
|
/** "pxebs" options */
|
|
|
|
struct pxebs_options {};
|
2007-01-12 10:53:28 +01:00
|
|
|
|
2010-11-21 19:18:01 +01:00
|
|
|
/** "pxebs" option list */
|
|
|
|
static struct option_descriptor pxebs_opts[] = {};
|
2007-01-12 10:53:28 +01:00
|
|
|
|
2010-11-21 19:18:01 +01:00
|
|
|
/** "pxebs" command descriptor */
|
|
|
|
static struct command_descriptor pxebs_cmd =
|
|
|
|
COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2,
|
|
|
|
"<interface> <server_type>",
|
|
|
|
"Perform PXE Boot Server discovery" );
|
2009-01-31 08:36:05 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The "pxebs" command
|
|
|
|
*
|
|
|
|
* @v argc Argument count
|
|
|
|
* @v argv Argument list
|
2010-11-21 19:18:01 +01:00
|
|
|
* @ret rc Return status code
|
2009-01-31 08:36:05 +01:00
|
|
|
*/
|
|
|
|
static int pxebs_exec ( int argc, char **argv ) {
|
2010-11-21 19:18:01 +01:00
|
|
|
struct pxebs_options opts;
|
2009-01-31 08:36:05 +01:00
|
|
|
struct net_device *netdev;
|
|
|
|
unsigned int pxe_type;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
/* Parse options */
|
2010-11-21 19:18:01 +01:00
|
|
|
if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Parse net device name */
|
|
|
|
if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
/* Parse boot server type */
|
|
|
|
if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
|
|
|
|
return rc;
|
2009-01-31 08:36:05 +01:00
|
|
|
|
|
|
|
/* Perform Boot Server Discovery */
|
2009-02-05 10:30:32 +01:00
|
|
|
if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
|
2009-01-31 08:36:05 +01:00
|
|
|
printf ( "Could not discover boot server on %s: %s\n",
|
|
|
|
netdev->name, strerror ( rc ) );
|
2010-11-21 19:18:01 +01:00
|
|
|
return rc;
|
2009-01-31 08:36:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-01-12 10:53:28 +01:00
|
|
|
/** DHCP management commands */
|
|
|
|
struct command dhcp_commands[] __command = {
|
|
|
|
{
|
|
|
|
.name = "dhcp",
|
|
|
|
.exec = dhcp_exec,
|
|
|
|
},
|
2009-01-31 08:36:05 +01:00
|
|
|
{
|
|
|
|
.name = "pxebs",
|
|
|
|
.exec = pxebs_exec,
|
|
|
|
},
|
2007-01-12 10:53:28 +01:00
|
|
|
};
|