libexplain  1.4.D001
libexplain/iocontrol/eql_setmastrcfg.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/master_config.h>
00027 #include <libexplain/capability.h>
00028 #include <libexplain/iocontrol/generic.h>
00029 #include <libexplain/iocontrol/eql_setmastrcfg.h>
00030 #include <libexplain/is_efault.h>
00031 
00032 #ifdef EQL_SETMASTRCFG
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_master_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 EFAULT:
00063         {
00064             const struct ifreq *q;
00065             const struct slaving_request *srqp;
00066 
00067             q = data;
00068             if (explain_is_efault_pointer(q, sizeof(*q)))
00069             {
00070                 explain_buffer_efault(sb, "data");
00071                 break;
00072             }
00073             srqp = (const struct slaving_request *)q->ifr_data;
00074             if (explain_is_efault_pointer(srqp, sizeof(*srqp)))
00075             {
00076                 explain_buffer_efault(sb, "data->ifr_data");
00077                 break;
00078             }
00079         }
00080         goto generic;
00081 
00082     case EINVAL:
00083         /*
00084          * FIXME: not a master
00085          */
00086         goto generic;
00087 
00088     default:
00089         generic:
00090         explain_iocontrol_generic_print_explanation
00091         (
00092             p,
00093             sb,
00094             errnum,
00095             fildes,
00096             request,
00097             data
00098         );
00099         break;
00100     }
00101 }
00102 
00103 
00104 const explain_iocontrol_t explain_iocontrol_eql_setmastrcfg =
00105 {
00106     "EQL_SETMASTRCFG", /* name */
00107     EQL_SETMASTRCFG, /* value */
00108     explain_iocontrol_disambiguate_is_if_eql,
00109     0, /* print_name */
00110     print_data,
00111     print_explanation,
00112     0, /* print_data_returned */
00113     sizeof(struct ifreq), /* data_size */
00114     "struct ifreq *", /* data_type */
00115     IOCONTROL_FLAG_NON_META, /* flags */
00116     __FILE__,
00117     __LINE__,
00118 };
00119 
00120 #else /* ndef EQL_SETMASTRCFG */
00121 
00122 const explain_iocontrol_t explain_iocontrol_eql_setmastrcfg =
00123 {
00124     0, /* name */
00125     0, /* value */
00126     0, /* disambiguate */
00127     0, /* print_name */
00128     0, /* print_data */
00129     0, /* print_explanation */
00130     0, /* print_data_returned */
00131     0, /* data_size */
00132     0, /* data_type */
00133     0, /* flags */
00134     __FILE__,
00135     __LINE__,
00136 };
00137 
00138 #endif /* EQL_SETMASTRCFG */
00139 
00140 
00141 /* vim: set ts=8 sw=4 et : */