Merge branch 'collectd-4.10' into collectd-5.0
[collectd.git] / src / owniptc / xtables.h
1 /**
2  * This file was imported from the iptables sources.
3  * Copyright (C) 1999-2008 Netfilter Core Team
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; only version 2 of the License is applicable.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License along
15  * with this program; if not, write to the Free Software Foundation, Inc.,
16  * 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
17  */
18
19 #ifndef _XTABLES_H
20 #define _XTABLES_H
21
22 #include <sys/types.h>
23 #include <linux/types.h>
24 #include <linux/netfilter/x_tables.h>
25 #include "libxtc.h"
26 #include <stdbool.h>
27
28 #ifndef IPPROTO_SCTP
29 #define IPPROTO_SCTP 132
30 #endif
31 #ifndef IPPROTO_DCCP
32 #define IPPROTO_DCCP 33
33 #endif
34 #ifndef IPPROTO_UDPLITE
35 #define IPPROTO_UDPLITE 136
36 #endif
37
38 #define XTABLES_VERSION "1.4.1.1"
39 #define XTABLES_VERSION_CODE (0x10000 * 1 + 0x100 * 4 + 1)
40
41 #define XTABLES_API_VERSION(x,y,z)    (0x10000*(x) + 0x100*(y) + z)
42
43 /* Include file for additions: new matches and targets. */
44 struct xtables_match
45 {
46         struct xtables_match *next;
47
48         xt_chainlabel name;
49
50         /* Revision of match (0 by default). */
51         u_int8_t revision;
52
53         u_int16_t family;
54
55         const char *version;
56
57         /* Size of match data. */
58         size_t size;
59
60         /* Size of match data relevent for userspace comparison purposes */
61         size_t userspacesize;
62
63         /* Function which prints out usage message. */
64         void (*help)(void);
65
66         /* Initialize the match. */
67         void (*init)(struct xt_entry_match *m);
68
69         /* Function which parses command options; returns true if it
70            ate an option */
71         /* entry is struct ipt_entry for example */
72         int (*parse)(int c, char **argv, int invert, unsigned int *flags,
73                      const void *entry,
74                      struct xt_entry_match **match);
75
76         /* Final check; exit if not ok. */
77         void (*final_check)(unsigned int flags);
78
79         /* Prints out the match iff non-NULL: put space at end */
80         /* ip is struct ipt_ip * for example */
81         void (*print)(const void *ip,
82                       const struct xt_entry_match *match, int numeric);
83
84         /* Saves the match info in parsable form to stdout. */
85         /* ip is struct ipt_ip * for example */
86         void (*save)(const void *ip, const struct xt_entry_match *match);
87
88         /* Pointer to list of extra command-line options */
89         const struct option *extra_opts;
90
91         /* Ignore these men behind the curtain: */
92         unsigned int option_offset;
93         struct xt_entry_match *m;
94         unsigned int mflags;
95 #ifdef NO_SHARED_LIBS
96         unsigned int loaded; /* simulate loading so options are merged properly */
97 #endif
98 };
99
100 struct xtables_target
101 {
102         struct xtables_target *next;
103
104         xt_chainlabel name;
105
106         /* Revision of target (0 by default). */
107         u_int8_t revision;
108
109         u_int16_t family;
110
111         const char *version;
112
113         /* Size of target data. */
114         size_t size;
115
116         /* Size of target data relevent for userspace comparison purposes */
117         size_t userspacesize;
118
119         /* Function which prints out usage message. */
120         void (*help)(void);
121
122         /* Initialize the target. */
123         void (*init)(struct xt_entry_target *t);
124
125         /* Function which parses command options; returns true if it
126            ate an option */
127         /* entry is struct ipt_entry for example */
128         int (*parse)(int c, char **argv, int invert, unsigned int *flags,
129                      const void *entry,
130                      struct xt_entry_target **targetinfo);
131
132         /* Final check; exit if not ok. */
133         void (*final_check)(unsigned int flags);
134
135         /* Prints out the target iff non-NULL: put space at end */
136         void (*print)(const void *ip,
137                       const struct xt_entry_target *target, int numeric);
138
139         /* Saves the targinfo in parsable form to stdout. */
140         void (*save)(const void *ip,
141                      const struct xt_entry_target *target);
142
143         /* Pointer to list of extra command-line options */
144         const struct option *extra_opts;
145
146         /* Ignore these men behind the curtain: */
147         unsigned int option_offset;
148         struct xt_entry_target *t;
149         unsigned int tflags;
150         unsigned int used;
151 #ifdef NO_SHARED_LIBS
152         unsigned int loaded; /* simulate loading so options are merged properly */
153 #endif
154 };
155
156 /* Your shared library should call one of these. */
157 extern void xtables_register_match(struct xtables_match *me);
158 extern void xtables_register_target(struct xtables_target *me);
159
160 extern int string_to_number_ll(const char *s,
161                                unsigned long long min,
162                                unsigned long long max,
163                                unsigned long long *ret);
164 extern int string_to_number_l(const char *s,
165                               unsigned long min,
166                               unsigned long max,
167                               unsigned long *ret);
168 extern int string_to_number(const char *s,
169                             unsigned int min,
170                             unsigned int max,
171                             unsigned int *ret);
172 extern bool strtonuml(const char *, char **, unsigned long *,
173         unsigned long, unsigned long);
174 extern bool strtonum(const char *, char **, unsigned int *,
175         unsigned int, unsigned int);
176 extern int service_to_port(const char *name, const char *proto);
177 extern u_int16_t parse_port(const char *port, const char *proto);
178 extern void
179 parse_interface(const char *arg, char *vianame, unsigned char *mask);
180
181 enum exittype {
182         OTHER_PROBLEM = 1,
183         PARAMETER_PROBLEM,
184         VERSION_PROBLEM,
185         RESOURCE_PROBLEM,
186         P_ONLY_ONCE,
187         P_NO_INVERT,
188         P_BAD_VALUE,
189         P_ONE_ACTION,
190 };
191
192 /* this is a special 64bit data type that is 8-byte aligned */
193 #define aligned_u64 u_int64_t __attribute__((aligned(8)))
194
195 int check_inverse(const char option[], int *invert, int *my_optind, int argc);
196 void exit_error(enum exittype, const char *, ...)__attribute__((noreturn,
197                                                           format(printf,2,3)));
198 extern void param_act(unsigned int, const char *, ...);
199 extern const char *program_name, *program_version;
200
201 extern const char *ipaddr_to_numeric(const struct in_addr *);
202 extern const char *ipaddr_to_anyname(const struct in_addr *);
203 extern const char *ipmask_to_numeric(const struct in_addr *);
204 extern struct in_addr *numeric_to_ipaddr(const char *);
205 extern struct in_addr *numeric_to_ipmask(const char *);
206 extern void ipparse_hostnetworkmask(const char *, struct in_addr **,
207         struct in_addr *, unsigned int *);
208
209 extern struct in6_addr *numeric_to_ip6addr(const char *);
210 extern const char *ip6addr_to_numeric(const struct in6_addr *);
211 extern const char *ip6addr_to_anyname(const struct in6_addr *);
212 extern const char *ip6mask_to_numeric(const struct in6_addr *);
213 extern void ip6parse_hostnetworkmask(const char *, struct in6_addr **,
214         struct in6_addr *, unsigned int *);
215
216 /**
217  * Print the specified value to standard output, quoting dangerous
218  * characters if required.
219  */
220 extern void save_string(const char *value);
221
222 #ifdef NO_SHARED_LIBS
223 #       ifdef _INIT
224 #               undef _init
225 #               define _init _INIT
226 #       endif
227         extern void init_extensions(void);
228 #else
229 #       define _init __attribute__((constructor)) _INIT
230 #endif
231
232 /* Present in both iptables.c and ip6tables.c */
233 extern u_int16_t parse_protocol(const char *s);
234
235 #ifdef XTABLES_INTERNAL
236 #       include <xtables/internal.h>
237 #endif
238
239 #endif /* _XTABLES_H */