libexplain  1.4.D001
libexplain/buffer/vlan_ioctl_args.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009-2011, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as
00007  * published by the Free Software Foundation; either version 3 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Lesser General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Lesser General Public License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/linux/if_vlan.h>
00020 
00021 #include <libexplain/buffer/int.h>
00022 #include <libexplain/buffer/pointer.h>
00023 #include <libexplain/buffer/short.h>
00024 #include <libexplain/buffer/vlan_ioctl_args.h>
00025 #include <libexplain/parse_bits.h>
00026 #include <libexplain/is_efault.h>
00027 #include <libexplain/sizeof.h>
00028 
00029 
00030 #ifdef HAVE_LINUX_IF_VLAN_H
00031 
00032 static void
00033 explain_buffer_vlan_ioctl_cmd(explain_string_buffer_t *sb, int value)
00034 {
00035     static const explain_parse_bits_table_t table[] =
00036     {
00037         { "ADD_VLAN_CMD", ADD_VLAN_CMD },
00038         { "DEL_VLAN_CMD", DEL_VLAN_CMD },
00039         { "GET_VLAN_EGRESS_PRIORITY_CMD", GET_VLAN_EGRESS_PRIORITY_CMD },
00040         { "GET_VLAN_INGRESS_PRIORITY_CMD", GET_VLAN_INGRESS_PRIORITY_CMD },
00041         { "GET_VLAN_REALDEV_NAME_CMD", GET_VLAN_REALDEV_NAME_CMD },
00042         { "GET_VLAN_VID_CMD", GET_VLAN_VID_CMD },
00043         { "SET_VLAN_EGRESS_PRIORITY_CMD", SET_VLAN_EGRESS_PRIORITY_CMD },
00044         { "SET_VLAN_FLAG_CMD", SET_VLAN_FLAG_CMD },
00045         { "SET_VLAN_INGRESS_PRIORITY_CMD", SET_VLAN_INGRESS_PRIORITY_CMD },
00046         { "SET_VLAN_NAME_TYPE_CMD", SET_VLAN_NAME_TYPE_CMD },
00047     };
00048 
00049     explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
00050 }
00051 
00052 
00053 static void
00054 explain_buffer_vlan_ioctl_flag(explain_string_buffer_t *sb, int value)
00055 {
00056     static const explain_parse_bits_table_t table[] =
00057     {
00058         { "VLAN_FLAG_REORDER_HDR", VLAN_FLAG_REORDER_HDR },
00059 #ifdef VLAN_FLAG_GVRP
00060         { "VLAN_FLAG_GVRP", VLAN_FLAG_GVRP },
00061 #endif
00062     };
00063 
00064     explain_parse_bits_print(sb, value, table, SIZEOF(table));
00065 }
00066 
00067 
00068 static void
00069 explain_buffer_vlan_ioctl_name_type(explain_string_buffer_t *sb, int value)
00070 {
00071     static const explain_parse_bits_table_t table[] =
00072     {
00073         { "VLAN_NAME_TYPE_PLUS_VID", VLAN_NAME_TYPE_PLUS_VID },
00074         { "VLAN_NAME_TYPE_RAW_PLUS_VID", VLAN_NAME_TYPE_RAW_PLUS_VID },
00075         { "VLAN_NAME_TYPE_PLUS_VID_NO_PAD", VLAN_NAME_TYPE_PLUS_VID_NO_PAD },
00076         { "VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD",
00077             VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD },
00078         { "VLAN_NAME_TYPE_HIGHEST", VLAN_NAME_TYPE_HIGHEST },
00079     };
00080 
00081     explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
00082 }
00083 
00084 
00085 void
00086 explain_buffer_vlan_ioctl_args(explain_string_buffer_t *sb,
00087     const struct vlan_ioctl_args *data, int all)
00088 {
00089     if (explain_is_efault_pointer(data, sizeof(*data)))
00090     {
00091         explain_buffer_pointer(sb, data);
00092         return;
00093     }
00094 
00095     explain_string_buffer_puts(sb, "{ cmd = ");
00096     explain_buffer_vlan_ioctl_cmd(sb, data->cmd);
00097     explain_string_buffer_puts(sb, ", device1 = ");
00098     explain_string_buffer_puts_quoted_n(sb, data->device1,
00099         sizeof(data->device1));
00100     switch (data->cmd)
00101     {
00102     case ADD_VLAN_CMD:
00103     case DEL_VLAN_CMD:
00104     case SET_VLAN_EGRESS_PRIORITY_CMD:
00105     case SET_VLAN_FLAG_CMD:
00106     case SET_VLAN_INGRESS_PRIORITY_CMD:
00107     case SET_VLAN_NAME_TYPE_CMD:
00108         all = 1;
00109         break;
00110 
00111     default:
00112         break;
00113     }
00114     if (all)
00115     {
00116         switch (data->cmd)
00117         {
00118         case SET_VLAN_INGRESS_PRIORITY_CMD:
00119         case GET_VLAN_INGRESS_PRIORITY_CMD:
00120         case SET_VLAN_EGRESS_PRIORITY_CMD:
00121         case GET_VLAN_EGRESS_PRIORITY_CMD:
00122             explain_string_buffer_puts(sb, ", skb_priority = ");
00123             explain_buffer_uint(sb, data->u.skb_priority);
00124             break;
00125 
00126         case SET_VLAN_NAME_TYPE_CMD:
00127             explain_string_buffer_puts(sb, ", name_type = ");
00128             explain_buffer_vlan_ioctl_name_type(sb, data->u.name_type);
00129             break;
00130 
00131         case SET_VLAN_FLAG_CMD:
00132             explain_string_buffer_puts(sb, ", flag = ");
00133             explain_buffer_vlan_ioctl_flag(sb, data->u.flag);
00134             break;
00135 
00136         case GET_VLAN_REALDEV_NAME_CMD:
00137             explain_string_buffer_puts(sb, ", device2 = ");
00138             explain_string_buffer_puts_quoted_n(sb, data->u.device2,
00139                 sizeof(data->u.device2));
00140             break;
00141 
00142         case GET_VLAN_VID_CMD:
00143             explain_string_buffer_puts(sb, ", vid = ");
00144             explain_buffer_int(sb, data->u.VID);
00145             break;
00146 
00147         case ADD_VLAN_CMD:
00148         case DEL_VLAN_CMD:
00149         default:
00150             /* do nothing */
00151             break;
00152         }
00153     }
00154     if (data->vlan_qos)
00155     {
00156         explain_string_buffer_puts(sb, ", vlan_qos = ");
00157         explain_buffer_short(sb, data->vlan_qos);
00158     }
00159     explain_string_buffer_puts(sb, " }");
00160 }
00161 
00162 #else
00163 
00164 void
00165 explain_buffer_vlan_ioctl_args(explain_string_buffer_t *sb,
00166     const struct vlan_ioctl_args *data, int all)
00167 {
00168     (void)all;
00169     explain_buffer_pointer(sb, data);
00170 }
00171 
00172 #endif
00173 
00174 
00175 /* vim: set ts=8 sw=4 et : */