|
|
1.1 ! root 1: /* ! 2: * Copyright (C) 2007 Michael Brown <[email protected]>. ! 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: FILE_LICENCE ( GPL2_OR_LATER ); ! 20: ! 21: #include <stdio.h> ! 22: #include <stdint.h> ! 23: #include <stdlib.h> ! 24: #include <stdio.h> ! 25: #include <errno.h> ! 26: #include <stddef.h> ! 27: #include <string.h> ! 28: #include <assert.h> ! 29: #include <getopt.h> ! 30: #include <ipxe/netdevice.h> ! 31: #include <ipxe/in.h> ! 32: #include <ipxe/command.h> ! 33: #include <ipxe/parseopt.h> ! 34: #include <usr/dhcpmgmt.h> ! 35: #include <hci/ifmgmt_cmd.h> ! 36: ! 37: /** @file ! 38: * ! 39: * DHCP management commands ! 40: * ! 41: */ ! 42: ! 43: /** "dhcp" command descriptor */ ! 44: static struct command_descriptor dhcp_cmd = ! 45: COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS, ! 46: "[<interface>...]" ); ! 47: ! 48: /** ! 49: * Execute "dhcp" command for a network device ! 50: * ! 51: * @v netdev Network device ! 52: * @ret rc Return status code ! 53: */ ! 54: static int dhcp_payload ( struct net_device *netdev ) { ! 55: int rc; ! 56: ! 57: if ( ( rc = dhcp ( netdev ) ) != 0 ) { ! 58: printf ( "Could not configure %s: %s\n", ! 59: netdev->name, strerror ( rc ) ); ! 60: ! 61: /* Close device on failure, to avoid memory exhaustion */ ! 62: netdev_close ( netdev ); ! 63: ! 64: return rc; ! 65: } ! 66: ! 67: return 0; ! 68: } ! 69: ! 70: /** ! 71: * The "dhcp" command ! 72: * ! 73: * @v argc Argument count ! 74: * @v argv Argument list ! 75: * @ret rc Return status code ! 76: */ ! 77: static int dhcp_exec ( int argc, char **argv ) { ! 78: return ifcommon_exec ( argc, argv, &dhcp_cmd, dhcp_payload, 1 ); ! 79: } ! 80: ! 81: /** "pxebs" options */ ! 82: struct pxebs_options {}; ! 83: ! 84: /** "pxebs" option list */ ! 85: static struct option_descriptor pxebs_opts[] = {}; ! 86: ! 87: /** "pxebs" command descriptor */ ! 88: static struct command_descriptor pxebs_cmd = ! 89: COMMAND_DESC ( struct pxebs_options, pxebs_opts, 2, 2, ! 90: "<interface> <server type>" ); ! 91: ! 92: /** ! 93: * The "pxebs" command ! 94: * ! 95: * @v argc Argument count ! 96: * @v argv Argument list ! 97: * @ret rc Return status code ! 98: */ ! 99: static int pxebs_exec ( int argc, char **argv ) { ! 100: struct pxebs_options opts; ! 101: struct net_device *netdev; ! 102: unsigned int pxe_type; ! 103: int rc; ! 104: ! 105: /* Parse options */ ! 106: if ( ( rc = parse_options ( argc, argv, &pxebs_cmd, &opts ) ) != 0 ) ! 107: return rc; ! 108: ! 109: /* Parse net device name */ ! 110: if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 ) ! 111: return rc; ! 112: ! 113: /* Parse boot server type */ ! 114: if ( ( rc = parse_integer ( argv[ optind + 1 ], &pxe_type ) ) != 0 ) ! 115: return rc; ! 116: ! 117: /* Perform Boot Server Discovery */ ! 118: if ( ( rc = pxebs ( netdev, pxe_type ) ) != 0 ) { ! 119: printf ( "Could not discover boot server on %s: %s\n", ! 120: netdev->name, strerror ( rc ) ); ! 121: return rc; ! 122: } ! 123: ! 124: return 0; ! 125: } ! 126: ! 127: /** DHCP management commands */ ! 128: struct command dhcp_commands[] __command = { ! 129: { ! 130: .name = "dhcp", ! 131: .exec = dhcp_exec, ! 132: }, ! 133: { ! 134: .name = "pxebs", ! 135: .exec = pxebs_exec, ! 136: }, ! 137: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.