|
|
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 <errno.h>
23: #include <getopt.h>
24: #include <ipxe/netdevice.h>
25: #include <ipxe/command.h>
26: #include <ipxe/parseopt.h>
27: #include <usr/ifmgmt.h>
28: #include <hci/ifmgmt_cmd.h>
29:
30: /** @file
31: *
32: * Network interface management commands
33: *
34: */
35:
36: /** "if<xxx>" command options */
37: struct option_descriptor ifcommon_opts[0];
38:
39: /**
40: * Execute if<xxx> command
41: *
42: * @v argc Argument count
43: * @v argv Argument list
44: * @v cmd Command descriptor
45: * @v payload Command to execute
46: * @v verb Verb describing the action of the command
47: * @ret rc Return status code
48: */
49: int ifcommon_exec ( int argc, char **argv,
50: struct command_descriptor *cmd,
51: int ( * payload ) ( struct net_device * ),
52: int stop_on_first_success ) {
53: struct ifcommon_options opts;
54: struct net_device *netdev;
55: int rc;
56:
57: /* Parse options */
58: if ( ( rc = parse_options ( argc, argv, cmd, &opts ) ) != 0 )
59: return rc;
60:
61: if ( optind != argc ) {
62: /* Treat arguments as a list of interfaces to try */
63: while ( optind != argc ) {
64: if ( ( rc = parse_netdev ( argv[optind++],
65: &netdev ) ) != 0 ) {
66: continue;
67: }
68: if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
69: stop_on_first_success ) {
70: return 0;
71: }
72: }
73: } else {
74: /* Try all interfaces */
75: rc = -ENODEV;
76: for_each_netdev ( netdev ) {
77: if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
78: stop_on_first_success ) {
79: return 0;
80: }
81: }
82: }
83:
84: return rc;
85: }
86:
87: /** "ifopen" command descriptor */
88: static struct command_descriptor ifopen_cmd =
89: COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
90: "[<interface>...]" );
91:
92: /**
93: * "ifopen" payload
94: *
95: * @v netdev Network device
96: * @ret rc Return status code
97: */
98: static int ifopen_payload ( struct net_device *netdev ) {
99: return ifopen ( netdev );
100: }
101:
102: /**
103: * The "ifopen" command
104: *
105: * @v argc Argument count
106: * @v argv Argument list
107: * @ret rc Return status code
108: */
109: static int ifopen_exec ( int argc, char **argv ) {
110: return ifcommon_exec ( argc, argv, &ifopen_cmd, ifopen_payload, 0 );
111: }
112:
113: /** "ifclose" command descriptor */
114: static struct command_descriptor ifclose_cmd =
115: COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
116: "[<interface>...]" );
117:
118: /**
119: * "ifclose" payload
120: *
121: * @v netdev Network device
122: * @ret rc Return status code
123: */
124: static int ifclose_payload ( struct net_device *netdev ) {
125: ifclose ( netdev );
126: return 0;
127: }
128:
129: /**
130: * The "ifclose" command
131: *
132: * @v argc Argument count
133: * @v argv Argument list
134: * @ret rc Return status code
135: */
136: static int ifclose_exec ( int argc, char **argv ) {
137: return ifcommon_exec ( argc, argv, &ifclose_cmd, ifclose_payload, 0 );
138: }
139:
140: /** "ifstat" command descriptor */
141: static struct command_descriptor ifstat_cmd =
142: COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
143: "[<interface>...]" );
144:
145: /**
146: * "ifstat" payload
147: *
148: * @v netdev Network device
149: * @ret rc Return status code
150: */
151: static int ifstat_payload ( struct net_device *netdev ) {
152: ifstat ( netdev );
153: return 0;
154: }
155:
156: /**
157: * The "ifstat" command
158: *
159: * @v argc Argument count
160: * @v argv Argument list
161: * @ret rc Return status code
162: */
163: static int ifstat_exec ( int argc, char **argv ) {
164: return ifcommon_exec ( argc, argv, &ifstat_cmd, ifstat_payload, 0 );
165: }
166:
167: /** Interface management commands */
168: struct command ifmgmt_commands[] __command = {
169: {
170: .name = "ifopen",
171: .exec = ifopen_exec,
172: },
173: {
174: .name = "ifclose",
175: .exec = ifclose_exec,
176: },
177: {
178: .name = "ifstat",
179: .exec = ifstat_exec,
180: },
181: };
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.