libexplain  1.4.D001
libexplain/iocontrol/eql_setslavecfg.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 it
00006  * under the terms of the GNU Lesser General Public License as published by
00007  * the Free Software Foundation; either version 3 of the License, or (at your
00008  * option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,but WITHOUT
00011  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
00013  * 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/sys/ioctl.h>
00020 #include <libexplain/ac/errno.h>
00021 #include <libexplain/ac/linux/if_eql.h>
00022 #include <libexplain/ac/net/if.h>
00023 
00024 #include <libexplain/buffer/efault.h>
00025 #include <libexplain/buffer/eperm.h>
00026 #include <libexplain/buffer/ifreq/slave_config.h>
00027 #include <libexplain/capability.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/eql_setslavecfg.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 #ifdef EQL_SETSLAVECFG
00033 
00034 
00035 static void
00036 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int
00037     errnum, int fildes, int request, const void *data)
00038 {
00039     (void)p;
00040     (void)errnum;
00041     (void)fildes;
00042     (void)request;
00043     explain_buffer_ifreq_slave_config(sb, data, 1);
00044 }
00045 
00046 
00047 static void
00048 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int
00049     errnum, int fildes, int request, const void *data)
00050 {
00051     /* see Linux kernel sources, drivers/net/eql.c */
00052     switch (errnum)
00053     {
00054     case EPERM:
00055         if (!explain_capability_net_admin())
00056         {
00057             explain_buffer_eperm_net_admin(sb, "ioctl EQL_EMANCIPATE");
00058             break;
00059         }
00060         goto generic;
00061 
00062     case EINVAL:
00063         /*
00064          * FIXME: the named slave device does not exist
00065          */
00066         goto generic;
00067 
00068     case ENODEV:
00069         /*
00070          * FIXME: the name slave device isn't a slave,
00071          */
00072         goto generic;
00073 
00074     case EFAULT:
00075         {
00076             const struct ifreq *q;
00077             const struct slaving_request *srqp;
00078 
00079             q = data;
00080             if (explain_is_efault_pointer(q, sizeof(*q)))
00081             {
00082                 explain_buffer_efault(sb, "data");
00083                 break;
00084             }
00085             srqp = (const struct slaving_request *)q->ifr_data;
00086             if (explain_is_efault_pointer(srqp, sizeof(*srqp)))
00087             {
00088                 explain_buffer_efault(sb, "data->ifr_data");
00089                 break;
00090             }
00091         }
00092         goto generic;
00093 
00094     default:
00095         generic:
00096         explain_iocontrol_generic_print_explanation
00097         (
00098             p,
00099             sb,
00100             errnum,
00101             fildes,
00102             request,
00103             data
00104         );
00105         break;
00106     }
00107 }
00108 
00109 
00110 const explain_iocontrol_t explain_iocontrol_eql_setslavecfg =
00111 {
00112     "EQL_SETSLAVECFG", /* name */
00113     EQL_SETSLAVECFG, /* value */
00114     explain_iocontrol_disambiguate_is_if_eql,
00115     0, /* print_name */
00116     print_data,
00117     print_explanation,
00118     0, /* print_data_returned */
00119     sizeof(struct ifreq), /* data_size */
00120     "struct ifreq *", /* data_type */
00121     IOCONTROL_FLAG_NON_META, /* flags */
00122     __FILE__,
00123     __LINE__,
00124 };
00125 
00126 #else /* ndef EQL_SETSLAVECFG */
00127 
00128 const explain_iocontrol_t explain_iocontrol_eql_setslavecfg =
00129 {
00130     0, /* name */
00131     0, /* value */
00132     0, /* disambiguate */
00133     0, /* print_name */
00134     0, /* print_data */
00135     0, /* print_explanation */
00136     0, /* print_data_returned */
00137     0, /* data_size */
00138     0, /* data_type */
00139     0, /* flags */
00140     __FILE__,
00141     __LINE__,
00142 };
00143 
00144 #endif /* EQL_SETSLAVECFG */
00145 
00146 
00147 /* vim: set ts=8 sw=4 et : */