blob: 2f00343471895079a8162ef02900f9ce96ebf5dc [file] [log] [blame]
Oliver Smith7c3ad052013-09-28 20:33:23 +02001/* Copyright (C) 2003-2013 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_getport.h>
25#include <linux/netfilter/ipset/ip_set_hash.h>
26
27#define IPSET_TYPE_REV_MIN 0
Josh Hunt07cf8f52014-02-28 22:14:57 -050028/* 0 Comments support added */
29#define IPSET_TYPE_REV_MAX 1 /* Forceadd support added */
Oliver Smith7c3ad052013-09-28 20:33:23 +020030
31MODULE_LICENSE("GPL");
32MODULE_AUTHOR("Oliver Smith <oliver@8.c.9.b.0.7.4.0.1.0.0.2.ip6.arpa>");
33IP_SET_MODULE_DESC("hash:net,port,net", IPSET_TYPE_REV_MIN, IPSET_TYPE_REV_MAX);
34MODULE_ALIAS("ip_set_hash:net,port,net");
35
36/* Type specific function prefix */
37#define HTYPE hash_netportnet
38#define IP_SET_HASH_WITH_PROTO
39#define IP_SET_HASH_WITH_NETS
40#define IPSET_NET_COUNT 2
41
42/* IPv4 variant */
43
44/* Member elements */
45struct hash_netportnet4_elem {
46 union {
47 __be32 ip[2];
48 __be64 ipcmp;
49 };
50 __be16 port;
51 union {
52 u8 cidr[2];
53 u16 ccmp;
54 };
55 u8 nomatch:1;
56 u8 proto;
57};
58
59/* Common functions */
60
61static inline bool
62hash_netportnet4_data_equal(const struct hash_netportnet4_elem *ip1,
63 const struct hash_netportnet4_elem *ip2,
64 u32 *multi)
65{
66 return ip1->ipcmp == ip2->ipcmp &&
67 ip1->ccmp == ip2->ccmp &&
68 ip1->port == ip2->port &&
69 ip1->proto == ip2->proto;
70}
71
72static inline int
73hash_netportnet4_do_data_match(const struct hash_netportnet4_elem *elem)
74{
75 return elem->nomatch ? -ENOTEMPTY : 1;
76}
77
78static inline void
79hash_netportnet4_data_set_flags(struct hash_netportnet4_elem *elem, u32 flags)
80{
81 elem->nomatch = !!((flags >> 16) & IPSET_FLAG_NOMATCH);
82}
83
84static inline void
85hash_netportnet4_data_reset_flags(struct hash_netportnet4_elem *elem, u8 *flags)
86{
87 swap(*flags, elem->nomatch);
88}
89
90static inline void
91hash_netportnet4_data_reset_elem(struct hash_netportnet4_elem *elem,
92 struct hash_netportnet4_elem *orig)
93{
94 elem->ip[1] = orig->ip[1];
95}
96
97static inline void
98hash_netportnet4_data_netmask(struct hash_netportnet4_elem *elem,
99 u8 cidr, bool inner)
100{
101 if (inner) {
102 elem->ip[1] &= ip_set_netmask(cidr);
103 elem->cidr[1] = cidr;
104 } else {
105 elem->ip[0] &= ip_set_netmask(cidr);
106 elem->cidr[0] = cidr;
107 }
108}
109
110static bool
111hash_netportnet4_data_list(struct sk_buff *skb,
112 const struct hash_netportnet4_elem *data)
113{
114 u32 flags = data->nomatch ? IPSET_FLAG_NOMATCH : 0;
115
116 if (nla_put_ipaddr4(skb, IPSET_ATTR_IP, data->ip[0]) ||
117 nla_put_ipaddr4(skb, IPSET_ATTR_IP2, data->ip[1]) ||
118 nla_put_net16(skb, IPSET_ATTR_PORT, data->port) ||
119 nla_put_u8(skb, IPSET_ATTR_CIDR, data->cidr[0]) ||
120 nla_put_u8(skb, IPSET_ATTR_CIDR2, data->cidr[1]) ||
121 nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto) ||
122 (flags &&
123 nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(flags))))
124 goto nla_put_failure;
125 return 0;
126
127nla_put_failure:
128 return 1;
129}
130
131static inline void
132hash_netportnet4_data_next(struct hash_netportnet4_elem *next,
133 const struct hash_netportnet4_elem *d)
134{
135 next->ipcmp = d->ipcmp;
136 next->port = d->port;
137}
138
139#define MTYPE hash_netportnet4
140#define PF 4
141#define HOST_MASK 32
142#include "ip_set_hash_gen.h"
143
144static int
145hash_netportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
146 const struct xt_action_param *par,
147 enum ipset_adt adt, struct ip_set_adt_opt *opt)
148{
149 const struct hash_netportnet *h = set->data;
150 ipset_adtfn adtfn = set->variant->adt[adt];
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200151 struct hash_netportnet4_elem e = { };
Oliver Smith7c3ad052013-09-28 20:33:23 +0200152 struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
153
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200154 e.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK);
155 e.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK);
Oliver Smith7c3ad052013-09-28 20:33:23 +0200156 if (adt == IPSET_TEST)
157 e.ccmp = (HOST_MASK << (sizeof(e.cidr[0]) * 8)) | HOST_MASK;
158
159 if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
160 &e.port, &e.proto))
161 return -EINVAL;
162
163 ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip[0]);
164 ip4addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &e.ip[1]);
165 e.ip[0] &= ip_set_netmask(e.cidr[0]);
166 e.ip[1] &= ip_set_netmask(e.cidr[1]);
167
168 return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
169}
170
171static int
172hash_netportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
173 enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
174{
175 const struct hash_netportnet *h = set->data;
176 ipset_adtfn adtfn = set->variant->adt[adt];
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200177 struct hash_netportnet4_elem e = { };
Oliver Smith7c3ad052013-09-28 20:33:23 +0200178 struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
179 u32 ip = 0, ip_to = 0, ip_last, p = 0, port, port_to;
180 u32 ip2_from = 0, ip2_to = 0, ip2_last, ip2;
181 bool with_ports = false;
182 u8 cidr, cidr2;
183 int ret;
184
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200185 e.cidr[0] = e.cidr[1] = HOST_MASK;
Oliver Smith7c3ad052013-09-28 20:33:23 +0200186 if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
187 !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
188 !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
189 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
190 !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) ||
191 !ip_set_optattr_netorder(tb, IPSET_ATTR_PACKETS) ||
192 !ip_set_optattr_netorder(tb, IPSET_ATTR_BYTES)))
193 return -IPSET_ERR_PROTOCOL;
194
195 if (tb[IPSET_ATTR_LINENO])
196 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
197
198 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP], &ip) ||
199 ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2], &ip2_from) ||
200 ip_set_get_extensions(set, tb, &ext);
201 if (ret)
202 return ret;
203
204 if (tb[IPSET_ATTR_CIDR]) {
205 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
206 if (!cidr || cidr > HOST_MASK)
207 return -IPSET_ERR_INVALID_CIDR;
208 e.cidr[0] = cidr;
209 }
210
211 if (tb[IPSET_ATTR_CIDR2]) {
212 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
213 if (!cidr || cidr > HOST_MASK)
214 return -IPSET_ERR_INVALID_CIDR;
215 e.cidr[1] = cidr;
216 }
217
218 if (tb[IPSET_ATTR_PORT])
219 e.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
220 else
221 return -IPSET_ERR_PROTOCOL;
222
223 if (tb[IPSET_ATTR_PROTO]) {
224 e.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
225 with_ports = ip_set_proto_with_ports(e.proto);
226
227 if (e.proto == 0)
228 return -IPSET_ERR_INVALID_PROTO;
229 } else
230 return -IPSET_ERR_MISSING_PROTO;
231
232 if (!(with_ports || e.proto == IPPROTO_ICMP))
233 e.port = 0;
234
235 if (tb[IPSET_ATTR_CADT_FLAGS]) {
236 u32 cadt_flags = ip_set_get_h32(tb[IPSET_ATTR_CADT_FLAGS]);
237 if (cadt_flags & IPSET_FLAG_NOMATCH)
238 flags |= (IPSET_FLAG_NOMATCH << 16);
239 }
240
241 with_ports = with_ports && tb[IPSET_ATTR_PORT_TO];
242 if (adt == IPSET_TEST ||
243 !(tb[IPSET_ATTR_IP_TO] || with_ports || tb[IPSET_ATTR_IP2_TO])) {
244 e.ip[0] = htonl(ip & ip_set_hostmask(e.cidr[0]));
245 e.ip[1] = htonl(ip2_from & ip_set_hostmask(e.cidr[1]));
246 ret = adtfn(set, &e, &ext, &ext, flags);
247 return ip_set_enomatch(ret, flags, adt, set) ? -ret :
248 ip_set_eexist(ret, flags) ? 0 : ret;
249 }
250
251 ip_to = ip;
252 if (tb[IPSET_ATTR_IP_TO]) {
253 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &ip_to);
254 if (ret)
255 return ret;
256 if (ip > ip_to)
257 swap(ip, ip_to);
258 if (unlikely(ip + UINT_MAX == ip_to))
259 return -IPSET_ERR_HASH_RANGE;
Sergey Popovich6e41ee62014-05-05 11:07:06 +0300260 } else
261 ip_set_mask_from_to(ip, ip_to, e.cidr[0]);
Oliver Smith7c3ad052013-09-28 20:33:23 +0200262
263 port_to = port = ntohs(e.port);
264 if (tb[IPSET_ATTR_PORT_TO]) {
265 port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
266 if (port > port_to)
267 swap(port, port_to);
268 }
269
270 ip2_to = ip2_from;
271 if (tb[IPSET_ATTR_IP2_TO]) {
272 ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2_TO], &ip2_to);
273 if (ret)
274 return ret;
275 if (ip2_from > ip2_to)
276 swap(ip2_from, ip2_to);
277 if (unlikely(ip2_from + UINT_MAX == ip2_to))
278 return -IPSET_ERR_HASH_RANGE;
Sergey Popovich6e41ee62014-05-05 11:07:06 +0300279 } else
280 ip_set_mask_from_to(ip2_from, ip2_to, e.cidr[1]);
Oliver Smith7c3ad052013-09-28 20:33:23 +0200281
282 if (retried)
283 ip = ntohl(h->next.ip[0]);
284
285 while (!after(ip, ip_to)) {
286 e.ip[0] = htonl(ip);
287 ip_last = ip_set_range_to_cidr(ip, ip_to, &cidr);
288 e.cidr[0] = cidr;
289 p = retried && ip == ntohl(h->next.ip[0]) ? ntohs(h->next.port)
290 : port;
291 for (; p <= port_to; p++) {
292 e.port = htons(p);
293 ip2 = (retried && ip == ntohl(h->next.ip[0]) &&
294 p == ntohs(h->next.port)) ? ntohl(h->next.ip[1])
295 : ip2_from;
296 while (!after(ip2, ip2_to)) {
297 e.ip[1] = htonl(ip2);
298 ip2_last = ip_set_range_to_cidr(ip2, ip2_to,
299 &cidr2);
300 e.cidr[1] = cidr2;
301 ret = adtfn(set, &e, &ext, &ext, flags);
302 if (ret && !ip_set_eexist(ret, flags))
303 return ret;
304 else
305 ret = 0;
306 ip2 = ip2_last + 1;
307 }
308 }
309 ip = ip_last + 1;
310 }
311 return ret;
312}
313
314/* IPv6 variant */
315
316struct hash_netportnet6_elem {
317 union nf_inet_addr ip[2];
318 __be16 port;
319 union {
320 u8 cidr[2];
321 u16 ccmp;
322 };
323 u8 nomatch:1;
324 u8 proto;
325};
326
327/* Common functions */
328
329static inline bool
330hash_netportnet6_data_equal(const struct hash_netportnet6_elem *ip1,
331 const struct hash_netportnet6_elem *ip2,
332 u32 *multi)
333{
334 return ipv6_addr_equal(&ip1->ip[0].in6, &ip2->ip[0].in6) &&
335 ipv6_addr_equal(&ip1->ip[1].in6, &ip2->ip[1].in6) &&
336 ip1->ccmp == ip2->ccmp &&
337 ip1->port == ip2->port &&
338 ip1->proto == ip2->proto;
339}
340
341static inline int
342hash_netportnet6_do_data_match(const struct hash_netportnet6_elem *elem)
343{
344 return elem->nomatch ? -ENOTEMPTY : 1;
345}
346
347static inline void
348hash_netportnet6_data_set_flags(struct hash_netportnet6_elem *elem, u32 flags)
349{
350 elem->nomatch = !!((flags >> 16) & IPSET_FLAG_NOMATCH);
351}
352
353static inline void
354hash_netportnet6_data_reset_flags(struct hash_netportnet6_elem *elem, u8 *flags)
355{
356 swap(*flags, elem->nomatch);
357}
358
359static inline void
360hash_netportnet6_data_reset_elem(struct hash_netportnet6_elem *elem,
361 struct hash_netportnet6_elem *orig)
362{
363 elem->ip[1] = orig->ip[1];
364}
365
366static inline void
367hash_netportnet6_data_netmask(struct hash_netportnet6_elem *elem,
368 u8 cidr, bool inner)
369{
370 if (inner) {
371 ip6_netmask(&elem->ip[1], cidr);
372 elem->cidr[1] = cidr;
373 } else {
374 ip6_netmask(&elem->ip[0], cidr);
375 elem->cidr[0] = cidr;
376 }
377}
378
379static bool
380hash_netportnet6_data_list(struct sk_buff *skb,
381 const struct hash_netportnet6_elem *data)
382{
383 u32 flags = data->nomatch ? IPSET_FLAG_NOMATCH : 0;
384
385 if (nla_put_ipaddr6(skb, IPSET_ATTR_IP, &data->ip[0].in6) ||
386 nla_put_ipaddr6(skb, IPSET_ATTR_IP2, &data->ip[1].in6) ||
387 nla_put_net16(skb, IPSET_ATTR_PORT, data->port) ||
388 nla_put_u8(skb, IPSET_ATTR_CIDR, data->cidr[0]) ||
389 nla_put_u8(skb, IPSET_ATTR_CIDR2, data->cidr[1]) ||
390 nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto) ||
391 (flags &&
392 nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(flags))))
393 goto nla_put_failure;
394 return 0;
395
396nla_put_failure:
397 return 1;
398}
399
400static inline void
401hash_netportnet6_data_next(struct hash_netportnet4_elem *next,
402 const struct hash_netportnet6_elem *d)
403{
404 next->port = d->port;
405}
406
407#undef MTYPE
408#undef PF
409#undef HOST_MASK
410
411#define MTYPE hash_netportnet6
412#define PF 6
413#define HOST_MASK 128
414#define IP_SET_EMIT_CREATE
415#include "ip_set_hash_gen.h"
416
417static int
418hash_netportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
419 const struct xt_action_param *par,
420 enum ipset_adt adt, struct ip_set_adt_opt *opt)
421{
422 const struct hash_netportnet *h = set->data;
423 ipset_adtfn adtfn = set->variant->adt[adt];
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200424 struct hash_netportnet6_elem e = { };
Oliver Smith7c3ad052013-09-28 20:33:23 +0200425 struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
426
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200427 e.cidr[0] = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK);
428 e.cidr[1] = IP_SET_INIT_CIDR(h->nets[0].cidr[1], HOST_MASK);
Oliver Smith7c3ad052013-09-28 20:33:23 +0200429 if (adt == IPSET_TEST)
430 e.ccmp = (HOST_MASK << (sizeof(u8) * 8)) | HOST_MASK;
431
432 if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
433 &e.port, &e.proto))
434 return -EINVAL;
435
436 ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip[0].in6);
437 ip6addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &e.ip[1].in6);
438 ip6_netmask(&e.ip[0], e.cidr[0]);
439 ip6_netmask(&e.ip[1], e.cidr[1]);
440
441 return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
442}
443
444static int
445hash_netportnet6_uadt(struct ip_set *set, struct nlattr *tb[],
446 enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
447{
448 const struct hash_netportnet *h = set->data;
449 ipset_adtfn adtfn = set->variant->adt[adt];
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200450 struct hash_netportnet6_elem e = { };
Oliver Smith7c3ad052013-09-28 20:33:23 +0200451 struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
452 u32 port, port_to;
453 bool with_ports = false;
454 int ret;
455
Jozsef Kadlecsik1a869202013-10-18 11:41:57 +0200456 e.cidr[0] = e.cidr[1] = HOST_MASK;
Oliver Smith7c3ad052013-09-28 20:33:23 +0200457 if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
458 !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
459 !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
460 !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
461 !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) ||
462 !ip_set_optattr_netorder(tb, IPSET_ATTR_PACKETS) ||
463 !ip_set_optattr_netorder(tb, IPSET_ATTR_BYTES)))
464 return -IPSET_ERR_PROTOCOL;
465 if (unlikely(tb[IPSET_ATTR_IP_TO] || tb[IPSET_ATTR_IP2_TO]))
466 return -IPSET_ERR_HASH_RANGE_UNSUPPORTED;
467
468 if (tb[IPSET_ATTR_LINENO])
469 *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
470
471 ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP], &e.ip[0]) ||
472 ip_set_get_ipaddr6(tb[IPSET_ATTR_IP2], &e.ip[1]) ||
473 ip_set_get_extensions(set, tb, &ext);
474 if (ret)
475 return ret;
476
477 if (tb[IPSET_ATTR_CIDR])
478 e.cidr[0] = nla_get_u8(tb[IPSET_ATTR_CIDR]);
479
480 if (tb[IPSET_ATTR_CIDR2])
481 e.cidr[1] = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
482
483 if (unlikely(!e.cidr[0] || e.cidr[0] > HOST_MASK || !e.cidr[1] ||
484 e.cidr[1] > HOST_MASK))
485 return -IPSET_ERR_INVALID_CIDR;
486
487 ip6_netmask(&e.ip[0], e.cidr[0]);
488 ip6_netmask(&e.ip[1], e.cidr[1]);
489
490 if (tb[IPSET_ATTR_PORT])
491 e.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
492 else
493 return -IPSET_ERR_PROTOCOL;
494
495 if (tb[IPSET_ATTR_PROTO]) {
496 e.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
497 with_ports = ip_set_proto_with_ports(e.proto);
498
499 if (e.proto == 0)
500 return -IPSET_ERR_INVALID_PROTO;
501 } else
502 return -IPSET_ERR_MISSING_PROTO;
503
504 if (!(with_ports || e.proto == IPPROTO_ICMPV6))
505 e.port = 0;
506
507 if (tb[IPSET_ATTR_CADT_FLAGS]) {
508 u32 cadt_flags = ip_set_get_h32(tb[IPSET_ATTR_CADT_FLAGS]);
509 if (cadt_flags & IPSET_FLAG_NOMATCH)
510 flags |= (IPSET_FLAG_NOMATCH << 16);
511 }
512
513 if (adt == IPSET_TEST || !with_ports || !tb[IPSET_ATTR_PORT_TO]) {
514 ret = adtfn(set, &e, &ext, &ext, flags);
515 return ip_set_enomatch(ret, flags, adt, set) ? -ret :
516 ip_set_eexist(ret, flags) ? 0 : ret;
517 }
518
519 port = ntohs(e.port);
520 port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
521 if (port > port_to)
522 swap(port, port_to);
523
524 if (retried)
525 port = ntohs(h->next.port);
526 for (; port <= port_to; port++) {
527 e.port = htons(port);
528 ret = adtfn(set, &e, &ext, &ext, flags);
529
530 if (ret && !ip_set_eexist(ret, flags))
531 return ret;
532 else
533 ret = 0;
534 }
535 return ret;
536}
537
538static struct ip_set_type hash_netportnet_type __read_mostly = {
539 .name = "hash:net,port,net",
540 .protocol = IPSET_PROTOCOL,
541 .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2 |
542 IPSET_TYPE_NOMATCH,
543 .dimension = IPSET_DIM_THREE,
544 .family = NFPROTO_UNSPEC,
545 .revision_min = IPSET_TYPE_REV_MIN,
546 .revision_max = IPSET_TYPE_REV_MAX,
547 .create = hash_netportnet_create,
548 .create_policy = {
549 [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
550 [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 },
551 [IPSET_ATTR_PROBES] = { .type = NLA_U8 },
552 [IPSET_ATTR_RESIZE] = { .type = NLA_U8 },
553 [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
554 [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
555 },
556 .adt_policy = {
557 [IPSET_ATTR_IP] = { .type = NLA_NESTED },
558 [IPSET_ATTR_IP_TO] = { .type = NLA_NESTED },
559 [IPSET_ATTR_IP2] = { .type = NLA_NESTED },
560 [IPSET_ATTR_IP2_TO] = { .type = NLA_NESTED },
561 [IPSET_ATTR_PORT] = { .type = NLA_U16 },
562 [IPSET_ATTR_PORT_TO] = { .type = NLA_U16 },
563 [IPSET_ATTR_CIDR] = { .type = NLA_U8 },
564 [IPSET_ATTR_CIDR2] = { .type = NLA_U8 },
565 [IPSET_ATTR_PROTO] = { .type = NLA_U8 },
566 [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
567 [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
568 [IPSET_ATTR_LINENO] = { .type = NLA_U32 },
569 [IPSET_ATTR_BYTES] = { .type = NLA_U64 },
570 [IPSET_ATTR_PACKETS] = { .type = NLA_U64 },
571 [IPSET_ATTR_COMMENT] = { .type = NLA_NUL_STRING },
572 },
573 .me = THIS_MODULE,
574};
575
576static int __init
577hash_netportnet_init(void)
578{
579 return ip_set_type_register(&hash_netportnet_type);
580}
581
582static void __exit
583hash_netportnet_fini(void)
584{
585 ip_set_type_unregister(&hash_netportnet_type);
586}
587
588module_init(hash_netportnet_init);
589module_exit(hash_netportnet_fini);