iPXE
dhcp_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2007 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stdio.h>
00027 #include <stdint.h>
00028 #include <stdlib.h>
00029 #include <stdio.h>
00030 #include <errno.h>
00031 #include <stddef.h>
00032 #include <string.h>
00033 #include <assert.h>
00034 #include <getopt.h>
00035 #include <ipxe/netdevice.h>
00036 #include <ipxe/in.h>
00037 #include <ipxe/command.h>
00038 #include <ipxe/parseopt.h>
00039 #include <usr/dhcpmgmt.h>
00040 #include <hci/ifmgmt_cmd.h>
00041 
00042 /** @file
00043  *
00044  * DHCP management commands
00045  *
00046  */
00047 
00048 /** "pxebs" options */
00049 struct pxebs_options {};
00050 
00051 /** "pxebs" option list */
00052 static struct option_descriptor pxebs_opts[] = {};
00053 
00054 /** "pxebs" command descriptor */
00055 static struct command_descriptor pxebs_cmd =
00056         COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2,
00057                        "<interface> <server type>" );
00058 
00059 /**
00060  * The "pxebs" command
00061  *
00062  * @v argc              Argument count
00063  * @v argv              Argument list
00064  * @ret rc              Return status code
00065  */
00066 static int pxebs_exec ( int argc, char **argv ) {
00067         struct pxebs_options opts;
00068         struct net_device *netdev;
00069         unsigned int pxe_type;
00070         int rc;
00071 
00072         /* Parse options */
00073         if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
00074                 return rc;
00075 
00076         /* Parse net device name */
00077         if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
00078                 return rc;
00079 
00080         /* Parse boot server type */
00081         if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
00082                 return rc;
00083 
00084         /* Perform Boot Server Discovery */
00085         if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
00086                 printf ( "Could not discover boot server on %s: %s\n",
00087                          netdev->name, strerror ( rc ) );
00088                 return rc;
00089         }
00090 
00091         return 0;
00092 }
00093 
00094 /** DHCP management commands */
00095 struct command dhcp_commands[] __command = {
00096         {
00097                 .name = "dhcp",
00098                 .exec = ifconf_exec, /* synonym for "ifconf" */
00099         },
00100         {
00101                 .name = "pxebs",
00102                 .exec = pxebs_exec,
00103         },
00104 };