blob: e63d171e40a07dbed24e49a00143573e24957d6b [file] [log] [blame]
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +00001#ifndef _XTABLES_H
2#define _XTABLES_H
3
Jan Engelhardtef18e812008-08-04 12:47:48 +02004#include <sys/socket.h> /* PF_* */
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +00005#include <sys/types.h>
Jan Engelhardtef18e812008-08-04 12:47:48 +02006#include <stdbool.h>
Jan Engelhardt03d99482008-11-18 12:27:54 +01007#include <netinet/in.h>
Jan Engelhardtef18e812008-08-04 12:47:48 +02008#include <net/if.h>
Jan Engelhardt5e9eaed2007-12-17 13:12:01 +00009#include <linux/types.h>
Jan Engelhardt03d99482008-11-18 12:27:54 +010010#include <linux/netfilter.h>
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000011#include <linux/netfilter/x_tables.h>
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000012
Yasuyuki KOZAKAI5cd1ff52007-07-24 05:55:12 +000013#ifndef IPPROTO_SCTP
14#define IPPROTO_SCTP 132
15#endif
16#ifndef IPPROTO_DCCP
17#define IPPROTO_DCCP 33
18#endif
19#ifndef IPPROTO_UDPLITE
20#define IPPROTO_UDPLITE 136
21#endif
22
Jan Engelhardt493c7122008-04-15 11:15:16 +020023#define XTABLES_VERSION "@PACKAGE_VERSION@"
Thomas Jaroschc634cb92008-06-03 15:02:18 +020024#define XTABLES_VERSION_CODE (0x10000 * @XTABLES_VERSION_MAJOR@ + 0x100 * @XTABLES_VERSION_MINOR@ + @XTABLES_VERSION_PATCH@)
25
26#define XTABLES_API_VERSION(x,y,z) (0x10000*(x) + 0x100*(y) + z)
Jan Engelhardt493c7122008-04-15 11:15:16 +020027
Jan Engelhardtef18e812008-08-04 12:47:48 +020028struct in_addr;
29
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000030/* Include file for additions: new matches and targets. */
31struct xtables_match
32{
33 struct xtables_match *next;
34
Jan Engelhardtef18e812008-08-04 12:47:48 +020035 const char *name;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000036
37 /* Revision of match (0 by default). */
38 u_int8_t revision;
39
40 u_int16_t family;
41
42 const char *version;
43
44 /* Size of match data. */
45 size_t size;
46
47 /* Size of match data relevent for userspace comparison purposes */
48 size_t userspacesize;
49
50 /* Function which prints out usage message. */
51 void (*help)(void);
52
53 /* Initialize the match. */
Peter Rileyea146a92007-09-02 13:09:07 +000054 void (*init)(struct xt_entry_match *m);
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000055
56 /* Function which parses command options; returns true if it
57 ate an option */
58 /* entry is struct ipt_entry for example */
59 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
60 const void *entry,
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000061 struct xt_entry_match **match);
62
63 /* Final check; exit if not ok. */
64 void (*final_check)(unsigned int flags);
65
66 /* Prints out the match iff non-NULL: put space at end */
67 /* ip is struct ipt_ip * for example */
68 void (*print)(const void *ip,
69 const struct xt_entry_match *match, int numeric);
70
71 /* Saves the match info in parsable form to stdout. */
72 /* ip is struct ipt_ip * for example */
73 void (*save)(const void *ip, const struct xt_entry_match *match);
74
75 /* Pointer to list of extra command-line options */
76 const struct option *extra_opts;
77
78 /* Ignore these men behind the curtain: */
79 unsigned int option_offset;
80 struct xt_entry_match *m;
81 unsigned int mflags;
82#ifdef NO_SHARED_LIBS
83 unsigned int loaded; /* simulate loading so options are merged properly */
84#endif
85};
86
87struct xtables_target
88{
89 struct xtables_target *next;
90
Jan Engelhardtef18e812008-08-04 12:47:48 +020091 const char *name;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +000092
93 /* Revision of target (0 by default). */
94 u_int8_t revision;
95
96 u_int16_t family;
97
98 const char *version;
99
100 /* Size of target data. */
101 size_t size;
102
103 /* Size of target data relevent for userspace comparison purposes */
104 size_t userspacesize;
105
106 /* Function which prints out usage message. */
107 void (*help)(void);
108
109 /* Initialize the target. */
Peter Rileyea146a92007-09-02 13:09:07 +0000110 void (*init)(struct xt_entry_target *t);
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000111
112 /* Function which parses command options; returns true if it
113 ate an option */
114 /* entry is struct ipt_entry for example */
115 int (*parse)(int c, char **argv, int invert, unsigned int *flags,
116 const void *entry,
117 struct xt_entry_target **targetinfo);
118
119 /* Final check; exit if not ok. */
120 void (*final_check)(unsigned int flags);
121
122 /* Prints out the target iff non-NULL: put space at end */
123 void (*print)(const void *ip,
124 const struct xt_entry_target *target, int numeric);
125
126 /* Saves the targinfo in parsable form to stdout. */
127 void (*save)(const void *ip,
128 const struct xt_entry_target *target);
129
130 /* Pointer to list of extra command-line options */
Jan Engelhardt33653322007-07-30 13:20:43 +0000131 const struct option *extra_opts;
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000132
133 /* Ignore these men behind the curtain: */
134 unsigned int option_offset;
135 struct xt_entry_target *t;
136 unsigned int tflags;
137 unsigned int used;
138#ifdef NO_SHARED_LIBS
139 unsigned int loaded; /* simulate loading so options are merged properly */
140#endif
141};
142
Jan Engelhardt630ef482009-01-27 14:58:41 +0100143extern void *xtables_calloc(size_t, size_t);
144extern void *xtables_malloc(size_t);
145
Yasuyuki KOZAKAI0d502bc2007-07-24 05:52:07 +0000146/* Your shared library should call one of these. */
147extern void xtables_register_match(struct xtables_match *me);
148extern void xtables_register_target(struct xtables_target *me);
149
Yasuyuki KOZAKAI04f8c542007-07-24 05:53:48 +0000150extern int string_to_number_ll(const char *s,
151 unsigned long long min,
152 unsigned long long max,
153 unsigned long long *ret);
154extern int string_to_number_l(const char *s,
155 unsigned long min,
156 unsigned long max,
157 unsigned long *ret);
158extern int string_to_number(const char *s,
159 unsigned int min,
160 unsigned int max,
161 unsigned int *ret);
Jan Engelhardtcd9e7aa2008-01-20 13:18:54 +0000162extern bool strtonuml(const char *, char **, unsigned long *,
163 unsigned long, unsigned long);
164extern bool strtonum(const char *, char **, unsigned int *,
165 unsigned int, unsigned int);
Yasuyuki KOZAKAI04f8c542007-07-24 05:53:48 +0000166extern int service_to_port(const char *name, const char *proto);
167extern u_int16_t parse_port(const char *port, const char *proto);
168extern void
169parse_interface(const char *arg, char *vianame, unsigned char *mask);
170
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000171enum exittype {
172 OTHER_PROBLEM = 1,
173 PARAMETER_PROBLEM,
174 VERSION_PROBLEM,
Jan Engelhardtaafd2692008-01-20 13:19:40 +0000175 RESOURCE_PROBLEM,
176 P_ONLY_ONCE,
177 P_NO_INVERT,
178 P_BAD_VALUE,
179 P_ONE_ACTION,
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000180};
181
182/* this is a special 64bit data type that is 8-byte aligned */
Patrick McHardyc329d6a2007-09-05 14:19:23 +0000183#define aligned_u64 u_int64_t __attribute__((aligned(8)))
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000184
Jan Engelhardtdbb77542008-02-11 00:33:30 +0100185int check_inverse(const char option[], int *invert, int *my_optind, int argc);
Jan Engelhardtd8840512007-08-01 15:19:15 +0000186void exit_error(enum exittype, const char *, ...)__attribute__((noreturn,
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000187 format(printf,2,3)));
Jan Engelhardtaafd2692008-01-20 13:19:40 +0000188extern void param_act(unsigned int, const char *, ...);
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000189extern const char *program_name, *program_version;
190
Jan Engelhardt08b16162008-01-20 13:36:08 +0000191extern const char *ipaddr_to_numeric(const struct in_addr *);
192extern const char *ipaddr_to_anyname(const struct in_addr *);
193extern const char *ipmask_to_numeric(const struct in_addr *);
Jan Engelhardtbd943842008-01-20 13:38:08 +0000194extern struct in_addr *numeric_to_ipaddr(const char *);
195extern struct in_addr *numeric_to_ipmask(const char *);
196extern void ipparse_hostnetworkmask(const char *, struct in_addr **,
197 struct in_addr *, unsigned int *);
Jan Engelhardt08b16162008-01-20 13:36:08 +0000198
Jan Engelhardtbd943842008-01-20 13:38:08 +0000199extern struct in6_addr *numeric_to_ip6addr(const char *);
Jan Engelhardt08b16162008-01-20 13:36:08 +0000200extern const char *ip6addr_to_numeric(const struct in6_addr *);
201extern const char *ip6addr_to_anyname(const struct in6_addr *);
202extern const char *ip6mask_to_numeric(const struct in6_addr *);
Jan Engelhardtbd943842008-01-20 13:38:08 +0000203extern void ip6parse_hostnetworkmask(const char *, struct in6_addr **,
204 struct in6_addr *, unsigned int *);
Jan Engelhardt08b16162008-01-20 13:36:08 +0000205
Max Kellermanna5d09942008-01-29 13:44:34 +0000206/**
207 * Print the specified value to standard output, quoting dangerous
208 * characters if required.
209 */
210extern void save_string(const char *value);
211
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000212#ifdef NO_SHARED_LIBS
Jan Engelhardtf82070f2008-01-20 13:14:00 +0000213# ifdef _INIT
214# undef _init
215# define _init _INIT
216# endif
217 extern void init_extensions(void);
218#else
219# define _init __attribute__((constructor)) _INIT
Yasuyuki KOZAKAIa3732db2007-07-24 06:39:40 +0000220#endif
221
Jan Engelhardt33690a12008-02-11 00:54:00 +0100222/* Present in both iptables.c and ip6tables.c */
223extern u_int16_t parse_protocol(const char *s);
224
225#ifdef XTABLES_INTERNAL
226# include <xtables/internal.h>
227#endif
228
Yasuyuki KOZAKAI52088062007-07-24 05:44:11 +0000229#endif /* _XTABLES_H */