00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 FILE_LICENCE ( GPL2_OR_LATER );
00020
00021 #include <stdio.h>
00022 #include <stdint.h>
00023 #include <stdlib.h>
00024 #include <stdio.h>
00025 #include <errno.h>
00026 #include <stddef.h>
00027 #include <string.h>
00028 #include <assert.h>
00029 #include <getopt.h>
00030 #include <gpxe/netdevice.h>
00031 #include <gpxe/in.h>
00032 #include <gpxe/command.h>
00033 #include <usr/dhcpmgmt.h>
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 static void dhcp_syntax ( char **argv ) {
00047 printf ( "Usage:\n"
00048 " %s <interface>\n"
00049 "\n"
00050 "Configure a network interface using DHCP\n",
00051 argv[0] );
00052 }
00053
00054
00055
00056
00057
00058
00059
00060
00061 static int dhcp_exec ( int argc, char **argv ) {
00062 static struct option longopts[] = {
00063 { "help", 0, NULL, 'h' },
00064 { NULL, 0, NULL, 0 },
00065 };
00066 const char *netdev_txt;
00067 struct net_device *netdev;
00068 int c;
00069 int rc;
00070
00071
00072 while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
00073 switch ( c ) {
00074 case 'h':
00075
00076 default:
00077
00078 dhcp_syntax ( argv );
00079 return 1;
00080 }
00081 }
00082
00083
00084 if ( optind != ( argc - 1 ) ) {
00085 dhcp_syntax ( argv );
00086 return 1;
00087 }
00088 netdev_txt = argv[optind];
00089
00090
00091 netdev = find_netdev ( netdev_txt );
00092 if ( ! netdev ) {
00093 printf ( "No such interface: %s\n", netdev_txt );
00094 return 1;
00095 }
00096
00097
00098 if ( ( rc = dhcp ( netdev ) ) != 0 ) {
00099 printf ( "Could not configure %s: %s\n", netdev->name,
00100 strerror ( rc ) );
00101 return 1;
00102 }
00103
00104 return 0;
00105 }
00106
00107
00108
00109
00110
00111
00112 static void pxebs_syntax ( char **argv ) {
00113 printf ( "Usage:\n"
00114 " %s <interface> <server_type>\n"
00115 "\n"
00116 "Perform PXE Boot Server discovery\n",
00117 argv[0] );
00118 }
00119
00120
00121
00122
00123
00124
00125
00126
00127 static int pxebs_exec ( int argc, char **argv ) {
00128 static struct option longopts[] = {
00129 { "help", 0, NULL, 'h' },
00130 { NULL, 0, NULL, 0 },
00131 };
00132 const char *netdev_txt;
00133 const char *pxe_type_txt;
00134 struct net_device *netdev;
00135 unsigned int pxe_type;
00136 char *end;
00137 int c;
00138 int rc;
00139
00140
00141 while ( ( c = getopt_long ( argc, argv, "h", longopts, NULL ) ) >= 0 ){
00142 switch ( c ) {
00143 case 'h':
00144
00145 default:
00146
00147 pxebs_syntax ( argv );
00148 return 1;
00149 }
00150 }
00151 if ( optind != ( argc - 2 ) ) {
00152 pxebs_syntax ( argv );
00153 return 1;
00154 }
00155 netdev_txt = argv[optind];
00156 pxe_type_txt = argv[ optind + 1 ];
00157
00158
00159 netdev = find_netdev ( netdev_txt );
00160 if ( ! netdev ) {
00161 printf ( "No such interface: %s\n", netdev_txt );
00162 return 1;
00163 }
00164 pxe_type = strtoul ( pxe_type_txt, &end, 0 );
00165 if ( *end ) {
00166 printf ( "Bad server type: %s\n", pxe_type_txt );
00167 return 1;
00168 }
00169
00170
00171 if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) {
00172 printf ( "Could not discover boot server on %s: %s\n",
00173 netdev->name, strerror ( rc ) );
00174 return 1;
00175 }
00176
00177 return 0;
00178 }
00179
00180
00181 struct command dhcp_commands[] __command = {
00182 {
00183 .name = "dhcp",
00184 .exec = dhcp_exec,
00185 },
00186 {
00187 .name = "pxebs",
00188 .exec = pxebs_exec,
00189 },
00190 };