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
19
* You can also choose to distribute this program under the terms of
20
* the Unmodified Binary Distribution Licence (as given in the file
21
* COPYING.UBDL), provided that you have satisfied its requirements.
24
FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
30
#include <ipxe/netdevice.h>
31
#include <ipxe/command.h>
32
#include <ipxe/parseopt.h>
33
#include <ipxe/vlan.h>
41
/** "vcreate" options */
42
struct vcreate_options {
45
/** VLAN default priority */
46
unsigned int priority;
49
/** "vcreate" option list */
50
static struct option_descriptor vcreate_opts[] = {
51
OPTION_DESC ( "tag", 't', required_argument,
52
struct vcreate_options, tag, parse_integer ),
53
OPTION_DESC ( "priority", 'p', required_argument,
54
struct vcreate_options, priority, parse_integer ),
57
/** "vcreate" command descriptor */
58
static struct command_descriptor vcreate_cmd =
59
COMMAND_DESC ( struct vcreate_options, vcreate_opts, 1, 1,
60
"<trunk interface>" );
65
* @v argc Argument count
66
* @v argv Argument list
67
* @ret rc Return status code
69
static int vcreate_exec ( int argc, char **argv ) {
70
struct vcreate_options opts;
71
struct net_device *trunk;
75
if ( ( rc = parse_options ( argc, argv, &vcreate_cmd, &opts ) ) != 0 )
78
/* Parse trunk interface */
79
if ( ( rc = parse_netdev ( argv[optind], &trunk ) ) != 0 )
82
/* Create VLAN device */
83
if ( ( rc = vlan_create ( trunk, opts.tag, opts.priority ) ) != 0 ) {
84
printf ( "Could not create VLAN device: %s\n",
92
/** "vdestroy" options */
93
struct vdestroy_options {};
95
/** "vdestroy" option list */
96
static struct option_descriptor vdestroy_opts[] = {};
98
/** "vdestroy" command descriptor */
99
static struct command_descriptor vdestroy_cmd =
100
COMMAND_DESC ( struct vdestroy_options, vdestroy_opts, 1, 1,
101
"<VLAN interface>" );
106
* @v argc Argument count
107
* @v argv Argument list
108
* @ret rc Return status code
110
static int vdestroy_exec ( int argc, char **argv ) {
111
struct vdestroy_options opts;
112
struct net_device *netdev;
116
if ( ( rc = parse_options ( argc, argv, &vdestroy_cmd, &opts ) ) != 0 )
119
/* Parse trunk interface */
120
if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
123
/* Destroy VLAN device */
124
if ( ( rc = vlan_destroy ( netdev ) ) != 0 ) {
125
printf ( "Could not destroy VLAN device: %s\n",
134
struct command vlan_commands[] __command = {
137
.exec = vcreate_exec,
141
.exec = vdestroy_exec,