~ubuntu-branches/debian/sid/netfilter-extensions/sid

« back to all changes in this revision

Viewing changes to net/ipv4/netfilter/ip_set_ipmap.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert S. Edmonds
  • Date: 2008-07-19 20:44:40 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080719204440-n8i2f0qiu48c6s36
Tags: 20080719+debian-1
2.6.25 compile fixes; closes: #481300.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * This program is free software; you can redistribute it and/or modify
6
6
 * it under the terms of the GNU General Public License version 2 as
7
 
 * published by the Free Software Foundation.  
 
7
 * published by the Free Software Foundation.
8
8
 */
9
9
 
10
10
/* Kernel module implementing an IP set type: the single bitmap type */
12
12
#include <linux/module.h>
13
13
#include <linux/ip.h>
14
14
#include <linux/skbuff.h>
 
15
#include <linux/version.h>
15
16
#include <linux/netfilter_ipv4/ip_tables.h>
16
17
#include <linux/netfilter_ipv4/ip_set.h>
17
18
#include <linux/errno.h>
30
31
static inline int
31
32
__testip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
32
33
{
33
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
34
        struct ip_set_ipmap *map = set->data;
34
35
        
35
36
        if (ip < map->first_ip || ip > map->last_ip)
36
37
                return -ERANGE;
45
46
testip(struct ip_set *set, const void *data, size_t size,
46
47
       ip_set_ip_t *hash_ip)
47
48
{
48
 
        struct ip_set_req_ipmap *req = 
49
 
            (struct ip_set_req_ipmap *) data;
 
49
        const struct ip_set_req_ipmap *req = data;
50
50
 
51
51
        if (size != sizeof(struct ip_set_req_ipmap)) {
52
52
                ip_set_printk("data length wrong (want %zu, have %zu)",
58
58
}
59
59
 
60
60
static int
61
 
testip_kernel(struct ip_set *set, 
 
61
testip_kernel(struct ip_set *set,
62
62
              const struct sk_buff *skb,
63
63
              ip_set_ip_t *hash_ip,
64
64
              const u_int32_t *flags,
65
65
              unsigned char index)
66
66
{
67
 
        int res;
68
 
        
69
 
        DP("flag: %s src: %u.%u.%u.%u dst: %u.%u.%u.%u",
70
 
           flags[index] & IPSET_SRC ? "SRC" : "DST",
71
 
           NIPQUAD(skb->nh.iph->saddr),
72
 
           NIPQUAD(skb->nh.iph->daddr));
73
 
 
74
 
        res =  __testip(set,
75
 
                        ntohl(flags[index] & IPSET_SRC 
76
 
                                ? skb->nh.iph->saddr 
 
67
        int res =  __testip(set,
 
68
                        ntohl(flags[index] & IPSET_SRC
 
69
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 
70
                                ? ip_hdr(skb)->saddr
 
71
                                : ip_hdr(skb)->daddr),
 
72
#else
 
73
                                ? skb->nh.iph->saddr
77
74
                                : skb->nh.iph->daddr),
 
75
#endif
78
76
                        hash_ip);
79
77
        return (res < 0 ? 0 : res);
80
78
}
82
80
static inline int
83
81
__addip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
84
82
{
85
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
83
        struct ip_set_ipmap *map = set->data;
86
84
 
87
85
        if (ip < map->first_ip || ip > map->last_ip)
88
86
                return -ERANGE;
99
97
addip(struct ip_set *set, const void *data, size_t size,
100
98
      ip_set_ip_t *hash_ip)
101
99
{
102
 
        struct ip_set_req_ipmap *req = 
103
 
            (struct ip_set_req_ipmap *) data;
 
100
        const struct ip_set_req_ipmap *req = data;
104
101
 
105
102
        if (size != sizeof(struct ip_set_req_ipmap)) {
106
103
                ip_set_printk("data length wrong (want %zu, have %zu)",
113
110
}
114
111
 
115
112
static int
116
 
addip_kernel(struct ip_set *set, 
 
113
addip_kernel(struct ip_set *set,
117
114
             const struct sk_buff *skb,
118
115
             ip_set_ip_t *hash_ip,
119
116
             const u_int32_t *flags,
120
117
             unsigned char index)
121
118
{
122
119
        return __addip(set,
123
 
                       ntohl(flags[index] & IPSET_SRC 
124
 
                                ? skb->nh.iph->saddr 
 
120
                       ntohl(flags[index] & IPSET_SRC
 
121
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 
122
                                ? ip_hdr(skb)->saddr
 
123
                                : ip_hdr(skb)->daddr),
 
124
#else
 
125
                                ? skb->nh.iph->saddr
125
126
                                : skb->nh.iph->daddr),
 
127
#endif
126
128
                       hash_ip);
127
129
}
128
130
 
129
 
static inline int 
 
131
static inline int
130
132
__delip(struct ip_set *set, ip_set_ip_t ip, ip_set_ip_t *hash_ip)
131
133
{
132
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
134
        struct ip_set_ipmap *map = set->data;
133
135
 
134
136
        if (ip < map->first_ip || ip > map->last_ip)
135
137
                return -ERANGE;
146
148
delip(struct ip_set *set, const void *data, size_t size,
147
149
      ip_set_ip_t *hash_ip)
148
150
{
149
 
        struct ip_set_req_ipmap *req =
150
 
            (struct ip_set_req_ipmap *) data;
 
151
        const struct ip_set_req_ipmap *req = data;
151
152
 
152
153
        if (size != sizeof(struct ip_set_req_ipmap)) {
153
154
                ip_set_printk("data length wrong (want %zu, have %zu)",
166
167
             unsigned char index)
167
168
{
168
169
        return __delip(set,
169
 
                       ntohl(flags[index] & IPSET_SRC 
170
 
                                ? skb->nh.iph->saddr 
 
170
                       ntohl(flags[index] & IPSET_SRC
 
171
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22)
 
172
                                ? ip_hdr(skb)->saddr
 
173
                                : ip_hdr(skb)->daddr),
 
174
#else
 
175
                                ? skb->nh.iph->saddr
171
176
                                : skb->nh.iph->daddr),
 
177
#endif
172
178
                       hash_ip);
173
179
}
174
180
 
175
181
static int create(struct ip_set *set, const void *data, size_t size)
176
182
{
177
183
        int newbytes;
178
 
        struct ip_set_req_ipmap_create *req =
179
 
            (struct ip_set_req_ipmap_create *) data;
 
184
        const struct ip_set_req_ipmap_create *req = data;
180
185
        struct ip_set_ipmap *map;
181
186
 
182
187
        if (size != sizeof(struct ip_set_req_ipmap_create)) {
247
252
 
248
253
static void destroy(struct ip_set *set)
249
254
{
250
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
255
        struct ip_set_ipmap *map = set->data;
251
256
        
252
257
        kfree(map->members);
253
258
        kfree(map);
257
262
 
258
263
static void flush(struct ip_set *set)
259
264
{
260
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
265
        struct ip_set_ipmap *map = set->data;
261
266
        memset(map->members, 0, bitmap_bytes(0, map->sizeid - 1));
262
267
}
263
268
 
264
269
static void list_header(const struct ip_set *set, void *data)
265
270
{
266
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
267
 
        struct ip_set_req_ipmap_create *header =
268
 
            (struct ip_set_req_ipmap_create *) data;
 
271
        const struct ip_set_ipmap *map = set->data;
 
272
        struct ip_set_req_ipmap_create *header = data;
269
273
 
270
274
        header->from = map->first_ip;
271
275
        header->to = map->last_ip;
274
278
 
275
279
static int list_members_size(const struct ip_set *set)
276
280
{
277
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
281
        const struct ip_set_ipmap *map = set->data;
278
282
 
279
283
        return bitmap_bytes(0, map->sizeid - 1);
280
284
}
281
285
 
282
286
static void list_members(const struct ip_set *set, void *data)
283
287
{
284
 
        struct ip_set_ipmap *map = (struct ip_set_ipmap *) set->data;
 
288
        const struct ip_set_ipmap *map = set->data;
285
289
        int bytes = bitmap_bytes(0, map->sizeid - 1);
286
290
 
287
291
        memcpy(data, map->members, bytes);
312
316
MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
313
317
MODULE_DESCRIPTION("ipmap type of IP sets");
314
318
 
315
 
static int __init init(void)
 
319
static int __init ip_set_ipmap_init(void)
316
320
{
317
321
        return ip_set_register_set_type(&ip_set_ipmap);
318
322
}
319
323
 
320
 
static void __exit fini(void)
 
324
static void __exit ip_set_ipmap_fini(void)
321
325
{
322
326
        /* FIXME: possible race with ip_set_create() */
323
327
        ip_set_unregister_set_type(&ip_set_ipmap);
324
328
}
325
329
 
326
 
module_init(init);
327
 
module_exit(fini);
 
330
module_init(ip_set_ipmap_init);
 
331
module_exit(ip_set_ipmap_fini);