Annotation of qemu/roms/ipxe/src/hci/commands/vlan_cmd.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.