iPXE
dhcp_cmd.c
Go to the documentation of this file.
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 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 FILE_SECBOOT ( PERMITTED );
26 
27 #include <stdio.h>
28 #include <stdint.h>
29 #include <stdlib.h>
30 #include <stdio.h>
31 #include <errno.h>
32 #include <stddef.h>
33 #include <string.h>
34 #include <assert.h>
35 #include <getopt.h>
36 #include <ipxe/netdevice.h>
37 #include <ipxe/in.h>
38 #include <ipxe/command.h>
39 #include <ipxe/parseopt.h>
40 #include <usr/dhcpmgmt.h>
41 #include <hci/ifmgmt_cmd.h>
42 
43 /** @file
44  *
45  * DHCP management commands
46  *
47  */
48 
49 /** "pxebs" options */
50 struct pxebs_options {};
51 
52 /** "pxebs" option list */
53 static struct option_descriptor pxebs_opts[] = {};
54 
55 /** "pxebs" command descriptor */
57  COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2,
58  "<interface> <server type>" );
59 
60 /**
61  * The "pxebs" command
62  *
63  * @v argc Argument count
64  * @v argv Argument list
65  * @ret rc Return status code
66  */
67 static int pxebs_exec ( int argc, char **argv ) {
68  struct pxebs_options opts;
69  struct net_device *netdev;
70  unsigned int pxe_type;
71  int rc;
72 
73  /* Parse options */
74  if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
75  return rc;
76 
77  /* Parse net device name */
78  if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
79  return rc;
80 
81  /* Parse boot server type */
82  if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
83  return rc;
84 
85  /* Perform Boot Server Discovery */
86  if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
87  printf ( "Could not discover boot server on %s: %s\n",
88  netdev->name, strerror ( rc ) );
89  return rc;
90  }
91 
92  return 0;
93 }
94 
95 /** DHCP management commands */
96 COMMAND ( dhcp, ifconf_exec ); /* synonym for "ifconf" */
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:465
"pxebs" options
Definition: dhcp_cmd.c:50
int optind
Current option index.
Definition: getopt.c:52
Error codes.
static struct option_descriptor pxebs_opts[]
"pxebs" option list
Definition: dhcp_cmd.c:53
DHCP management.
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:485
int ifconf_exec(int argc, char **argv)
The "ifconf" command.
Definition: ifmgmt_cmd.c:250
A command descriptor.
Definition: parseopt.h:78
Assertions.
Parse command-line options.
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
COMMAND(dhcp, ifconf_exec)
DHCP management commands.
Command line option parsing.
A network device.
Definition: netdevice.h:353
Network device management.
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:363
A command-line option descriptor.
Definition: parseopt.h:24
static union @447 opts
"cert<xxx>" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109
FILE_SECBOOT(PERMITTED)
static int pxebs_exec(int argc, char **argv)
The "pxebs" command.
Definition: dhcp_cmd.c:67
static struct command_descriptor pxebs_cmd
"pxebs" command descriptor
Definition: dhcp_cmd.c:56
String functions.
int pxebs(struct net_device *netdev, unsigned int pxe_type)
Definition: dhcpmgmt.c:42
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition: parseopt.c:159
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)