These changes are the raw update to qemu-2.6.
[kvmfornfv.git] / qemu / roms / ipxe / src / hci / commands / vlan_cmd.c
1 /*
2  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
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., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
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.
22  */
23
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <getopt.h>
30 #include <ipxe/netdevice.h>
31 #include <ipxe/command.h>
32 #include <ipxe/parseopt.h>
33 #include <ipxe/vlan.h>
34
35 /** @file
36  *
37  * VLAN commands
38  *
39  */
40
41 /** "vcreate" options */
42 struct vcreate_options {
43         /** VLAN tag */
44         unsigned int tag;
45         /** VLAN default priority */
46         unsigned int priority;
47 };
48
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 ),
55 };
56
57 /** "vcreate" command descriptor */
58 static struct command_descriptor vcreate_cmd =
59         COMMAND_DESC ( struct vcreate_options, vcreate_opts, 1, 1,
60                        "<trunk interface>" );
61
62 /**
63  * "vcreate" command
64  *
65  * @v argc              Argument count
66  * @v argv              Argument list
67  * @ret rc              Return status code
68  */
69 static int vcreate_exec ( int argc, char **argv ) {
70         struct vcreate_options opts;
71         struct net_device *trunk;
72         int rc;
73
74         /* Parse options */
75         if ( ( rc = parse_options ( argc, argv, &vcreate_cmd, &opts ) ) != 0 )
76                 return rc;
77
78         /* Parse trunk interface */
79         if ( ( rc = parse_netdev ( argv[optind], &trunk ) ) != 0 )
80                 return rc;
81
82         /* Create VLAN device */
83         if ( ( rc = vlan_create ( trunk, opts.tag, opts.priority ) ) != 0 ) {
84                 printf ( "Could not create VLAN device: %s\n",
85                          strerror ( rc ) );
86                 return rc;
87         }
88
89         return 0;
90 }
91
92 /** "vdestroy" options */
93 struct vdestroy_options {};
94
95 /** "vdestroy" option list */
96 static struct option_descriptor vdestroy_opts[] = {};
97
98 /** "vdestroy" command descriptor */
99 static struct command_descriptor vdestroy_cmd =
100         COMMAND_DESC ( struct vdestroy_options, vdestroy_opts, 1, 1,
101                        "<VLAN interface>" );
102
103 /**
104  * "vdestroy" command
105  *
106  * @v argc              Argument count
107  * @v argv              Argument list
108  * @ret rc              Return status code
109  */
110 static int vdestroy_exec ( int argc, char **argv ) {
111         struct vdestroy_options opts;
112         struct net_device *netdev;
113         int rc;
114
115         /* Parse options */
116         if ( ( rc = parse_options ( argc, argv, &vdestroy_cmd, &opts ) ) != 0 )
117                 return rc;
118
119         /* Parse trunk interface */
120         if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
121                 return rc;
122
123         /* Destroy VLAN device */
124         if ( ( rc = vlan_destroy ( netdev ) ) != 0 ) {
125                 printf ( "Could not destroy VLAN device: %s\n",
126                          strerror ( rc ) );
127                 return rc;
128         }
129
130         return 0;
131 }
132
133 /** VLAN commands */
134 struct command vlan_commands[] __command = {
135         {
136                 .name = "vcreate",
137                 .exec = vcreate_exec,
138         },
139         {
140                 .name = "vdestroy",
141                 .exec = vdestroy_exec,
142         },
143 };