iPXE
vlan_cmd.c
Go to the documentation of this file.
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 */
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,
53  OPTION_DESC ( "priority", 'p', required_argument,
55 };
56 
57 /** "vcreate" command descriptor */
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 */
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 };
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:88
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
int optind
Current option index.
Definition: getopt.c:51
static struct command_descriptor vcreate_cmd
"vcreate" command descriptor
Definition: vlan_cmd.c:58
A command-line command.
Definition: command.h:9
unsigned int tag
VLAN tag.
Definition: vlan_cmd.c:44
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:447
static int vdestroy_exec(int argc, char **argv)
"vdestroy" command
Definition: vlan_cmd.c:110
"vcreate" options
Definition: vlan_cmd.c:42
A command descriptor.
Definition: parseopt.h:76
int vlan_create(struct net_device *trunk, unsigned int tag, unsigned int priority)
Create VLAN device.
Definition: vlan.c:338
static int vcreate_exec(int argc, char **argv)
"vcreate" command
Definition: vlan_cmd.c:69
unsigned int priority
VLAN default priority.
Definition: vlan_cmd.c:46
Parse command-line options.
static struct net_device * netdev
Definition: gdbudp.c:52
static union @423 opts
"cert<xxx>" option list
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
Command line option parsing.
A network device.
Definition: netdevice.h:348
struct command vlan_commands [] __command
VLAN commands.
Definition: vlan_cmd.c:134
int vlan_destroy(struct net_device *netdev)
Destroy VLAN device.
Definition: vlan.c:428
const char * name
Name of the command.
Definition: command.h:11
Network device management.
static struct option_descriptor vdestroy_opts[]
"vdestroy" option list
Definition: vlan_cmd.c:96
uint16_t priority
Priotity.
Definition: stp.h:12
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:66
Option requires an argument.
Definition: getopt.h:18
A command-line option descriptor.
Definition: parseopt.h:22
Virtual LANs.
static struct command_descriptor vdestroy_cmd
"vdestroy" command descriptor
Definition: vlan_cmd.c:99
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:107
uint64_t tag
Identity tag.
Definition: edd.h:30
"vdestroy" options
Definition: vlan_cmd.c:93
String functions.
static struct option_descriptor vcreate_opts[]
"vcreate" option list
Definition: vlan_cmd.c:50
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition: parseopt.c:132