iptables.h revision a6c1d926f6c3c00e0c1875d80b9579c95bde2cfa
1#ifndef _IPTABLES_USER_H
2#define _IPTABLES_USER_H
3
4#include "iptables_common.h"
5#include "libiptc/libiptc.h"
6
7#ifndef IPT_LIB_DIR
8#define IPT_LIB_DIR "/usr/local/lib/iptables"
9#endif
10
11#ifndef IPPROTO_SCTP
12#define IPPROTO_SCTP 132
13#endif
14#ifndef IPPROTO_DCCP
15#define IPPROTO_DCCP 33
16#endif
17
18#ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */
19#define IPT_SO_GET_REVISION_MATCH	(IPT_BASE_CTL + 2)
20#define IPT_SO_GET_REVISION_TARGET	(IPT_BASE_CTL + 3)
21
22struct ipt_get_revision
23{
24	char name[IPT_FUNCTION_MAXNAMELEN-1];
25
26	u_int8_t revision;
27};
28#endif /* IPT_SO_GET_REVISION_MATCH   Old kernel source */
29
30struct iptables_rule_match
31{
32	struct iptables_rule_match *next;
33
34	struct iptables_match *match;
35
36	/* Multiple matches of the same type: the ones before
37	   the current one are completed from parsing point of view */
38	unsigned int completed;
39};
40
41/* Include file for additions: new matches and targets. */
42struct iptables_match
43{
44	struct iptables_match *next;
45
46	ipt_chainlabel name;
47
48	/* Revision of match (0 by default). */
49	u_int8_t revision;
50
51	const char *version;
52
53	/* Size of match data. */
54	size_t size;
55
56	/* Size of match data relevent for userspace comparison purposes */
57	size_t userspacesize;
58
59	/* Function which prints out usage message. */
60	void (*help)(void);
61
62	/* Initialize the match. */
63	void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
64
65	/* Function which parses command options; returns true if it
66           ate an option */
67	int (*parse)(int c, char **argv, int invert, unsigned int *flags,
68		     const struct ipt_entry *entry,
69		     unsigned int *nfcache,
70		     struct ipt_entry_match **match);
71
72	/* Final check; exit if not ok. */
73	void (*final_check)(unsigned int flags);
74
75	/* Prints out the match iff non-NULL: put space at end */
76	void (*print)(const struct ipt_ip *ip,
77		      const struct ipt_entry_match *match, int numeric);
78
79	/* Saves the match info in parsable form to stdout. */
80	void (*save)(const struct ipt_ip *ip,
81		     const struct ipt_entry_match *match);
82
83	/* Pointer to list of extra command-line options */
84	const struct option *extra_opts;
85
86	/* Ignore these men behind the curtain: */
87	unsigned int option_offset;
88	struct ipt_entry_match *m;
89	unsigned int mflags;
90#ifdef NO_SHARED_LIBS
91	unsigned int loaded; /* simulate loading so options are merged properly */
92#endif
93};
94
95struct iptables_target
96{
97	struct iptables_target *next;
98
99	ipt_chainlabel name;
100
101	/* Revision of target (0 by default). */
102	u_int8_t revision;
103
104	const char *version;
105
106	/* Size of target data. */
107	size_t size;
108
109	/* Size of target data relevent for userspace comparison purposes */
110	size_t userspacesize;
111
112	/* Function which prints out usage message. */
113	void (*help)(void);
114
115	/* Initialize the target. */
116	void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
117
118	/* Function which parses command options; returns true if it
119           ate an option */
120	int (*parse)(int c, char **argv, int invert, unsigned int *flags,
121		     const struct ipt_entry *entry,
122		     struct ipt_entry_target **target);
123
124	/* Final check; exit if not ok. */
125	void (*final_check)(unsigned int flags);
126
127	/* Prints out the target iff non-NULL: put space at end */
128	void (*print)(const struct ipt_ip *ip,
129		      const struct ipt_entry_target *target, int numeric);
130
131	/* Saves the targinfo in parsable form to stdout. */
132	void (*save)(const struct ipt_ip *ip,
133		     const struct ipt_entry_target *target);
134
135	/* Pointer to list of extra command-line options */
136	struct option *extra_opts;
137
138	/* Ignore these men behind the curtain: */
139	unsigned int option_offset;
140	struct ipt_entry_target *t;
141	unsigned int tflags;
142	unsigned int used;
143#ifdef NO_SHARED_LIBS
144	unsigned int loaded; /* simulate loading so options are merged properly */
145#endif
146};
147
148extern int line;
149
150/* Your shared library should call one of these. */
151extern void register_match(struct iptables_match *me);
152extern void register_target(struct iptables_target *me);
153
154extern char *proto_to_name(u_int8_t proto, int nolookup);
155extern int service_to_port(const char *name, const char *proto);
156extern u_int16_t parse_port(const char *port, const char *proto);
157extern struct in_addr *dotted_to_addr(const char *dotted);
158extern char *addr_to_dotted(const struct in_addr *addrp);
159extern char *addr_to_anyname(const struct in_addr *addr);
160extern char *mask_to_dotted(const struct in_addr *mask);
161
162extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
163                      struct in_addr *maskp, unsigned int *naddrs);
164extern u_int16_t parse_protocol(const char *s);
165extern void parse_interface(const char *arg, char *vianame, unsigned char *mask);
166
167extern int do_command(int argc, char *argv[], char **table,
168		      iptc_handle_t *handle);
169/* Keeping track of external matches and targets: linked lists.  */
170extern struct iptables_match *iptables_matches;
171extern struct iptables_target *iptables_targets;
172
173enum ipt_tryload {
174	DONT_LOAD,
175	DURING_LOAD,
176	TRY_LOAD,
177	LOAD_MUST_SUCCEED
178};
179
180extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
181extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
182
183extern int delete_chain(const ipt_chainlabel chain, int verbose,
184			iptc_handle_t *handle);
185extern int flush_entries(const ipt_chainlabel chain, int verbose,
186			iptc_handle_t *handle);
187extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
188		int verbose, int builtinstoo, iptc_handle_t *handle);
189
190/* kernel revision handling */
191extern int kernel_version;
192extern void get_kernel_version(void);
193#define LINUX_VERSION(x,y,z)	(0x10000*(x) + 0x100*(y) + z)
194#define LINUX_VERSION_MAJOR(x)	(((x)>>16) & 0xFF)
195#define LINUX_VERSION_MINOR(x)	(((x)>> 8) & 0xFF)
196#define LINUX_VERSION_PATCH(x)	( (x)      & 0xFF)
197
198#endif /*_IPTABLES_USER_H*/
199