blob: 7eff5b235d3155a024cd3b26044bda186fddec5e [file] [log] [blame]
Bart De Schuymer1abc55d2002-06-01 19:23:47 +00001/*
2 * $Id: ebtables.c,v 1.03 2002/01/19
3 *
4 * Copyright (C) 2001-2002 Bart De Schuymer
5 *
6 * This code is stongly inspired on the iptables code which is
7 * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of the
12 * License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#ifndef EBTABLES_U_H
25#define EBTABLES_U_H
26#include <linux/netfilter_bridge/ebtables.h>
27#include <linux/br_db.h>
28
29struct ebt_u_entries
30{
Bart De Schuymer09765902002-06-23 08:15:51 +000031 int policy;
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000032 __u32 nentries;
Bart De Schuymer09765902002-06-23 08:15:51 +000033 // counter offset for this chain
34 unsigned int counter_offset;
35 // used for udc
36 unsigned int hook_mask;
37 char name[EBT_CHAIN_MAXNAMELEN];
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000038 struct ebt_u_entry *entries;
39};
40
Bart De Schuymer09765902002-06-23 08:15:51 +000041struct ebt_u_chain_list
42{
43 struct ebt_u_entries *udc;
44 struct ebt_u_chain_list *next;
45 // this is only used internally, in communications.c
46 char *kernel_start;
47};
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000048
49struct ebt_u_replace
50{
51 char name[EBT_TABLE_MAXNAMELEN];
52 unsigned int valid_hooks;
53 // nr of rules in the table
54 unsigned int nentries;
55 struct ebt_u_entries *hook_entry[NF_BR_NUMHOOKS];
Bart De Schuymer09765902002-06-23 08:15:51 +000056 // user defined chains (udc) list
57 struct ebt_u_chain_list *udc;
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000058 // nr of counters userspace expects back
59 unsigned int num_counters;
60 // where the kernel will put the old counters
61 struct ebt_counter *counters;
62 // can be used e.g. to know if a standard option
63 // has been specified twice
64 unsigned int flags;
65 // we stick the specified command (e.g. -A) in here
66 char command;
67 // here we stick the hook to do our thing on (can be -1 if unspecified)
68 int selected_hook;
Bart De Schuymer8330e892002-07-14 19:06:47 +000069 // used for the atomic option
70 char *filename;
Bart De Schuymer1abc55d2002-06-01 19:23:47 +000071};
72
73struct ebt_u_table
74{
75 char name[EBT_TABLE_MAXNAMELEN];
76 int (*check)(struct ebt_u_replace *repl);
77 void (*help)(char **);
78 struct ebt_u_table *next;
79};
80
81struct ebt_u_match_list
82{
83 struct ebt_u_match_list *next;
84 struct ebt_entry_match *m;
85};
86
87struct ebt_u_watcher_list
88{
89 struct ebt_u_watcher_list *next;
90 struct ebt_entry_watcher *w;
91};
92
93struct ebt_u_entry
94{
95 __u32 bitmask;
96 __u32 invflags;
97 __u16 ethproto;
98 __u8 in[IFNAMSIZ];
99 __u8 logical_in[IFNAMSIZ];
100 __u8 out[IFNAMSIZ];
101 __u8 logical_out[IFNAMSIZ];
102 __u8 sourcemac[ETH_ALEN];
103 __u8 sourcemsk[ETH_ALEN];
104 __u8 destmac[ETH_ALEN];
105 __u8 destmsk[ETH_ALEN];
106 struct ebt_u_match_list *m_list;
107 struct ebt_u_watcher_list *w_list;
108 struct ebt_entry_target *t;
109 struct ebt_u_entry *next;
110};
111
112struct ebt_u_match
113{
114 char name[EBT_FUNCTION_MAXNAMELEN];
115 // size of the real match data + sizeof struct ebt_match
116 unsigned int size;
117 void (*help)(void);
118 void (*init)(struct ebt_entry_match *m);
119 int (*parse)(int c, char **argv, int argc,
120 const struct ebt_u_entry *entry, unsigned int *flags,
121 struct ebt_entry_match **match);
122 void (*final_check)(const struct ebt_u_entry *entry,
123 const struct ebt_entry_match *match,
Bart De Schuymer7b9aaeb2002-06-23 20:38:34 +0000124 const char *name, unsigned int hook_mask, unsigned int time);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000125 void (*print)(const struct ebt_u_entry *entry,
126 const struct ebt_entry_match *match);
127 int (*compare)(const struct ebt_entry_match *m1,
128 const struct ebt_entry_match *m2);
129 const struct option *extra_ops;
130 // can be used e.g. to check for multiple occurance of the same option
131 unsigned int flags;
132 unsigned int option_offset;
133 struct ebt_entry_match *m;
134 // if used == 1 we no longer have to add it to
135 // the match chain of the new entry
136 unsigned int used;
137 struct ebt_u_match *next;
138};
139
140struct ebt_u_watcher
141{
142 char name[EBT_FUNCTION_MAXNAMELEN];
143 unsigned int size;
144 void (*help)(void);
145 void (*init)(struct ebt_entry_watcher *w);
146 int (*parse)(int c, char **argv, int argc,
147 const struct ebt_u_entry *entry, unsigned int *flags,
148 struct ebt_entry_watcher **watcher);
149 void (*final_check)(const struct ebt_u_entry *entry,
150 const struct ebt_entry_watcher *watch, const char *name,
Bart De Schuymer7b9aaeb2002-06-23 20:38:34 +0000151 unsigned int hook_mask, unsigned int time);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000152 void (*print)(const struct ebt_u_entry *entry,
153 const struct ebt_entry_watcher *watcher);
154 int (*compare)(const struct ebt_entry_watcher *w1,
155 const struct ebt_entry_watcher *w2);
156 const struct option *extra_ops;
157 unsigned int flags;
158 unsigned int option_offset;
159 struct ebt_entry_watcher *w;
160 unsigned int used;
161 struct ebt_u_watcher *next;
162};
163
164struct ebt_u_target
165{
166 char name[EBT_FUNCTION_MAXNAMELEN];
167 unsigned int size;
168 void (*help)(void);
169 void (*init)(struct ebt_entry_target *t);
170 int (*parse)(int c, char **argv, int argc,
171 const struct ebt_u_entry *entry, unsigned int *flags,
172 struct ebt_entry_target **target);
173 void (*final_check)(const struct ebt_u_entry *entry,
174 const struct ebt_entry_target *target, const char *name,
Bart De Schuymer7b9aaeb2002-06-23 20:38:34 +0000175 unsigned int hook_mask, unsigned int time);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000176 void (*print)(const struct ebt_u_entry *entry,
177 const struct ebt_entry_target *target);
178 int (*compare)(const struct ebt_entry_target *t1,
179 const struct ebt_entry_target *t2);
180 const struct option *extra_ops;
181 unsigned int option_offset;
182 unsigned int flags;
183 struct ebt_entry_target *t;
184 unsigned int used;
185 struct ebt_u_target *next;
186};
187
188void register_table(struct ebt_u_table *);
189void register_match(struct ebt_u_match *);
190void register_watcher(struct ebt_u_watcher *);
191void register_target(struct ebt_u_target *t);
Bart De Schuymer9ce6ee92002-06-14 21:56:35 +0000192int get_table(struct ebt_u_replace *repl);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000193struct ebt_u_target *find_target(const char *name);
194struct ebt_u_match *find_match(const char *name);
195struct ebt_u_watcher *find_watcher(const char *name);
Bart De Schuymer8330e892002-07-14 19:06:47 +0000196struct ebt_u_table *find_table(char *name);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000197void deliver_counters(struct ebt_u_replace *repl,
198 unsigned short * counterchanges);
199void deliver_table(struct ebt_u_replace *repl);
200void get_dbinfo(struct brdb_dbinfo *nr);
201void get_db(int len, struct brdb_dbentry *db);
202void deliver_allowdb(__u16 *decision);
Bart De Schuymer28bf6f62002-06-26 18:57:24 +0000203int name_to_number(char *name, __u16 *proto);
fnm384532742002-06-25 16:39:46 +0000204int number_to_name(unsigned short proto, char *name);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000205void check_option(unsigned int *flags, unsigned int mask);
206int check_inverse(const char option[]);
207#define print_bug(format, args...) \
208 {printf("BUG: "format".\n", ##args); exit(-1);}
209#define print_error(format, args...) {printf(format".\n", ##args); exit(-1);}
210#define print_memory() {printf("Ebtables: " __FILE__ " " __FUNCTION__ \
211 " %d :Out of memory.\n", __LINE__); exit(-1);}
212
213
214
215// used for keeping the rule counters right during rule adds or deletes
216#define CNT_NORM 0
217#define CNT_DEL 1
218#define CNT_ADD 2
219#define CNT_END 3
220#define CNT_ZERO 4
221
222#endif /* EBTABLES_U_H */