blob: f0cad8daa672fa0039078fe7ed7df546044f2f8f [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;
32};
33
Marc Bouchere6869a82000-03-20 06:03:29 +000034/* Include file for additions: new matches and targets. */
35struct iptables_match
36{
37 struct iptables_match *next;
38
39 ipt_chainlabel name;
40
Rusty Russell3aef54d2005-01-03 03:48:40 +000041 /* Revision of match (0 by default). */
42 u_int8_t revision;
43
Marc Bouchere6869a82000-03-20 06:03:29 +000044 const char *version;
45
46 /* Size of match data. */
47 size_t size;
48
Rusty Russelledf14cf2000-04-19 11:26:44 +000049 /* Size of match data relevent for userspace comparison purposes */
50 size_t userspacesize;
51
Marc Bouchere6869a82000-03-20 06:03:29 +000052 /* Function which prints out usage message. */
53 void (*help)(void);
54
55 /* Initialize the match. */
56 void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
57
58 /* Function which parses command options; returns true if it
59 ate an option */
60 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
61 const struct ipt_entry *entry,
62 unsigned int *nfcache,
63 struct ipt_entry_match **match);
64
65 /* Final check; exit if not ok. */
66 void (*final_check)(unsigned int flags);
67
68 /* Prints out the match iff non-NULL: put space at end */
69 void (*print)(const struct ipt_ip *ip,
70 const struct ipt_entry_match *match, int numeric);
71
Rusty Russell79dee072000-05-02 16:45:16 +000072 /* Saves the match info in parsable form to stdout. */
Marc Bouchere6869a82000-03-20 06:03:29 +000073 void (*save)(const struct ipt_ip *ip,
74 const struct ipt_entry_match *match);
75
76 /* Pointer to list of extra command-line options */
Jan Echternachb6db3312000-08-27 07:39:08 +000077 const struct option *extra_opts;
Marc Bouchere6869a82000-03-20 06:03:29 +000078
79 /* Ignore these men behind the curtain: */
80 unsigned int option_offset;
81 struct ipt_entry_match *m;
82 unsigned int mflags;
Harald Welte3efb6ea2001-08-06 18:50:21 +000083#ifdef NO_SHARED_LIBS
84 unsigned int loaded; /* simulate loading so options are merged properly */
85#endif
Marc Bouchere6869a82000-03-20 06:03:29 +000086};
87
88struct iptables_target
89{
90 struct iptables_target *next;
91
92 ipt_chainlabel name;
93
Rusty Russell3aef54d2005-01-03 03:48:40 +000094 /* Revision of target (0 by default). */
95 u_int8_t revision;
96
Marc Bouchere6869a82000-03-20 06:03:29 +000097 const char *version;
98
99 /* Size of target data. */
100 size_t size;
101
Rusty Russelledf14cf2000-04-19 11:26:44 +0000102 /* Size of target data relevent for userspace comparison purposes */
103 size_t userspacesize;
104
Marc Bouchere6869a82000-03-20 06:03:29 +0000105 /* Function which prints out usage message. */
106 void (*help)(void);
107
108 /* Initialize the target. */
109 void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
110
111 /* Function which parses command options; returns true if it
112 ate an option */
113 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
114 const struct ipt_entry *entry,
115 struct ipt_entry_target **target);
116
117 /* Final check; exit if not ok. */
118 void (*final_check)(unsigned int flags);
119
120 /* Prints out the target iff non-NULL: put space at end */
121 void (*print)(const struct ipt_ip *ip,
122 const struct ipt_entry_target *target, int numeric);
123
124 /* Saves the targinfo in parsable form to stdout. */
125 void (*save)(const struct ipt_ip *ip,
126 const struct ipt_entry_target *target);
127
128 /* Pointer to list of extra command-line options */
129 struct option *extra_opts;
130
131 /* Ignore these men behind the curtain: */
132 unsigned int option_offset;
133 struct ipt_entry_target *t;
134 unsigned int tflags;
Harald Weltea114e9e2000-12-01 14:28:19 +0000135 unsigned int used;
Harald Welte3efb6ea2001-08-06 18:50:21 +0000136#ifdef NO_SHARED_LIBS
137 unsigned int loaded; /* simulate loading so options are merged properly */
138#endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000139};
140
Illes Marci63e90632003-03-03 08:08:37 +0000141extern int line;
142
Marc Bouchere6869a82000-03-20 06:03:29 +0000143/* Your shared library should call one of these. */
144extern void register_match(struct iptables_match *me);
145extern void register_target(struct iptables_target *me);
146
Rusty Russell79dee072000-05-02 16:45:16 +0000147extern struct in_addr *dotted_to_addr(const char *dotted);
Marc Bouchere6869a82000-03-20 06:03:29 +0000148extern char *addr_to_dotted(const struct in_addr *addrp);
Marc Boucherb93c7982001-12-06 14:50:19 +0000149extern char *addr_to_anyname(const struct in_addr *addr);
150extern char *mask_to_dotted(const struct in_addr *mask);
151
152extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
153 struct in_addr *maskp, unsigned int *naddrs);
154extern u_int16_t parse_protocol(const char *s);
Yasuyuki KOZAKAI9867e812005-06-22 12:24:21 +0000155extern void parse_interface(const char *arg, char *vianame, unsigned char *mask);
Marc Bouchere6869a82000-03-20 06:03:29 +0000156
157extern int do_command(int argc, char *argv[], char **table,
158 iptc_handle_t *handle);
159/* Keeping track of external matches and targets: linked lists. */
160extern struct iptables_match *iptables_matches;
161extern struct iptables_target *iptables_targets;
162
Rusty Russell79dee072000-05-02 16:45:16 +0000163enum ipt_tryload {
164 DONT_LOAD,
165 TRY_LOAD,
166 LOAD_MUST_SUCCEED
167};
168
169extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
Martin Josefsson78cafda2004-02-02 20:01:18 +0000170extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
Harald Weltea114e9e2000-12-01 14:28:19 +0000171
172extern int delete_chain(const ipt_chainlabel chain, int verbose,
173 iptc_handle_t *handle);
174extern int flush_entries(const ipt_chainlabel chain, int verbose,
175 iptc_handle_t *handle);
176extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
177 int verbose, int builtinstoo, iptc_handle_t *handle);
Marc Bouchere6869a82000-03-20 06:03:29 +0000178#endif /*_IPTABLES_USER_H*/