blob: 719db54465c1b98c94f588e5ea3c6747014c02cf [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
7/* Include file for additions: new matches and targets. */
8struct iptables_match
9{
10 struct iptables_match *next;
11
12 ipt_chainlabel name;
13
14 const char *version;
15
16 /* Size of match data. */
17 size_t size;
18
Rusty Russelledf14cf2000-04-19 11:26:44 +000019 /* Size of match data relevent for userspace comparison purposes */
20 size_t userspacesize;
21
Marc Bouchere6869a82000-03-20 06:03:29 +000022 /* Function which prints out usage message. */
23 void (*help)(void);
24
25 /* Initialize the match. */
26 void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
27
28 /* Function which parses command options; returns true if it
29 ate an option */
30 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
31 const struct ipt_entry *entry,
32 unsigned int *nfcache,
33 struct ipt_entry_match **match);
34
35 /* Final check; exit if not ok. */
36 void (*final_check)(unsigned int flags);
37
38 /* Prints out the match iff non-NULL: put space at end */
39 void (*print)(const struct ipt_ip *ip,
40 const struct ipt_entry_match *match, int numeric);
41
Rusty Russell79dee072000-05-02 16:45:16 +000042 /* Saves the match info in parsable form to stdout. */
Marc Bouchere6869a82000-03-20 06:03:29 +000043 void (*save)(const struct ipt_ip *ip,
44 const struct ipt_entry_match *match);
45
46 /* Pointer to list of extra command-line options */
Jan Echternachb6db3312000-08-27 07:39:08 +000047 const struct option *extra_opts;
Marc Bouchere6869a82000-03-20 06:03:29 +000048
49 /* Ignore these men behind the curtain: */
50 unsigned int option_offset;
51 struct ipt_entry_match *m;
52 unsigned int mflags;
Harald Weltea114e9e2000-12-01 14:28:19 +000053 unsigned int used;
Marc Bouchere6869a82000-03-20 06:03:29 +000054};
55
56struct iptables_target
57{
58 struct iptables_target *next;
59
60 ipt_chainlabel name;
61
62 const char *version;
63
64 /* Size of target data. */
65 size_t size;
66
Rusty Russelledf14cf2000-04-19 11:26:44 +000067 /* Size of target data relevent for userspace comparison purposes */
68 size_t userspacesize;
69
Marc Bouchere6869a82000-03-20 06:03:29 +000070 /* Function which prints out usage message. */
71 void (*help)(void);
72
73 /* Initialize the target. */
74 void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
75
76 /* Function which parses command options; returns true if it
77 ate an option */
78 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
79 const struct ipt_entry *entry,
80 struct ipt_entry_target **target);
81
82 /* Final check; exit if not ok. */
83 void (*final_check)(unsigned int flags);
84
85 /* Prints out the target iff non-NULL: put space at end */
86 void (*print)(const struct ipt_ip *ip,
87 const struct ipt_entry_target *target, int numeric);
88
89 /* Saves the targinfo in parsable form to stdout. */
90 void (*save)(const struct ipt_ip *ip,
91 const struct ipt_entry_target *target);
92
93 /* Pointer to list of extra command-line options */
94 struct option *extra_opts;
95
96 /* Ignore these men behind the curtain: */
97 unsigned int option_offset;
98 struct ipt_entry_target *t;
99 unsigned int tflags;
Harald Weltea114e9e2000-12-01 14:28:19 +0000100 unsigned int used;
Marc Bouchere6869a82000-03-20 06:03:29 +0000101};
102
103/* Your shared library should call one of these. */
104extern void register_match(struct iptables_match *me);
105extern void register_target(struct iptables_target *me);
106
Rusty Russell79dee072000-05-02 16:45:16 +0000107extern struct in_addr *dotted_to_addr(const char *dotted);
Marc Bouchere6869a82000-03-20 06:03:29 +0000108extern char *addr_to_dotted(const struct in_addr *addrp);
Marc Bouchere6869a82000-03-20 06:03:29 +0000109
110extern int do_command(int argc, char *argv[], char **table,
111 iptc_handle_t *handle);
112/* Keeping track of external matches and targets: linked lists. */
113extern struct iptables_match *iptables_matches;
114extern struct iptables_target *iptables_targets;
115
Rusty Russell79dee072000-05-02 16:45:16 +0000116enum ipt_tryload {
117 DONT_LOAD,
118 TRY_LOAD,
119 LOAD_MUST_SUCCEED
120};
121
122extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
123extern struct iptables_match *find_match(const char *name, enum ipt_tryload);
Harald Weltea114e9e2000-12-01 14:28:19 +0000124
125extern int delete_chain(const ipt_chainlabel chain, int verbose,
126 iptc_handle_t *handle);
127extern int flush_entries(const ipt_chainlabel chain, int verbose,
128 iptc_handle_t *handle);
129extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
130 int verbose, int builtinstoo, iptc_handle_t *handle);
Marc Bouchere6869a82000-03-20 06:03:29 +0000131#endif /*_IPTABLES_USER_H*/