xref: /freebsd-src/sbin/ipf/libipf/interror.c (revision c1f6704bf810bc28b2af6cb0d0e60cb8f5a9b44b)
141edb306SCy Schubert /*
241edb306SCy Schubert  * Copyright (C) 2012 by Darren Reed.
341edb306SCy Schubert  *
441edb306SCy Schubert  * See the IPFILTER.LICENCE file for details on licencing.
541edb306SCy Schubert  *
641edb306SCy Schubert  * $Id: interror.c,v 1.9.2.12 2012/07/22 08:03:39 darren_r Exp $
741edb306SCy Schubert  */
841edb306SCy Schubert 
941edb306SCy Schubert #include "ipf.h"
1041edb306SCy Schubert #include <fcntl.h>
1141edb306SCy Schubert #include <sys/ioctl.h>
1241edb306SCy Schubert 
1341edb306SCy Schubert typedef	struct	{
1441edb306SCy Schubert 	int	iee_number;
1541edb306SCy Schubert 	char	*iee_text;
1641edb306SCy Schubert } ipf_error_entry_t;
1741edb306SCy Schubert 
1841edb306SCy Schubert static ipf_error_entry_t *find_error(int);
1941edb306SCy Schubert 
20c47db49bSCy Schubert #define	IPF_NUM_ERRORS	477
2141edb306SCy Schubert 
2241edb306SCy Schubert /*
2341edb306SCy Schubert  * NO REUSE OF NUMBERS!
2441edb306SCy Schubert  *
2541edb306SCy Schubert  * IF YOU WANT TO ADD AN ERROR TO THIS TABLE, _ADD_ A NEW NUMBER.
2641edb306SCy Schubert  * DO _NOT_ USE AN EMPTY NUMBER OR FILL IN A GAP.
2741edb306SCy Schubert  */
2841edb306SCy Schubert static ipf_error_entry_t ipf_errors[IPF_NUM_ERRORS] = {
2941edb306SCy Schubert 	{	1,	"auth table locked/full" },
3041edb306SCy Schubert 	{	2,	"" },
3141edb306SCy Schubert 	{	3,	"copyinptr received bad address" },
3241edb306SCy Schubert 	{	4,	"copyoutptr received bad address" },
3341edb306SCy Schubert 	{	5,	"" },
3441edb306SCy Schubert 	{	6,	"cannot load a rule with FR_T_BUILTIN flag set" },
3541edb306SCy Schubert 	{	7,	"internal rule without FR_T_BUILDINT flag set" },
3641edb306SCy Schubert 	{	8,	"no data provided with filter rule" },
3741edb306SCy Schubert 	{	9,	"invalid ioctl for rule" },
3841edb306SCy Schubert 	{	10,	"rule protocol is not 4 or 6" },
3941edb306SCy Schubert 	{	11,	"cannot find rule function" },
4041edb306SCy Schubert 	{	12,	"cannot find rule group" },
4141edb306SCy Schubert 	{	13,	"group in/out does not match rule in/out" },
4241edb306SCy Schubert 	{	14,	"rule without in/out does not belong to a group" },
4341edb306SCy Schubert 	{	15,	"cannot determine where to append rule" },
4441edb306SCy Schubert 	{	16,	"malloc for rule data failed" },
4541edb306SCy Schubert 	{	17,	"copyin for rule data failed" },
4641edb306SCy Schubert 	{	18,	"" },
4741edb306SCy Schubert 	{	19,	"zero data size for BPF rule" },
4841edb306SCy Schubert 	{	20,	"BPF validation failed" },
4941edb306SCy Schubert 	{	21,	"incorrect data size for IPF rule" },
5041edb306SCy Schubert 	{	22,	"'keep state' rule included 'with oow'" },
5141edb306SCy Schubert 	{	23,	"bad interface index with dynamic source address" },
5241edb306SCy Schubert 	{	24,	"bad interface index with dynamic dest. address" },
5341edb306SCy Schubert 	{	25,	"match array verif failed for filter rule" },
5441edb306SCy Schubert 	{	26,	"bad filter rule type" },
5541edb306SCy Schubert 	{	27,	"rule not found for zero'stats" },
5641edb306SCy Schubert 	{	28,	"copyout failed for zero'ing stats" },
5741edb306SCy Schubert 	{	29,	"rule not found for removing" },
5841edb306SCy Schubert 	{	30,	"cannot remove internal rule" },
5941edb306SCy Schubert 	{	31,	"rule in use" },
6041edb306SCy Schubert 	{	32,	"rule already exists" },
6141edb306SCy Schubert 	{	33,	"no memory for another rule" },
6241edb306SCy Schubert 	{	34,	"could not find function" },
6341edb306SCy Schubert 	{	35,	"copyout failed for resolving function name -> addr" },
6441edb306SCy Schubert 	{	36,	"copyout failed for resolving function addr -> name" },
6541edb306SCy Schubert 	{	37,	"function name/addr resolving search failed" },
6641edb306SCy Schubert 	{	38,	"group map cannot find it's hash table" },
6741edb306SCy Schubert 	{	39,	"group map hash-table in/out do not match rule" },
6841edb306SCy Schubert 	{	40,	"bcopyout failed for SIOCIPFINTERROR" },
6941edb306SCy Schubert 	{	41,	"" },
7041edb306SCy Schubert 	{	42,	"ipfilter not enabled for NAT ioctl" },
7141edb306SCy Schubert 	{	43,	"ipfilter not enabled for state ioctl" },
7241edb306SCy Schubert 	{	44,	"ipfilter not enabled for auth ioctl" },
730939cf32SElyes Haouas 	{	45,	"ipfilter not enabled for sync ioctl" },
7441edb306SCy Schubert 	{	46,	"ipfilter not enabled for scan ioctl" },
7541edb306SCy Schubert 	{	47,	"ipfilter not enabled for lookup ioctl" },
7641edb306SCy Schubert 	{	48,	"unrecognised device minor number for ioctl" },
7741edb306SCy Schubert 	{	49,	"unrecognised object type for copying in ipfobj" },
7841edb306SCy Schubert 	{	50,	"mismatching object type for copying in ipfobj" },
7941edb306SCy Schubert 	{	51,	"object size too small for copying in ipfobj" },
8041edb306SCy Schubert 	{	52,	"object size mismatch for copying in ipfobj" },
8141edb306SCy Schubert 	{	53,	"compat object size too small for copying in ipfobj" },
8241edb306SCy Schubert 	{	54,	"compat object size mismatch for copying in ipfobj" },
8341edb306SCy Schubert 	{	55,	"error doing copyin of data for in ipfobj" },
8441edb306SCy Schubert 	{	56,	"unrecognised object type for size copy in ipfobj" },
8541edb306SCy Schubert 	{	57,	"object size too small for size copy in ipfobj" },
8641edb306SCy Schubert 	{	58,	"mismatching object type for size copy in ipfobj" },
8741edb306SCy Schubert 	{	59,	"object size mismatch for size copy in ipfobj" },
8841edb306SCy Schubert 	{	60,	"compat object size mismatch for size copy in ipfobj" },
8941edb306SCy Schubert 	{	61,	"error doing size copyin of data for in ipfobj" },
9041edb306SCy Schubert 	{	62,	"bad object type for size copy out ipfobj" },
9141edb306SCy Schubert 	{	63,	"mismatching object type for size copy out ipfobj" },
9241edb306SCy Schubert 	{	64,	"object size mismatch for size copy out ipfobj" },
9341edb306SCy Schubert 	{	65,	"compat object size wrong for size copy out ipfobj" },
9441edb306SCy Schubert 	{	66,	"error doing size copyout of data for out ipfobj" },
9541edb306SCy Schubert 	{	67,	"unrecognised object type for copying out ipfobj" },
9641edb306SCy Schubert 	{	68,	"mismatching object type for copying out ipfobj" },
9741edb306SCy Schubert 	{	69,	"object size too small for copying out ipfobj" },
9841edb306SCy Schubert 	{	70,	"object size mismatch for copying out ipfobj" },
9941edb306SCy Schubert 	{	71,	"compat object size too small for copying out ipfobj" },
10041edb306SCy Schubert 	{	72,	"compat object size mismatch for copying out ipfobj" },
10141edb306SCy Schubert 	{	73,	"error doing copyout of data for out ipfobj" },
10241edb306SCy Schubert 	{	74,	"attempt to add existing tunable name" },
10341edb306SCy Schubert 	{	75,	"cannot find tunable name to delete" },
10441edb306SCy Schubert 	{	76,	"internal data too big for next tunable" },
10541edb306SCy Schubert 	{	77,	"could not find tunable" },
10641edb306SCy Schubert 	{	78,	"tunable can only be changed when ipfilter disabled" },
10741edb306SCy Schubert 	{	79,	"new tunable value outside accepted range" },
10841edb306SCy Schubert 	{	80,	"ipftune called for unrecognised ioctl" },
10941edb306SCy Schubert 	{	81,	"" },
11041edb306SCy Schubert 	{	82,	"could not find token to delete" },
11141edb306SCy Schubert 	{	83,	"" },
11241edb306SCy Schubert 	{	84,	"attempt to get next rule when no more exist" },
11341edb306SCy Schubert 	{	85,	"value for iri_inout outside accepted range" },
11441edb306SCy Schubert 	{	86,	"value for iri_active outside accepted range" },
11541edb306SCy Schubert 	{	87,	"value for iri_nrules is 0" },
11641edb306SCy Schubert 	{	88,	"NULL pointer specified for where to copy rule to" },
11741edb306SCy Schubert 	{	89,	"copyout of rule failed" },
11841edb306SCy Schubert 	{	90,	"" },
11941edb306SCy Schubert 	{	91,	"could not get token for rule iteration" },
12041edb306SCy Schubert 	{	92,	"unrecognised generic iterator" },
12141edb306SCy Schubert 	{	93,	"could not find token for generic iterator" },
12241edb306SCy Schubert 	{	94,	"need write permissions to disable/enable ipfilter" },
12341edb306SCy Schubert 	{	95,	"error copying in enable/disable value" },
12441edb306SCy Schubert 	{	96,	"need write permissions to set ipf tunable" },
12541edb306SCy Schubert 	{	97,	"need write permissions to set ipf flags" },
12641edb306SCy Schubert 	{	98,	"error doing copyin of ipf flags" },
12741edb306SCy Schubert 	{	99,	"error doing copyout of ipf flags" },
12841edb306SCy Schubert 	{	100,	"need write permissions to add another rule" },
12941edb306SCy Schubert 	{	101,	"need write permissions to insert another rule" },
13041edb306SCy Schubert 	{	102,	"need write permissions to swap active rule set" },
13141edb306SCy Schubert 	{	103,	"error copying out current active rule set" },
13241edb306SCy Schubert 	{	104,	"need write permissions to zero ipf stats" },
13341edb306SCy Schubert 	{	105,	"need write permissions to flush ipf v4 rules" },
13441edb306SCy Schubert 	{	106,	"error copying out v4 flush results" },
13541edb306SCy Schubert 	{	107,	"error copying in v4 flush command" },
13641edb306SCy Schubert 	{	108,	"need write permissions to flush ipf v6 rules" },
13741edb306SCy Schubert 	{	109,	"error copying out v6 flush results" },
13841edb306SCy Schubert 	{	110,	"error copying in v6 flush command" },
13941edb306SCy Schubert 	{	111,	"error copying in new lock state for ipfilter" },
14041edb306SCy Schubert 	{	112,	"need write permissions to flush ipf logs" },
14141edb306SCy Schubert 	{	113,	"error copying out results of log flush" },
14241edb306SCy Schubert 	{	114,	"need write permissions to resync ipf" },
14341edb306SCy Schubert 	{	115,	"unrecognised ipf ioctl" },
14441edb306SCy Schubert 	{	116,	"error copying in match array" },
14541edb306SCy Schubert 	{	117,	"match array type is not IPFOBJ_IPFEXPR" },
14641edb306SCy Schubert 	{	118,	"bad size for match array" },
147*c1f6704bSElyes Haouas 	{	119,	"cannot allocate memory for match array" },
14841edb306SCy Schubert 	{	120,	"error copying in match array" },
14941edb306SCy Schubert 	{	121,	"error verifying contents of match array" },
15041edb306SCy Schubert 	{	122,	"need write permissions to set ipf lock status" },
15141edb306SCy Schubert 	{	123,	"error copying in data for function resolution" },
15241edb306SCy Schubert 	{	124,	"error copying in ipfobj structure" },
15341edb306SCy Schubert 	{	125,	"error copying in ipfobj structure" },
15441edb306SCy Schubert 	{	126,	"error copying in ipfobj structure" },
15541edb306SCy Schubert 	{	127,	"error copying in ipfobj structure" },
15641edb306SCy Schubert 	{	128,	"no memory for filter rule comment" },
15741edb306SCy Schubert 	{	129,	"error copying in filter rule comment" },
15841edb306SCy Schubert 	{	130,	"error copying out filter rule comment" },
15941edb306SCy Schubert 	{	131,	"no memory for new rule alloc buffer" },
16041edb306SCy Schubert 	{	132,	"cannot find source lookup pool" },
16141edb306SCy Schubert 	{	133,	"unknown source address type" },
16241edb306SCy Schubert 	{	134,	"cannot find destination lookup pool" },
16341edb306SCy Schubert 	{	135,	"unknown destination address type" },
16441edb306SCy Schubert 	{	136,	"icmp head group name index incorrect" },
16541edb306SCy Schubert 	{	137,	"group head name index incorrect" },
16641edb306SCy Schubert 	{	138,	"group name index incorrect" },
16741edb306SCy Schubert 	{	139,	"to interface name index incorrect" },
16841edb306SCy Schubert 	{	140,	"dup-to interface name index incorrect" },
16941edb306SCy Schubert 	{	141,	"reply-to interface name index incorrect" },
17041edb306SCy Schubert 	{	142,	"could not initialise call now function" },
17141edb306SCy Schubert 	{	143,	"could not initialise call function" },
17241edb306SCy Schubert 	{	144,	"could not find destination list" },
17341edb306SCy Schubert 	{	145,	"auth rules cannot have dup/to/fastroute" },
17441edb306SCy Schubert 	{	146,	"incorrect size for object to copy out" },
17541edb306SCy Schubert 	{	147,	"object type out of bounds for kernel copyout" },
17641edb306SCy Schubert 	{	148,	"object size too small for kernel copyout" },
17741edb306SCy Schubert 	{	149,	"object size validation failed for kernel copyout" },
17841edb306SCy Schubert 	{	150,	"error copying data out for kernel copyout" },
17941edb306SCy Schubert 	{	151,	"version mismatch for kernel copyout" },
18041edb306SCy Schubert /* -------------------------------------------------------------------------- */
18141edb306SCy Schubert 	{	10001,	"could not find token for auth iterator" },
18241edb306SCy Schubert 	{	10002,	"write permissions require to add/remove auth rule" },
18341edb306SCy Schubert 	{	10003,	"need write permissions to set auth lock" },
18441edb306SCy Schubert 	{	10004,	"error copying out results of auth flush" },
18541edb306SCy Schubert 	{	10005,	"unknown auth ioctl" },
18641edb306SCy Schubert 	{	10006,	"can only append or remove preauth rules" },
18741edb306SCy Schubert 	{	10007,	"NULL pointers passed in for preauth remove" },
18841edb306SCy Schubert 	{	10008,	"preauth rule not found to remove" },
18941edb306SCy Schubert 	{	10009,	"could not malloc memory for preauth entry" },
19041edb306SCy Schubert 	{	10010,	"unrecognised preauth rule ioctl command" },
19141edb306SCy Schubert 	{	10011,	"iterator data supplied with NULL pointer" },
19241edb306SCy Schubert 	{	10012,	"unknown auth iterator type" },
19341edb306SCy Schubert 	{	10013,	"iterator error copying out auth data" },
19441edb306SCy Schubert 	{	10014,	"sleep waiting for auth packet interrupted" },
19541edb306SCy Schubert 	{	10015,	"bad index supplied in auth reply" },
19641edb306SCy Schubert 	{	10016,	"error injecting outbound packet back into kernel" },
19741edb306SCy Schubert 	{	10017,	"error injecting inbound packet back into kernel" },
19841edb306SCy Schubert 	{	10018,	"could not attempt to inject packet back into kernel" },
19941edb306SCy Schubert 	{	10019,	"packet id does not match" },
20041edb306SCy Schubert /* -------------------------------------------------------------------------- */
20141edb306SCy Schubert 	{	20001,	"invalid frag token data pointer supplied" },
20241edb306SCy Schubert 	{	20002,	"error copying out frag token data" },
20341edb306SCy Schubert 	{	20003,	"can only copy one fragment state entry at a time" },
20441edb306SCy Schubert /* -------------------------------------------------------------------------- */
20541edb306SCy Schubert 	{	30001,	"incorrect object size to get hash table stats" },
20641edb306SCy Schubert 	{	30002,	"could not malloc memory for new hash table" },
20741edb306SCy Schubert 	{	30003,	"error coping in hash table structure" },
20841edb306SCy Schubert 	{	30004,	"hash table already exists" },
2090939cf32SElyes Haouas 	{	30005,	"mismatch between new hash table and operation unit" },
21041edb306SCy Schubert 	{	30006,	"could not malloc memory for hash table base" },
21141edb306SCy Schubert 	{	30007,	"could not find hash table" },
21241edb306SCy Schubert 	{	30008,	"mismatch between hash table and operation unit" },
21341edb306SCy Schubert 	{	30009,	"could not find hash table for iterators next node" },
21441edb306SCy Schubert 	{	30010,	"unknown iterator tpe" },
21541edb306SCy Schubert 	{	30011,	"iterator error copying out hash table" },
21641edb306SCy Schubert 	{	30012,	"iterator error copying out hash table entry" },
21741edb306SCy Schubert 	{	30013,	"error copying out hash table statistics" },
21841edb306SCy Schubert 	{	30014,	"table node delete structure wrong size" },
21941edb306SCy Schubert 	{	30015,	"error copying in node to delete" },
22041edb306SCy Schubert 	{	30016,	"table to delete node from does not exist" },
22141edb306SCy Schubert 	{	30017,	"could not find table to remove node from" },
22241edb306SCy Schubert 	{	30018,	"table node add structure wrong size" },
22341edb306SCy Schubert 	{	30019,	"error copying in node to add" },
22441edb306SCy Schubert 	{	30020,	"could not find table to add node to" },
22541edb306SCy Schubert 	{	30021,	"node already exists in the table" },
22641edb306SCy Schubert 	{	30022,	"could not find node to delete in table" },
22741edb306SCy Schubert 	{	30023,	"uid mismatch on node to delete" },
22841edb306SCy Schubert 	{	30024,	"object size incorrect for hash table" },
22941edb306SCy Schubert 	{	30025,	"hash table size must be at least 1"},
23041edb306SCy Schubert 	{	30026,	"cannot allocate memory for hash table context" },
23141edb306SCy Schubert /* -------------------------------------------------------------------------- */
2320939cf32SElyes Haouas 	{	40001,	"invalid minor device number for log read" },
23341edb306SCy Schubert 	{	40002,	"read size too small" },
23441edb306SCy Schubert 	{	40003,	"interrupted waiting for log data to read" },
23541edb306SCy Schubert 	{	40004,	"interrupted waiting for log data to read" },
23641edb306SCy Schubert 	{	40005,	"read size too large" },
23741edb306SCy Schubert 	{	40006,	"uiomove for read operation failed" },
23841edb306SCy Schubert /* -------------------------------------------------------------------------- */
23941edb306SCy Schubert 	{	50001,	"unknown lookup ioctl" },
24041edb306SCy Schubert 	{	50002,	"error copying in object data for add node" },
24141edb306SCy Schubert 	{	50003,	"invalid unit for lookup add node" },
24241edb306SCy Schubert 	{	50004,	"incorrect size for adding a pool node" },
24341edb306SCy Schubert 	{	50005,	"error copying in pool node structure" },
24441edb306SCy Schubert 	{	50006,	"mismatch in pool node address/mask families" },
24541edb306SCy Schubert 	{	50007,	"could not find pool name" },
24641edb306SCy Schubert 	{	50008,	"node already exists in pool" },
24741edb306SCy Schubert 	{	50009,	"incorrect size for adding a hash node" },
24841edb306SCy Schubert 	{	50010,	"error copying in hash node structure" },
24941edb306SCy Schubert 	{	50011,	"could not find hash table name" },
25041edb306SCy Schubert 	{	50012,	"unrecognised object type for lookup add node" },
25141edb306SCy Schubert 	{	50013,	"invalid unit for lookup delete node" },
25241edb306SCy Schubert 	{	50014,	"incorrect size for deleting a pool node" },
25341edb306SCy Schubert 	{	50015,	"error copying in pool node structure" },
25441edb306SCy Schubert 	{	50016,	"could not find pool name" },
25541edb306SCy Schubert 	{	50017,	"could not find pool node" },
25641edb306SCy Schubert 	{	50018,	"incorrect size for removing a hash node" },
25741edb306SCy Schubert 	{	50019,	"error copying in hash node structure" },
25841edb306SCy Schubert 	{	50020,	"could not find hash table name" },
25941edb306SCy Schubert 	{	50021,	"unrecognised object type for lookup delete node" },
26041edb306SCy Schubert 	{	50022,	"error copying in add table data" },
26141edb306SCy Schubert 	{	50023,	"invalid unit for lookup add table" },
26241edb306SCy Schubert 	{	50024,	"pool name already exists" },
26341edb306SCy Schubert 	{	50025,	"hash table name already exists" },
26441edb306SCy Schubert 	{	50026,	"unrecognised object type for lookup add table" },
26541edb306SCy Schubert 	{	50027,	"error copying table data back out" },
26641edb306SCy Schubert 	{	50028,	"error copying in remove table data" },
26741edb306SCy Schubert 	{	50029,	"invalid unit for lookup remove table" },
26841edb306SCy Schubert 	{	50030,	"unrecognised object type for lookup remove table" },
26941edb306SCy Schubert 	{	50031,	"error copying in lookup stats structure" },
27041edb306SCy Schubert 	{	50032,	"invalid unit for lookup stats" },
27141edb306SCy Schubert 	{	50033,	"unrecognised object type for lookup stats" },
27241edb306SCy Schubert 	{	50034,	"error copying in flush lookup data" },
27341edb306SCy Schubert 	{	50035,	"invalid unit for lookup flush" },
27441edb306SCy Schubert 	{	50036,	"incorrect table type for lookup flush" },
27541edb306SCy Schubert 	{	50037,	"error copying out lookup flush results" },
27641edb306SCy Schubert 	{	50038,	"invalid unit for lookup iterator" },
27741edb306SCy Schubert 	{	50039,	"invalid unit for lookup iterator" },
27841edb306SCy Schubert 	{	50040,	"could not find token for lookup iterator" },
2790939cf32SElyes Haouas 	{	50041,	"unrecognised object type for lookup iterator" },
28041edb306SCy Schubert 	{	50042,	"error copying in lookup delete node operation" },
28141edb306SCy Schubert /* -------------------------------------------------------------------------- */
28241edb306SCy Schubert 	{	60001,	"insufficient privilege for NAT write operation" },
28341edb306SCy Schubert 	{	60002,	"need write permissions to flush NAT logs" },
28441edb306SCy Schubert 	{	60003,	"need write permissions to turn NAT logging on/off" },
28541edb306SCy Schubert 	{	60004,	"error copying out current NAT log setting" },
28641edb306SCy Schubert 	{	60005,	"error copying out bytes waiting to be read in NAT \
28741edb306SCy Schubert log" },
28841edb306SCy Schubert 	{	60006,	"need write permissions to add NAT rule" },
28941edb306SCy Schubert 	{	60007,	"NAT rule already exists" },
29041edb306SCy Schubert 	{	60008,	"could not allocate memory for NAT rule" },
29141edb306SCy Schubert 	{	60009,	"need write permissions to remove NAT rule" },
29241edb306SCy Schubert 	{	60010,	"NAT rule could not be found" },
29341edb306SCy Schubert 	{	60011,	"could not find NAT entry for redirect lookup" },
29441edb306SCy Schubert 	{	60012,	"need write permissions to flush NAT table" },
29541edb306SCy Schubert 	{	60013,	"error copying in NAT flush command" },
29641edb306SCy Schubert 	{	60014,	"need write permissions to do matching NAT flush" },
29741edb306SCy Schubert 	{	60015,	"need write permissions to set NAT lock" },
29841edb306SCy Schubert 	{	60016,	"need write permissions to add entry to NAT table" },
29941edb306SCy Schubert 	{	60017,	"NAT not locked for size retrieval" },
30041edb306SCy Schubert 	{	60018,	"NAT not locked for fetching NAT table entry" },
30141edb306SCy Schubert 	{	60019,	"error copying in NAT token data for deletion" },
30241edb306SCy Schubert 	{	60020,	"unknown NAT ioctl" },
30341edb306SCy Schubert 	{	60021,	"" },
30441edb306SCy Schubert 	{	60022,	"resolving proxy name in NAT rule failed" },
30541edb306SCy Schubert 	{	60023,	"only reply age specified in NAT rule" },
30641edb306SCy Schubert 	{	60024,	"error doing copyin to determine NAT entry size" },
30741edb306SCy Schubert 	{	60025,	"error copying out NAT size of 0" },
30841edb306SCy Schubert 	{	60026,	"NAT entry not found" },
30941edb306SCy Schubert 	{	60027,	"error doing copyout of NAT entry size" },
31041edb306SCy Schubert 	{	60028,	"invalid data size for getting NAT entry" },
31141edb306SCy Schubert 	{	60029,	"could not malloc temporary space for NAT entry" },
31241edb306SCy Schubert 	{	60030,	"no NAT table entries present" },
31341edb306SCy Schubert 	{	60031,	"NAT entry to get next from not found" },
31441edb306SCy Schubert 	{	60032,	"not enough space for proxy structure" },
31541edb306SCy Schubert 	{	60033,	"not enough space for private proxy data" },
31641edb306SCy Schubert 	{	60034,	"NAT entry size is too large" },
31741edb306SCy Schubert 	{	60035,	"could not malloc memory for NAT entry sratch space" },
31841edb306SCy Schubert 	{	60036,	"" },
31941edb306SCy Schubert 	{	60037,	"could not malloc memory for NAT entry" },
32041edb306SCy Schubert 	{	60038,	"could not malloc memory for NAT entry rule" },
32141edb306SCy Schubert 	{	60039,	"could not resolve NAT entry rule's proxy" },
32241edb306SCy Schubert 	{	60040,	"cannot add outbound duplicate NAT entry" },
32341edb306SCy Schubert 	{	60041,	"cannot add inbound duplicate NAT entry" },
32441edb306SCy Schubert 	{	60042,	"cannot add NAT entry that is neither IN nor OUT" },
32541edb306SCy Schubert 	{	60043,	"could not malloc memory for NAT proxy data" },
32641edb306SCy Schubert 	{	60044,	"proxy data size too big" },
32741edb306SCy Schubert 	{	60045,	"could not malloc proxy private data for NAT entry" },
32841edb306SCy Schubert 	{	60046,	"could not malloc memory for new NAT filter rule" },
32941edb306SCy Schubert 	{	60047,	"could not find existing filter rule for NAT entry" },
33041edb306SCy Schubert 	{	60048,	"insertion into NAT table failed" },
33141edb306SCy Schubert 	{	60049,	"iterator error copying out hostmap data" },
33241edb306SCy Schubert 	{	60050,	"iterator error copying out NAT rule data" },
33341edb306SCy Schubert 	{	60051,	"iterator error copying out NAT entry data" },
33441edb306SCy Schubert 	{	60052,	"iterator data supplied with NULL pointer" },
33541edb306SCy Schubert 	{	60053,	"unknown NAT iterator type" },
3360939cf32SElyes Haouas 	{	60054,	"unknown next address type" },
33741edb306SCy Schubert 	{	60055,	"iterator suppled with unknown type for get-next" },
33841edb306SCy Schubert 	{	60056,	"unknown lookup group for next address" },
33941edb306SCy Schubert 	{	60057,	"error copying out NAT log flush results" },
34041edb306SCy Schubert 	{	60058,	"bucket table type is incorrect" },
34141edb306SCy Schubert 	{	60059,	"error copying out NAT bucket table" },
34241edb306SCy Schubert 	{	60060,	"function not found for lookup" },
34341edb306SCy Schubert 	{	60061,	"address family not supported with SIOCSTPUT" },
34441edb306SCy Schubert 	{	60062,	"unknown timeout name" },
34541edb306SCy Schubert 	{	60063,	"cannot allocate new inbound NAT entry table" },
34641edb306SCy Schubert 	{	60064,	"cannot allocate new outbound NAT entry table" },
34741edb306SCy Schubert 	{	60065,	"cannot allocate new inbound NAT bucketlen table" },
34841edb306SCy Schubert 	{	60066,	"cannot allocate new outbound NAT bucketlen table" },
34941edb306SCy Schubert 	{	60067,	"cannot allocate new NAT rules table" },
35041edb306SCy Schubert 	{	60068,	"cannot allocate new NAT hostmap table" },
35141edb306SCy Schubert 	{	60069,	"new source lookup type is not dstlist" },
35241edb306SCy Schubert 	{	60070,	"cannot allocate NAT rule scratch space" },
35341edb306SCy Schubert 	{	60071,	"new destination lookup type is not dstlist" },
35441edb306SCy Schubert 	{	60072,	"function not found for lookup (ipv6)" },
35541edb306SCy Schubert 	{	60073,	"unknown lookup group for next address (ipv6)" },
35641edb306SCy Schubert 	{	60074,	"unknown next address type (ipv6)" },
35741edb306SCy Schubert 	{	60075,	"one object at a time must be copied" },
358c47db49bSCy Schubert 	{	60076,	"NAT ioctl denied in jail without VNET" },
35941edb306SCy Schubert /* -------------------------------------------------------------------------- */
36041edb306SCy Schubert 	{	70001,	"incorrect object size to get pool stats" },
36141edb306SCy Schubert 	{	70002,	"could not malloc memory for new pool node" },
36241edb306SCy Schubert 	{	70003,	"invalid address length for new pool node" },
36341edb306SCy Schubert 	{	70004,	"invalid mask length for new pool node" },
36441edb306SCy Schubert 	{	70005,	"error adding node to pool" },
36541edb306SCy Schubert 	{	70006,	"pool already exists" },
36641edb306SCy Schubert 	{	70007,	"could not malloc memory for new pool" },
36741edb306SCy Schubert 	{	70008,	"could not allocate radix tree for new pool" },
36841edb306SCy Schubert 	{	70009,	"could not find pool" },
36941edb306SCy Schubert 	{	70010,	"unknown pool name for iteration" },
37041edb306SCy Schubert 	{	70011,	"unknown pool iterator" },
37141edb306SCy Schubert 	{	70012,	"error copying out pool head" },
37241edb306SCy Schubert 	{	70013,	"error copying out pool node" },
37341edb306SCy Schubert 	{	70014,	"add node size incorrect" },
37441edb306SCy Schubert 	{	70015,	"error copying in pool node" },
37541edb306SCy Schubert 	{	70016,	"" },
37641edb306SCy Schubert 	{	70017,	"cannot find pool for node" },
37741edb306SCy Schubert 	{	70018,	"node entry already present in pool" },
37841edb306SCy Schubert 	{	70019,	"delete node size incorrect" },
37941edb306SCy Schubert 	{	70020,	"error copying in node to delete" },
38041edb306SCy Schubert 	{	70021,	"cannot find pool to delete node from" },
38141edb306SCy Schubert 	{	70022,	"cannot find node to delete in pool" },
38241edb306SCy Schubert 	{	70023,	"pool name already exists" },
38341edb306SCy Schubert 	{	70024,	"uid mismatch for node removal" },
38441edb306SCy Schubert 	{	70025,	"stats device unit is invalid" },
38541edb306SCy Schubert 	{	70026,	"error copying out statistics" },
38641edb306SCy Schubert 	{	70027,	"could not remove node from radix tree" },
38741edb306SCy Schubert 	{	70028,	"incorrect address length in pool node add" },
38841edb306SCy Schubert 	{	70029,	"incorrect mask length in pool node add" },
38941edb306SCy Schubert 	{	70030,	"incorrect address length in pool node remove" },
39041edb306SCy Schubert 	{	70031,	"incorrect mask length in pool node remove" },
39141edb306SCy Schubert 	{	70032,	"cannot allocate memory for pool context" },
39241edb306SCy Schubert 	{	70033,	"cannot allocate memory for radix tree context" },
39341edb306SCy Schubert 	{	70034,	"adding IPv6 node with incorrect address length" },
39441edb306SCy Schubert 	{	70035,	"IPv4 address not masked" },
39541edb306SCy Schubert 	{	70036,	"IPv6 address not masked" },
39641edb306SCy Schubert 	{	70037,	"removing IPv6 node with incorrect address length" },
39741edb306SCy Schubert /* -------------------------------------------------------------------------- */
39841edb306SCy Schubert 	{	80001,	"could not find proxy" },
39941edb306SCy Schubert 	{	80002,	"proxy does not support control operations" },
40041edb306SCy Schubert 	{	80003,	"could not allocate data to hold proxy operation" },
40141edb306SCy Schubert 	{	80004,	"unknown proxy ioctl" },
40241edb306SCy Schubert 	{	80005,	"could not copyin proxy control structure" },
40341edb306SCy Schubert 	{	80006,	"DNS proxy could not find rule to delete" },
40441edb306SCy Schubert 	{	80007,	"DNS proxy found existing matching rule" },
40541edb306SCy Schubert 	{	80008,	"DNS proxy could not allocate memory for new rule" },
40641edb306SCy Schubert 	{	80009,	"DNS proxy unknown command request" },
40741edb306SCy Schubert /* -------------------------------------------------------------------------- */
40841edb306SCy Schubert 	{	90001,	"could not malloc space for new scan structure" },
40941edb306SCy Schubert 	{	90002,	"scan tag already exists" },
41041edb306SCy Schubert 	{	90003,	"scan structure in use" },
41141edb306SCy Schubert 	{	90004,	"could not find matching scan tag for filter rule" },
41241edb306SCy Schubert 	{	90005,	"could not copyout scan statistics" },
41341edb306SCy Schubert /* -------------------------------------------------------------------------- */
41441edb306SCy Schubert 	{	100001,	"cannot find matching state entry to remove" },
41541edb306SCy Schubert 	{	100002,	"error copying in v4 state flush command" },
41641edb306SCy Schubert 	{	100003,	"error copying out v4 state flush results" },
41741edb306SCy Schubert 	{	100004,	"error copying in v6 state flush command" },
41841edb306SCy Schubert 	{	100005,	"error copying out v6 state flush results" },
41941edb306SCy Schubert 	{	100006,	"" },
42041edb306SCy Schubert 	{	100007,	"" },
42141edb306SCy Schubert 	{	100008,	"need write permissions to flush state log" },
4220939cf32SElyes Haouas 	{	100009,	"error copyout results of flushing state log" },
42341edb306SCy Schubert 	{	100010,	"need write permissions to turn state logging on/off" },
42441edb306SCy Schubert 	{	100011,	"error copying in new state logging state" },
42541edb306SCy Schubert 	{	100012,	"error copying out current state logging state" },
42641edb306SCy Schubert 	{	100013,	"error copying out bytes waiting to be read in state \
42741edb306SCy Schubert log" },
42841edb306SCy Schubert 	{	100014,	"need write permissions to set state lock" },
42941edb306SCy Schubert 	{	100015,	"need write permissions to add entry to state table" },
43041edb306SCy Schubert 	{	100016,	"state not locked for size retrieval" },
43141edb306SCy Schubert 	{	100017,	"error copying out hash table bucket lengths" },
43241edb306SCy Schubert 	{	100018,	"could not find token for state iterator" },
43341edb306SCy Schubert 	{	100019,	"error copying in state token data for deletion" },
43441edb306SCy Schubert 	{	100020,	"unknown state ioctl" },
43541edb306SCy Schubert 	{	100021,	"no state table entries present" },
43641edb306SCy Schubert 	{	100022,	"state entry to get next from not found" },
43741edb306SCy Schubert 	{	100023,	"could not malloc memory for state entry" },
43841edb306SCy Schubert 	{	100024,	"could not malloc memory for state entry rule" },
43941edb306SCy Schubert 	{	100025,	"could not copy back state entry to user space" },
44041edb306SCy Schubert 	{	100026,	"iterator data supplied with NULL pointer" },
44141edb306SCy Schubert 	{	100027,	"iterator supplied with 0 item count" },
44241edb306SCy Schubert 	{	100028,	"iterator type is incorrect" },
44341edb306SCy Schubert 	{	100029,	"invalid state token data pointer supplied" },
44441edb306SCy Schubert 	{	100030,	"error copying out next state entry" },
44541edb306SCy Schubert 	{	100031,	"unrecognised table request" },
44641edb306SCy Schubert 	{	100032,	"error copying out bucket length data" },
44741edb306SCy Schubert 	{	100033,	"could not find existing filter rule for state entry" },
44841edb306SCy Schubert 	{	100034,	"could not find timeout name" },
44941edb306SCy Schubert 	{	100035, "could not allocate new state table" },
45041edb306SCy Schubert 	{	100036, "could not allocate new state bucket length table" },
45141edb306SCy Schubert /* -------------------------------------------------------------------------- */
45241edb306SCy Schubert 	{	110001,	"sync write header magic number is incorrect" },
45341edb306SCy Schubert 	{	110002,	"sync write header protocol is incorrect" },
45441edb306SCy Schubert 	{	110003,	"sync write header command is incorrect" },
45541edb306SCy Schubert 	{	110004,	"sync write header table number is incorrect" },
45641edb306SCy Schubert 	{	110005,	"data structure too small for sync write operation" },
45741edb306SCy Schubert 	{	110006,	"zero length data with sync write header" },
45841edb306SCy Schubert 	{	110007,	"insufficient data for sync write" },
45941edb306SCy Schubert 	{	110008,	"bad sync read size" },
46041edb306SCy Schubert 	{	110009,	"interrupted sync read (solaris)" },
46141edb306SCy Schubert 	{	110010,	"interrupted sync read (hpux)" },
46241edb306SCy Schubert 	{	110011,	"interrupted sync read (osf)" },
46341edb306SCy Schubert 	{	110012,	"interrupted sync read" },
46441edb306SCy Schubert 	{	110013,	"could not malloc memory for sync'd state" },
46541edb306SCy Schubert 	{	110014,	"could not malloc memory for sync-state list item" },
46641edb306SCy Schubert 	{	110015,	"sync update could not find state" },
46741edb306SCy Schubert 	{	110016,	"unrecognised sync state command" },
46841edb306SCy Schubert 	{	110017,	"could not malloc memory for new sync'd NAT entry" },
46941edb306SCy Schubert 	{	110018,	"could not malloc memory for sync-NAT list item" },
47041edb306SCy Schubert 	{	110019,	"sync update could not find NAT entry" },
47141edb306SCy Schubert 	{	110020,	"unrecognised sync NAT command" },
47241edb306SCy Schubert 	{	110021,	"ioctls are not handled with sync" },
47341edb306SCy Schubert /* -------------------------------------------------------------------------- */
47441edb306SCy Schubert 	{	120001,	"null data pointer for iterator" },
47541edb306SCy Schubert 	{	120002,	"unit outside of acceptable range" },
47641edb306SCy Schubert 	{	120003,	"unknown iterator subtype" },
47741edb306SCy Schubert 	{	120004,	"cannot find dest. list for iteration" },
47841edb306SCy Schubert 	{	120005,	"error copying out destination iteration list" },
47941edb306SCy Schubert 	{	120006,	"error copying out destination iteration node" },
48041edb306SCy Schubert 	{	120007,	"wrong size for frdest_t structure" },
48141edb306SCy Schubert 	{	120008,	"cannot allocate memory for new destination node" },
48241edb306SCy Schubert 	{	120009,	"error copying in destination node to add" },
48341edb306SCy Schubert 	{	120010,	"could not find destination list to add node to" },
48441edb306SCy Schubert 	{	120011,	"error copying in destination node to remove" },
48541edb306SCy Schubert 	{	120012,	"could not find dest. list to remove node from" },
48641edb306SCy Schubert 	{	120013,	"destination list already exists" },
48741edb306SCy Schubert 	{	120014,	"could not allocate new destination table" },
48841edb306SCy Schubert 	{	120015,	"could not find destination list to remove" },
48941edb306SCy Schubert 	{	120016,	"destination list cannot be removed - it is busy" },
49041edb306SCy Schubert 	{	120017,	"error copying in names for destination" },
49141edb306SCy Schubert 	{	120018,	"destination name is too long/short" },
49241edb306SCy Schubert 	{	120019,	"unrecognised address family in destination" },
49341edb306SCy Schubert 	{	120020,	"" },
49441edb306SCy Schubert 	{	120021,	"error copying in new destination table" },
49541edb306SCy Schubert 	{	120022,	"cannot allocate memory for node table" },
49641edb306SCy Schubert 	{	120023,	"stats object size is incorrect for dest. lists" },
49741edb306SCy Schubert 	{	120024,	"stats device unit is invalid for dest. lists" },
49841edb306SCy Schubert 	{	120025,	"error copying out dest. list statistics" },
49941edb306SCy Schubert 	{	120026,	"cannot allocate memory for destination node" },
50041edb306SCy Schubert 	{	120027,	"error copying in destination node" },
50141edb306SCy Schubert 	{	120028,	"cannot allocate memory for destination context " },
50241edb306SCy Schubert /* -------------------------------------------------------------------------- */
50341edb306SCy Schubert 	{	130001,	"ioctl denied by system security level" },
50441edb306SCy Schubert 	{	130002,	"ioctl operation on invalid minor device" },
50541edb306SCy Schubert 	{	130003,	"ioctl on device denied, ipfitler is disabled" },
50641edb306SCy Schubert 	{	130004,	"ioctl command not allowed when disabled" },
50741edb306SCy Schubert 	{	130005,	"ioctl denied due to insufficient authorisation" },
50841edb306SCy Schubert 	{	130006,	"cannot read while ipfilter is disabled" },
50941edb306SCy Schubert 	{	130007,	"read on minor device not supported" },
51041edb306SCy Schubert 	{	130008,	"cannot write while ipfilter is disabled" },
51141edb306SCy Schubert 	{	130009,	"write on minor device not supported" },
51241edb306SCy Schubert 	{	130010,	"poll on minor device is not supported" },
51341edb306SCy Schubert 	{	130011,	"error removing IPv4 filter hooks" },
51441edb306SCy Schubert 	{	130012,	"error removing IPv6 filter hooks" },
51541edb306SCy Schubert 	{	130013,	"attaching IPv4 hook failed" },
51641edb306SCy Schubert 	{	130014,	"attaching IPv6 hook failed" },
51741edb306SCy Schubert 	{	130015,	"ipf_init_all failed" },
51841edb306SCy Schubert 	{	130016,	"finding pfil head failed" },
51941edb306SCy Schubert 	{	130017,	"ipfilter is already initialised and running" },
520c47db49bSCy Schubert 	{	130018,	"ioctl denied in jail without VNET" },
52141edb306SCy Schubert };
52241edb306SCy Schubert 
52341edb306SCy Schubert 
52441edb306SCy Schubert static ipf_error_entry_t *
find_error(int errnum)525efeb8bffSCy Schubert find_error(int errnum)
52641edb306SCy Schubert {
52741edb306SCy Schubert 	ipf_error_entry_t *ie;
52841edb306SCy Schubert 
52941edb306SCy Schubert 	int l = -1, r = IPF_NUM_ERRORS + 1, step;
530540be39bSElyes Haouas 	step = (r - l) / 2;
53141edb306SCy Schubert 
53241edb306SCy Schubert 	while (step != 0) {
53341edb306SCy Schubert 		ie = ipf_errors + l + step;
53441edb306SCy Schubert 		if (ie->iee_number == errnum)
5352582ae57SCy Schubert 			return (ie);
53641edb306SCy Schubert 		step = l + step;
53741edb306SCy Schubert 		if (ie->iee_number > errnum)
53841edb306SCy Schubert 			r = step;
53941edb306SCy Schubert 		else
54041edb306SCy Schubert 			l = step;
541540be39bSElyes Haouas 		step = (r - l) / 2;
54241edb306SCy Schubert 	}
54341edb306SCy Schubert 
5442582ae57SCy Schubert 	return (NULL);
54541edb306SCy Schubert }
54641edb306SCy Schubert 
54741edb306SCy Schubert char *
ipf_geterror(int fd,ioctlfunc_t * func)548efeb8bffSCy Schubert ipf_geterror(int fd, ioctlfunc_t *func)
54941edb306SCy Schubert {
55041edb306SCy Schubert 	static char text[80];
55141edb306SCy Schubert 	ipf_error_entry_t *ie;
55241edb306SCy Schubert 	int errnum;
55341edb306SCy Schubert 
55441edb306SCy Schubert 	if ((*func)(fd, SIOCIPFINTERROR, &errnum) == 0) {
55541edb306SCy Schubert 
55641edb306SCy Schubert 		ie = find_error(errnum);
55741edb306SCy Schubert 		if (ie != NULL)
5582582ae57SCy Schubert 			return (ie->iee_text);
55941edb306SCy Schubert 		snprintf(text, sizeof(text), "unknown error %d", errnum);
56041edb306SCy Schubert 	} else {
56141edb306SCy Schubert 		snprintf(text, sizeof(text), "retrieving error number failed (%d)", errno);
56241edb306SCy Schubert 	}
5632582ae57SCy Schubert 	return (text);
56441edb306SCy Schubert }
56541edb306SCy Schubert 
56641edb306SCy Schubert 
56741edb306SCy Schubert char *
ipf_strerror(int errnum)568efeb8bffSCy Schubert ipf_strerror(int errnum)
56941edb306SCy Schubert {
57041edb306SCy Schubert 	static char text[80];
57141edb306SCy Schubert 	ipf_error_entry_t *ie;
57241edb306SCy Schubert 
57341edb306SCy Schubert 
57441edb306SCy Schubert 	ie = find_error(errnum);
57541edb306SCy Schubert 	if (ie != NULL)
5762582ae57SCy Schubert 		return (ie->iee_text);
57741edb306SCy Schubert 
57841edb306SCy Schubert 	snprintf(text, sizeof(text), "unknown error %d", errnum);
5792582ae57SCy Schubert 	return (text);
58041edb306SCy Schubert }
581