1 #ifndef _IPTABLES_USER_H
2 #define _IPTABLES_USER_H
4 #include "iptables_common.h"
5 #include "libiptc/libiptc.h"
8 #define IPT_LIB_DIR "/usr/local/lib/iptables"
12 #define IPPROTO_SCTP 132
15 #define IPPROTO_DCCP 33
17 #ifndef IPPROTO_UDPLITE
18 #define IPPROTO_UDPLITE 136
21 #ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */
22 #define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2)
23 #define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3)
25 struct ipt_get_revision
27 char name[IPT_FUNCTION_MAXNAMELEN-1];
31 #endif /* IPT_SO_GET_REVISION_MATCH Old kernel source */
33 struct iptables_rule_match
35 struct iptables_rule_match *next;
37 struct iptables_match *match;
39 /* Multiple matches of the same type: the ones before
40 the current one are completed from parsing point of view */
41 unsigned int completed;
44 /* Include file for additions: new matches and targets. */
47 struct iptables_match *next;
51 /* Revision of match (0 by default). */
56 /* Size of match data. */
59 /* Size of match data relevent for userspace comparison purposes */
62 /* Function which prints out usage message. */
65 /* Initialize the match. */
66 void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
68 /* Function which parses command options; returns true if it
70 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
71 const struct ipt_entry *entry,
72 unsigned int *nfcache,
73 struct ipt_entry_match **match);
75 /* Final check; exit if not ok. */
76 void (*final_check)(unsigned int flags);
78 /* Prints out the match iff non-NULL: put space at end */
79 void (*print)(const struct ipt_ip *ip,
80 const struct ipt_entry_match *match, int numeric);
82 /* Saves the match info in parsable form to stdout. */
83 void (*save)(const struct ipt_ip *ip,
84 const struct ipt_entry_match *match);
86 /* Pointer to list of extra command-line options */
87 const struct option *extra_opts;
89 /* Ignore these men behind the curtain: */
90 unsigned int option_offset;
91 struct ipt_entry_match *m;
94 unsigned int loaded; /* simulate loading so options are merged properly */
98 struct iptables_target
100 struct iptables_target *next;
104 /* Revision of target (0 by default). */
109 /* Size of target data. */
112 /* Size of target data relevent for userspace comparison purposes */
113 size_t userspacesize;
115 /* Function which prints out usage message. */
118 /* Initialize the target. */
119 void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
121 /* Function which parses command options; returns true if it
123 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
124 const struct ipt_entry *entry,
125 struct ipt_entry_target **target);
127 /* Final check; exit if not ok. */
128 void (*final_check)(unsigned int flags);
130 /* Prints out the target iff non-NULL: put space at end */
131 void (*print)(const struct ipt_ip *ip,
132 const struct ipt_entry_target *target, int numeric);
134 /* Saves the targinfo in parsable form to stdout. */
135 void (*save)(const struct ipt_ip *ip,
136 const struct ipt_entry_target *target);
138 /* Pointer to list of extra command-line options */
139 struct option *extra_opts;
141 /* Ignore these men behind the curtain: */
142 unsigned int option_offset;
143 struct ipt_entry_target *t;
146 #ifdef NO_SHARED_LIBS
147 unsigned int loaded; /* simulate loading so options are merged properly */
153 /* Your shared library should call one of these. */
154 extern void register_match(struct iptables_match *me);
155 extern void register_target(struct iptables_target *me);
157 extern int service_to_port(const char *name, const char *proto);
158 extern u_int16_t parse_port(const char *port, const char *proto);
159 extern struct in_addr *dotted_to_addr(const char *dotted);
160 extern struct in_addr *dotted_to_mask(const char *dotted);
161 extern char *addr_to_dotted(const struct in_addr *addrp);
162 extern char *addr_to_anyname(const struct in_addr *addr);
163 extern char *mask_to_dotted(const struct in_addr *mask);
165 extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
166 struct in_addr *maskp, unsigned int *naddrs);
167 extern u_int16_t parse_protocol(const char *s);
168 extern void parse_interface(const char *arg, char *vianame, unsigned char *mask);
170 extern int do_command(int argc, char *argv[], char **table,
171 iptc_handle_t *handle);
172 /* Keeping track of external matches and targets: linked lists. */
173 extern struct iptables_match *iptables_matches;
174 extern struct iptables_target *iptables_targets;
183 extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
184 extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
186 extern int delete_chain(const ipt_chainlabel chain, int verbose,
187 iptc_handle_t *handle);
188 extern int flush_entries(const ipt_chainlabel chain, int verbose,
189 iptc_handle_t *handle);
190 extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
191 int verbose, int builtinstoo, iptc_handle_t *handle);
193 /* kernel revision handling */
194 extern int kernel_version;
195 extern void get_kernel_version(void);
196 #define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
197 #define LINUX_VERSION_MAJOR(x) (((x)>>16) & 0xFF)
198 #define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
199 #define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
201 #endif /*_IPTABLES_USER_H*/