blob: a0dda602223c3d6965ed21fda35cef1e9d37ae35 [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 Josefsson78cafda2004-02-02 20:01:18 +00007struct iptables_rule_match
8{
9 struct iptables_rule_match *next;
10
11 struct iptables_match *match;
12};
13
Marc Bouchere6869a82000-03-20 06:03:29 +000014/* Include file for additions: new matches and targets. */
15struct iptables_match
16{
17 struct iptables_match *next;
18
19 ipt_chainlabel name;
20
21 const char *version;
22
23 /* Size of match data. */
24 size_t size;
25
Rusty Russelledf14cf2000-04-19 11:26:44 +000026 /* Size of match data relevent for userspace comparison purposes */
27 size_t userspacesize;
28
Marc Bouchere6869a82000-03-20 06:03:29 +000029 /* Function which prints out usage message. */
30 void (*help)(void);
31
32 /* Initialize the match. */
33 void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
34
35 /* Function which parses command options; returns true if it
36 ate an option */
37 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
38 const struct ipt_entry *entry,
39 unsigned int *nfcache,
40 struct ipt_entry_match **match);
41
42 /* Final check; exit if not ok. */
43 void (*final_check)(unsigned int flags);
44
45 /* Prints out the match iff non-NULL: put space at end */
46 void (*print)(const struct ipt_ip *ip,
47 const struct ipt_entry_match *match, int numeric);
48
Rusty Russell79dee072000-05-02 16:45:16 +000049 /* Saves the match info in parsable form to stdout. */
Marc Bouchere6869a82000-03-20 06:03:29 +000050 void (*save)(const struct ipt_ip *ip,
51 const struct ipt_entry_match *match);
52
53 /* Pointer to list of extra command-line options */
Jan Echternachb6db3312000-08-27 07:39:08 +000054 const struct option *extra_opts;
Marc Bouchere6869a82000-03-20 06:03:29 +000055
56 /* Ignore these men behind the curtain: */
57 unsigned int option_offset;
58 struct ipt_entry_match *m;
59 unsigned int mflags;
Harald Welte3efb6ea2001-08-06 18:50:21 +000060#ifdef NO_SHARED_LIBS
61 unsigned int loaded; /* simulate loading so options are merged properly */
62#endif
Marc Bouchere6869a82000-03-20 06:03:29 +000063};
64
65struct iptables_target
66{
67 struct iptables_target *next;
68
69 ipt_chainlabel name;
70
71 const char *version;
72
73 /* Size of target data. */
74 size_t size;
75
Rusty Russelledf14cf2000-04-19 11:26:44 +000076 /* Size of target data relevent for userspace comparison purposes */
77 size_t userspacesize;
78
Marc Bouchere6869a82000-03-20 06:03:29 +000079 /* Function which prints out usage message. */
80 void (*help)(void);
81
82 /* Initialize the target. */
83 void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
84
85 /* Function which parses command options; returns true if it
86 ate an option */
87 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
88 const struct ipt_entry *entry,
89 struct ipt_entry_target **target);
90
91 /* Final check; exit if not ok. */
92 void (*final_check)(unsigned int flags);
93
94 /* Prints out the target iff non-NULL: put space at end */
95 void (*print)(const struct ipt_ip *ip,
96 const struct ipt_entry_target *target, int numeric);
97
98 /* Saves the targinfo in parsable form to stdout. */
99 void (*save)(const struct ipt_ip *ip,
100 const struct ipt_entry_target *target);
101
102 /* Pointer to list of extra command-line options */
103 struct option *extra_opts;
104
105 /* Ignore these men behind the curtain: */
106 unsigned int option_offset;
107 struct ipt_entry_target *t;
108 unsigned int tflags;
Harald Weltea114e9e2000-12-01 14:28:19 +0000109 unsigned int used;
Harald Welte3efb6ea2001-08-06 18:50:21 +0000110#ifdef NO_SHARED_LIBS
111 unsigned int loaded; /* simulate loading so options are merged properly */
112#endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000113};
114
Illes Marci63e90632003-03-03 08:08:37 +0000115extern int line;
116
Marc Bouchere6869a82000-03-20 06:03:29 +0000117/* Your shared library should call one of these. */
118extern void register_match(struct iptables_match *me);
119extern void register_target(struct iptables_target *me);
120
Rusty Russell79dee072000-05-02 16:45:16 +0000121extern struct in_addr *dotted_to_addr(const char *dotted);
Marc Bouchere6869a82000-03-20 06:03:29 +0000122extern char *addr_to_dotted(const struct in_addr *addrp);
Marc Boucherb93c7982001-12-06 14:50:19 +0000123extern char *addr_to_anyname(const struct in_addr *addr);
124extern char *mask_to_dotted(const struct in_addr *mask);
125
126extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
127 struct in_addr *maskp, unsigned int *naddrs);
128extern u_int16_t parse_protocol(const char *s);
Marc Bouchere6869a82000-03-20 06:03:29 +0000129
130extern int do_command(int argc, char *argv[], char **table,
131 iptc_handle_t *handle);
132/* Keeping track of external matches and targets: linked lists. */
133extern struct iptables_match *iptables_matches;
134extern struct iptables_target *iptables_targets;
135
Rusty Russell79dee072000-05-02 16:45:16 +0000136enum ipt_tryload {
137 DONT_LOAD,
138 TRY_LOAD,
139 LOAD_MUST_SUCCEED
140};
141
142extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
Martin Josefsson78cafda2004-02-02 20:01:18 +0000143extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
Harald Weltea114e9e2000-12-01 14:28:19 +0000144
145extern int delete_chain(const ipt_chainlabel chain, int verbose,
146 iptc_handle_t *handle);
147extern int flush_entries(const ipt_chainlabel chain, int verbose,
148 iptc_handle_t *handle);
149extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
150 int verbose, int builtinstoo, iptc_handle_t *handle);
Marc Bouchere6869a82000-03-20 06:03:29 +0000151#endif /*_IPTABLES_USER_H*/