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