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/gettext.h> 00027 #include <libexplain/buffer/ifreq/slaving_request.h> 00028 #include <libexplain/capability.h> 00029 #include <libexplain/iocontrol/generic.h> 00030 #include <libexplain/iocontrol/eql_emancipate.h> 00031 #include <libexplain/is_efault.h> 00032 00033 #ifdef EQL_EMANCIPATE 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 *dat) 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 *q; 00066 const struct slaving_request *srqp; 00067 00068 q = dat; 00069 if (explain_is_efault_pointer(q, sizeof(*q))) 00070 { 00071 explain_buffer_efault(sb, "data"); 00072 break; 00073 } 00074 srqp = (const struct slaving_request *)q->ifr_data; 00075 if (explain_is_efault_pointer(srqp, sizeof(*srqp))) 00076 { 00077 explain_buffer_efault(sb, "data->ifr_data"); 00078 break; 00079 } 00080 } 00081 goto generic; 00082 00083 case EINVAL: 00084 if (explain_iocontrol_disambiguate_is_if_eql(fildes, request, dat) >= 0) 00085 { 00086 explain_buffer_gettext 00087 ( 00088 sb, 00089 /* 00090 * xgettext: this error message is issued when ioctl 00091 * EQL_EMANCIPATE reports an EINVAL error. We already 00092 * know the file descriptor is suitable. 00093 */ 00094 i18n("the named slave network interface cannot be emancipated") 00095 ); 00096 break; 00097 } 00098 goto generic; 00099 00100 default: 00101 generic: 00102 explain_iocontrol_generic_print_explanation 00103 ( 00104 p, 00105 sb, 00106 errnum, 00107 fildes, 00108 request, 00109 dat 00110 ); 00111 break; 00112 } 00113 } 00114 00115 00116 const explain_iocontrol_t explain_iocontrol_eql_emancipate = 00117 { 00118 "EQL_EMANCIPATE", /* name */ 00119 EQL_EMANCIPATE, /* value */ 00120 explain_iocontrol_disambiguate_is_if_eql, /* disambiguate */ 00121 0, /* print_name */ 00122 print_data, 00123 print_explanation, 00124 0, /* print_data_returned */ 00125 sizeof(struct ifreq), /* data_size */ 00126 "struct ifreq *", /* data_type */ 00127 IOCONTROL_FLAG_NON_META, /* flags */ 00128 __FILE__, 00129 __LINE__, 00130 }; 00131 00132 #else /* ndef EQL_EMANCIPATE */ 00133 00134 const explain_iocontrol_t explain_iocontrol_eql_emancipate = 00135 { 00136 0, /* name */ 00137 0, /* value */ 00138 0, /* disambiguate */ 00139 0, /* print_name */ 00140 0, /* print_data */ 00141 0, /* print_explanation */ 00142 0, /* print_data_returned */ 00143 0, /* data_size */ 00144 0, /* data_type */ 00145 0, /* flags */ 00146 __FILE__, 00147 __LINE__, 00148 }; 00149 00150 #endif /* EQL_EMANCIPATE */ 00151 00152 00153 /* vim: set ts=8 sw=4 et : */