blob: 4c4168baca920d65af5087810fc5f86e51cf3317 [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;
69};
70
71struct ebt_u_table
72{
73 char name[EBT_TABLE_MAXNAMELEN];
74 int (*check)(struct ebt_u_replace *repl);
75 void (*help)(char **);
76 struct ebt_u_table *next;
77};
78
79struct ebt_u_match_list
80{
81 struct ebt_u_match_list *next;
82 struct ebt_entry_match *m;
83};
84
85struct ebt_u_watcher_list
86{
87 struct ebt_u_watcher_list *next;
88 struct ebt_entry_watcher *w;
89};
90
91struct ebt_u_entry
92{
93 __u32 bitmask;
94 __u32 invflags;
95 __u16 ethproto;
96 __u8 in[IFNAMSIZ];
97 __u8 logical_in[IFNAMSIZ];
98 __u8 out[IFNAMSIZ];
99 __u8 logical_out[IFNAMSIZ];
100 __u8 sourcemac[ETH_ALEN];
101 __u8 sourcemsk[ETH_ALEN];
102 __u8 destmac[ETH_ALEN];
103 __u8 destmsk[ETH_ALEN];
104 struct ebt_u_match_list *m_list;
105 struct ebt_u_watcher_list *w_list;
106 struct ebt_entry_target *t;
107 struct ebt_u_entry *next;
108};
109
110struct ebt_u_match
111{
112 char name[EBT_FUNCTION_MAXNAMELEN];
113 // size of the real match data + sizeof struct ebt_match
114 unsigned int size;
115 void (*help)(void);
116 void (*init)(struct ebt_entry_match *m);
117 int (*parse)(int c, char **argv, int argc,
118 const struct ebt_u_entry *entry, unsigned int *flags,
119 struct ebt_entry_match **match);
120 void (*final_check)(const struct ebt_u_entry *entry,
121 const struct ebt_entry_match *match,
Bart De Schuymer09765902002-06-23 08:15:51 +0000122 const char *name, unsigned int hook_mask);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000123 void (*print)(const struct ebt_u_entry *entry,
124 const struct ebt_entry_match *match);
125 int (*compare)(const struct ebt_entry_match *m1,
126 const struct ebt_entry_match *m2);
127 const struct option *extra_ops;
128 // can be used e.g. to check for multiple occurance of the same option
129 unsigned int flags;
130 unsigned int option_offset;
131 struct ebt_entry_match *m;
132 // if used == 1 we no longer have to add it to
133 // the match chain of the new entry
134 unsigned int used;
135 struct ebt_u_match *next;
136};
137
138struct ebt_u_watcher
139{
140 char name[EBT_FUNCTION_MAXNAMELEN];
141 unsigned int size;
142 void (*help)(void);
143 void (*init)(struct ebt_entry_watcher *w);
144 int (*parse)(int c, char **argv, int argc,
145 const struct ebt_u_entry *entry, unsigned int *flags,
146 struct ebt_entry_watcher **watcher);
147 void (*final_check)(const struct ebt_u_entry *entry,
148 const struct ebt_entry_watcher *watch, const char *name,
Bart De Schuymer09765902002-06-23 08:15:51 +0000149 unsigned int hook_mask);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000150 void (*print)(const struct ebt_u_entry *entry,
151 const struct ebt_entry_watcher *watcher);
152 int (*compare)(const struct ebt_entry_watcher *w1,
153 const struct ebt_entry_watcher *w2);
154 const struct option *extra_ops;
155 unsigned int flags;
156 unsigned int option_offset;
157 struct ebt_entry_watcher *w;
158 unsigned int used;
159 struct ebt_u_watcher *next;
160};
161
162struct ebt_u_target
163{
164 char name[EBT_FUNCTION_MAXNAMELEN];
165 unsigned int size;
166 void (*help)(void);
167 void (*init)(struct ebt_entry_target *t);
168 int (*parse)(int c, char **argv, int argc,
169 const struct ebt_u_entry *entry, unsigned int *flags,
170 struct ebt_entry_target **target);
171 void (*final_check)(const struct ebt_u_entry *entry,
172 const struct ebt_entry_target *target, const char *name,
Bart De Schuymer09765902002-06-23 08:15:51 +0000173 unsigned int hook_mask);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000174 void (*print)(const struct ebt_u_entry *entry,
175 const struct ebt_entry_target *target);
176 int (*compare)(const struct ebt_entry_target *t1,
177 const struct ebt_entry_target *t2);
178 const struct option *extra_ops;
179 unsigned int option_offset;
180 unsigned int flags;
181 struct ebt_entry_target *t;
182 unsigned int used;
183 struct ebt_u_target *next;
184};
185
186void register_table(struct ebt_u_table *);
187void register_match(struct ebt_u_match *);
188void register_watcher(struct ebt_u_watcher *);
189void register_target(struct ebt_u_target *t);
Bart De Schuymer9ce6ee92002-06-14 21:56:35 +0000190int get_table(struct ebt_u_replace *repl);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000191struct ebt_u_target *find_target(const char *name);
192struct ebt_u_match *find_match(const char *name);
193struct ebt_u_watcher *find_watcher(const char *name);
194void deliver_counters(struct ebt_u_replace *repl,
195 unsigned short * counterchanges);
196void deliver_table(struct ebt_u_replace *repl);
197void get_dbinfo(struct brdb_dbinfo *nr);
198void get_db(int len, struct brdb_dbentry *db);
199void deliver_allowdb(__u16 *decision);
Bart De Schuymere2ac8a82002-06-03 16:29:12 +0000200int name_to_protocol(char *name);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000201void check_option(unsigned int *flags, unsigned int mask);
202int check_inverse(const char option[]);
203#define print_bug(format, args...) \
204 {printf("BUG: "format".\n", ##args); exit(-1);}
205#define print_error(format, args...) {printf(format".\n", ##args); exit(-1);}
206#define print_memory() {printf("Ebtables: " __FILE__ " " __FUNCTION__ \
207 " %d :Out of memory.\n", __LINE__); exit(-1);}
208
209
210
211// used for keeping the rule counters right during rule adds or deletes
212#define CNT_NORM 0
213#define CNT_DEL 1
214#define CNT_ADD 2
215#define CNT_END 3
216#define CNT_ZERO 4
217
218#endif /* EBTABLES_U_H */