ip_set_hash_ipportnet.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. /* 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. /* Kernel module implementing an IP set type: the hash:ip,port,net type */
  8. #include <linux/jhash.h>
  9. #include <linux/module.h>
  10. #include <linux/ip.h>
  11. #include <linux/skbuff.h>
  12. #include <linux/errno.h>
  13. #include <linux/random.h>
  14. #include <net/ip.h>
  15. #include <net/ipv6.h>
  16. #include <net/netlink.h>
  17. #include <net/tcp.h>
  18. #include <linux/netfilter.h>
  19. #include <linux/netfilter/ipset/pfxlen.h>
  20. #include <linux/netfilter/ipset/ip_set.h>
  21. #include <linux/netfilter/ipset/ip_set_getport.h>
  22. #include <linux/netfilter/ipset/ip_set_hash.h>
  23. #define IPSET_TYPE_REV_MIN 0
  24. /* 1 SCTP and UDPLITE support added */
  25. /* 2 Range as input support for IPv4 added */
  26. /* 3 nomatch flag support added */
  27. /* 4 Counters support added */
  28. /* 5 Comments support added */
  29. /* 6 Forceadd support added */
  30. #define IPSET_TYPE_REV_MAX 7 /* skbinfo support added */
  31. MODULE_LICENSE("GPL");
  32. MODULE_AUTHOR("Jozsef Kadlecsik <kadlec@blackhole.kfki.hu>");
  33. IP_SET_MODULE_DESC("hash:ip,port,net", IPSET_TYPE_REV_MIN, IPSET_TYPE_REV_MAX);
  34. MODULE_ALIAS("ip_set_hash:ip,port,net");
  35. /* Type specific function prefix */
  36. #define HTYPE hash_ipportnet
  37. /* We squeeze the "nomatch" flag into cidr: we don't support cidr == 0
  38. * However this way we have to store internally cidr - 1,
  39. * dancing back and forth.
  40. */
  41. #define IP_SET_HASH_WITH_NETS_PACKED
  42. #define IP_SET_HASH_WITH_PROTO
  43. #define IP_SET_HASH_WITH_NETS
  44. /* IPv4 variant */
  45. /* Member elements */
  46. struct hash_ipportnet4_elem {
  47. __be32 ip;
  48. __be32 ip2;
  49. __be16 port;
  50. u8 cidr:7;
  51. u8 nomatch:1;
  52. u8 proto;
  53. };
  54. /* Common functions */
  55. static inline bool
  56. hash_ipportnet4_data_equal(const struct hash_ipportnet4_elem *ip1,
  57. const struct hash_ipportnet4_elem *ip2,
  58. u32 *multi)
  59. {
  60. return ip1->ip == ip2->ip &&
  61. ip1->ip2 == ip2->ip2 &&
  62. ip1->cidr == ip2->cidr &&
  63. ip1->port == ip2->port &&
  64. ip1->proto == ip2->proto;
  65. }
  66. static inline int
  67. hash_ipportnet4_do_data_match(const struct hash_ipportnet4_elem *elem)
  68. {
  69. return elem->nomatch ? -ENOTEMPTY : 1;
  70. }
  71. static inline void
  72. hash_ipportnet4_data_set_flags(struct hash_ipportnet4_elem *elem, u32 flags)
  73. {
  74. elem->nomatch = !!((flags >> 16) & IPSET_FLAG_NOMATCH);
  75. }
  76. static inline void
  77. hash_ipportnet4_data_reset_flags(struct hash_ipportnet4_elem *elem, u8 *flags)
  78. {
  79. swap(*flags, elem->nomatch);
  80. }
  81. static inline void
  82. hash_ipportnet4_data_netmask(struct hash_ipportnet4_elem *elem, u8 cidr)
  83. {
  84. elem->ip2 &= ip_set_netmask(cidr);
  85. elem->cidr = cidr - 1;
  86. }
  87. static bool
  88. hash_ipportnet4_data_list(struct sk_buff *skb,
  89. const struct hash_ipportnet4_elem *data)
  90. {
  91. u32 flags = data->nomatch ? IPSET_FLAG_NOMATCH : 0;
  92. if (nla_put_ipaddr4(skb, IPSET_ATTR_IP, data->ip) ||
  93. nla_put_ipaddr4(skb, IPSET_ATTR_IP2, data->ip2) ||
  94. nla_put_net16(skb, IPSET_ATTR_PORT, data->port) ||
  95. nla_put_u8(skb, IPSET_ATTR_CIDR2, data->cidr + 1) ||
  96. nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto) ||
  97. (flags &&
  98. nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(flags))))
  99. goto nla_put_failure;
  100. return false;
  101. nla_put_failure:
  102. return true;
  103. }
  104. static inline void
  105. hash_ipportnet4_data_next(struct hash_ipportnet4_elem *next,
  106. const struct hash_ipportnet4_elem *d)
  107. {
  108. next->ip = d->ip;
  109. next->port = d->port;
  110. next->ip2 = d->ip2;
  111. }
  112. #define MTYPE hash_ipportnet4
  113. #define HOST_MASK 32
  114. #include "ip_set_hash_gen.h"
  115. static int
  116. hash_ipportnet4_kadt(struct ip_set *set, const struct sk_buff *skb,
  117. const struct xt_action_param *par,
  118. enum ipset_adt adt, struct ip_set_adt_opt *opt)
  119. {
  120. const struct hash_ipportnet *h = set->data;
  121. ipset_adtfn adtfn = set->variant->adt[adt];
  122. struct hash_ipportnet4_elem e = {
  123. .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
  124. };
  125. struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
  126. if (adt == IPSET_TEST)
  127. e.cidr = HOST_MASK - 1;
  128. if (!ip_set_get_ip4_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
  129. &e.port, &e.proto))
  130. return -EINVAL;
  131. ip4addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip);
  132. ip4addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &e.ip2);
  133. e.ip2 &= ip_set_netmask(e.cidr + 1);
  134. return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
  135. }
  136. static int
  137. hash_ipportnet4_uadt(struct ip_set *set, struct nlattr *tb[],
  138. enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
  139. {
  140. const struct hash_ipportnet *h = set->data;
  141. ipset_adtfn adtfn = set->variant->adt[adt];
  142. struct hash_ipportnet4_elem e = { .cidr = HOST_MASK - 1 };
  143. struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
  144. u32 ip = 0, ip_to = 0, p = 0, port, port_to;
  145. u32 ip2_from = 0, ip2_to = 0, ip2_last, ip2;
  146. bool with_ports = false;
  147. u8 cidr;
  148. int ret;
  149. if (tb[IPSET_ATTR_LINENO])
  150. *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
  151. if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
  152. !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
  153. !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
  154. !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS)))
  155. return -IPSET_ERR_PROTOCOL;
  156. ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP], &ip);
  157. if (ret)
  158. return ret;
  159. ret = ip_set_get_extensions(set, tb, &ext);
  160. if (ret)
  161. return ret;
  162. ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2], &ip2_from);
  163. if (ret)
  164. return ret;
  165. if (tb[IPSET_ATTR_CIDR2]) {
  166. cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
  167. if (!cidr || cidr > HOST_MASK)
  168. return -IPSET_ERR_INVALID_CIDR;
  169. e.cidr = cidr - 1;
  170. }
  171. e.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
  172. if (tb[IPSET_ATTR_PROTO]) {
  173. e.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
  174. with_ports = ip_set_proto_with_ports(e.proto);
  175. if (e.proto == 0)
  176. return -IPSET_ERR_INVALID_PROTO;
  177. } else {
  178. return -IPSET_ERR_MISSING_PROTO;
  179. }
  180. if (!(with_ports || e.proto == IPPROTO_ICMP))
  181. e.port = 0;
  182. if (tb[IPSET_ATTR_CADT_FLAGS]) {
  183. u32 cadt_flags = ip_set_get_h32(tb[IPSET_ATTR_CADT_FLAGS]);
  184. if (cadt_flags & IPSET_FLAG_NOMATCH)
  185. flags |= (IPSET_FLAG_NOMATCH << 16);
  186. }
  187. with_ports = with_ports && tb[IPSET_ATTR_PORT_TO];
  188. if (adt == IPSET_TEST ||
  189. !(tb[IPSET_ATTR_CIDR] || tb[IPSET_ATTR_IP_TO] || with_ports ||
  190. tb[IPSET_ATTR_IP2_TO])) {
  191. e.ip = htonl(ip);
  192. e.ip2 = htonl(ip2_from & ip_set_hostmask(e.cidr + 1));
  193. ret = adtfn(set, &e, &ext, &ext, flags);
  194. return ip_set_enomatch(ret, flags, adt, set) ? -ret :
  195. ip_set_eexist(ret, flags) ? 0 : ret;
  196. }
  197. ip_to = ip;
  198. if (tb[IPSET_ATTR_IP_TO]) {
  199. ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP_TO], &ip_to);
  200. if (ret)
  201. return ret;
  202. if (ip > ip_to)
  203. swap(ip, ip_to);
  204. } else 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. ip_set_mask_from_to(ip, ip_to, cidr);
  209. }
  210. port_to = port = ntohs(e.port);
  211. if (tb[IPSET_ATTR_PORT_TO]) {
  212. port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
  213. if (port > port_to)
  214. swap(port, port_to);
  215. }
  216. ip2_to = ip2_from;
  217. if (tb[IPSET_ATTR_IP2_TO]) {
  218. ret = ip_set_get_hostipaddr4(tb[IPSET_ATTR_IP2_TO], &ip2_to);
  219. if (ret)
  220. return ret;
  221. if (ip2_from > ip2_to)
  222. swap(ip2_from, ip2_to);
  223. if (ip2_from + UINT_MAX == ip2_to)
  224. return -IPSET_ERR_HASH_RANGE;
  225. } else {
  226. ip_set_mask_from_to(ip2_from, ip2_to, e.cidr + 1);
  227. }
  228. if (retried)
  229. ip = ntohl(h->next.ip);
  230. for (; !before(ip_to, ip); ip++) {
  231. e.ip = htonl(ip);
  232. p = retried && ip == ntohl(h->next.ip) ? ntohs(h->next.port)
  233. : port;
  234. for (; p <= port_to; p++) {
  235. e.port = htons(p);
  236. ip2 = retried &&
  237. ip == ntohl(h->next.ip) &&
  238. p == ntohs(h->next.port)
  239. ? ntohl(h->next.ip2) : ip2_from;
  240. while (!after(ip2, ip2_to)) {
  241. e.ip2 = htonl(ip2);
  242. ip2_last = ip_set_range_to_cidr(ip2, ip2_to,
  243. &cidr);
  244. e.cidr = cidr - 1;
  245. ret = adtfn(set, &e, &ext, &ext, flags);
  246. if (ret && !ip_set_eexist(ret, flags))
  247. return ret;
  248. ret = 0;
  249. ip2 = ip2_last + 1;
  250. }
  251. }
  252. }
  253. return ret;
  254. }
  255. /* IPv6 variant */
  256. struct hash_ipportnet6_elem {
  257. union nf_inet_addr ip;
  258. union nf_inet_addr ip2;
  259. __be16 port;
  260. u8 cidr:7;
  261. u8 nomatch:1;
  262. u8 proto;
  263. };
  264. /* Common functions */
  265. static inline bool
  266. hash_ipportnet6_data_equal(const struct hash_ipportnet6_elem *ip1,
  267. const struct hash_ipportnet6_elem *ip2,
  268. u32 *multi)
  269. {
  270. return ipv6_addr_equal(&ip1->ip.in6, &ip2->ip.in6) &&
  271. ipv6_addr_equal(&ip1->ip2.in6, &ip2->ip2.in6) &&
  272. ip1->cidr == ip2->cidr &&
  273. ip1->port == ip2->port &&
  274. ip1->proto == ip2->proto;
  275. }
  276. static inline int
  277. hash_ipportnet6_do_data_match(const struct hash_ipportnet6_elem *elem)
  278. {
  279. return elem->nomatch ? -ENOTEMPTY : 1;
  280. }
  281. static inline void
  282. hash_ipportnet6_data_set_flags(struct hash_ipportnet6_elem *elem, u32 flags)
  283. {
  284. elem->nomatch = !!((flags >> 16) & IPSET_FLAG_NOMATCH);
  285. }
  286. static inline void
  287. hash_ipportnet6_data_reset_flags(struct hash_ipportnet6_elem *elem, u8 *flags)
  288. {
  289. swap(*flags, elem->nomatch);
  290. }
  291. static inline void
  292. hash_ipportnet6_data_netmask(struct hash_ipportnet6_elem *elem, u8 cidr)
  293. {
  294. ip6_netmask(&elem->ip2, cidr);
  295. elem->cidr = cidr - 1;
  296. }
  297. static bool
  298. hash_ipportnet6_data_list(struct sk_buff *skb,
  299. const struct hash_ipportnet6_elem *data)
  300. {
  301. u32 flags = data->nomatch ? IPSET_FLAG_NOMATCH : 0;
  302. if (nla_put_ipaddr6(skb, IPSET_ATTR_IP, &data->ip.in6) ||
  303. nla_put_ipaddr6(skb, IPSET_ATTR_IP2, &data->ip2.in6) ||
  304. nla_put_net16(skb, IPSET_ATTR_PORT, data->port) ||
  305. nla_put_u8(skb, IPSET_ATTR_CIDR2, data->cidr + 1) ||
  306. nla_put_u8(skb, IPSET_ATTR_PROTO, data->proto) ||
  307. (flags &&
  308. nla_put_net32(skb, IPSET_ATTR_CADT_FLAGS, htonl(flags))))
  309. goto nla_put_failure;
  310. return false;
  311. nla_put_failure:
  312. return true;
  313. }
  314. static inline void
  315. hash_ipportnet6_data_next(struct hash_ipportnet4_elem *next,
  316. const struct hash_ipportnet6_elem *d)
  317. {
  318. next->port = d->port;
  319. }
  320. #undef MTYPE
  321. #undef HOST_MASK
  322. #define MTYPE hash_ipportnet6
  323. #define HOST_MASK 128
  324. #define IP_SET_EMIT_CREATE
  325. #include "ip_set_hash_gen.h"
  326. static int
  327. hash_ipportnet6_kadt(struct ip_set *set, const struct sk_buff *skb,
  328. const struct xt_action_param *par,
  329. enum ipset_adt adt, struct ip_set_adt_opt *opt)
  330. {
  331. const struct hash_ipportnet *h = set->data;
  332. ipset_adtfn adtfn = set->variant->adt[adt];
  333. struct hash_ipportnet6_elem e = {
  334. .cidr = INIT_CIDR(h->nets[0].cidr[0], HOST_MASK),
  335. };
  336. struct ip_set_ext ext = IP_SET_INIT_KEXT(skb, opt, set);
  337. if (adt == IPSET_TEST)
  338. e.cidr = HOST_MASK - 1;
  339. if (!ip_set_get_ip6_port(skb, opt->flags & IPSET_DIM_TWO_SRC,
  340. &e.port, &e.proto))
  341. return -EINVAL;
  342. ip6addrptr(skb, opt->flags & IPSET_DIM_ONE_SRC, &e.ip.in6);
  343. ip6addrptr(skb, opt->flags & IPSET_DIM_THREE_SRC, &e.ip2.in6);
  344. ip6_netmask(&e.ip2, e.cidr + 1);
  345. return adtfn(set, &e, &ext, &opt->ext, opt->cmdflags);
  346. }
  347. static int
  348. hash_ipportnet6_uadt(struct ip_set *set, struct nlattr *tb[],
  349. enum ipset_adt adt, u32 *lineno, u32 flags, bool retried)
  350. {
  351. const struct hash_ipportnet *h = set->data;
  352. ipset_adtfn adtfn = set->variant->adt[adt];
  353. struct hash_ipportnet6_elem e = { .cidr = HOST_MASK - 1 };
  354. struct ip_set_ext ext = IP_SET_INIT_UEXT(set);
  355. u32 port, port_to;
  356. bool with_ports = false;
  357. u8 cidr;
  358. int ret;
  359. if (tb[IPSET_ATTR_LINENO])
  360. *lineno = nla_get_u32(tb[IPSET_ATTR_LINENO]);
  361. if (unlikely(!tb[IPSET_ATTR_IP] || !tb[IPSET_ATTR_IP2] ||
  362. !ip_set_attr_netorder(tb, IPSET_ATTR_PORT) ||
  363. !ip_set_optattr_netorder(tb, IPSET_ATTR_PORT_TO) ||
  364. !ip_set_optattr_netorder(tb, IPSET_ATTR_CADT_FLAGS)))
  365. return -IPSET_ERR_PROTOCOL;
  366. if (unlikely(tb[IPSET_ATTR_IP_TO]))
  367. return -IPSET_ERR_HASH_RANGE_UNSUPPORTED;
  368. if (unlikely(tb[IPSET_ATTR_CIDR])) {
  369. u8 cidr = nla_get_u8(tb[IPSET_ATTR_CIDR]);
  370. if (cidr != HOST_MASK)
  371. return -IPSET_ERR_INVALID_CIDR;
  372. }
  373. ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP], &e.ip);
  374. if (ret)
  375. return ret;
  376. ret = ip_set_get_extensions(set, tb, &ext);
  377. if (ret)
  378. return ret;
  379. ret = ip_set_get_ipaddr6(tb[IPSET_ATTR_IP2], &e.ip2);
  380. if (ret)
  381. return ret;
  382. if (tb[IPSET_ATTR_CIDR2]) {
  383. cidr = nla_get_u8(tb[IPSET_ATTR_CIDR2]);
  384. if (!cidr || cidr > HOST_MASK)
  385. return -IPSET_ERR_INVALID_CIDR;
  386. e.cidr = cidr - 1;
  387. }
  388. ip6_netmask(&e.ip2, e.cidr + 1);
  389. e.port = nla_get_be16(tb[IPSET_ATTR_PORT]);
  390. if (tb[IPSET_ATTR_PROTO]) {
  391. e.proto = nla_get_u8(tb[IPSET_ATTR_PROTO]);
  392. with_ports = ip_set_proto_with_ports(e.proto);
  393. if (e.proto == 0)
  394. return -IPSET_ERR_INVALID_PROTO;
  395. } else {
  396. return -IPSET_ERR_MISSING_PROTO;
  397. }
  398. if (!(with_ports || e.proto == IPPROTO_ICMPV6))
  399. e.port = 0;
  400. if (tb[IPSET_ATTR_CADT_FLAGS]) {
  401. u32 cadt_flags = ip_set_get_h32(tb[IPSET_ATTR_CADT_FLAGS]);
  402. if (cadt_flags & IPSET_FLAG_NOMATCH)
  403. flags |= (IPSET_FLAG_NOMATCH << 16);
  404. }
  405. if (adt == IPSET_TEST || !with_ports || !tb[IPSET_ATTR_PORT_TO]) {
  406. ret = adtfn(set, &e, &ext, &ext, flags);
  407. return ip_set_enomatch(ret, flags, adt, set) ? -ret :
  408. ip_set_eexist(ret, flags) ? 0 : ret;
  409. }
  410. port = ntohs(e.port);
  411. port_to = ip_set_get_h16(tb[IPSET_ATTR_PORT_TO]);
  412. if (port > port_to)
  413. swap(port, port_to);
  414. if (retried)
  415. port = ntohs(h->next.port);
  416. for (; port <= port_to; port++) {
  417. e.port = htons(port);
  418. ret = adtfn(set, &e, &ext, &ext, flags);
  419. if (ret && !ip_set_eexist(ret, flags))
  420. return ret;
  421. ret = 0;
  422. }
  423. return ret;
  424. }
  425. static struct ip_set_type hash_ipportnet_type __read_mostly = {
  426. .name = "hash:ip,port,net",
  427. .protocol = IPSET_PROTOCOL,
  428. .features = IPSET_TYPE_IP | IPSET_TYPE_PORT | IPSET_TYPE_IP2 |
  429. IPSET_TYPE_NOMATCH,
  430. .dimension = IPSET_DIM_THREE,
  431. .family = NFPROTO_UNSPEC,
  432. .revision_min = IPSET_TYPE_REV_MIN,
  433. .revision_max = IPSET_TYPE_REV_MAX,
  434. .create = hash_ipportnet_create,
  435. .create_policy = {
  436. [IPSET_ATTR_HASHSIZE] = { .type = NLA_U32 },
  437. [IPSET_ATTR_MAXELEM] = { .type = NLA_U32 },
  438. [IPSET_ATTR_PROBES] = { .type = NLA_U8 },
  439. [IPSET_ATTR_RESIZE] = { .type = NLA_U8 },
  440. [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
  441. [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
  442. },
  443. .adt_policy = {
  444. [IPSET_ATTR_IP] = { .type = NLA_NESTED },
  445. [IPSET_ATTR_IP_TO] = { .type = NLA_NESTED },
  446. [IPSET_ATTR_IP2] = { .type = NLA_NESTED },
  447. [IPSET_ATTR_IP2_TO] = { .type = NLA_NESTED },
  448. [IPSET_ATTR_PORT] = { .type = NLA_U16 },
  449. [IPSET_ATTR_PORT_TO] = { .type = NLA_U16 },
  450. [IPSET_ATTR_CIDR] = { .type = NLA_U8 },
  451. [IPSET_ATTR_CIDR2] = { .type = NLA_U8 },
  452. [IPSET_ATTR_PROTO] = { .type = NLA_U8 },
  453. [IPSET_ATTR_CADT_FLAGS] = { .type = NLA_U32 },
  454. [IPSET_ATTR_TIMEOUT] = { .type = NLA_U32 },
  455. [IPSET_ATTR_LINENO] = { .type = NLA_U32 },
  456. [IPSET_ATTR_BYTES] = { .type = NLA_U64 },
  457. [IPSET_ATTR_PACKETS] = { .type = NLA_U64 },
  458. [IPSET_ATTR_COMMENT] = { .type = NLA_NUL_STRING,
  459. .len = IPSET_MAX_COMMENT_SIZE },
  460. [IPSET_ATTR_SKBMARK] = { .type = NLA_U64 },
  461. [IPSET_ATTR_SKBPRIO] = { .type = NLA_U32 },
  462. [IPSET_ATTR_SKBQUEUE] = { .type = NLA_U16 },
  463. },
  464. .me = THIS_MODULE,
  465. };
  466. static int __init
  467. hash_ipportnet_init(void)
  468. {
  469. return ip_set_type_register(&hash_ipportnet_type);
  470. }
  471. static void __exit
  472. hash_ipportnet_fini(void)
  473. {
  474. rcu_barrier();
  475. ip_set_type_unregister(&hash_ipportnet_type);
  476. }
  477. module_init(hash_ipportnet_init);
  478. module_exit(hash_ipportnet_fini);