libexplain
1.4.D001
|
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/slaving_request.h> 00027 #include <libexplain/capability.h> 00028 #include <libexplain/iocontrol/disambiguate/if_ppp.h> 00029 #include <libexplain/iocontrol/generic.h> 00030 #include <libexplain/iocontrol/eql_enslave.h> 00031 #include <libexplain/is_efault.h> 00032 00033 #ifdef EQL_ENSLAVE 00034 00035 00036 static void 00037 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int 00038 errnum, int fildes, int request, const void *data) 00039 { 00040 (void)p; 00041 (void)errnum; 00042 (void)fildes; 00043 (void)request; 00044 explain_buffer_ifreq_slaving_request(sb, data, 1); 00045 } 00046 00047 00048 static void 00049 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb, int 00050 errnum, int fildes, int request, const void *data) 00051 { 00052 /* see Linux kernel sources, drivers/net/eql.c */ 00053 switch (errnum) 00054 { 00055 case EPERM: 00056 if (!explain_capability_net_admin()) 00057 { 00058 explain_buffer_eperm_net_admin(sb, "ioctl EQL_EMANCIPATE"); 00059 break; 00060 } 00061 goto generic; 00062 00063 case EFAULT: 00064 { 00065 const struct ifreq *i; 00066 const struct slaving_request *s; 00067 00068 i = data; 00069 if (explain_is_efault_pointer(i, sizeof(*i))) 00070 { 00071 explain_buffer_efault(sb, "data"); 00072 break; 00073 } 00074 00075 s = (const struct slaving_request *)i->ifr_data; 00076 if (explain_is_efault_pointer(s, sizeof(*s))) 00077 { 00078 explain_buffer_efault(sb, "data->ifr_data"); 00079 break; 00080 } 00081 } 00082 goto generic; 00083 00084 case ENOMEM: 00085 goto generic; 00086 00087 case EINVAL: 00088 /* 00089 * FIXME: not suitable: the slave may not exist, it could 00090 * already be a slave, it could already be a master, the master 00091 * interface may not be IFF_UP. 00092 */ 00093 goto generic; 00094 00095 default: 00096 generic: 00097 explain_iocontrol_generic_print_explanation 00098 ( 00099 p, 00100 sb, 00101 errnum, 00102 fildes, 00103 request, 00104 data 00105 ); 00106 break; 00107 } 00108 } 00109 00110 00111 const explain_iocontrol_t explain_iocontrol_eql_enslave = 00112 { 00113 "EQL_ENSLAVE", /* name */ 00114 EQL_ENSLAVE, /* value */ 00115 explain_iocontrol_disambiguate_is_if_ppp, 00116 0, /* print_name */ 00117 print_data, 00118 print_explanation, 00119 0, /* print_data_returned */ 00120 sizeof(struct ifreq), /* data_size */ 00121 "struct ifreq *", /* data_type */ 00122 IOCONTROL_FLAG_NON_META, /* flags */ 00123 __FILE__, 00124 __LINE__, 00125 }; 00126 00127 #else /* ndef EQL_ENSLAVE */ 00128 00129 const explain_iocontrol_t explain_iocontrol_eql_enslave = 00130 { 00131 0, /* name */ 00132 0, /* value */ 00133 0, /* disambiguate */ 00134 0, /* print_name */ 00135 0, /* print_data */ 00136 0, /* print_explanation */ 00137 0, /* print_data_returned */ 00138 0, /* data_size */ 00139 0, /* data_type */ 00140 0, /* flags */ 00141 __FILE__, 00142 __LINE__, 00143 }; 00144 00145 #endif /* EQL_ENSLAVE */ 00146 00147 00148 /* vim: set ts=8 sw=4 et : */