|
@@ -0,0 +1,103 @@
|
|
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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
17
|
+ */
|
|
18
|
+
|
|
19
|
+#include <stdint.h>
|
|
20
|
+#include <stdlib.h>
|
|
21
|
+#include <getopt.h>
|
|
22
|
+#include <vsprintf.h>
|
|
23
|
+#include <gpxe/netdevice.h>
|
|
24
|
+#include <gpxe/command.h>
|
|
25
|
+#include <usr/dhcpmgmt.h>
|
|
26
|
+
|
|
27
|
+/** @file
|
|
28
|
+ *
|
|
29
|
+ * DHCP management commands
|
|
30
|
+ *
|
|
31
|
+ */
|
|
32
|
+
|
|
33
|
+/**
|
|
34
|
+ * "dhcp" command syntax message
|
|
35
|
+ *
|
|
36
|
+ * @v argv Argument list
|
|
37
|
+ */
|
|
38
|
+static void dhcp_syntax ( char **argv ) {
|
|
39
|
+ printf ( "Usage:\n"
|
|
40
|
+ " %s <interface>\n"
|
|
41
|
+ "\n"
|
|
42
|
+ "Configure a network interface using DHCP\n",
|
|
43
|
+ argv[0] );
|
|
44
|
+}
|
|
45
|
+
|
|
46
|
+/**
|
|
47
|
+ * The "dhcp" command
|
|
48
|
+ *
|
|
49
|
+ * @v argc Argument count
|
|
50
|
+ * @v argv Argument list
|
|
51
|
+ * @ret rc Exit code
|
|
52
|
+ */
|
|
53
|
+static int dhcp_exec ( int argc, char **argv ) {
|
|
54
|
+ static struct option longopts[] = {
|
|
55
|
+ { "help", 0, NULL, 'h' },
|
|
56
|
+ { NULL, 0, NULL, 0 },
|
|
57
|
+ };
|
|
58
|
+ const char *name;
|
|
59
|
+ struct net_device *netdev;
|
|
60
|
+ int c;
|
|
61
|
+ int rc;
|
|
62
|
+
|
|
63
|
+ /* Parse options */
|
|
64
|
+ while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
|
|
65
|
+ switch ( c ) {
|
|
66
|
+ case 'h':
|
|
67
|
+ /* Display help text */
|
|
68
|
+ default:
|
|
69
|
+ /* Unrecognised/invalid option */
|
|
70
|
+ dhcp_syntax ( argv );
|
|
71
|
+ return 1;
|
|
72
|
+ }
|
|
73
|
+ }
|
|
74
|
+
|
|
75
|
+ /* Need exactly one interface name remaining after the options */
|
|
76
|
+ if ( optind != ( argc - 1 ) ) {
|
|
77
|
+ dhcp_syntax ( argv );
|
|
78
|
+ return 1;
|
|
79
|
+ }
|
|
80
|
+ name = argv[optind];
|
|
81
|
+
|
|
82
|
+ /* Perform DHCP */
|
|
83
|
+ netdev = find_netdev ( name );
|
|
84
|
+ if ( ! netdev ) {
|
|
85
|
+ printf ( "No such interface: %s\n", name );
|
|
86
|
+ return 1;
|
|
87
|
+ }
|
|
88
|
+ if ( ( rc = dhcp ( netdev ) ) != 0 ) {
|
|
89
|
+ printf ( "Could not configure %s: %s\n", netdev->name,
|
|
90
|
+ strerror ( rc ) );
|
|
91
|
+ return 1;
|
|
92
|
+ }
|
|
93
|
+
|
|
94
|
+ return 0;
|
|
95
|
+}
|
|
96
|
+
|
|
97
|
+/** DHCP management commands */
|
|
98
|
+struct command dhcp_commands[] __command = {
|
|
99
|
+ {
|
|
100
|
+ .name = "dhcp",
|
|
101
|
+ .exec = dhcp_exec,
|
|
102
|
+ },
|
|
103
|
+};
|