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 FILE_SECBOOT ( PERMITTED );
26 
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <getopt.h>
31 #include <ipxe/netdevice.h>
32 #include <ipxe/command.h>
33 #include <ipxe/parseopt.h>
34 #include <ipxe/vlan.h>
35 
36 /** @file
37  *
38  * VLAN commands
39  *
40  */
41 
42 /** "vcreate" options */
44  /** VLAN tag */
45  unsigned int tag;
46  /** VLAN default priority */
47  unsigned int priority;
48 };
49 
50 /** "vcreate" option list */
51 static struct option_descriptor vcreate_opts[] = {
52  OPTION_DESC ( "tag", 't', required_argument,
54  OPTION_DESC ( "priority", 'p', required_argument,
56 };
57 
58 /** "vcreate" command descriptor */
61  "<trunk interface>" );
62 
63 /**
64  * "vcreate" command
65  *
66  * @v argc Argument count
67  * @v argv Argument list
68  * @ret rc Return status code
69  */
70 static int vcreate_exec ( int argc, char **argv ) {
71  struct vcreate_options opts;
72  struct net_device *trunk;
73  int rc;
74 
75  /* Parse options */
76  if ( ( rc = parse_options ( argc, argv, &vcreate_cmd, &opts ) ) != 0 )
77  return rc;
78 
79  /* Parse trunk interface */
80  if ( ( rc = parse_netdev ( argv[optind], &trunk ) ) != 0 )
81  return rc;
82 
83  /* Create VLAN device */
84  if ( ( rc = vlan_create ( trunk, opts.tag, opts.priority ) ) != 0 ) {
85  printf ( "Could not create VLAN device: %s\n",
86  strerror ( rc ) );
87  return rc;
88  }
89 
90  return 0;
91 }
92 
93 /** "vdestroy" options */
94 struct vdestroy_options {};
95 
96 /** "vdestroy" option list */
97 static struct option_descriptor vdestroy_opts[] = {};
98 
99 /** "vdestroy" command descriptor */
102  "<VLAN interface>" );
103 
104 /**
105  * "vdestroy" command
106  *
107  * @v argc Argument count
108  * @v argv Argument list
109  * @ret rc Return status code
110  */
111 static int vdestroy_exec ( int argc, char **argv ) {
112  struct vdestroy_options opts;
113  struct net_device *netdev;
114  int rc;
115 
116  /* Parse options */
117  if ( ( rc = parse_options ( argc, argv, &vdestroy_cmd, &opts ) ) != 0 )
118  return rc;
119 
120  /* Parse trunk interface */
121  if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
122  return rc;
123 
124  /* Destroy VLAN device */
125  if ( ( rc = vlan_destroy ( netdev ) ) != 0 ) {
126  printf ( "Could not destroy VLAN device: %s\n",
127  strerror ( rc ) );
128  return rc;
129  }
130 
131  return 0;
132 }
133 
134 /** VLAN commands */
135 COMMAND ( vcreate, vcreate_exec );
136 COMMAND ( vdestroy, vdestroy_exec );
int parse_integer(char *text, unsigned int *value)
Parse integer value.
Definition: parseopt.c:92
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:465
int optind
Current option index.
Definition: getopt.c:52
static struct command_descriptor vcreate_cmd
"vcreate" command descriptor
Definition: vlan_cmd.c:59
unsigned int tag
VLAN tag.
Definition: vlan_cmd.c:45
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:485
static int vdestroy_exec(int argc, char **argv)
"vdestroy" command
Definition: vlan_cmd.c:111
"vcreate" options
Definition: vlan_cmd.c:43
A command descriptor.
Definition: parseopt.h:78
int vlan_create(struct net_device *trunk, unsigned int tag, unsigned int priority)
Create VLAN device.
Definition: vlan.c:344
FILE_SECBOOT(PERMITTED)
static int vcreate_exec(int argc, char **argv)
"vcreate" command
Definition: vlan_cmd.c:70
unsigned int priority
VLAN default priority.
Definition: vlan_cmd.c:47
Parse command-line options.
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:79
COMMAND(vcreate, vcreate_exec)
VLAN commands.
Command line option parsing.
A network device.
Definition: netdevice.h:353
int vlan_destroy(struct net_device *netdev)
Destroy VLAN device.
Definition: vlan.c:434
Network device management.
static struct option_descriptor vdestroy_opts[]
"vdestroy" option list
Definition: vlan_cmd.c:97
uint16_t priority
Priotity.
Definition: stp.h:13
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19
A command-line option descriptor.
Definition: parseopt.h:24
Virtual LANs.
static struct command_descriptor vdestroy_cmd
"vdestroy" command descriptor
Definition: vlan_cmd.c:100
static union @447 opts
"cert<xxx>" option list
#define COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage)
Construct command descriptor.
Definition: parseopt.h:109
uint64_t tag
Identity tag.
Definition: edd.h:31
"vdestroy" options
Definition: vlan_cmd.c:94
String functions.
static struct option_descriptor vcreate_opts[]
"vcreate" option list
Definition: vlan_cmd.c:51
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition: parseopt.c:159