blob: 781c4b0decbb141dd4a204cb1d84c31b2ea738db [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{
31 __u8 policy;
32 __u32 nentries;
33 struct ebt_u_entry *entries;
34};
35
36
37struct ebt_u_replace
38{
39 char name[EBT_TABLE_MAXNAMELEN];
40 unsigned int valid_hooks;
41 // nr of rules in the table
42 unsigned int nentries;
43 struct ebt_u_entries *hook_entry[NF_BR_NUMHOOKS];
44 // how many counters in front of it?
45 unsigned int counter_entry[NF_BR_NUMHOOKS];
46 // nr of counters userspace expects back
47 unsigned int num_counters;
48 // where the kernel will put the old counters
49 struct ebt_counter *counters;
50 // can be used e.g. to know if a standard option
51 // has been specified twice
52 unsigned int flags;
53 // we stick the specified command (e.g. -A) in here
54 char command;
55 // here we stick the hook to do our thing on (can be -1 if unspecified)
56 int selected_hook;
57};
58
59struct ebt_u_table
60{
61 char name[EBT_TABLE_MAXNAMELEN];
62 int (*check)(struct ebt_u_replace *repl);
63 void (*help)(char **);
64 struct ebt_u_table *next;
65};
66
67struct ebt_u_match_list
68{
69 struct ebt_u_match_list *next;
70 struct ebt_entry_match *m;
71};
72
73struct ebt_u_watcher_list
74{
75 struct ebt_u_watcher_list *next;
76 struct ebt_entry_watcher *w;
77};
78
79struct ebt_u_entry
80{
81 __u32 bitmask;
82 __u32 invflags;
83 __u16 ethproto;
84 __u8 in[IFNAMSIZ];
85 __u8 logical_in[IFNAMSIZ];
86 __u8 out[IFNAMSIZ];
87 __u8 logical_out[IFNAMSIZ];
88 __u8 sourcemac[ETH_ALEN];
89 __u8 sourcemsk[ETH_ALEN];
90 __u8 destmac[ETH_ALEN];
91 __u8 destmsk[ETH_ALEN];
92 struct ebt_u_match_list *m_list;
93 struct ebt_u_watcher_list *w_list;
94 struct ebt_entry_target *t;
95 struct ebt_u_entry *next;
96};
97
98struct ebt_u_match
99{
100 char name[EBT_FUNCTION_MAXNAMELEN];
101 // size of the real match data + sizeof struct ebt_match
102 unsigned int size;
103 void (*help)(void);
104 void (*init)(struct ebt_entry_match *m);
105 int (*parse)(int c, char **argv, int argc,
106 const struct ebt_u_entry *entry, unsigned int *flags,
107 struct ebt_entry_match **match);
108 void (*final_check)(const struct ebt_u_entry *entry,
109 const struct ebt_entry_match *match,
110 const char *name, unsigned int hook);
111 void (*print)(const struct ebt_u_entry *entry,
112 const struct ebt_entry_match *match);
113 int (*compare)(const struct ebt_entry_match *m1,
114 const struct ebt_entry_match *m2);
115 const struct option *extra_ops;
116 // can be used e.g. to check for multiple occurance of the same option
117 unsigned int flags;
118 unsigned int option_offset;
119 struct ebt_entry_match *m;
120 // if used == 1 we no longer have to add it to
121 // the match chain of the new entry
122 unsigned int used;
123 struct ebt_u_match *next;
124};
125
126struct ebt_u_watcher
127{
128 char name[EBT_FUNCTION_MAXNAMELEN];
129 unsigned int size;
130 void (*help)(void);
131 void (*init)(struct ebt_entry_watcher *w);
132 int (*parse)(int c, char **argv, int argc,
133 const struct ebt_u_entry *entry, unsigned int *flags,
134 struct ebt_entry_watcher **watcher);
135 void (*final_check)(const struct ebt_u_entry *entry,
136 const struct ebt_entry_watcher *watch, const char *name,
137 unsigned int hook);
138 void (*print)(const struct ebt_u_entry *entry,
139 const struct ebt_entry_watcher *watcher);
140 int (*compare)(const struct ebt_entry_watcher *w1,
141 const struct ebt_entry_watcher *w2);
142 const struct option *extra_ops;
143 unsigned int flags;
144 unsigned int option_offset;
145 struct ebt_entry_watcher *w;
146 unsigned int used;
147 struct ebt_u_watcher *next;
148};
149
150struct ebt_u_target
151{
152 char name[EBT_FUNCTION_MAXNAMELEN];
153 unsigned int size;
154 void (*help)(void);
155 void (*init)(struct ebt_entry_target *t);
156 int (*parse)(int c, char **argv, int argc,
157 const struct ebt_u_entry *entry, unsigned int *flags,
158 struct ebt_entry_target **target);
159 void (*final_check)(const struct ebt_u_entry *entry,
160 const struct ebt_entry_target *target, const char *name,
161 unsigned int hook);
162 void (*print)(const struct ebt_u_entry *entry,
163 const struct ebt_entry_target *target);
164 int (*compare)(const struct ebt_entry_target *t1,
165 const struct ebt_entry_target *t2);
166 const struct option *extra_ops;
167 unsigned int option_offset;
168 unsigned int flags;
169 struct ebt_entry_target *t;
170 unsigned int used;
171 struct ebt_u_target *next;
172};
173
174void register_table(struct ebt_u_table *);
175void register_match(struct ebt_u_match *);
176void register_watcher(struct ebt_u_watcher *);
177void register_target(struct ebt_u_target *t);
178void get_table(struct ebt_u_replace *repl);
179struct ebt_u_target *find_target(const char *name);
180struct ebt_u_match *find_match(const char *name);
181struct ebt_u_watcher *find_watcher(const char *name);
182void deliver_counters(struct ebt_u_replace *repl,
183 unsigned short * counterchanges);
184void deliver_table(struct ebt_u_replace *repl);
185void get_dbinfo(struct brdb_dbinfo *nr);
186void get_db(int len, struct brdb_dbentry *db);
187void deliver_allowdb(__u16 *decision);
Bart De Schuymere2ac8a82002-06-03 16:29:12 +0000188int name_to_protocol(char *name);
Bart De Schuymer1abc55d2002-06-01 19:23:47 +0000189int getmac(char *from, char *to);
190void check_option(unsigned int *flags, unsigned int mask);
191int check_inverse(const char option[]);
192#define print_bug(format, args...) \
193 {printf("BUG: "format".\n", ##args); exit(-1);}
194#define print_error(format, args...) {printf(format".\n", ##args); exit(-1);}
195#define print_memory() {printf("Ebtables: " __FILE__ " " __FUNCTION__ \
196 " %d :Out of memory.\n", __LINE__); exit(-1);}
197
198
199
200// used for keeping the rule counters right during rule adds or deletes
201#define CNT_NORM 0
202#define CNT_DEL 1
203#define CNT_ADD 2
204#define CNT_END 3
205#define CNT_ZERO 4
206
207#endif /* EBTABLES_U_H */