blob: c56a00571a24e8cb0be421989b051a3c84b53756 [file] [log] [blame]
Marc Bouchere6869a82000-03-20 06:03:29 +00001#ifndef _IPTABLES_USER_H
2#define _IPTABLES_USER_H
3
Rusty Russell79dee072000-05-02 16:45:16 +00004#include "iptables_common.h"
Marc Bouchere6869a82000-03-20 06:03:29 +00005#include "libiptc/libiptc.h"
6
Martin Josefsson357d59d2004-12-27 19:49:28 +00007#ifndef IPT_LIB_DIR
8#define IPT_LIB_DIR "/usr/local/lib/iptables"
9#endif
10
Harald Weltedb0422f2004-03-04 07:45:30 +000011#ifndef IPPROTO_SCTP
12#define IPPROTO_SCTP 132
13#endif
14
Rusty Russell3aef54d2005-01-03 03:48:40 +000015#ifndef IPT_SO_GET_REVISION_MATCH /* Old kernel source. */
16#define IPT_SO_GET_REVISION_MATCH (IPT_BASE_CTL + 2)
17#define IPT_SO_GET_REVISION_TARGET (IPT_BASE_CTL + 3)
18
19struct ipt_get_revision
20{
21 char name[IPT_FUNCTION_MAXNAMELEN-1];
22
23 u_int8_t revision;
24};
25#endif /* IPT_SO_GET_REVISION_MATCH Old kernel source */
26
Martin Josefsson78cafda2004-02-02 20:01:18 +000027struct iptables_rule_match
28{
29 struct iptables_rule_match *next;
30
31 struct iptables_match *match;
Joszef Kadlecsika258ad72006-03-03 09:36:50 +000032
33 /* Multiple matches of the same type: the ones before
34 the current one are completed from parsing point of view */
35 unsigned int completed;
Martin Josefsson78cafda2004-02-02 20:01:18 +000036};
37
Marc Bouchere6869a82000-03-20 06:03:29 +000038/* Include file for additions: new matches and targets. */
39struct iptables_match
40{
41 struct iptables_match *next;
42
43 ipt_chainlabel name;
44
Rusty Russell3aef54d2005-01-03 03:48:40 +000045 /* Revision of match (0 by default). */
46 u_int8_t revision;
47
Marc Bouchere6869a82000-03-20 06:03:29 +000048 const char *version;
49
50 /* Size of match data. */
51 size_t size;
52
Rusty Russelledf14cf2000-04-19 11:26:44 +000053 /* Size of match data relevent for userspace comparison purposes */
54 size_t userspacesize;
55
Marc Bouchere6869a82000-03-20 06:03:29 +000056 /* Function which prints out usage message. */
57 void (*help)(void);
58
59 /* Initialize the match. */
60 void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
61
62 /* Function which parses command options; returns true if it
63 ate an option */
64 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
65 const struct ipt_entry *entry,
66 unsigned int *nfcache,
67 struct ipt_entry_match **match);
68
69 /* Final check; exit if not ok. */
70 void (*final_check)(unsigned int flags);
71
72 /* Prints out the match iff non-NULL: put space at end */
73 void (*print)(const struct ipt_ip *ip,
74 const struct ipt_entry_match *match, int numeric);
75
Rusty Russell79dee072000-05-02 16:45:16 +000076 /* Saves the match info in parsable form to stdout. */
Marc Bouchere6869a82000-03-20 06:03:29 +000077 void (*save)(const struct ipt_ip *ip,
78 const struct ipt_entry_match *match);
79
80 /* Pointer to list of extra command-line options */
Jan Echternachb6db3312000-08-27 07:39:08 +000081 const struct option *extra_opts;
Marc Bouchere6869a82000-03-20 06:03:29 +000082
83 /* Ignore these men behind the curtain: */
84 unsigned int option_offset;
85 struct ipt_entry_match *m;
86 unsigned int mflags;
Harald Welte3efb6ea2001-08-06 18:50:21 +000087#ifdef NO_SHARED_LIBS
88 unsigned int loaded; /* simulate loading so options are merged properly */
89#endif
Marc Bouchere6869a82000-03-20 06:03:29 +000090};
91
92struct iptables_target
93{
94 struct iptables_target *next;
95
96 ipt_chainlabel name;
97
Rusty Russell3aef54d2005-01-03 03:48:40 +000098 /* Revision of target (0 by default). */
99 u_int8_t revision;
100
Marc Bouchere6869a82000-03-20 06:03:29 +0000101 const char *version;
102
103 /* Size of target data. */
104 size_t size;
105
Rusty Russelledf14cf2000-04-19 11:26:44 +0000106 /* Size of target data relevent for userspace comparison purposes */
107 size_t userspacesize;
108
Marc Bouchere6869a82000-03-20 06:03:29 +0000109 /* Function which prints out usage message. */
110 void (*help)(void);
111
112 /* Initialize the target. */
113 void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
114
115 /* Function which parses command options; returns true if it
116 ate an option */
117 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
118 const struct ipt_entry *entry,
119 struct ipt_entry_target **target);
120
121 /* Final check; exit if not ok. */
122 void (*final_check)(unsigned int flags);
123
124 /* Prints out the target iff non-NULL: put space at end */
125 void (*print)(const struct ipt_ip *ip,
126 const struct ipt_entry_target *target, int numeric);
127
128 /* Saves the targinfo in parsable form to stdout. */
129 void (*save)(const struct ipt_ip *ip,
130 const struct ipt_entry_target *target);
131
132 /* Pointer to list of extra command-line options */
133 struct option *extra_opts;
134
135 /* Ignore these men behind the curtain: */
136 unsigned int option_offset;
137 struct ipt_entry_target *t;
138 unsigned int tflags;
Harald Weltea114e9e2000-12-01 14:28:19 +0000139 unsigned int used;
Harald Welte3efb6ea2001-08-06 18:50:21 +0000140#ifdef NO_SHARED_LIBS
141 unsigned int loaded; /* simulate loading so options are merged properly */
142#endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000143};
144
Illes Marci63e90632003-03-03 08:08:37 +0000145extern int line;
146
Marc Bouchere6869a82000-03-20 06:03:29 +0000147/* Your shared library should call one of these. */
148extern void register_match(struct iptables_match *me);
149extern void register_target(struct iptables_target *me);
150
Rusty Russell79dee072000-05-02 16:45:16 +0000151extern struct in_addr *dotted_to_addr(const char *dotted);
Marc Bouchere6869a82000-03-20 06:03:29 +0000152extern char *addr_to_dotted(const struct in_addr *addrp);
Marc Boucherb93c7982001-12-06 14:50:19 +0000153extern char *addr_to_anyname(const struct in_addr *addr);
154extern char *mask_to_dotted(const struct in_addr *mask);
155
156extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
157 struct in_addr *maskp, unsigned int *naddrs);
158extern u_int16_t parse_protocol(const char *s);
Yasuyuki KOZAKAI9867e812005-06-22 12:24:21 +0000159extern void parse_interface(const char *arg, char *vianame, unsigned char *mask);
Marc Bouchere6869a82000-03-20 06:03:29 +0000160
161extern int do_command(int argc, char *argv[], char **table,
162 iptc_handle_t *handle);
163/* Keeping track of external matches and targets: linked lists. */
164extern struct iptables_match *iptables_matches;
165extern struct iptables_target *iptables_targets;
166
Rusty Russell79dee072000-05-02 16:45:16 +0000167enum ipt_tryload {
168 DONT_LOAD,
Jones Desougif5b86e62005-12-22 03:33:50 +0000169 DURING_LOAD,
Rusty Russell79dee072000-05-02 16:45:16 +0000170 TRY_LOAD,
171 LOAD_MUST_SUCCEED
172};
173
174extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
Martin Josefsson78cafda2004-02-02 20:01:18 +0000175extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
Harald Weltea114e9e2000-12-01 14:28:19 +0000176
177extern int delete_chain(const ipt_chainlabel chain, int verbose,
178 iptc_handle_t *handle);
179extern int flush_entries(const ipt_chainlabel chain, int verbose,
180 iptc_handle_t *handle);
181extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
182 int verbose, int builtinstoo, iptc_handle_t *handle);
Phil Oester8cf65912005-09-19 15:00:33 +0000183
184/* kernel revision handling */
185extern int kernel_version;
186extern void get_kernel_version(void);
187#define LINUX_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
188#define LINUX_VERSION_MAJOR(x) (((x)>>16) & 0xFF)
189#define LINUX_VERSION_MINOR(x) (((x)>> 8) & 0xFF)
190#define LINUX_VERSION_PATCH(x) ( (x) & 0xFF)
191
Marc Bouchere6869a82000-03-20 06:03:29 +0000192#endif /*_IPTABLES_USER_H*/