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