iPXE
vlan_cmd.c
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2010 Michael Brown <mbrown@fensystems.co.uk>.
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License as
00006  * published by the Free Software Foundation; either version 2 of the
00007  * License, or any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012  * General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301, USA.
00018  *
00019  * You can also choose to distribute this program under the terms of
00020  * the Unmodified Binary Distribution Licence (as given in the file
00021  * COPYING.UBDL), provided that you have satisfied its requirements.
00022  */
00023 
00024 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
00025 
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <getopt.h>
00030 #include <ipxe/netdevice.h>
00031 #include <ipxe/command.h>
00032 #include <ipxe/parseopt.h>
00033 #include <ipxe/vlan.h>
00034 
00035 /** @file
00036  *
00037  * VLAN commands
00038  *
00039  */
00040 
00041 /** "vcreate" options */
00042 struct vcreate_options {
00043         /** VLAN tag */
00044         unsigned int tag;
00045         /** VLAN default priority */
00046         unsigned int priority;
00047 };
00048 
00049 /** "vcreate" option list */
00050 static struct option_descriptor vcreate_opts[] = {
00051         OPTION_DESC ( "tag", 't', required_argument,
00052                       struct vcreate_options, tag, parse_integer ),
00053         OPTION_DESC ( "priority", 'p', required_argument,
00054                       struct vcreate_options, priority, parse_integer ),
00055 };
00056 
00057 /** "vcreate" command descriptor */
00058 static struct command_descriptor vcreate_cmd =
00059         COMMAND_DESC ( struct vcreate_options, vcreate_opts, 1, 1,
00060                        "<trunk interface>" );
00061 
00062 /**
00063  * "vcreate" command
00064  *
00065  * @v argc              Argument count
00066  * @v argv              Argument list
00067  * @ret rc              Return status code
00068  */
00069 static int vcreate_exec ( int argc, char **argv ) {
00070         struct vcreate_options opts;
00071         struct net_device *trunk;
00072         int rc;
00073 
00074         /* Parse options */
00075         if ( ( rc = parse_options ( argc, argv, &vcreate_cmd, &opts ) ) != 0 )
00076                 return rc;
00077 
00078         /* Parse trunk interface */
00079         if ( ( rc = parse_netdev ( argv[optind], &trunk ) ) != 0 )
00080                 return rc;
00081 
00082         /* Create VLAN device */
00083         if ( ( rc = vlan_create ( trunk, opts.tag, opts.priority ) ) != 0 ) {
00084                 printf ( "Could not create VLAN device: %s\n",
00085                          strerror ( rc ) );
00086                 return rc;
00087         }
00088 
00089         return 0;
00090 }
00091 
00092 /** "vdestroy" options */
00093 struct vdestroy_options {};
00094 
00095 /** "vdestroy" option list */
00096 static struct option_descriptor vdestroy_opts[] = {};
00097 
00098 /** "vdestroy" command descriptor */
00099 static struct command_descriptor vdestroy_cmd =
00100         COMMAND_DESC ( struct vdestroy_options, vdestroy_opts, 1, 1,
00101                        "<VLAN interface>" );
00102 
00103 /**
00104  * "vdestroy" command
00105  *
00106  * @v argc              Argument count
00107  * @v argv              Argument list
00108  * @ret rc              Return status code
00109  */
00110 static int vdestroy_exec ( int argc, char **argv ) {
00111         struct vdestroy_options opts;
00112         struct net_device *netdev;
00113         int rc;
00114 
00115         /* Parse options */
00116         if ( ( rc = parse_options ( argc, argv, &vdestroy_cmd, &opts ) ) != 0 )
00117                 return rc;
00118 
00119         /* Parse trunk interface */
00120         if ( ( rc = parse_netdev ( argv[optind], &netdev ) ) != 0 )
00121                 return rc;
00122 
00123         /* Destroy VLAN device */
00124         if ( ( rc = vlan_destroy ( netdev ) ) != 0 ) {
00125                 printf ( "Could not destroy VLAN device: %s\n",
00126                          strerror ( rc ) );
00127                 return rc;
00128         }
00129 
00130         return 0;
00131 }
00132 
00133 /** VLAN commands */
00134 struct command vlan_commands[] __command = {
00135         {
00136                 .name = "vcreate",
00137                 .exec = vcreate_exec,
00138         },
00139         {
00140                 .name = "vdestroy",
00141                 .exec = vdestroy_exec,
00142         },
00143 };