2 * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
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.
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.
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
20 FILE_LICENCE ( GPL2_OR_LATER );
26 #include <ipxe/netdevice.h>
27 #include <ipxe/command.h>
28 #include <ipxe/parseopt.h>
29 #include <ipxe/vlan.h>
37 /** "vcreate" options */
38 struct vcreate_options {
41 /** VLAN default priority */
42 unsigned int priority;
45 /** "vcreate" option list */
46 static struct option_descriptor vcreate_opts[] = {
47 OPTION_DESC ( "tag", 't', required_argument,
48 struct vcreate_options, tag, parse_integer ),
49 OPTION_DESC ( "priority", 'p', required_argument,
50 struct vcreate_options, priority, parse_integer ),
53 /** "vcreate" command descriptor */
54 static struct command_descriptor vcreate_cmd =
55 COMMAND_DESC ( struct vcreate_options, vcreate_opts, 1, 1,
56 "<trunk interface>" );
61 * @v argc Argument count
62 * @v argv Argument list
63 * @ret rc Return status code
65 static int vcreate_exec ( int argc, char **argv ) {
66 struct vcreate_options opts;
67 struct net_device *trunk;
71 if ( ( rc = parse_options ( argc, argv, &vcreate_cmd, &opts ) ) != 0 )
74 /* Parse trunk interface */
75 if ( ( rc = parse_netdev ( argv[optind], &trunk ) ) != 0 )
78 /* Create VLAN device */
79 if ( ( rc = vlan_create ( trunk, opts.tag, opts.priority ) ) != 0 ) {
80 printf ( "Could not create VLAN device: %s\n",
88 /** "vdestroy" options */
89 struct vdestroy_options {};
91 /** "vdestroy" option list */
92 static struct option_descriptor vdestroy_opts[] = {};
94 /** "vdestroy" command descriptor */
95 static struct command_descriptor vdestroy_cmd =
96 COMMAND_DESC ( struct vdestroy_options, vdestroy_opts, 1, 1,
102 * @v argc Argument count
103 * @v argv Argument list
104 * @ret rc Return status code
106 static int vdestroy_exec ( int argc, char **argv ) {
107 struct vdestroy_options opts;
108 struct net_device *netdev;
112 if ( ( rc = parse_options ( argc, argv, &vdestroy_cmd, &opts ) ) != 0 )
115 /* Parse trunk interface */
116 if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
119 /* Destroy VLAN device */
120 if ( ( rc = vlan_destroy ( netdev ) ) != 0 ) {
121 printf ( "Could not destroy VLAN device: %s\n",
130 struct command vlan_commands[] __command = {
133 .exec = vcreate_exec,
137 .exec = vdestroy_exec,