Add qemu 2.4.0
[kvmfornfv.git] / qemu / roms / ipxe / src / hci / commands / dhcp_cmd.c
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
20 FILE_LICENCE ( GPL2_OR_LATER );
21
22 #include <stdio.h>
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <stdio.h>
26 #include <errno.h>
27 #include <stddef.h>
28 #include <string.h>
29 #include <assert.h>
30 #include <getopt.h>
31 #include <ipxe/netdevice.h>
32 #include <ipxe/in.h>
33 #include <ipxe/command.h>
34 #include <ipxe/parseopt.h>
35 #include <usr/dhcpmgmt.h>
36 #include <hci/ifmgmt_cmd.h>
37
38 /** @file
39  *
40  * DHCP management commands
41  *
42  */
43
44 /** "pxebs" options */
45 struct pxebs_options {};
46
47 /** "pxebs" option list */
48 static struct option_descriptor pxebs_opts[] = {};
49
50 /** "pxebs" command descriptor */
51 static struct command_descriptor pxebs_cmd =
52         COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2,
53                        "<interface> <server type>" );
54
55 /**
56  * The "pxebs" command
57  *
58  * @v argc              Argument count
59  * @v argv              Argument list
60  * @ret rc              Return status code
61  */
62 static int pxebs_exec ( int argc, char **argv ) {
63         struct pxebs_options opts;
64         struct net_device *netdev;
65         unsigned int pxe_type;
66         int rc;
67
68         /* Parse options */
69         if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 )
70                 return rc;
71
72         /* Parse net device name */
73         if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
74                 return rc;
75
76         /* Parse boot server type */
77         if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 )
78                 return rc;
79
80         /* Perform Boot Server Discovery */
81         if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
82                 printf ( "Could not discover boot server on %s: %s\n",
83                          netdev->name, strerror ( rc ) );
84                 return rc;
85         }
86
87         return 0;
88 }
89
90 /** DHCP management commands */
91 struct command dhcp_commands[] __command = {
92         {
93                 .name = "dhcp",
94                 .exec = ifconf_exec, /* synonym for "ifconf" */
95         },
96         {
97                 .name = "pxebs",
98                 .exec = pxebs_exec,
99         },
100 };