blob: 5aca69a6a0a9ba31874fb8c0681e20e04b403ef4 [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
Harald Weltedb0422f2004-03-04 07:45:30 +00007#ifndef IPPROTO_SCTP
8#define IPPROTO_SCTP 132
9#endif
10
Martin Josefsson78cafda2004-02-02 20:01:18 +000011struct iptables_rule_match
12{
13 struct iptables_rule_match *next;
14
15 struct iptables_match *match;
16};
17
Marc Bouchere6869a82000-03-20 06:03:29 +000018/* Include file for additions: new matches and targets. */
19struct iptables_match
20{
21 struct iptables_match *next;
22
23 ipt_chainlabel name;
24
25 const char *version;
26
27 /* Size of match data. */
28 size_t size;
29
Rusty Russelledf14cf2000-04-19 11:26:44 +000030 /* Size of match data relevent for userspace comparison purposes */
31 size_t userspacesize;
32
Marc Bouchere6869a82000-03-20 06:03:29 +000033 /* Function which prints out usage message. */
34 void (*help)(void);
35
36 /* Initialize the match. */
37 void (*init)(struct ipt_entry_match *m, unsigned int *nfcache);
38
39 /* Function which parses command options; returns true if it
40 ate an option */
41 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
42 const struct ipt_entry *entry,
43 unsigned int *nfcache,
44 struct ipt_entry_match **match);
45
46 /* Final check; exit if not ok. */
47 void (*final_check)(unsigned int flags);
48
49 /* Prints out the match iff non-NULL: put space at end */
50 void (*print)(const struct ipt_ip *ip,
51 const struct ipt_entry_match *match, int numeric);
52
Rusty Russell79dee072000-05-02 16:45:16 +000053 /* Saves the match info in parsable form to stdout. */
Marc Bouchere6869a82000-03-20 06:03:29 +000054 void (*save)(const struct ipt_ip *ip,
55 const struct ipt_entry_match *match);
56
57 /* Pointer to list of extra command-line options */
Jan Echternachb6db3312000-08-27 07:39:08 +000058 const struct option *extra_opts;
Marc Bouchere6869a82000-03-20 06:03:29 +000059
60 /* Ignore these men behind the curtain: */
61 unsigned int option_offset;
62 struct ipt_entry_match *m;
63 unsigned int mflags;
Harald Welte3efb6ea2001-08-06 18:50:21 +000064#ifdef NO_SHARED_LIBS
65 unsigned int loaded; /* simulate loading so options are merged properly */
66#endif
Marc Bouchere6869a82000-03-20 06:03:29 +000067};
68
69struct iptables_target
70{
71 struct iptables_target *next;
72
73 ipt_chainlabel name;
74
75 const char *version;
76
77 /* Size of target data. */
78 size_t size;
79
Rusty Russelledf14cf2000-04-19 11:26:44 +000080 /* Size of target data relevent for userspace comparison purposes */
81 size_t userspacesize;
82
Marc Bouchere6869a82000-03-20 06:03:29 +000083 /* Function which prints out usage message. */
84 void (*help)(void);
85
86 /* Initialize the target. */
87 void (*init)(struct ipt_entry_target *t, unsigned int *nfcache);
88
89 /* Function which parses command options; returns true if it
90 ate an option */
91 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
92 const struct ipt_entry *entry,
93 struct ipt_entry_target **target);
94
95 /* Final check; exit if not ok. */
96 void (*final_check)(unsigned int flags);
97
98 /* Prints out the target iff non-NULL: put space at end */
99 void (*print)(const struct ipt_ip *ip,
100 const struct ipt_entry_target *target, int numeric);
101
102 /* Saves the targinfo in parsable form to stdout. */
103 void (*save)(const struct ipt_ip *ip,
104 const struct ipt_entry_target *target);
105
106 /* Pointer to list of extra command-line options */
107 struct option *extra_opts;
108
109 /* Ignore these men behind the curtain: */
110 unsigned int option_offset;
111 struct ipt_entry_target *t;
112 unsigned int tflags;
Harald Weltea114e9e2000-12-01 14:28:19 +0000113 unsigned int used;
Harald Welte3efb6ea2001-08-06 18:50:21 +0000114#ifdef NO_SHARED_LIBS
115 unsigned int loaded; /* simulate loading so options are merged properly */
116#endif
Marc Bouchere6869a82000-03-20 06:03:29 +0000117};
118
Illes Marci63e90632003-03-03 08:08:37 +0000119extern int line;
120
Marc Bouchere6869a82000-03-20 06:03:29 +0000121/* Your shared library should call one of these. */
122extern void register_match(struct iptables_match *me);
123extern void register_target(struct iptables_target *me);
124
Rusty Russell79dee072000-05-02 16:45:16 +0000125extern struct in_addr *dotted_to_addr(const char *dotted);
Marc Bouchere6869a82000-03-20 06:03:29 +0000126extern char *addr_to_dotted(const struct in_addr *addrp);
Marc Boucherb93c7982001-12-06 14:50:19 +0000127extern char *addr_to_anyname(const struct in_addr *addr);
128extern char *mask_to_dotted(const struct in_addr *mask);
129
130extern void parse_hostnetworkmask(const char *name, struct in_addr **addrpp,
131 struct in_addr *maskp, unsigned int *naddrs);
132extern u_int16_t parse_protocol(const char *s);
Marc Bouchere6869a82000-03-20 06:03:29 +0000133
134extern int do_command(int argc, char *argv[], char **table,
135 iptc_handle_t *handle);
136/* Keeping track of external matches and targets: linked lists. */
137extern struct iptables_match *iptables_matches;
138extern struct iptables_target *iptables_targets;
139
Rusty Russell79dee072000-05-02 16:45:16 +0000140enum ipt_tryload {
141 DONT_LOAD,
142 TRY_LOAD,
143 LOAD_MUST_SUCCEED
144};
145
146extern struct iptables_target *find_target(const char *name, enum ipt_tryload);
Martin Josefsson78cafda2004-02-02 20:01:18 +0000147extern struct iptables_match *find_match(const char *name, enum ipt_tryload, struct iptables_rule_match **match);
Harald Weltea114e9e2000-12-01 14:28:19 +0000148
149extern int delete_chain(const ipt_chainlabel chain, int verbose,
150 iptc_handle_t *handle);
151extern int flush_entries(const ipt_chainlabel chain, int verbose,
152 iptc_handle_t *handle);
153extern int for_each_chain(int (*fn)(const ipt_chainlabel, int, iptc_handle_t *),
154 int verbose, int builtinstoo, iptc_handle_t *handle);
Marc Bouchere6869a82000-03-20 06:03:29 +0000155#endif /*_IPTABLES_USER_H*/