Merge branch 'v4l_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab...
[pandora-kernel.git] / net / netfilter / ipset / ip_set_hash_ipportnet.c
1 /* Copyright (C) 2003-2011 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
2  *
3  * This program is free software; you can redistribute it and/or modify
4  * it under the terms of the GNU General Public License version 2 as
5  * published by the Free Software Foundation.
6  */
7
8 /* Kernel module implementing an IP set type: the hash:ip,port,net type */
9
10 #include <linux/jhash.h>
11 #include <linux/module.h>
12 #include <linux/ip.h>
13 #include <linux/skbuff.h>
14 #include <linux/errno.h>
15 #include <linux/random.h>
16 #include <net/ip.h>
17 #include <net/ipv6.h>
18 #include <net/netlink.h>
19 #include <net/tcp.h>
20
21 #include <linux/netfilter.h>
22 #include <linux/netfilter/ipset/pfxlen.h>
23 #include <linux/netfilter/ipset/ip_set.h>
24 #include <linux/netfilter/ipset/ip_set_timeout.h>
25 #include <linux/netfilter/ipset/ip_set_getport.h>
26 #include <linux/netfilter/ipset/ip_set_hash.h>
27
28 MODULE_LICENSE("GPL");
29 MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
30 MODULE_DESCRIPTION("hash:ip,port,net type of IP sets");
31 MODULE_ALIAS("ip_set_hash:ip,port,net");
32
33 /* Type specific function prefix */
34 #define TYPE            hash_ipportnet
35
36 static bool
37 hash_ipportnet_same_set(const struct ip_set *a, const struct ip_set *b);
38
39 #define hash_ipportnet4_same_set        hash_ipportnet_same_set
40 #define hash_ipportnet6_same_set        hash_ipportnet_same_set
41
42 /* The type variant functions: IPv4 */
43
44 /* Member elements without timeout */
45 struct hash_ipportnet4_elem {
46         __be32 ip;
47         __be32 ip2;
48         __be16 port;
49         u8 cidr;
50         u8 proto;
51 };
52
53 /* Member elements with timeout support */
54 struct hash_ipportnet4_telem {
55         __be32 ip;
56         __be32 ip2;
57         __be16 port;
58         u8 cidr;
59         u8 proto;
60         unsigned long timeout;
61 };
62
63 static inline bool
64 hash_ipportnet4_data_equal(const struct hash_ipportnet4_elem *ip1,
65                            const struct hash_ipportnet4_elem *ip2)
66 {
67         return ip1->ip == ip2->ip &&
68                ip1->ip2 == ip2->ip2 &&
69                ip1->cidr == ip2->cidr &&
70                ip1->port == ip2->port &&
71                ip1->proto == ip2->proto;
72 }
73
74 static inline bool
75 hash_ipportnet4_data_isnull(const struct hash_ipportnet4_elem *elem)
76 {
77         return elem->proto == 0;
78 }
79
80 static inline void
81 hash_ipportnet4_data_copy(struct hash_ipportnet4_elem *dst,
82                           const struct hash_ipportnet4_elem *src)
83 {
84         memcpy(dst, src, sizeof(*dst));
85 }
86
87 static inline void
88 hash_ipportnet4_data_netmask(struct hash_ipportnet4_elem *elem, u8 cidr)
89 {
90         elem->ip2 &= ip_set_netmask(cidr);
91         elem->cidr = cidr;
92 }
93
94 static inline void
95 hash_ipportnet4_data_zero_out(struct hash_ipportnet4_elem *elem)
96 {
97         elem->proto = 0;
98 }
99
100 static bool
101 hash_ipportnet4_data_list(struct sk_buff *skb,
102                           const struct hash_ipportnet4_elem *data)
103 {
104         NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP, data->ip);
105         NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP2, data->ip2);
106         NLA_PUT_NET16(skb, IPSET_ATTR_PORT, data->port);
107         NLA_PUT_U8(skb, IPSET_ATTR_CIDR2, data->cidr);
108         NLA_PUT_U8(skb, IPSET_ATTR_PROTO, data->proto);
109         return 0;
110
111 nla_put_failure:
112         return 1;
113 }
114
115 static bool
116 hash_ipportnet4_data_tlist(struct sk_buff *skb,
117                            const struct hash_ipportnet4_elem *data)
118 {
119         const struct hash_ipportnet4_telem *tdata =
120                 (const struct hash_ipportnet4_telem *)data;
121
122         NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP, tdata->ip);
123         NLA_PUT_IPADDR4(skb, IPSET_ATTR_IP2, tdata->ip2);
124         NLA_PUT_NET16(skb, IPSET_ATTR_PORT, tdata->port);
125         NLA_PUT_U8(skb, IPSET_ATTR_CIDR2, data->cidr);
126         NLA_PUT_U8(skb, IPSET_ATTR_PROTO, data->proto);
127         NLA_PUT_NET32(skb, IPSET_ATTR_TIMEOUT,
128                       htonl(ip_set_timeout_get(tdata->timeout)));
129
130         return 0;
131
132 nla_put_failure:
133         return 1;
134 }
135
136 #define IP_SET_HASH_WITH_PROTO
137 #define IP_SET_HASH_WITH_NETS
138
139 #define PF              4
140 #define HOST_MASK       32
141 #include <linux/netfilter/ipset/ip_set_ahash.h>
142
143 static int
144 hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
145                      enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
146 {
147         const struct ip_set_hash *h = set->data;
148         ipset_adtfn adtfn = set->variant->adt[adt];
149         struct hash_ipportnet4_elem data = {
150                 .cidr = h->nets[0].cidr ? h->nets[0].cidr : HOST_MASK
151         };
152
153         if (data.cidr == 0)
154                 return -EINVAL;
155         if (adt == IPSET_TEST)
156                 data.cidr = HOST_MASK;
157
158         if (!ip_set_get_ip4_port(skb, flags & IPSET_DIM_TWO_SRC,
159                                  &data.port, &data.proto))
160                 return -EINVAL;
161
162         ip4addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip);
163         ip4addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2);
164         data.ip2 &= ip_set_netmask(data.cidr);
165
166         return adtfn(set, &data, h->timeout);
167 }
168
169 static int
170 hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
171                      enum ipset_adt adt, u32 *lineno, u32 flags)
172 {
173         const struct ip_set_hash *h = set->data;
174         ipset_adtfn adtfn = set->variant->adt[adt];
175         struct hash_ipportnet4_elem data = { .cidr = HOST_MASK };
176         u32 ip, ip_to, p, port, port_to;
177         u32 timeout = h->timeout;
178         bool with_ports = false;
179         int ret;
180
181         if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
182                      !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
183                      !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
184                      !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT)))
185                 return -IPSET_ERR_PROTOCOL;
186
187         if (tb[IPSET_ATTR_LINENO])
188                 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
189
190         ret = ip_set_get_ipaddr4(tb[IPSET_ATTR_IP], &data.ip);
191         if (ret)
192                 return ret;
193
194         ret = ip_set_get_ipaddr4(tb[IPSET_ATTR_IP2], &data.ip2);
195         if (ret)
196                 return ret;
197
198         if (tb[IPSET_ATTR_CIDR2])
199                 data.cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
200
201         if (!data.cidr)
202                 return -IPSET_ERR_INVALID_CIDR;
203
204         data.ip2 &= ip_set_netmask(data.cidr);
205
206         if (tb[IPSET_ATTR_PORT])
207                 data.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
208         else
209                 return -IPSET_ERR_PROTOCOL;
210
211         if (tb[IPSET_ATTR_PROTO]) {
212                 data.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
213                 with_ports = ip_set_proto_with_ports(data.proto);
214
215                 if (data.proto == 0)
216                         return -IPSET_ERR_INVALID_PROTO;
217         } else
218                 return -IPSET_ERR_MISSING_PROTO;
219
220         if (!(with_ports || data.proto == IPPROTO_ICMP))
221                 data.port = 0;
222
223         if (tb[IPSET_ATTR_TIMEOUT]) {
224                 if (!with_timeout(h->timeout))
225                         return -IPSET_ERR_TIMEOUT;
226                 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
227         }
228
229         if (adt == IPSET_TEST ||
230             !(tb[IPSET_ATTR_IP_TO] || tb[IPSET_ATTR_CIDR] ||
231               tb[IPSET_ATTR_PORT_TO])) {
232                 ret = adtfn(set, &data, timeout);
233                 return ip_set_eexist(ret, flags) ? 0 : ret;
234         }
235
236         ip = ntohl(data.ip);
237         if (tb[IPSET_ATTR_IP_TO]) {
238                 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &ip_to);
239                 if (ret)
240                         return ret;
241                 if (ip > ip_to)
242                         swap(ip, ip_to);
243         } else if (tb[IPSET_ATTR_CIDR]) {
244                 u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
245
246                 if (cidr > 32)
247                         return -IPSET_ERR_INVALID_CIDR;
248                 ip &= ip_set_hostmask(cidr);
249                 ip_to = ip | ~ip_set_hostmask(cidr);
250         } else
251                 ip_to = ip;
252
253         port_to = port = ntohs(data.port);
254         if (with_ports && tb[IPSET_ATTR_PORT_TO]) {
255                 port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
256                 if (port > port_to)
257                         swap(port, port_to);
258         }
259
260         for (; !before(ip_to, ip); ip++)
261                 for (p = port; p <= port_to; p++) {
262                         data.ip = htonl(ip);
263                         data.port = htons(p);
264                         ret = adtfn(set, &data, timeout);
265
266                         if (ret && !ip_set_eexist(ret, flags))
267                                 return ret;
268                         else
269                                 ret = 0;
270                 }
271         return ret;
272 }
273
274 static bool
275 hash_ipportnet_same_set(const struct ip_set *a, const struct ip_set *b)
276 {
277         const struct ip_set_hash *x = a->data;
278         const struct ip_set_hash *y = b->data;
279
280         /* Resizing changes htable_bits, so we ignore it */
281         return x->maxelem == y->maxelem &&
282                x->timeout == y->timeout;
283 }
284
285 /* The type variant functions: IPv6 */
286
287 struct hash_ipportnet6_elem {
288         union nf_inet_addr ip;
289         union nf_inet_addr ip2;
290         __be16 port;
291         u8 cidr;
292         u8 proto;
293 };
294
295 struct hash_ipportnet6_telem {
296         union nf_inet_addr ip;
297         union nf_inet_addr ip2;
298         __be16 port;
299         u8 cidr;
300         u8 proto;
301         unsigned long timeout;
302 };
303
304 static inline bool
305 hash_ipportnet6_data_equal(const struct hash_ipportnet6_elem *ip1,
306                            const struct hash_ipportnet6_elem *ip2)
307 {
308         return ipv6_addr_cmp(&ip1->ip.in6, &ip2->ip.in6) == 0 &&
309                ipv6_addr_cmp(&ip1->ip2.in6, &ip2->ip2.in6) == 0 &&
310                ip1->cidr == ip2->cidr &&
311                ip1->port == ip2->port &&
312                ip1->proto == ip2->proto;
313 }
314
315 static inline bool
316 hash_ipportnet6_data_isnull(const struct hash_ipportnet6_elem *elem)
317 {
318         return elem->proto == 0;
319 }
320
321 static inline void
322 hash_ipportnet6_data_copy(struct hash_ipportnet6_elem *dst,
323                           const struct hash_ipportnet6_elem *src)
324 {
325         memcpy(dst, src, sizeof(*dst));
326 }
327
328 static inline void
329 hash_ipportnet6_data_zero_out(struct hash_ipportnet6_elem *elem)
330 {
331         elem->proto = 0;
332 }
333
334 static inline void
335 ip6_netmask(union nf_inet_addr *ip, u8 prefix)
336 {
337         ip->ip6[0] &= ip_set_netmask6(prefix)[0];
338         ip->ip6[1] &= ip_set_netmask6(prefix)[1];
339         ip->ip6[2] &= ip_set_netmask6(prefix)[2];
340         ip->ip6[3] &= ip_set_netmask6(prefix)[3];
341 }
342
343 static inline void
344 hash_ipportnet6_data_netmask(struct hash_ipportnet6_elem *elem, u8 cidr)
345 {
346         ip6_netmask(&elem->ip2, cidr);
347         elem->cidr = cidr;
348 }
349
350 static bool
351 hash_ipportnet6_data_list(struct sk_buff *skb,
352                           const struct hash_ipportnet6_elem *data)
353 {
354         NLA_PUT_IPADDR6(skb, IPSET_ATTR_IP, &data->ip);
355         NLA_PUT_IPADDR6(skb, IPSET_ATTR_IP2, &data->ip2);
356         NLA_PUT_NET16(skb, IPSET_ATTR_PORT, data->port);
357         NLA_PUT_U8(skb, IPSET_ATTR_CIDR2, data->cidr);
358         NLA_PUT_U8(skb, IPSET_ATTR_PROTO, data->proto);
359         return 0;
360
361 nla_put_failure:
362         return 1;
363 }
364
365 static bool
366 hash_ipportnet6_data_tlist(struct sk_buff *skb,
367                            const struct hash_ipportnet6_elem *data)
368 {
369         const struct hash_ipportnet6_telem *e =
370                 (const struct hash_ipportnet6_telem *)data;
371
372         NLA_PUT_IPADDR6(skb, IPSET_ATTR_IP, &e->ip);
373         NLA_PUT_IPADDR6(skb, IPSET_ATTR_IP2, &data->ip2);
374         NLA_PUT_NET16(skb, IPSET_ATTR_PORT, data->port);
375         NLA_PUT_U8(skb, IPSET_ATTR_CIDR2, data->cidr);
376         NLA_PUT_U8(skb, IPSET_ATTR_PROTO, data->proto);
377         NLA_PUT_NET32(skb, IPSET_ATTR_TIMEOUT,
378                       htonl(ip_set_timeout_get(e->timeout)));
379         return 0;
380
381 nla_put_failure:
382         return 1;
383 }
384
385 #undef PF
386 #undef HOST_MASK
387
388 #define PF              6
389 #define HOST_MASK       128
390 #include <linux/netfilter/ipset/ip_set_ahash.h>
391
392 static int
393 hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
394                      enum ipset_adt adt, u8 pf, u8 dim, u8 flags)
395 {
396         const struct ip_set_hash *h = set->data;
397         ipset_adtfn adtfn = set->variant->adt[adt];
398         struct hash_ipportnet6_elem data = {
399                 .cidr = h->nets[0].cidr ? h->nets[0].cidr : HOST_MASK
400         };
401
402         if (data.cidr == 0)
403                 return -EINVAL;
404         if (adt == IPSET_TEST)
405                 data.cidr = HOST_MASK;
406
407         if (!ip_set_get_ip6_port(skb, flags & IPSET_DIM_TWO_SRC,
408                                  &data.port, &data.proto))
409                 return -EINVAL;
410
411         ip6addrptr(skb, flags & IPSET_DIM_ONE_SRC, &data.ip.in6);
412         ip6addrptr(skb, flags & IPSET_DIM_THREE_SRC, &data.ip2.in6);
413         ip6_netmask(&data.ip2, data.cidr);
414
415         return adtfn(set, &data, h->timeout);
416 }
417
418 static int
419 hash_ipportnet6_uadt(struct ip_set *set, struct nlattr *tb[],
420                      enum ipset_adt adt, u32 *lineno, u32 flags)
421 {
422         const struct ip_set_hash *h = set->data;
423         ipset_adtfn adtfn = set->variant->adt[adt];
424         struct hash_ipportnet6_elem data = { .cidr = HOST_MASK };
425         u32 port, port_to;
426         u32 timeout = h->timeout;
427         bool with_ports = false;
428         int ret;
429
430         if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
431                      !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
432                      !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
433                      !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
434                      tb[IPSET_ATTR_IP_TO] ||
435                      tb[IPSET_ATTR_CIDR]))
436                 return -IPSET_ERR_PROTOCOL;
437
438         if (tb[IPSET_ATTR_LINENO])
439                 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
440
441         ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP], &data.ip);
442         if (ret)
443                 return ret;
444
445         ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP2], &data.ip2);
446         if (ret)
447                 return ret;
448
449         if (tb[IPSET_ATTR_CIDR2])
450                 data.cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
451
452         if (!data.cidr)
453                 return -IPSET_ERR_INVALID_CIDR;
454
455         ip6_netmask(&data.ip2, data.cidr);
456
457         if (tb[IPSET_ATTR_PORT])
458                 data.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
459         else
460                 return -IPSET_ERR_PROTOCOL;
461
462         if (tb[IPSET_ATTR_PROTO]) {
463                 data.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
464                 with_ports = ip_set_proto_with_ports(data.proto);
465
466                 if (data.proto == 0)
467                         return -IPSET_ERR_INVALID_PROTO;
468         } else
469                 return -IPSET_ERR_MISSING_PROTO;
470
471         if (!(with_ports || data.proto == IPPROTO_ICMPV6))
472                 data.port = 0;
473
474         if (tb[IPSET_ATTR_TIMEOUT]) {
475                 if (!with_timeout(h->timeout))
476                         return -IPSET_ERR_TIMEOUT;
477                 timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
478         }
479
480         if (adt == IPSET_TEST || !with_ports || !tb[IPSET_ATTR_PORT_TO]) {
481                 ret = adtfn(set, &data, timeout);
482                 return ip_set_eexist(ret, flags) ? 0 : ret;
483         }
484
485         port = ntohs(data.port);
486         port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
487         if (port > port_to)
488                 swap(port, port_to);
489
490         for (; port <= port_to; port++) {
491                 data.port = htons(port);
492                 ret = adtfn(set, &data, timeout);
493
494                 if (ret && !ip_set_eexist(ret, flags))
495                         return ret;
496                 else
497                         ret = 0;
498         }
499         return ret;
500 }
501
502 /* Create hash:ip type of sets */
503
504 static int
505 hash_ipportnet_create(struct ip_set *set, struct nlattr *tb[], u32 flags)
506 {
507         struct ip_set_hash *h;
508         u32 hashsize = IPSET_DEFAULT_HASHSIZE, maxelem = IPSET_DEFAULT_MAXELEM;
509         u8 hbits;
510
511         if (!(set->family == AF_INET || set->family == AF_INET6))
512                 return -IPSET_ERR_INVALID_FAMILY;
513
514         if (unlikely(!ip_set_optattr_netorder(tb, IPSET_ATTR_HASHSIZE) ||
515                      !ip_set_optattr_netorder(tb, IPSET_ATTR_MAXELEM) ||
516                      !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT)))
517                 return -IPSET_ERR_PROTOCOL;
518
519         if (tb[IPSET_ATTR_HASHSIZE]) {
520                 hashsize = ip_set_get_h32(tb[IPSET_ATTR_HASHSIZE]);
521                 if (hashsize < IPSET_MIMINAL_HASHSIZE)
522                         hashsize = IPSET_MIMINAL_HASHSIZE;
523         }
524
525         if (tb[IPSET_ATTR_MAXELEM])
526                 maxelem = ip_set_get_h32(tb[IPSET_ATTR_MAXELEM]);
527
528         h = kzalloc(sizeof(*h)
529                     + sizeof(struct ip_set_hash_nets)
530                       * (set->family == AF_INET ? 32 : 128), GFP_KERNEL);
531         if (!h)
532                 return -ENOMEM;
533
534         h->maxelem = maxelem;
535         get_random_bytes(&h->initval, sizeof(h->initval));
536         h->timeout = IPSET_NO_TIMEOUT;
537
538         hbits = htable_bits(hashsize);
539         h->table = ip_set_alloc(
540                         sizeof(struct htable)
541                         + jhash_size(hbits) * sizeof(struct hbucket));
542         if (!h->table) {
543                 kfree(h);
544                 return -ENOMEM;
545         }
546         h->table->htable_bits = hbits;
547
548         set->data = h;
549
550         if (tb[IPSET_ATTR_TIMEOUT]) {
551                 h->timeout = ip_set_timeout_uget(tb[IPSET_ATTR_TIMEOUT]);
552
553                 set->variant = set->family == AF_INET
554                         ? &hash_ipportnet4_tvariant
555                         : &hash_ipportnet6_tvariant;
556
557                 if (set->family == AF_INET)
558                         hash_ipportnet4_gc_init(set);
559                 else
560                         hash_ipportnet6_gc_init(set);
561         } else {
562                 set->variant = set->family == AF_INET
563                         ? &hash_ipportnet4_variant : &hash_ipportnet6_variant;
564         }
565
566         pr_debug("create %s hashsize %u (%u) maxelem %u: %p(%p)\n",
567                  set->name, jhash_size(h->table->htable_bits),
568                  h->table->htable_bits, h->maxelem, set->data, h->table);
569
570         return 0;
571 }
572
573 static struct ip_set_type hash_ipportnet_type __read_mostly = {
574         .name           = "hash:ip,port,net",
575         .protocol       = IPSET_PROTOCOL,
576         .features       = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2,
577         .dimension      = IPSET_DIM_THREE,
578         .family         = AF_UNSPEC,
579         .revision       = 1,
580         .create         = hash_ipportnet_create,
581         .create_policy  = {
582                 [IPSET_ATTR_HASHSIZE]   = { .type = NLA_U32 },
583                 [IPSET_ATTR_MAXELEM]    = { .type = NLA_U32 },
584                 [IPSET_ATTR_PROBES]     = { .type = NLA_U8 },
585                 [IPSET_ATTR_RESIZE]     = { .type = NLA_U8  },
586                 [IPSET_ATTR_TIMEOUT]    = { .type = NLA_U32 },
587         },
588         .adt_policy     = {
589                 [IPSET_ATTR_IP]         = { .type = NLA_NESTED },
590                 [IPSET_ATTR_IP_TO]      = { .type = NLA_NESTED },
591                 [IPSET_ATTR_IP2]        = { .type = NLA_NESTED },
592                 [IPSET_ATTR_PORT]       = { .type = NLA_U16 },
593                 [IPSET_ATTR_PORT_TO]    = { .type = NLA_U16 },
594                 [IPSET_ATTR_CIDR]       = { .type = NLA_U8 },
595                 [IPSET_ATTR_CIDR2]      = { .type = NLA_U8 },
596                 [IPSET_ATTR_PROTO]      = { .type = NLA_U8 },
597                 [IPSET_ATTR_TIMEOUT]    = { .type = NLA_U32 },
598                 [IPSET_ATTR_LINENO]     = { .type = NLA_U32 },
599         },
600         .me             = THIS_MODULE,
601 };
602
603 static int __init
604 hash_ipportnet_init(void)
605 {
606         return ip_set_type_register(&hash_ipportnet_type);
607 }
608
609 static void __exit
610 hash_ipportnet_fini(void)
611 {
612         ip_set_type_unregister(&hash_ipportnet_type);
613 }
614
615 module_init(hash_ipportnet_init);
616 module_exit(hash_ipportnet_fini);