~ubuntu-branches/ubuntu/precise/xtables-addons/precise-updates

« back to all changes in this revision

Viewing changes to extensions/ipset-6/ip_set_ahash.h

  • Committer: Bazaar Package Importer
  • Author(s): Pierre Chifflier
  • Date: 2011-08-07 20:48:13 UTC
  • mfrom: (1.3.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110807204813-lqf8ovq06adveq3j
Tags: 1.37-1
Imported Upstream version 1.37
This will trigger a rebuild and fix version on iptables libs
(Closes: #636905)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#include "jhash.h"
6
6
#include "ip_set_timeout.h"
7
7
 
 
8
#define CONCAT(a, b, c)         a##b##c
 
9
#define TOKEN(a, b, c)          CONCAT(a, b, c)
 
10
 
 
11
#define type_pf_next            TOKEN(TYPE, PF, _elem)
 
12
 
8
13
/* Hashing which uses arrays to resolve clashing. The hash table is resized
9
14
 * (doubled) when searching becomes too long.
10
15
 * Internally jhash is used with the assumption that the size of the
38
43
        struct hbucket bucket[0]; /* hashtable buckets */
39
44
};
40
45
 
41
 
#define hbucket(h, i)           &((h)->bucket[i])
 
46
#define hbucket(h, i)           (&((h)->bucket[i]))
42
47
 
43
48
/* Book-keeping of the prefixes added to the set */
44
49
struct ip_set_hash_nets {
54
59
        u32 initval;            /* random jhash init value */
55
60
        u32 timeout;            /* timeout value, if enabled */
56
61
        struct timer_list gc;   /* garbage collection when timeout enabled */
 
62
        struct type_pf_next next; /* temporary storage for uadd */
57
63
#ifdef IP_SET_HASH_WITH_NETMASK
58
64
        u8 netmask;             /* netmask value for subnets to store */
59
65
#endif
 
66
#ifdef IP_SET_HASH_WITH_RBTREE
 
67
        struct rb_root rbtree;
 
68
#endif
60
69
#ifdef IP_SET_HASH_WITH_NETS
61
70
        struct ip_set_hash_nets nets[0]; /* book-keeping of prefixes */
62
71
#endif
194
203
                del_timer_sync(&h->gc);
195
204
 
196
205
        ahash_destroy(h->table);
 
206
#ifdef IP_SET_HASH_WITH_RBTREE
 
207
        rbtree_destroy(&h->rbtree);
 
208
#endif
197
209
        kfree(h);
198
210
 
199
211
        set->data = NULL;
217
229
#define type_pf_data_netmask    TOKEN(TYPE, PF, _data_netmask)
218
230
#define type_pf_data_list       TOKEN(TYPE, PF, _data_list)
219
231
#define type_pf_data_tlist      TOKEN(TYPE, PF, _data_tlist)
 
232
#define type_pf_data_next       TOKEN(TYPE, PF, _data_next)
220
233
 
221
234
#define type_pf_elem            TOKEN(TYPE, PF, _elem)
222
235
#define type_pf_telem           TOKEN(TYPE, PF, _telem)
346
359
        return 0;
347
360
}
348
361
 
 
362
static void
 
363
type_pf_data_next(struct ip_set_hash *h, const struct type_pf_elem *d);
 
364
 
349
365
/* Add an element to a hash and update the internal counters when succeeded,
350
366
 * otherwise report the proper error code. */
351
367
static int
372
388
                }
373
389
 
374
390
        ret = type_pf_elem_add(n, value);
375
 
        if (ret != 0)
 
391
        if (ret != 0) {
 
392
                if (ret == -EAGAIN)
 
393
                        type_pf_data_next(h, d);
376
394
                goto out;
 
395
        }
377
396
 
378
397
#ifdef IP_SET_HASH_WITH_NETS
379
398
        add_cidr(h, d->cidr, HOST_MASK);
586
605
 
587
606
static int
588
607
type_pf_kadt(struct ip_set *set, const struct sk_buff * skb,
589
 
             enum ipset_adt adt, u8 pf, u8 dim, u8 flags);
 
608
             const struct xt_action_param *par,
 
609
             enum ipset_adt adt, const struct ip_set_adt_opt *opt);
590
610
static int
591
611
type_pf_uadt(struct ip_set *set, struct nlattr *tb[],
592
 
             enum ipset_adt adt, u32 *lineno, u32 flags);
 
612
             enum ipset_adt adt, u32 *lineno, u32 flags, bool retried);
593
613
 
594
614
static const struct ip_set_type_variant type_pf_variant = {
595
615
        .kadt   = type_pf_kadt,
821
841
                goto out;
822
842
        }
823
843
        ret = type_pf_elem_tadd(n, d, timeout);
824
 
        if (ret != 0)
 
844
        if (ret != 0) {
 
845
                if (ret == -EAGAIN)
 
846
                        type_pf_data_next(h, d);
825
847
                goto out;
 
848
        }
826
849
 
827
850
#ifdef IP_SET_HASH_WITH_NETS
828
851
        add_cidr(h, d->cidr, HOST_MASK);
840
863
        struct htable *t = h->table;
841
864
        const struct type_pf_elem *d = value;
842
865
        struct hbucket *n;
843
 
        int i, ret = 0;
 
866
        int i;
844
867
        struct type_pf_elem *data;
845
868
        u32 key;
846
869
 
851
874
                if (!type_pf_data_equal(data, d))
852
875
                        continue;
853
876
                if (type_pf_data_expired(data))
854
 
                        ret = -IPSET_ERR_EXIST;
 
877
                        return -IPSET_ERR_EXIST;
855
878
                if (i != n->pos - 1)
856
879
                        /* Not last one */
857
880
                        type_pf_data_copy(data, ahash_tdata(n, n->pos - 1));