ip_set_hash_ipportnet.c 15.6 KB
Newer Older
1
/* Copyright (C) 2003-2013 Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */

/* Kernel module implementing an IP set type: the hash:ip,port,net type */

#include <linux/jhash.h>
#include <linux/module.h>
#include <linux/ip.h>
#include <linux/skbuff.h>
#include <linux/errno.h>
#include <linux/random.h>
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/netlink.h>
#include <net/tcp.h>

#include <linux/netfilter.h>
#include <linux/netfilter/ipset/pfxlen.h>
#include <linux/netfilter/ipset/ip_set.h>
#include <linux/netfilter/ipset/ip_set_getport.h>
#include <linux/netfilter/ipset/ip_set_hash.h>

27 28 29 30
#define IPSET_TYPE_REV_MIN	0
/*				1    SCTP and UDPLITE support added */
/*				2    Range as input support for IPv4 added */
/*				3    nomatch flag support added */
31
/*				4    Counters support added */
32
/*				5    Comments support added */
33 34
/*				6    Forceadd support added */
#define IPSET_TYPE_REV_MAX	7 /* skbinfo support added */
35

36 37
MODULE_LICENSE("GPL");
MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
38
IP_SET_MODULE_DESC("hash:ip,port,net", IPSET_TYPE_REV_MIN, IPSET_TYPE_REV_MAX);
39 40 41
MODULE_ALIAS("ip_set_hash:ip,port,net");

/* Type specific function prefix */
42
#define HTYPE		hash_ipportnet
43

44 45 46 47 48
/* We squeeze the "nomatch" flag into cidr: we don't support cidr == 0
 * However this way we have to store internally cidr - 1,
 * dancing back and forth.
 */
#define IP_SET_HASH_WITH_NETS_PACKED
49 50
#define IP_SET_HASH_WITH_PROTO
#define IP_SET_HASH_WITH_NETS
51

52
/* IPv4 variant */
53 54

/* Member elements */
55 56 57 58
struct hash_ipportnet4_elem {
	__be32 ip;
	__be32 ip2;
	__be16 port;
59 60
	u8 cidr:7;
	u8 nomatch:1;
61 62 63
	u8 proto;
};

64 65
/* Common functions */

66 67
static inline bool
hash_ipportnet4_data_equal(const struct hash_ipportnet4_elem *ip1,
68 69
			   const struct hash_ipportnet4_elem *ip2,
			   u32 *multi)
70 71 72 73 74 75 76 77
{
	return ip1->ip == ip2->ip &&
	       ip1->ip2 == ip2->ip2 &&
	       ip1->cidr == ip2->cidr &&
	       ip1->port == ip2->port &&
	       ip1->proto == ip2->proto;
}

78 79
static inline int
hash_ipportnet4_do_data_match(const struct hash_ipportnet4_elem *elem)
80
{
81
	return elem->nomatch ? -ENOTEMPTY : 1;
82 83 84
}

static inline void
85
hash_ipportnet4_data_set_flags(struct hash_ipportnet4_elem *elem, u32 flags)
86
{
87
	elem->nomatch = !!((flags >> 16) & IPSET_FLAG_NOMATCH);
88 89
}

90
static inline void
91
hash_ipportnet4_data_reset_flags(struct hash_ipportnet4_elem *elem, u8 *flags)
92
{
93
	swap(*flags, elem->nomatch);
94 95
}

96 97 98 99
static inline void
hash_ipportnet4_data_netmask(struct hash_ipportnet4_elem *elem, u8 cidr)
{
	elem->ip2 &= ip_set_netmask(cidr);
100
	elem->cidr = cidr - 1;
101 102 103 104 105 106
}

static bool
hash_ipportnet4_data_list(struct sk_buff *skb,
			  const struct hash_ipportnet4_elem *data)
{
107 108
	u32 flags = data->nomatch ? IPSET_FLAG_NOMATCH : 0;

D
David S. Miller 已提交
109 110 111 112 113 114 115 116
	if (nla_put_ipaddr4(skb, IPSET_ATTR_IP, data->ip) ||
	    nla_put_ipaddr4(skb, IPSET_ATTR_IP2, data->ip2) ||
	    nla_put_net16(skb, IPSET_ATTR_PORT, data->port) ||
	    nla_put_u8(skb, IPSET_ATTR_CIDR2, data->cidr + 1) ||
	    nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto) ||
	    (flags &&
	     nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(flags))))
		goto nla_put_failure;
117 118 119 120 121 122
	return 0;

nla_put_failure:
	return 1;
}

123 124 125
static inline void
hash_ipportnet4_data_next(struct hash_ipportnet4_elem *next,
			  const struct hash_ipportnet4_elem *d)
126
{
127 128 129
	next->ip = d->ip;
	next->port = d->port;
	next->ip2 = d->ip2;
130 131
}

132
#define MTYPE		hash_ipportnet4
133
#define HOST_MASK	32
134
#include "ip_set_hash_gen.h"
135

136 137
static int
hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
138
		     const struct xt_action_param *par,
139
		     enum ipset_adt adt, struct ip_set_adt_opt *opt)
140
{
141
	const struct hash_ipportnet *h = set->data;
142
	ipset_adtfn adtfn = set->variant->adt[adt];
143
	struct hash_ipportnet4_elem e = {
144
		.cidr = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK) - 1,
145
	};
146
	struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
147 148

	if (adt == IPSET_TEST)
149
		e.cidr = HOST_MASK - 1;
150

151
	if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
152
				 &e.port, &e.proto))
153 154
		return -EINVAL;

155 156 157
	ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip);
	ip4addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &e.ip2);
	e.ip2 &= ip_set_netmask(e.cidr + 1);
158

159
	return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
160 161 162 163
}

static int
hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
164
		     enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
165
{
166
	const struct hash_ipportnet *h = set->data;
167
	ipset_adtfn adtfn = set->variant->adt[adt];
168
	struct hash_ipportnet4_elem e = { .cidr = HOST_MASK - 1 };
169
	struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
170 171
	u32 ip = 0, ip_to = 0, p = 0, port, port_to;
	u32 ip2_from = 0, ip2_to = 0, ip2_last, ip2;
172
	bool with_ports = false;
173
	u8 cidr;
174 175 176 177 178
	int ret;

	if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
		     !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
179
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
180 181
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_PACKETS) ||
182 183 184 185
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_BYTES) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_SKBMARK) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_SKBPRIO) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_SKBQUEUE)))
186 187 188 189 190
		return -IPSET_ERR_PROTOCOL;

	if (tb[IPSET_ATTR_LINENO])
		*lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);

191 192 193 194 195
	ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP], &ip);
	if (ret)
		return ret;

	ret = ip_set_get_extensions(set, tb, &ext);
196 197 198
	if (ret)
		return ret;

199
	ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2], &ip2_from);
200 201 202
	if (ret)
		return ret;

203
	if (tb[IPSET_ATTR_CIDR2]) {
204 205
		cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
		if (!cidr || cidr > HOST_MASK)
206
			return -IPSET_ERR_INVALID_CIDR;
207
		e.cidr = cidr - 1;
208
	}
209 210

	if (tb[IPSET_ATTR_PORT])
211
		e.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
212 213 214 215
	else
		return -IPSET_ERR_PROTOCOL;

	if (tb[IPSET_ATTR_PROTO]) {
216 217
		e.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
		with_ports = ip_set_proto_with_ports(e.proto);
218

219
		if (e.proto == 0)
220 221 222 223
			return -IPSET_ERR_INVALID_PROTO;
	} else
		return -IPSET_ERR_MISSING_PROTO;

224 225
	if (!(with_ports || e.proto == IPPROTO_ICMP))
		e.port = 0;
226

227
	if (tb[IPSET_ATTR_CADT_FLAGS]) {
228 229
		u32 cadt_flags = ip_set_get_h32(tb[IPSET_ATTR_CADT_FLAGS]);
		if (cadt_flags & IPSET_FLAG_NOMATCH)
230
			flags |= (IPSET_FLAG_NOMATCH << 16);
231 232
	}

233
	with_ports = with_ports && tb[IPSET_ATTR_PORT_TO];
234
	if (adt == IPSET_TEST ||
235 236
	    !(tb[IPSET_ATTR_CIDR] || tb[IPSET_ATTR_IP_TO] || with_ports ||
	      tb[IPSET_ATTR_IP2_TO])) {
237 238 239
		e.ip = htonl(ip);
		e.ip2 = htonl(ip2_from & ip_set_hostmask(e.cidr + 1));
		ret = adtfn(set, &e, &ext, &ext, flags);
240
		return ip_set_enomatch(ret, flags, adt, set) ? -ret :
241
		       ip_set_eexist(ret, flags) ? 0 : ret;
242 243
	}

244
	ip_to = ip;
245 246 247 248 249 250 251
	if (tb[IPSET_ATTR_IP_TO]) {
		ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &ip_to);
		if (ret)
			return ret;
		if (ip > ip_to)
			swap(ip, ip_to);
	} else if (tb[IPSET_ATTR_CIDR]) {
252
		cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
253

254
		if (!cidr || cidr > 32)
255
			return -IPSET_ERR_INVALID_CIDR;
256
		ip_set_mask_from_to(ip, ip_to, cidr);
257
	}
258

259
	port_to = port = ntohs(e.port);
260
	if (tb[IPSET_ATTR_PORT_TO]) {
261 262 263
		port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
		if (port > port_to)
			swap(port, port_to);
264
	}
265 266

	ip2_to = ip2_from;
267 268 269 270 271 272 273 274
	if (tb[IPSET_ATTR_IP2_TO]) {
		ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2_TO], &ip2_to);
		if (ret)
			return ret;
		if (ip2_from > ip2_to)
			swap(ip2_from, ip2_to);
		if (ip2_from + UINT_MAX == ip2_to)
			return -IPSET_ERR_HASH_RANGE;
275 276
	} else
		ip_set_mask_from_to(ip2_from, ip2_to, e.cidr + 1);
277

278
	if (retried)
279
		ip = ntohl(h->next.ip);
280
	for (; !before(ip_to, ip); ip++) {
281
		e.ip = htonl(ip);
282 283
		p = retried && ip == ntohl(h->next.ip) ? ntohs(h->next.port)
						       : port;
284
		for (; p <= port_to; p++) {
285
			e.port = htons(p);
286 287 288
			ip2 = retried &&
			      ip == ntohl(h->next.ip) &&
			      p == ntohs(h->next.port)
289
				? ntohl(h->next.ip2) : ip2_from;
290
			while (!after(ip2, ip2_to)) {
291
				e.ip2 = htonl(ip2);
292
				ip2_last = ip_set_range_to_cidr(ip2, ip2_to,
293
								&cidr);
294 295
				e.cidr = cidr - 1;
				ret = adtfn(set, &e, &ext, &ext, flags);
296 297 298 299 300 301 302

				if (ret && !ip_set_eexist(ret, flags))
					return ret;
				else
					ret = 0;
				ip2 = ip2_last + 1;
			}
303
		}
304
	}
305 306 307
	return ret;
}

308
/* IPv6 variant */
309 310 311 312 313

struct hash_ipportnet6_elem {
	union nf_inet_addr ip;
	union nf_inet_addr ip2;
	__be16 port;
314 315
	u8 cidr:7;
	u8 nomatch:1;
316 317 318
	u8 proto;
};

319 320
/* Common functions */

321 322
static inline bool
hash_ipportnet6_data_equal(const struct hash_ipportnet6_elem *ip1,
323 324
			   const struct hash_ipportnet6_elem *ip2,
			   u32 *multi)
325
{
326 327
	return ipv6_addr_equal(&ip1->ip.in6, &ip2->ip.in6) &&
	       ipv6_addr_equal(&ip1->ip2.in6, &ip2->ip2.in6) &&
328 329 330 331 332
	       ip1->cidr == ip2->cidr &&
	       ip1->port == ip2->port &&
	       ip1->proto == ip2->proto;
}

333 334
static inline int
hash_ipportnet6_do_data_match(const struct hash_ipportnet6_elem *elem)
335
{
336
	return elem->nomatch ? -ENOTEMPTY : 1;
337 338
}

339
static inline void
340
hash_ipportnet6_data_set_flags(struct hash_ipportnet6_elem *elem, u32 flags)
341
{
342
	elem->nomatch = !!((flags >> 16) & IPSET_FLAG_NOMATCH);
343 344
}

345
static inline void
346
hash_ipportnet6_data_reset_flags(struct hash_ipportnet6_elem *elem, u8 *flags)
347
{
348
	swap(*flags, elem->nomatch);
349 350 351 352 353 354
}

static inline void
hash_ipportnet6_data_netmask(struct hash_ipportnet6_elem *elem, u8 cidr)
{
	ip6_netmask(&elem->ip2, cidr);
355
	elem->cidr = cidr - 1;
356 357 358 359 360 361
}

static bool
hash_ipportnet6_data_list(struct sk_buff *skb,
			  const struct hash_ipportnet6_elem *data)
{
362 363
	u32 flags = data->nomatch ? IPSET_FLAG_NOMATCH : 0;

D
David S. Miller 已提交
364 365 366 367 368 369 370 371
	if (nla_put_ipaddr6(skb, IPSET_ATTR_IP, &data->ip.in6) ||
	    nla_put_ipaddr6(skb, IPSET_ATTR_IP2, &data->ip2.in6) ||
	    nla_put_net16(skb, IPSET_ATTR_PORT, data->port) ||
	    nla_put_u8(skb, IPSET_ATTR_CIDR2, data->cidr + 1) ||
	    nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto) ||
	    (flags &&
	     nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(flags))))
		goto nla_put_failure;
372 373 374 375 376 377
	return 0;

nla_put_failure:
	return 1;
}

378 379 380
static inline void
hash_ipportnet6_data_next(struct hash_ipportnet4_elem *next,
			  const struct hash_ipportnet6_elem *d)
381
{
382
	next->port = d->port;
383 384
}

385
#undef MTYPE
386 387
#undef HOST_MASK

388
#define MTYPE		hash_ipportnet6
389
#define HOST_MASK	128
390 391
#define IP_SET_EMIT_CREATE
#include "ip_set_hash_gen.h"
392

393 394
static int
hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
395
		     const struct xt_action_param *par,
396
		     enum ipset_adt adt, struct ip_set_adt_opt *opt)
397
{
398
	const struct hash_ipportnet *h = set->data;
399
	ipset_adtfn adtfn = set->variant->adt[adt];
400
	struct hash_ipportnet6_elem e = {
401
		.cidr = IP_SET_INIT_CIDR(h->nets[0].cidr[0], HOST_MASK) - 1,
402
	};
403
	struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
404 405

	if (adt == IPSET_TEST)
406
		e.cidr = HOST_MASK - 1;
407

408
	if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
409
				 &e.port, &e.proto))
410 411
		return -EINVAL;

412 413 414
	ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip.in6);
	ip6addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &e.ip2.in6);
	ip6_netmask(&e.ip2, e.cidr + 1);
415

416
	return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
417 418 419 420
}

static int
hash_ipportnet6_uadt(struct ip_set *set, struct nlattr *tb[],
421
		     enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
422
{
423
	const struct hash_ipportnet *h = set->data;
424
	ipset_adtfn adtfn = set->variant->adt[adt];
425
	struct hash_ipportnet6_elem e = { .cidr = HOST_MASK - 1 };
426
	struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
427
	u32 port, port_to;
428
	bool with_ports = false;
429
	u8 cidr;
430 431 432 433 434 435
	int ret;

	if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
		     !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_TIMEOUT) ||
436
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS) ||
437 438
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_PACKETS) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_BYTES) ||
439 440 441
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_SKBMARK) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_SKBPRIO) ||
		     !ip_set_optattr_netorder(tb, IPSET_ATTR_SKBQUEUE) ||
442 443 444
		     tb[IPSET_ATTR_IP_TO] ||
		     tb[IPSET_ATTR_CIDR]))
		return -IPSET_ERR_PROTOCOL;
445 446
	if (unlikely(tb[IPSET_ATTR_IP_TO]))
		return -IPSET_ERR_HASH_RANGE_UNSUPPORTED;
447 448 449 450

	if (tb[IPSET_ATTR_LINENO])
		*lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);

451 452 453 454 455
	ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP], &e.ip);
	if (ret)
		return ret;

	ret = ip_set_get_extensions(set, tb, &ext);
456 457 458
	if (ret)
		return ret;

459
	ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP2], &e.ip2);
460 461 462
	if (ret)
		return ret;

463 464 465 466
	if (tb[IPSET_ATTR_CIDR2]) {
		cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
		if (!cidr || cidr > HOST_MASK)
			return -IPSET_ERR_INVALID_CIDR;
467
		e.cidr = cidr - 1;
468
	}
469

470
	ip6_netmask(&e.ip2, e.cidr + 1);
471 472

	if (tb[IPSET_ATTR_PORT])
473
		e.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
474 475 476 477
	else
		return -IPSET_ERR_PROTOCOL;

	if (tb[IPSET_ATTR_PROTO]) {
478 479
		e.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
		with_ports = ip_set_proto_with_ports(e.proto);
480

481
		if (e.proto == 0)
482 483 484 485
			return -IPSET_ERR_INVALID_PROTO;
	} else
		return -IPSET_ERR_MISSING_PROTO;

486 487
	if (!(with_ports || e.proto == IPPROTO_ICMPV6))
		e.port = 0;
488

489
	if (tb[IPSET_ATTR_CADT_FLAGS]) {
490 491
		u32 cadt_flags = ip_set_get_h32(tb[IPSET_ATTR_CADT_FLAGS]);
		if (cadt_flags & IPSET_FLAG_NOMATCH)
492
			flags |= (IPSET_FLAG_NOMATCH << 16);
493 494
	}

495
	if (adt == IPSET_TEST || !with_ports || !tb[IPSET_ATTR_PORT_TO]) {
496
		ret = adtfn(set, &e, &ext, &ext, flags);
497
		return ip_set_enomatch(ret, flags, adt, set) ? -ret :
498
		       ip_set_eexist(ret, flags) ? 0 : ret;
499 500
	}

501
	port = ntohs(e.port);
502 503 504 505
	port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
	if (port > port_to)
		swap(port, port_to);

506
	if (retried)
507
		port = ntohs(h->next.port);
508
	for (; port <= port_to; port++) {
509 510
		e.port = htons(port);
		ret = adtfn(set, &e, &ext, &ext, flags);
511 512 513 514 515 516 517 518 519 520 521 522

		if (ret && !ip_set_eexist(ret, flags))
			return ret;
		else
			ret = 0;
	}
	return ret;
}

static struct ip_set_type hash_ipportnet_type __read_mostly = {
	.name		= "hash:ip,port,net",
	.protocol	= IPSET_PROTOCOL,
523 524
	.features	= IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2 |
			  IPSET_TYPE_NOMATCH,
525
	.dimension	= IPSET_DIM_THREE,
526
	.family		= NFPROTO_UNSPEC,
527 528
	.revision_min	= IPSET_TYPE_REV_MIN,
	.revision_max	= IPSET_TYPE_REV_MAX,
529 530 531 532 533 534 535
	.create		= hash_ipportnet_create,
	.create_policy	= {
		[IPSET_ATTR_HASHSIZE]	= { .type = NLA_U32 },
		[IPSET_ATTR_MAXELEM]	= { .type = NLA_U32 },
		[IPSET_ATTR_PROBES]	= { .type = NLA_U8 },
		[IPSET_ATTR_RESIZE]	= { .type = NLA_U8  },
		[IPSET_ATTR_TIMEOUT]	= { .type = NLA_U32 },
536
		[IPSET_ATTR_CADT_FLAGS]	= { .type = NLA_U32 },
537 538 539 540 541
	},
	.adt_policy	= {
		[IPSET_ATTR_IP]		= { .type = NLA_NESTED },
		[IPSET_ATTR_IP_TO]	= { .type = NLA_NESTED },
		[IPSET_ATTR_IP2]	= { .type = NLA_NESTED },
542
		[IPSET_ATTR_IP2_TO]	= { .type = NLA_NESTED },
543 544 545 546 547
		[IPSET_ATTR_PORT]	= { .type = NLA_U16 },
		[IPSET_ATTR_PORT_TO]	= { .type = NLA_U16 },
		[IPSET_ATTR_CIDR]	= { .type = NLA_U8 },
		[IPSET_ATTR_CIDR2]	= { .type = NLA_U8 },
		[IPSET_ATTR_PROTO]	= { .type = NLA_U8 },
548
		[IPSET_ATTR_CADT_FLAGS]	= { .type = NLA_U32 },
549 550
		[IPSET_ATTR_TIMEOUT]	= { .type = NLA_U32 },
		[IPSET_ATTR_LINENO]	= { .type = NLA_U32 },
551 552
		[IPSET_ATTR_BYTES]	= { .type = NLA_U64 },
		[IPSET_ATTR_PACKETS]	= { .type = NLA_U64 },
553
		[IPSET_ATTR_COMMENT]	= { .type = NLA_NUL_STRING },
554 555 556
		[IPSET_ATTR_SKBMARK]	= { .type = NLA_U64 },
		[IPSET_ATTR_SKBPRIO]	= { .type = NLA_U32 },
		[IPSET_ATTR_SKBQUEUE]	= { .type = NLA_U16 },
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574
	},
	.me		= THIS_MODULE,
};

static int __init
hash_ipportnet_init(void)
{
	return ip_set_type_register(&hash_ipportnet_type);
}

static void __exit
hash_ipportnet_fini(void)
{
	ip_set_type_unregister(&hash_ipportnet_type);
}

module_init(hash_ipportnet_init);
module_exit(hash_ipportnet_fini);