1254219Scy/*
2254219Scy * Copyright (C) 2012 by Darren Reed.
3254219Scy *
4254219Scy * See the IPFILTER.LICENCE file for details on licencing.
5254219Scy *
6254219Scy * $Id: interror.c,v 1.9.2.12 2012/07/22 08:03:39 darren_r Exp $
7254219Scy */
8254219Scy
9254219Scy#include "ipf.h"
10254219Scy#include <fcntl.h>
11254219Scy#include <sys/ioctl.h>
12254219Scy
13254219Scytypedef	struct	{
14254219Scy	int	iee_number;
15254219Scy	char	*iee_text;
16254219Scy} ipf_error_entry_t;
17254219Scy
18369245Sgit2svnstatic ipf_error_entry_t *find_error(int);
19254219Scy
20254219Scy#define	IPF_NUM_ERRORS	475
21254219Scy
22254219Scy/*
23254219Scy * NO REUSE OF NUMBERS!
24254219Scy *
25254219Scy * IF YOU WANT TO ADD AN ERROR TO THIS TABLE, _ADD_ A NEW NUMBER.
26254219Scy * DO _NOT_ USE AN EMPTY NUMBER OR FILL IN A GAP.
27254219Scy */
28254219Scystatic ipf_error_entry_t ipf_errors[IPF_NUM_ERRORS] = {
29254219Scy	{	1,	"auth table locked/full" },
30254219Scy	{	2,	"" },
31254219Scy	{	3,	"copyinptr received bad address" },
32254219Scy	{	4,	"copyoutptr received bad address" },
33254219Scy	{	5,	"" },
34254219Scy	{	6,	"cannot load a rule with FR_T_BUILTIN flag set" },
35254219Scy	{	7,	"internal rule without FR_T_BUILDINT flag set" },
36254219Scy	{	8,	"no data provided with filter rule" },
37254219Scy	{	9,	"invalid ioctl for rule" },
38254219Scy	{	10,	"rule protocol is not 4 or 6" },
39254219Scy	{	11,	"cannot find rule function" },
40254219Scy	{	12,	"cannot find rule group" },
41254219Scy	{	13,	"group in/out does not match rule in/out" },
42254219Scy	{	14,	"rule without in/out does not belong to a group" },
43254219Scy	{	15,	"cannot determine where to append rule" },
44254219Scy	{	16,	"malloc for rule data failed" },
45254219Scy	{	17,	"copyin for rule data failed" },
46254219Scy	{	18,	"" },
47254219Scy	{	19,	"zero data size for BPF rule" },
48254219Scy	{	20,	"BPF validation failed" },
49254219Scy	{	21,	"incorrect data size for IPF rule" },
50254219Scy	{	22,	"'keep state' rule included 'with oow'" },
51254219Scy	{	23,	"bad interface index with dynamic source address" },
52254219Scy	{	24,	"bad interface index with dynamic dest. address" },
53254219Scy	{	25,	"match array verif failed for filter rule" },
54254219Scy	{	26,	"bad filter rule type" },
55254219Scy	{	27,	"rule not found for zero'stats" },
56254219Scy	{	28,	"copyout failed for zero'ing stats" },
57254219Scy	{	29,	"rule not found for removing" },
58254219Scy	{	30,	"cannot remove internal rule" },
59254219Scy	{	31,	"rule in use" },
60254219Scy	{	32,	"rule already exists" },
61254219Scy	{	33,	"no memory for another rule" },
62254219Scy	{	34,	"could not find function" },
63254219Scy	{	35,	"copyout failed for resolving function name -> addr" },
64254219Scy	{	36,	"copyout failed for resolving function addr -> name" },
65254219Scy	{	37,	"function name/addr resolving search failed" },
66254219Scy	{	38,	"group map cannot find it's hash table" },
67254219Scy	{	39,	"group map hash-table in/out do not match rule" },
68254219Scy	{	40,	"bcopyout failed for SIOCIPFINTERROR" },
69254219Scy	{	41,	"" },
70254219Scy	{	42,	"ipfilter not enabled for NAT ioctl" },
71254219Scy	{	43,	"ipfilter not enabled for state ioctl" },
72254219Scy	{	44,	"ipfilter not enabled for auth ioctl" },
73254219Scy	{	45,	"ipfilter not enbaled for sync ioctl" },
74254219Scy	{	46,	"ipfilter not enabled for scan ioctl" },
75254219Scy	{	47,	"ipfilter not enabled for lookup ioctl" },
76254219Scy	{	48,	"unrecognised device minor number for ioctl" },
77254219Scy	{	49,	"unrecognised object type for copying in ipfobj" },
78254219Scy	{	50,	"mismatching object type for copying in ipfobj" },
79254219Scy	{	51,	"object size too small for copying in ipfobj" },
80254219Scy	{	52,	"object size mismatch for copying in ipfobj" },
81254219Scy	{	53,	"compat object size too small for copying in ipfobj" },
82254219Scy	{	54,	"compat object size mismatch for copying in ipfobj" },
83254219Scy	{	55,	"error doing copyin of data for in ipfobj" },
84254219Scy	{	56,	"unrecognised object type for size copy in ipfobj" },
85254219Scy	{	57,	"object size too small for size copy in ipfobj" },
86254219Scy	{	58,	"mismatching object type for size copy in ipfobj" },
87254219Scy	{	59,	"object size mismatch for size copy in ipfobj" },
88254219Scy	{	60,	"compat object size mismatch for size copy in ipfobj" },
89254219Scy	{	61,	"error doing size copyin of data for in ipfobj" },
90254219Scy	{	62,	"bad object type for size copy out ipfobj" },
91254219Scy	{	63,	"mismatching object type for size copy out ipfobj" },
92254219Scy	{	64,	"object size mismatch for size copy out ipfobj" },
93254219Scy	{	65,	"compat object size wrong for size copy out ipfobj" },
94254219Scy	{	66,	"error doing size copyout of data for out ipfobj" },
95254219Scy	{	67,	"unrecognised object type for copying out ipfobj" },
96254219Scy	{	68,	"mismatching object type for copying out ipfobj" },
97254219Scy	{	69,	"object size too small for copying out ipfobj" },
98254219Scy	{	70,	"object size mismatch for copying out ipfobj" },
99254219Scy	{	71,	"compat object size too small for copying out ipfobj" },
100254219Scy	{	72,	"compat object size mismatch for copying out ipfobj" },
101254219Scy	{	73,	"error doing copyout of data for out ipfobj" },
102254219Scy	{	74,	"attempt to add existing tunable name" },
103254219Scy	{	75,	"cannot find tunable name to delete" },
104254219Scy	{	76,	"internal data too big for next tunable" },
105254219Scy	{	77,	"could not find tunable" },
106254219Scy	{	78,	"tunable can only be changed when ipfilter disabled" },
107254219Scy	{	79,	"new tunable value outside accepted range" },
108254219Scy	{	80,	"ipftune called for unrecognised ioctl" },
109254219Scy	{	81,	"" },
110254219Scy	{	82,	"could not find token to delete" },
111254219Scy	{	83,	"" },
112254219Scy	{	84,	"attempt to get next rule when no more exist" },
113254219Scy	{	85,	"value for iri_inout outside accepted range" },
114254219Scy	{	86,	"value for iri_active outside accepted range" },
115254219Scy	{	87,	"value for iri_nrules is 0" },
116254219Scy	{	88,	"NULL pointer specified for where to copy rule to" },
117254219Scy	{	89,	"copyout of rule failed" },
118254219Scy	{	90,	"" },
119254219Scy	{	91,	"could not get token for rule iteration" },
120254219Scy	{	92,	"unrecognised generic iterator" },
121254219Scy	{	93,	"could not find token for generic iterator" },
122254219Scy	{	94,	"need write permissions to disable/enable ipfilter" },
123254219Scy	{	95,	"error copying in enable/disable value" },
124254219Scy	{	96,	"need write permissions to set ipf tunable" },
125254219Scy	{	97,	"need write permissions to set ipf flags" },
126254219Scy	{	98,	"error doing copyin of ipf flags" },
127254219Scy	{	99,	"error doing copyout of ipf flags" },
128254219Scy	{	100,	"need write permissions to add another rule" },
129254219Scy	{	101,	"need write permissions to insert another rule" },
130254219Scy	{	102,	"need write permissions to swap active rule set" },
131254219Scy	{	103,	"error copying out current active rule set" },
132254219Scy	{	104,	"need write permissions to zero ipf stats" },
133254219Scy	{	105,	"need write permissions to flush ipf v4 rules" },
134254219Scy	{	106,	"error copying out v4 flush results" },
135254219Scy	{	107,	"error copying in v4 flush command" },
136254219Scy	{	108,	"need write permissions to flush ipf v6 rules" },
137254219Scy	{	109,	"error copying out v6 flush results" },
138254219Scy	{	110,	"error copying in v6 flush command" },
139254219Scy	{	111,	"error copying in new lock state for ipfilter" },
140254219Scy	{	112,	"need write permissions to flush ipf logs" },
141254219Scy	{	113,	"error copying out results of log flush" },
142254219Scy	{	114,	"need write permissions to resync ipf" },
143254219Scy	{	115,	"unrecognised ipf ioctl" },
144254219Scy	{	116,	"error copying in match array" },
145254219Scy	{	117,	"match array type is not IPFOBJ_IPFEXPR" },
146254219Scy	{	118,	"bad size for match array" },
147254219Scy	{	119,	"cannot allocate memory for match aray" },
148254219Scy	{	120,	"error copying in match array" },
149254219Scy	{	121,	"error verifying contents of match array" },
150254219Scy	{	122,	"need write permissions to set ipf lock status" },
151254219Scy	{	123,	"error copying in data for function resolution" },
152254219Scy	{	124,	"error copying in ipfobj structure" },
153254219Scy	{	125,	"error copying in ipfobj structure" },
154254219Scy	{	126,	"error copying in ipfobj structure" },
155254219Scy	{	127,	"error copying in ipfobj structure" },
156254219Scy	{	128,	"no memory for filter rule comment" },
157254219Scy	{	129,	"error copying in filter rule comment" },
158254219Scy	{	130,	"error copying out filter rule comment" },
159254219Scy	{	131,	"no memory for new rule alloc buffer" },
160254219Scy	{	132,	"cannot find source lookup pool" },
161254219Scy	{	133,	"unknown source address type" },
162254219Scy	{	134,	"cannot find destination lookup pool" },
163254219Scy	{	135,	"unknown destination address type" },
164254219Scy	{	136,	"icmp head group name index incorrect" },
165254219Scy	{	137,	"group head name index incorrect" },
166254219Scy	{	138,	"group name index incorrect" },
167254219Scy	{	139,	"to interface name index incorrect" },
168254219Scy	{	140,	"dup-to interface name index incorrect" },
169254219Scy	{	141,	"reply-to interface name index incorrect" },
170254219Scy	{	142,	"could not initialise call now function" },
171254219Scy	{	143,	"could not initialise call function" },
172254219Scy	{	144,	"could not find destination list" },
173254219Scy	{	145,	"auth rules cannot have dup/to/fastroute" },
174254219Scy	{	146,	"incorrect size for object to copy out" },
175254219Scy	{	147,	"object type out of bounds for kernel copyout" },
176254219Scy	{	148,	"object size too small for kernel copyout" },
177254219Scy	{	149,	"object size validation failed for kernel copyout" },
178254219Scy	{	150,	"error copying data out for kernel copyout" },
179254219Scy	{	151,	"version mismatch for kernel copyout" },
180254219Scy/* -------------------------------------------------------------------------- */
181254219Scy	{	10001,	"could not find token for auth iterator" },
182254219Scy	{	10002,	"write permissions require to add/remove auth rule" },
183254219Scy	{	10003,	"need write permissions to set auth lock" },
184254219Scy	{	10004,	"error copying out results of auth flush" },
185254219Scy	{	10005,	"unknown auth ioctl" },
186254219Scy	{	10006,	"can only append or remove preauth rules" },
187254219Scy	{	10007,	"NULL pointers passed in for preauth remove" },
188254219Scy	{	10008,	"preauth rule not found to remove" },
189254219Scy	{	10009,	"could not malloc memory for preauth entry" },
190254219Scy	{	10010,	"unrecognised preauth rule ioctl command" },
191254219Scy	{	10011,	"iterator data supplied with NULL pointer" },
192254219Scy	{	10012,	"unknown auth iterator type" },
193254219Scy	{	10013,	"iterator error copying out auth data" },
194254219Scy	{	10014,	"sleep waiting for auth packet interrupted" },
195254219Scy	{	10015,	"bad index supplied in auth reply" },
196254219Scy	{	10016,	"error injecting outbound packet back into kernel" },
197254219Scy	{	10017,	"error injecting inbound packet back into kernel" },
198254219Scy	{	10018,	"could not attempt to inject packet back into kernel" },
199254219Scy	{	10019,	"packet id does not match" },
200254219Scy/* -------------------------------------------------------------------------- */
201254219Scy	{	20001,	"invalid frag token data pointer supplied" },
202254219Scy	{	20002,	"error copying out frag token data" },
203254219Scy	{	20003,	"can only copy one fragment state entry at a time" },
204254219Scy/* -------------------------------------------------------------------------- */
205254219Scy	{	30001,	"incorrect object size to get hash table stats" },
206254219Scy	{	30002,	"could not malloc memory for new hash table" },
207254219Scy	{	30003,	"error coping in hash table structure" },
208254219Scy	{	30004,	"hash table already exists" },
209254219Scy	{	30005,	"mismach between new hash table and operation unit" },
210254219Scy	{	30006,	"could not malloc memory for hash table base" },
211254219Scy	{	30007,	"could not find hash table" },
212254219Scy	{	30008,	"mismatch between hash table and operation unit" },
213254219Scy	{	30009,	"could not find hash table for iterators next node" },
214254219Scy	{	30010,	"unknown iterator tpe" },
215254219Scy	{	30011,	"iterator error copying out hash table" },
216254219Scy	{	30012,	"iterator error copying out hash table entry" },
217254219Scy	{	30013,	"error copying out hash table statistics" },
218254219Scy	{	30014,	"table node delete structure wrong size" },
219254219Scy	{	30015,	"error copying in node to delete" },
220254219Scy	{	30016,	"table to delete node from does not exist" },
221254219Scy	{	30017,	"could not find table to remove node from" },
222254219Scy	{	30018,	"table node add structure wrong size" },
223254219Scy	{	30019,	"error copying in node to add" },
224254219Scy	{	30020,	"could not find table to add node to" },
225254219Scy	{	30021,	"node already exists in the table" },
226254219Scy	{	30022,	"could not find node to delete in table" },
227254219Scy	{	30023,	"uid mismatch on node to delete" },
228254219Scy	{	30024,	"object size incorrect for hash table" },
229254219Scy	{	30025,	"hash table size must be at least 1"},
230254219Scy	{	30026,	"cannot allocate memory for hash table context" },
231254219Scy/* -------------------------------------------------------------------------- */
232254219Scy	{	40001,	"invalid minor device numebr for log read" },
233254219Scy	{	40002,	"read size too small" },
234254219Scy	{	40003,	"interrupted waiting for log data to read" },
235254219Scy	{	40004,	"interrupted waiting for log data to read" },
236254219Scy	{	40005,	"read size too large" },
237254219Scy	{	40006,	"uiomove for read operation failed" },
238254219Scy/* -------------------------------------------------------------------------- */
239254219Scy	{	50001,	"unknown lookup ioctl" },
240254219Scy	{	50002,	"error copying in object data for add node" },
241254219Scy	{	50003,	"invalid unit for lookup add node" },
242254219Scy	{	50004,	"incorrect size for adding a pool node" },
243254219Scy	{	50005,	"error copying in pool node structure" },
244254219Scy	{	50006,	"mismatch in pool node address/mask families" },
245254219Scy	{	50007,	"could not find pool name" },
246254219Scy	{	50008,	"node already exists in pool" },
247254219Scy	{	50009,	"incorrect size for adding a hash node" },
248254219Scy	{	50010,	"error copying in hash node structure" },
249254219Scy	{	50011,	"could not find hash table name" },
250254219Scy	{	50012,	"unrecognised object type for lookup add node" },
251254219Scy	{	50013,	"invalid unit for lookup delete node" },
252254219Scy	{	50014,	"incorrect size for deleting a pool node" },
253254219Scy	{	50015,	"error copying in pool node structure" },
254254219Scy	{	50016,	"could not find pool name" },
255254219Scy	{	50017,	"could not find pool node" },
256254219Scy	{	50018,	"incorrect size for removing a hash node" },
257254219Scy	{	50019,	"error copying in hash node structure" },
258254219Scy	{	50020,	"could not find hash table name" },
259254219Scy	{	50021,	"unrecognised object type for lookup delete node" },
260254219Scy	{	50022,	"error copying in add table data" },
261254219Scy	{	50023,	"invalid unit for lookup add table" },
262254219Scy	{	50024,	"pool name already exists" },
263254219Scy	{	50025,	"hash table name already exists" },
264254219Scy	{	50026,	"unrecognised object type for lookup add table" },
265254219Scy	{	50027,	"error copying table data back out" },
266254219Scy	{	50028,	"error copying in remove table data" },
267254219Scy	{	50029,	"invalid unit for lookup remove table" },
268254219Scy	{	50030,	"unrecognised object type for lookup remove table" },
269254219Scy	{	50031,	"error copying in lookup stats structure" },
270254219Scy	{	50032,	"invalid unit for lookup stats" },
271254219Scy	{	50033,	"unrecognised object type for lookup stats" },
272254219Scy	{	50034,	"error copying in flush lookup data" },
273254219Scy	{	50035,	"invalid unit for lookup flush" },
274254219Scy	{	50036,	"incorrect table type for lookup flush" },
275254219Scy	{	50037,	"error copying out lookup flush results" },
276254219Scy	{	50038,	"invalid unit for lookup iterator" },
277254219Scy	{	50039,	"invalid unit for lookup iterator" },
278254219Scy	{	50040,	"could not find token for lookup iterator" },
279254219Scy	{	50041,	"unrecognised object type for lookup interator" },
280254219Scy	{	50042,	"error copying in lookup delete node operation" },
281254219Scy/* -------------------------------------------------------------------------- */
282254219Scy	{	60001,	"insufficient privilege for NAT write operation" },
283254219Scy	{	60002,	"need write permissions to flush NAT logs" },
284254219Scy	{	60003,	"need write permissions to turn NAT logging on/off" },
285254219Scy	{	60004,	"error copying out current NAT log setting" },
286254219Scy	{	60005,	"error copying out bytes waiting to be read in NAT \
287254219Scylog" },
288254219Scy	{	60006,	"need write permissions to add NAT rule" },
289254219Scy	{	60007,	"NAT rule already exists" },
290254219Scy	{	60008,	"could not allocate memory for NAT rule" },
291254219Scy	{	60009,	"need write permissions to remove NAT rule" },
292254219Scy	{	60010,	"NAT rule could not be found" },
293254219Scy	{	60011,	"could not find NAT entry for redirect lookup" },
294254219Scy	{	60012,	"need write permissions to flush NAT table" },
295254219Scy	{	60013,	"error copying in NAT flush command" },
296254219Scy	{	60014,	"need write permissions to do matching NAT flush" },
297254219Scy	{	60015,	"need write permissions to set NAT lock" },
298254219Scy	{	60016,	"need write permissions to add entry to NAT table" },
299254219Scy	{	60017,	"NAT not locked for size retrieval" },
300254219Scy	{	60018,	"NAT not locked for fetching NAT table entry" },
301254219Scy	{	60019,	"error copying in NAT token data for deletion" },
302254219Scy	{	60020,	"unknown NAT ioctl" },
303254219Scy	{	60021,	"" },
304254219Scy	{	60022,	"resolving proxy name in NAT rule failed" },
305254219Scy	{	60023,	"only reply age specified in NAT rule" },
306254219Scy	{	60024,	"error doing copyin to determine NAT entry size" },
307254219Scy	{	60025,	"error copying out NAT size of 0" },
308254219Scy	{	60026,	"NAT entry not found" },
309254219Scy	{	60027,	"error doing copyout of NAT entry size" },
310254219Scy	{	60028,	"invalid data size for getting NAT entry" },
311254219Scy	{	60029,	"could not malloc temporary space for NAT entry" },
312254219Scy	{	60030,	"no NAT table entries present" },
313254219Scy	{	60031,	"NAT entry to get next from not found" },
314254219Scy	{	60032,	"not enough space for proxy structure" },
315254219Scy	{	60033,	"not enough space for private proxy data" },
316254219Scy	{	60034,	"NAT entry size is too large" },
317254219Scy	{	60035,	"could not malloc memory for NAT entry sratch space" },
318254219Scy	{	60036,	"" },
319254219Scy	{	60037,	"could not malloc memory for NAT entry" },
320254219Scy	{	60038,	"could not malloc memory for NAT entry rule" },
321254219Scy	{	60039,	"could not resolve NAT entry rule's proxy" },
322254219Scy	{	60040,	"cannot add outbound duplicate NAT entry" },
323254219Scy	{	60041,	"cannot add inbound duplicate NAT entry" },
324254219Scy	{	60042,	"cannot add NAT entry that is neither IN nor OUT" },
325254219Scy	{	60043,	"could not malloc memory for NAT proxy data" },
326254219Scy	{	60044,	"proxy data size too big" },
327254219Scy	{	60045,	"could not malloc proxy private data for NAT entry" },
328254219Scy	{	60046,	"could not malloc memory for new NAT filter rule" },
329254219Scy	{	60047,	"could not find existing filter rule for NAT entry" },
330254219Scy	{	60048,	"insertion into NAT table failed" },
331254219Scy	{	60049,	"iterator error copying out hostmap data" },
332254219Scy	{	60050,	"iterator error copying out NAT rule data" },
333254219Scy	{	60051,	"iterator error copying out NAT entry data" },
334254219Scy	{	60052,	"iterator data supplied with NULL pointer" },
335254219Scy	{	60053,	"unknown NAT iterator type" },
336254219Scy	{	60054,	"unknwon next address type" },
337254219Scy	{	60055,	"iterator suppled with unknown type for get-next" },
338254219Scy	{	60056,	"unknown lookup group for next address" },
339254219Scy	{	60057,	"error copying out NAT log flush results" },
340254219Scy	{	60058,	"bucket table type is incorrect" },
341254219Scy	{	60059,	"error copying out NAT bucket table" },
342254219Scy	{	60060,	"function not found for lookup" },
343254219Scy	{	60061,	"address family not supported with SIOCSTPUT" },
344254219Scy	{	60062,	"unknown timeout name" },
345254219Scy	{	60063,	"cannot allocate new inbound NAT entry table" },
346254219Scy	{	60064,	"cannot allocate new outbound NAT entry table" },
347254219Scy	{	60065,	"cannot allocate new inbound NAT bucketlen table" },
348254219Scy	{	60066,	"cannot allocate new outbound NAT bucketlen table" },
349254219Scy	{	60067,	"cannot allocate new NAT rules table" },
350254219Scy	{	60068,	"cannot allocate new NAT hostmap table" },
351254219Scy	{	60069,	"new source lookup type is not dstlist" },
352254219Scy	{	60070,	"cannot allocate NAT rule scratch space" },
353254219Scy	{	60071,	"new destination lookup type is not dstlist" },
354254219Scy	{	60072,	"function not found for lookup (ipv6)" },
355254219Scy	{	60073,	"unknown lookup group for next address (ipv6)" },
356254219Scy	{	60074,	"unknown next address type (ipv6)" },
357254219Scy	{	60075,	"one object at a time must be copied" },
358254219Scy/* -------------------------------------------------------------------------- */
359254219Scy	{	70001,	"incorrect object size to get pool stats" },
360254219Scy	{	70002,	"could not malloc memory for new pool node" },
361254219Scy	{	70003,	"invalid addresss length for new pool node" },
362254219Scy	{	70004,	"invalid mask length for new pool node" },
363254219Scy	{	70005,	"error adding node to pool" },
364254219Scy	{	70006,	"pool already exists" },
365254219Scy	{	70007,	"could not malloc memory for new pool" },
366254219Scy	{	70008,	"could not allocate radix tree for new pool" },
367254219Scy	{	70009,	"could not find pool" },
368254219Scy	{	70010,	"unknown pool name for iteration" },
369254219Scy	{	70011,	"unknown pool iterator" },
370254219Scy	{	70012,	"error copying out pool head" },
371254219Scy	{	70013,	"error copying out pool node" },
372254219Scy	{	70014,	"add node size incorrect" },
373254219Scy	{	70015,	"error copying in pool node" },
374254219Scy	{	70016,	"" },
375254219Scy	{	70017,	"cannot find pool for node" },
376254219Scy	{	70018,	"node entry already present in pool" },
377254219Scy	{	70019,	"delete node size incorrect" },
378254219Scy	{	70020,	"error copying in node to delete" },
379254219Scy	{	70021,	"cannot find pool to delete node from" },
380254219Scy	{	70022,	"cannot find node to delete in pool" },
381254219Scy	{	70023,	"pool name already exists" },
382254219Scy	{	70024,	"uid mismatch for node removal" },
383254219Scy	{	70025,	"stats device unit is invalid" },
384254219Scy	{	70026,	"error copying out statistics" },
385254219Scy	{	70027,	"could not remove node from radix tree" },
386254219Scy	{	70028,	"incorrect address length in pool node add" },
387254219Scy	{	70029,	"incorrect mask length in pool node add" },
388254219Scy	{	70030,	"incorrect address length in pool node remove" },
389254219Scy	{	70031,	"incorrect mask length in pool node remove" },
390254219Scy	{	70032,	"cannot allocate memory for pool context" },
391254219Scy	{	70033,	"cannot allocate memory for radix tree context" },
392254219Scy	{	70034,	"adding IPv6 node with incorrect address length" },
393254219Scy	{	70035,	"IPv4 address not masked" },
394254219Scy	{	70036,	"IPv6 address not masked" },
395254219Scy	{	70037,	"removing IPv6 node with incorrect address length" },
396254219Scy/* -------------------------------------------------------------------------- */
397254219Scy	{	80001,	"could not find proxy" },
398254219Scy	{	80002,	"proxy does not support control operations" },
399254219Scy	{	80003,	"could not allocate data to hold proxy operation" },
400254219Scy	{	80004,	"unknown proxy ioctl" },
401254219Scy	{	80005,	"could not copyin proxy control structure" },
402254219Scy	{	80006,	"DNS proxy could not find rule to delete" },
403254219Scy	{	80007,	"DNS proxy found existing matching rule" },
404254219Scy	{	80008,	"DNS proxy could not allocate memory for new rule" },
405254219Scy	{	80009,	"DNS proxy unknown command request" },
406254219Scy/* -------------------------------------------------------------------------- */
407254219Scy	{	90001,	"could not malloc space for new scan structure" },
408254219Scy	{	90002,	"scan tag already exists" },
409254219Scy	{	90003,	"scan structure in use" },
410254219Scy	{	90004,	"could not find matching scan tag for filter rule" },
411254219Scy	{	90005,	"could not copyout scan statistics" },
412254219Scy/* -------------------------------------------------------------------------- */
413254219Scy	{	100001,	"cannot find matching state entry to remove" },
414254219Scy	{	100002,	"error copying in v4 state flush command" },
415254219Scy	{	100003,	"error copying out v4 state flush results" },
416254219Scy	{	100004,	"error copying in v6 state flush command" },
417254219Scy	{	100005,	"error copying out v6 state flush results" },
418254219Scy	{	100006,	"" },
419254219Scy	{	100007,	"" },
420254219Scy	{	100008,	"need write permissions to flush state log" },
421254219Scy	{	100009,	"erorr copyout results of flushing state log" },
422254219Scy	{	100010,	"need write permissions to turn state logging on/off" },
423254219Scy	{	100011,	"error copying in new state logging state" },
424254219Scy	{	100012,	"error copying out current state logging state" },
425254219Scy	{	100013,	"error copying out bytes waiting to be read in state \
426254219Scylog" },
427254219Scy	{	100014,	"need write permissions to set state lock" },
428254219Scy	{	100015,	"need write permissions to add entry to state table" },
429254219Scy	{	100016,	"state not locked for size retrieval" },
430254219Scy	{	100017,	"error copying out hash table bucket lengths" },
431254219Scy	{	100018,	"could not find token for state iterator" },
432254219Scy	{	100019,	"error copying in state token data for deletion" },
433254219Scy	{	100020,	"unknown state ioctl" },
434254219Scy	{	100021,	"no state table entries present" },
435254219Scy	{	100022,	"state entry to get next from not found" },
436254219Scy	{	100023,	"could not malloc memory for state entry" },
437254219Scy	{	100024,	"could not malloc memory for state entry rule" },
438254219Scy	{	100025,	"could not copy back state entry to user space" },
439254219Scy	{	100026,	"iterator data supplied with NULL pointer" },
440254219Scy	{	100027,	"iterator supplied with 0 item count" },
441254219Scy	{	100028,	"iterator type is incorrect" },
442254219Scy	{	100029,	"invalid state token data pointer supplied" },
443254219Scy	{	100030,	"error copying out next state entry" },
444254219Scy	{	100031,	"unrecognised table request" },
445254219Scy	{	100032,	"error copying out bucket length data" },
446254219Scy	{	100033,	"could not find existing filter rule for state entry" },
447254219Scy	{	100034,	"could not find timeout name" },
448254219Scy	{	100035, "could not allocate new state table" },
449254219Scy	{	100036, "could not allocate new state bucket length table" },
450254219Scy/* -------------------------------------------------------------------------- */
451254219Scy	{	110001,	"sync write header magic number is incorrect" },
452254219Scy	{	110002,	"sync write header protocol is incorrect" },
453254219Scy	{	110003,	"sync write header command is incorrect" },
454254219Scy	{	110004,	"sync write header table number is incorrect" },
455254219Scy	{	110005,	"data structure too small for sync write operation" },
456254219Scy	{	110006,	"zero length data with sync write header" },
457254219Scy	{	110007,	"insufficient data for sync write" },
458254219Scy	{	110008,	"bad sync read size" },
459254219Scy	{	110009,	"interrupted sync read (solaris)" },
460254219Scy	{	110010,	"interrupted sync read (hpux)" },
461254219Scy	{	110011,	"interrupted sync read (osf)" },
462254219Scy	{	110012,	"interrupted sync read" },
463254219Scy	{	110013,	"could not malloc memory for sync'd state" },
464254219Scy	{	110014,	"could not malloc memory for sync-state list item" },
465254219Scy	{	110015,	"sync update could not find state" },
466254219Scy	{	110016,	"unrecognised sync state command" },
467254219Scy	{	110017,	"could not malloc memory for new sync'd NAT entry" },
468254219Scy	{	110018,	"could not malloc memory for sync-NAT list item" },
469254219Scy	{	110019,	"sync update could not find NAT entry" },
470254219Scy	{	110020,	"unrecognised sync NAT command" },
471254219Scy	{	110021,	"ioctls are not handled with sync" },
472254219Scy/* -------------------------------------------------------------------------- */
473254219Scy	{	120001,	"null data pointer for iterator" },
474254219Scy	{	120002,	"unit outside of acceptable range" },
475254219Scy	{	120003,	"unknown iterator subtype" },
476254219Scy	{	120004,	"cannot find dest. list for iteration" },
477254219Scy	{	120005,	"error copying out destination iteration list" },
478254219Scy	{	120006,	"error copying out destination iteration node" },
479254219Scy	{	120007,	"wrong size for frdest_t structure" },
480254219Scy	{	120008,	"cannot allocate memory for new destination node" },
481254219Scy	{	120009,	"error copying in destination node to add" },
482254219Scy	{	120010,	"could not find destination list to add node to" },
483254219Scy	{	120011,	"error copying in destination node to remove" },
484254219Scy	{	120012,	"could not find dest. list to remove node from" },
485254219Scy	{	120013,	"destination list already exists" },
486254219Scy	{	120014,	"could not allocate new destination table" },
487254219Scy	{	120015,	"could not find destination list to remove" },
488254219Scy	{	120016,	"destination list cannot be removed - it is busy" },
489254219Scy	{	120017,	"error copying in names for destination" },
490254219Scy	{	120018,	"destination name is too long/short" },
491254219Scy	{	120019,	"unrecognised address family in destination" },
492254219Scy	{	120020,	"" },
493254219Scy	{	120021,	"error copying in new destination table" },
494254219Scy	{	120022,	"cannot allocate memory for node table" },
495254219Scy	{	120023,	"stats object size is incorrect for dest. lists" },
496254219Scy	{	120024,	"stats device unit is invalid for dest. lists" },
497254219Scy	{	120025,	"error copying out dest. list statistics" },
498254219Scy	{	120026,	"cannot allocate memory for destination node" },
499254219Scy	{	120027,	"error copying in destination node" },
500254219Scy	{	120028,	"cannot allocate memory for destination context " },
501254219Scy/* -------------------------------------------------------------------------- */
502254219Scy	{	130001,	"ioctl denied by system security level" },
503254219Scy	{	130002,	"ioctl operation on invalid minor device" },
504254219Scy	{	130003,	"ioctl on device denied, ipfitler is disabled" },
505254219Scy	{	130004,	"ioctl command not allowed when disabled" },
506254219Scy	{	130005,	"ioctl denied due to insufficient authorisation" },
507254219Scy	{	130006,	"cannot read while ipfilter is disabled" },
508254219Scy	{	130007,	"read on minor device not supported" },
509254219Scy	{	130008,	"cannot write while ipfilter is disabled" },
510254219Scy	{	130009,	"write on minor device not supported" },
511254219Scy	{	130010,	"poll on minor device is not supported" },
512254219Scy	{	130011,	"error removing IPv4 filter hooks" },
513254219Scy	{	130012,	"error removing IPv6 filter hooks" },
514254219Scy	{	130013,	"attaching IPv4 hook failed" },
515254219Scy	{	130014,	"attaching IPv6 hook failed" },
516254219Scy	{	130015,	"ipf_init_all failed" },
517254219Scy	{	130016,	"finding pfil head failed" },
518254219Scy	{	130017,	"ipfilter is already initialised and running" },
519254219Scy};
520254219Scy
521254219Scy
522254219Scystatic ipf_error_entry_t *
523254219Scyfind_error(errnum)
524254219Scy	int errnum;
525254219Scy{
526254219Scy	ipf_error_entry_t *ie;
527254219Scy
528254219Scy	int l = -1, r = IPF_NUM_ERRORS + 1, step;
529254219Scy	step = (r - l) / 2;;
530254219Scy
531254219Scy	while (step != 0) {
532254219Scy		ie = ipf_errors + l + step;
533254219Scy		if (ie->iee_number == errnum)
534254219Scy			return ie;
535254219Scy		step = l + step;
536254219Scy		if (ie->iee_number > errnum)
537254219Scy			r = step;
538254219Scy		else
539254219Scy			l = step;
540254219Scy		step = (r - l) / 2;;
541254219Scy	}
542254219Scy
543254219Scy	return NULL;
544254219Scy}
545254219Scy
546254219Scychar *
547254219Scyipf_geterror(fd, func)
548254219Scy	int fd;
549254219Scy	ioctlfunc_t *func;
550254219Scy{
551254219Scy	static char text[80];
552254219Scy	ipf_error_entry_t *ie;
553254219Scy	int errnum;
554254219Scy
555254219Scy	if ((*func)(fd, SIOCIPFINTERROR, &errnum) == 0) {
556254219Scy
557254219Scy		ie = find_error(errnum);
558254219Scy		if (ie != NULL)
559254219Scy			return ie->iee_text;
560254219Scy		sprintf(text, "unknown error %d", errnum);
561254219Scy	} else {
562254219Scy		sprintf(text, "retrieving error number failed (%d)", errno);
563254219Scy	}
564254219Scy	return text;
565254219Scy}
566254219Scy
567254219Scy
568254219Scychar *
569254219Scyipf_strerror(errnum)
570254219Scy	int errnum;
571254219Scy{
572254219Scy	static char text[80];
573254219Scy	ipf_error_entry_t *ie;
574254219Scy
575254219Scy
576254219Scy	ie = find_error(errnum);
577254219Scy	if (ie != NULL)
578254219Scy		return ie->iee_text;
579254219Scy
580254219Scy	sprintf(text, "unknown error %d", errnum);
581254219Scy	return text;
582254219Scy}
583