blob: 6b3b956ad81296bec5fb05713dff0c01a834c6ed [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
Patrick McHardy2452baf2006-04-28 08:10:08 +000014#ifndef IPPROTO_DCCP
15#define IPPROTO_DCCP 33
16#endif
Harald Weltedb0422f2004-03-04 07:45:30 +000017
Rusty Russell3aef54d2005-01-03 03:48:40 +000018#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
Martin Josefsson78cafda2004-02-02 20:01:18 +000030struct iptables_rule_match
31{
32 struct iptables_rule_match *next;
33
34 struct iptables_match *match;
Joszef Kadlecsika258ad72006-03-03 09:36:50 +000035
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;
Martin Josefsson78cafda2004-02-02 20:01:18 +000039};
40
Marc Bouchere6869a82000-03-20 06:03:29 +000041/* Include file for additions: new matches and targets. */
42struct iptables_match
43{
44 struct iptables_match *next;
45
46 ipt_chainlabel name;
47
Rusty Russell3aef54d2005-01-03 03:48:40 +000048 /* Revision of match (0 by default). */
49 u_int8_t revision;
50
Marc Bouchere6869a82000-03-20 06:03:29 +000051 const char *version;
52
53 /* Size of match data. */
54 size_t size;
55
Rusty Russelledf14cf2000-04-19 11:26:44 +000056 /* Size of match data relevent for userspace comparison purposes */
57 size_t userspacesize;
58
Marc Bouchere6869a82000-03-20 06:03:29 +000059 /* 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
Rusty Russell79dee072000-05-02 16:45:16 +000079 /* Saves the match info in parsable form to stdout. */
Marc Bouchere6869a82000-03-20 06:03:29 +000080 void (*save)(const struct ipt_ip *ip,
81 const struct ipt_entry_match *match);
82
83 /* Pointer to list of extra command-line options */
Jan Echternachb6db3312000-08-27 07:39:08 +000084 const struct option *extra_opts;
Marc Bouchere6869a82000-03-20 06:03:29 +000085
86 /* Ignore these men behind the curtain: */
87 unsigned int option_offset;
88 struct ipt_entry_match *m;
89 unsigned int mflags;
Harald Welte3efb6ea2001-08-06 18:50:21 +000090#ifdef NO_SHARED_LIBS
91 unsigned int loaded; /* simulate loading so options are merged properly */
92#endif
Marc Bouchere6869a82000-03-20 06:03:29 +000093};
94
95struct iptables_target
96{
97 struct iptables_target *next;
98
99 ipt_chainlabel name;
100
Rusty Russell3aef54d2005-01-03 03:48:40 +0000101 /* Revision of target (0 by default). */
102 u_int8_t revision;
103
Marc Bouchere6869a82000-03-20 06:03:29 +0000104 const char *version;
105
106 /* Size of target data. */
107 size_t size;
108
Rusty Russelledf14cf2000-04-19 11:26:44 +0000109 /* Size of target data relevent for userspace comparison purposes */
110 size_t userspacesize;
111
Marc Bouchere6869a82000-03-20 06:03:29 +0000112 /* 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;
Harald Weltea114e9e2000-12-01 14:28:19 +0000142 unsigned int used;
Harald Welte3efb6ea2001-08-06 18:50:21 +0000143#ifdef NO_SHARED_LIBS
144 unsigned int loaded; /* simulate loading so options are merged properly */
145#endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000146};
147
Illes Marci63e90632003-03-03 08:08:37 +0000148extern int line;
149
Marc Bouchere6869a82000-03-20 06:03:29 +0000150/* 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
Phil Oester58179b12006-07-20 17:00:19 +0000154extern int service_to_port(const char *name, const char *proto);
Phil Oesterdbac8ad2006-07-20 17:01:54 +0000155extern u_int16_t parse_port(const char *port, const char *proto);
Rusty Russell79dee072000-05-02 16:45:16 +0000156extern struct in_addr *dotted_to_addr(const char *dotted);
Pablo Neira Ayuso267a5702006-11-29 13:32:32 +0000157extern struct in_addr *dotted_to_mask(const char *dotted);
Marc Bouchere6869a82000-03-20 06:03:29 +0000158extern char *addr_to_dotted(const struct in_addr *addrp);
Marc Boucherb93c7982001-12-06 14:50:19 +0000159extern 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);
Yasuyuki KOZAKAI9867e812005-06-22 12:24:21 +0000165extern void parse_interface(const char *arg, char *vianame, unsigned char *mask);
Marc Bouchere6869a82000-03-20 06:03:29 +0000166
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
Rusty Russell79dee072000-05-02 16:45:16 +0000173enum ipt_tryload {
174 DONT_LOAD,
Jones Desougif5b86e62005-12-22 03:33:50 +0000175 DURING_LOAD,
Rusty Russell79dee072000-05-02 16:45:16 +0000176 TRY_LOAD,
177 LOAD_MUST_SUCCEED
178};
179
180extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
Martin Josefsson78cafda2004-02-02 20:01:18 +0000181extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
Harald Weltea114e9e2000-12-01 14:28:19 +0000182
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);
Phil Oester8cf65912005-09-19 15:00:33 +0000189
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
Marc Bouchere6869a82000-03-20 06:03:29 +0000198#endif /*_IPTABLES_USER_H*/