Skip to content

Commit 2e4e6a1

Browse files
laf0rgeDavid S. Miller
authored and
David S. Miller
committed
[NETFILTER] x_tables: Abstraction layer for {ip,ip6,arp}_tables
This monster-patch tries to do the best job for unifying the data structures and backend interfaces for the three evil clones ip_tables, ip6_tables and arp_tables. In an ideal world we would never have allowed this kind of copy+paste programming... but well, our world isn't (yet?) ideal. o introduce a new x_tables module o {ip,arp,ip6}_tables depend on this x_tables module o registration functions for tables, matches and targets are only wrappers around x_tables provided functions o all matches/targets that are used from ip_tables and ip6_tables are now implemented as xt_FOOBAR.c files and provide module aliases to ipt_FOOBAR and ip6t_FOOBAR o header files for xt_matches are in include/linux/netfilter/, include/linux/netfilter_{ipv4,ipv6} contains compatibility wrappers around the xt_FOOBAR.h headers Based on this patchset we're going to further unify the code, gradually getting rid of all the layer 3 specific assumptions. Signed-off-by: Harald Welte <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 880b005 commit 2e4e6a1

File tree

154 files changed

+3615
-4149
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

154 files changed

+3615
-4149
lines changed

include/linux/netfilter/nf_conntrack_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ struct ip_conntrack_stat
154154
unsigned int expect_delete;
155155
};
156156

157+
/* call to create an explicit dependency on nf_conntrack. */
158+
extern void need_conntrack(void);
159+
157160
#endif /* __KERNEL__ */
158161

159162
#endif /* _NF_CONNTRACK_COMMON_H */

include/linux/netfilter/x_tables.h

Lines changed: 224 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,224 @@
1+
#ifndef _X_TABLES_H
2+
#define _X_TABLES_H
3+
4+
#define XT_FUNCTION_MAXNAMELEN 30
5+
#define XT_TABLE_MAXNAMELEN 32
6+
7+
/* The argument to IPT_SO_GET_REVISION_*. Returns highest revision
8+
* kernel supports, if >= revision. */
9+
struct xt_get_revision
10+
{
11+
char name[XT_FUNCTION_MAXNAMELEN-1];
12+
13+
u_int8_t revision;
14+
};
15+
16+
/* CONTINUE verdict for targets */
17+
#define XT_CONTINUE 0xFFFFFFFF
18+
19+
/* For standard target */
20+
#define XT_RETURN (-NF_REPEAT - 1)
21+
22+
#define XT_ALIGN(s) (((s) + (__alignof__(void *)-1)) & ~(__alignof__(void *)-1))
23+
24+
/* Standard return verdict, or do jump. */
25+
#define XT_STANDARD_TARGET ""
26+
/* Error verdict. */
27+
#define XT_ERROR_TARGET "ERROR"
28+
29+
/*
30+
* New IP firewall options for [gs]etsockopt at the RAW IP level.
31+
* Unlike BSD Linux inherits IP options so you don't have to use a raw
32+
* socket for this. Instead we check rights in the calls. */
33+
#define XT_BASE_CTL 64 /* base for firewall socket options */
34+
35+
#define XT_SO_SET_REPLACE (XT_BASE_CTL)
36+
#define XT_SO_SET_ADD_COUNTERS (XT_BASE_CTL + 1)
37+
#define XT_SO_SET_MAX XT_SO_SET_ADD_COUNTERS
38+
39+
#define XT_SO_GET_INFO (XT_BASE_CTL)
40+
#define XT_SO_GET_ENTRIES (XT_BASE_CTL + 1)
41+
#define XT_SO_GET_REVISION_MATCH (XT_BASE_CTL + 2)
42+
#define XT_SO_GET_REVISION_TARGET (XT_BASE_CTL + 3)
43+
#define XT_SO_GET_MAX XT_SO_GET_REVISION_TARGET
44+
45+
#define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0)
46+
#define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0)
47+
48+
struct xt_counters
49+
{
50+
u_int64_t pcnt, bcnt; /* Packet and byte counters */
51+
};
52+
53+
/* The argument to IPT_SO_ADD_COUNTERS. */
54+
struct xt_counters_info
55+
{
56+
/* Which table. */
57+
char name[XT_TABLE_MAXNAMELEN];
58+
59+
unsigned int num_counters;
60+
61+
/* The counters (actually `number' of these). */
62+
struct xt_counters counters[0];
63+
};
64+
65+
#define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */
66+
67+
#ifdef __KERNEL__
68+
69+
#include <linux/netdevice.h>
70+
71+
#define ASSERT_READ_LOCK(x)
72+
#define ASSERT_WRITE_LOCK(x)
73+
#include <linux/netfilter_ipv4/listhelp.h>
74+
75+
struct xt_match
76+
{
77+
struct list_head list;
78+
79+
const char name[XT_FUNCTION_MAXNAMELEN-1];
80+
81+
u_int8_t revision;
82+
83+
/* Return true or false: return FALSE and set *hotdrop = 1 to
84+
force immediate packet drop. */
85+
/* Arguments changed since 2.6.9, as this must now handle
86+
non-linear skb, using skb_header_pointer and
87+
skb_ip_make_writable. */
88+
int (*match)(const struct sk_buff *skb,
89+
const struct net_device *in,
90+
const struct net_device *out,
91+
const void *matchinfo,
92+
int offset,
93+
unsigned int protoff,
94+
int *hotdrop);
95+
96+
/* Called when user tries to insert an entry of this type. */
97+
/* Should return true or false. */
98+
int (*checkentry)(const char *tablename,
99+
const void *ip,
100+
void *matchinfo,
101+
unsigned int matchinfosize,
102+
unsigned int hook_mask);
103+
104+
/* Called when entry of this type deleted. */
105+
void (*destroy)(void *matchinfo, unsigned int matchinfosize);
106+
107+
/* Set this to THIS_MODULE if you are a module, otherwise NULL */
108+
struct module *me;
109+
};
110+
111+
/* Registration hooks for targets. */
112+
struct xt_target
113+
{
114+
struct list_head list;
115+
116+
const char name[XT_FUNCTION_MAXNAMELEN-1];
117+
118+
u_int8_t revision;
119+
120+
/* Returns verdict. Argument order changed since 2.6.9, as this
121+
must now handle non-linear skbs, using skb_copy_bits and
122+
skb_ip_make_writable. */
123+
unsigned int (*target)(struct sk_buff **pskb,
124+
const struct net_device *in,
125+
const struct net_device *out,
126+
unsigned int hooknum,
127+
const void *targinfo,
128+
void *userdata);
129+
130+
/* Called when user tries to insert an entry of this type:
131+
hook_mask is a bitmask of hooks from which it can be
132+
called. */
133+
/* Should return true or false. */
134+
int (*checkentry)(const char *tablename,
135+
const void *entry,
136+
void *targinfo,
137+
unsigned int targinfosize,
138+
unsigned int hook_mask);
139+
140+
/* Called when entry of this type deleted. */
141+
void (*destroy)(void *targinfo, unsigned int targinfosize);
142+
143+
/* Set this to THIS_MODULE if you are a module, otherwise NULL */
144+
struct module *me;
145+
};
146+
147+
/* Furniture shopping... */
148+
struct xt_table
149+
{
150+
struct list_head list;
151+
152+
/* A unique name... */
153+
char name[XT_TABLE_MAXNAMELEN];
154+
155+
/* What hooks you will enter on */
156+
unsigned int valid_hooks;
157+
158+
/* Lock for the curtain */
159+
rwlock_t lock;
160+
161+
/* Man behind the curtain... */
162+
//struct ip6t_table_info *private;
163+
void *private;
164+
165+
/* Set this to THIS_MODULE if you are a module, otherwise NULL */
166+
struct module *me;
167+
168+
int af; /* address/protocol family */
169+
};
170+
171+
#include <linux/netfilter_ipv4.h>
172+
173+
/* The table itself */
174+
struct xt_table_info
175+
{
176+
/* Size per table */
177+
unsigned int size;
178+
/* Number of entries: FIXME. --RR */
179+
unsigned int number;
180+
/* Initial number of entries. Needed for module usage count */
181+
unsigned int initial_entries;
182+
183+
/* Entry points and underflows */
184+
unsigned int hook_entry[NF_IP_NUMHOOKS];
185+
unsigned int underflow[NF_IP_NUMHOOKS];
186+
187+
/* ipt_entry tables: one per CPU */
188+
char *entries[NR_CPUS];
189+
};
190+
191+
extern int xt_register_target(int af, struct xt_target *target);
192+
extern void xt_unregister_target(int af, struct xt_target *target);
193+
extern int xt_register_match(int af, struct xt_match *target);
194+
extern void xt_unregister_match(int af, struct xt_match *target);
195+
196+
extern int xt_register_table(struct xt_table *table,
197+
struct xt_table_info *bootstrap,
198+
struct xt_table_info *newinfo);
199+
extern void *xt_unregister_table(struct xt_table *table);
200+
201+
extern struct xt_table_info *xt_replace_table(struct xt_table *table,
202+
unsigned int num_counters,
203+
struct xt_table_info *newinfo,
204+
int *error);
205+
206+
extern struct xt_match *xt_find_match(int af, const char *name, u8 revision);
207+
extern struct xt_target *xt_find_target(int af, const char *name, u8 revision);
208+
extern struct xt_target *xt_request_find_target(int af, const char *name,
209+
u8 revision);
210+
extern int xt_find_revision(int af, const char *name, u8 revision, int target,
211+
int *err);
212+
213+
extern struct xt_table *xt_find_table_lock(int af, const char *name);
214+
extern void xt_table_unlock(struct xt_table *t);
215+
216+
extern int xt_proto_init(int af);
217+
extern void xt_proto_fini(int af);
218+
219+
extern struct xt_table_info *xt_alloc_table_info(unsigned int size);
220+
extern void xt_free_table_info(struct xt_table_info *info);
221+
222+
#endif /* __KERNEL__ */
223+
224+
#endif /* _X_TABLES_H */

include/linux/netfilter/xt_CLASSIFY.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#ifndef _XT_CLASSIFY_H
2+
#define _XT_CLASSIFY_H
3+
4+
struct xt_classify_target_info {
5+
u_int32_t priority;
6+
};
7+
8+
#endif /*_XT_CLASSIFY_H */

include/linux/netfilter/xt_CONNMARK.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef _XT_CONNMARK_H_target
2+
#define _XT_CONNMARK_H_target
3+
4+
/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
5+
* by Henrik Nordstrom <[email protected]>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*/
12+
13+
enum {
14+
XT_CONNMARK_SET = 0,
15+
XT_CONNMARK_SAVE,
16+
XT_CONNMARK_RESTORE
17+
};
18+
19+
struct xt_connmark_target_info {
20+
unsigned long mark;
21+
unsigned long mask;
22+
u_int8_t mode;
23+
};
24+
25+
#endif /*_XT_CONNMARK_H_target*/

include/linux/netfilter/xt_MARK.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#ifndef _XT_MARK_H_target
2+
#define _XT_MARK_H_target
3+
4+
/* Version 0 */
5+
struct xt_mark_target_info {
6+
unsigned long mark;
7+
};
8+
9+
/* Version 1 */
10+
enum {
11+
XT_MARK_SET=0,
12+
XT_MARK_AND,
13+
XT_MARK_OR,
14+
};
15+
16+
struct xt_mark_target_info_v1 {
17+
unsigned long mark;
18+
u_int8_t mode;
19+
};
20+
21+
#endif /*_XT_MARK_H_target */

include/linux/netfilter/xt_NFQUEUE.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* iptables module for using NFQUEUE mechanism
2+
*
3+
* (C) 2005 Harald Welte <[email protected]>
4+
*
5+
* This software is distributed under GNU GPL v2, 1991
6+
*
7+
*/
8+
#ifndef _XT_NFQ_TARGET_H
9+
#define _XT_NFQ_TARGET_H
10+
11+
/* target info */
12+
struct xt_NFQ_info {
13+
u_int16_t queuenum;
14+
};
15+
16+
#endif /* _XT_NFQ_TARGET_H */

include/linux/netfilter/xt_comment.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef _XT_COMMENT_H
2+
#define _XT_COMMENT_H
3+
4+
#define XT_MAX_COMMENT_LEN 256
5+
6+
struct xt_comment_info {
7+
unsigned char comment[XT_MAX_COMMENT_LEN];
8+
};
9+
10+
#endif /* XT_COMMENT_H */
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef _XT_CONNBYTES_H
2+
#define _XT_CONNBYTES_H
3+
4+
enum xt_connbytes_what {
5+
XT_CONNBYTES_PKTS,
6+
XT_CONNBYTES_BYTES,
7+
XT_CONNBYTES_AVGPKT,
8+
};
9+
10+
enum xt_connbytes_direction {
11+
XT_CONNBYTES_DIR_ORIGINAL,
12+
XT_CONNBYTES_DIR_REPLY,
13+
XT_CONNBYTES_DIR_BOTH,
14+
};
15+
16+
struct xt_connbytes_info
17+
{
18+
struct {
19+
aligned_u64 from; /* count to be matched */
20+
aligned_u64 to; /* count to be matched */
21+
} count;
22+
u_int8_t what; /* ipt_connbytes_what */
23+
u_int8_t direction; /* ipt_connbytes_direction */
24+
};
25+
#endif

include/linux/netfilter/xt_connmark.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#ifndef _XT_CONNMARK_H
2+
#define _XT_CONNMARK_H
3+
4+
/* Copyright (C) 2002,2004 MARA Systems AB <http://www.marasystems.com>
5+
* by Henrik Nordstrom <[email protected]>
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*/
12+
13+
struct xt_connmark_info {
14+
unsigned long mark, mask;
15+
u_int8_t invert;
16+
};
17+
18+
#endif /*_XT_CONNMARK_H*/

0 commit comments

Comments
 (0)