2 * (C) 2012 Pablo Neira Ayuso <pablo@netfilter.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation (or any later at your option).
8 * This software has been sponsored by Vyatta Inc. <http://www.vyatta.com>
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
13 #include <linux/skbuff.h>
14 #include <linux/netlink.h>
15 #include <linux/rculist.h>
16 #include <linux/slab.h>
17 #include <linux/types.h>
18 #include <linux/list.h>
19 #include <linux/errno.h>
20 #include <net/netlink.h>
23 #include <net/netfilter/nf_conntrack_helper.h>
24 #include <net/netfilter/nf_conntrack_expect.h>
25 #include <net/netfilter/nf_conntrack_ecache.h>
27 #include <linux/netfilter/nfnetlink.h>
28 #include <linux/netfilter/nfnetlink_conntrack.h>
29 #include <linux/netfilter/nfnetlink_cthelper.h>
31 MODULE_LICENSE("GPL");
32 MODULE_AUTHOR("Pablo Neira Ayuso <pablo@netfilter.org>");
33 MODULE_DESCRIPTION("nfnl_cthelper: User-space connection tracking helpers");
36 nfnl_userspace_cthelper(struct sk_buff
*skb
, unsigned int protoff
,
37 struct nf_conn
*ct
, enum ip_conntrack_info ctinfo
)
39 const struct nf_conn_help
*help
;
40 struct nf_conntrack_helper
*helper
;
46 /* rcu_read_lock()ed by nf_hook_thresh */
47 helper
= rcu_dereference(help
->helper
);
51 /* This is a user-space helper not yet configured, skip. */
53 (NF_CT_HELPER_F_USERSPACE
| NF_CT_HELPER_F_CONFIGURED
)) ==
54 NF_CT_HELPER_F_USERSPACE
)
57 /* If the user-space helper is not available, don't block traffic. */
58 return NF_QUEUE_NR(helper
->queue_num
) | NF_VERDICT_FLAG_QUEUE_BYPASS
;
61 static const struct nla_policy nfnl_cthelper_tuple_pol
[NFCTH_TUPLE_MAX
+1] = {
62 [NFCTH_TUPLE_L3PROTONUM
] = { .type
= NLA_U16
, },
63 [NFCTH_TUPLE_L4PROTONUM
] = { .type
= NLA_U8
, },
67 nfnl_cthelper_parse_tuple(struct nf_conntrack_tuple
*tuple
,
68 const struct nlattr
*attr
)
71 struct nlattr
*tb
[NFCTH_TUPLE_MAX
+1];
73 err
= nla_parse_nested(tb
, NFCTH_TUPLE_MAX
, attr
, nfnl_cthelper_tuple_pol
);
77 if (!tb
[NFCTH_TUPLE_L3PROTONUM
] || !tb
[NFCTH_TUPLE_L4PROTONUM
])
80 /* Not all fields are initialized so first zero the tuple */
81 memset(tuple
, 0, sizeof(struct nf_conntrack_tuple
));
83 tuple
->src
.l3num
= ntohs(nla_get_be16(tb
[NFCTH_TUPLE_L3PROTONUM
]));
84 tuple
->dst
.protonum
= nla_get_u8(tb
[NFCTH_TUPLE_L4PROTONUM
]);
90 nfnl_cthelper_from_nlattr(struct nlattr
*attr
, struct nf_conn
*ct
)
92 struct nf_conn_help
*help
= nfct_help(ct
);
97 if (help
->helper
->data_len
== 0)
100 memcpy(help
->data
, nla_data(attr
), help
->helper
->data_len
);
105 nfnl_cthelper_to_nlattr(struct sk_buff
*skb
, const struct nf_conn
*ct
)
107 const struct nf_conn_help
*help
= nfct_help(ct
);
109 if (help
->helper
->data_len
&&
110 nla_put(skb
, CTA_HELP_INFO
, help
->helper
->data_len
, &help
->data
))
111 goto nla_put_failure
;
119 static const struct nla_policy nfnl_cthelper_expect_pol
[NFCTH_POLICY_MAX
+1] = {
120 [NFCTH_POLICY_NAME
] = { .type
= NLA_NUL_STRING
,
121 .len
= NF_CT_HELPER_NAME_LEN
-1 },
122 [NFCTH_POLICY_EXPECT_MAX
] = { .type
= NLA_U32
, },
123 [NFCTH_POLICY_EXPECT_TIMEOUT
] = { .type
= NLA_U32
, },
127 nfnl_cthelper_expect_policy(struct nf_conntrack_expect_policy
*expect_policy
,
128 const struct nlattr
*attr
)
131 struct nlattr
*tb
[NFCTH_POLICY_MAX
+1];
133 err
= nla_parse_nested(tb
, NFCTH_POLICY_MAX
, attr
, nfnl_cthelper_expect_pol
);
137 if (!tb
[NFCTH_POLICY_NAME
] ||
138 !tb
[NFCTH_POLICY_EXPECT_MAX
] ||
139 !tb
[NFCTH_POLICY_EXPECT_TIMEOUT
])
142 strncpy(expect_policy
->name
,
143 nla_data(tb
[NFCTH_POLICY_NAME
]), NF_CT_HELPER_NAME_LEN
);
144 expect_policy
->max_expected
=
145 ntohl(nla_get_be32(tb
[NFCTH_POLICY_EXPECT_MAX
]));
146 expect_policy
->timeout
=
147 ntohl(nla_get_be32(tb
[NFCTH_POLICY_EXPECT_TIMEOUT
]));
152 static const struct nla_policy
153 nfnl_cthelper_expect_policy_set
[NFCTH_POLICY_SET_MAX
+1] = {
154 [NFCTH_POLICY_SET_NUM
] = { .type
= NLA_U32
, },
158 nfnl_cthelper_parse_expect_policy(struct nf_conntrack_helper
*helper
,
159 const struct nlattr
*attr
)
162 struct nf_conntrack_expect_policy
*expect_policy
;
163 struct nlattr
*tb
[NFCTH_POLICY_SET_MAX
+1];
164 unsigned int class_max
;
166 ret
= nla_parse_nested(tb
, NFCTH_POLICY_SET_MAX
, attr
,
167 nfnl_cthelper_expect_policy_set
);
171 if (!tb
[NFCTH_POLICY_SET_NUM
])
174 class_max
= ntohl(nla_get_be32(tb
[NFCTH_POLICY_SET_NUM
]));
177 if (class_max
> NF_CT_MAX_EXPECT_CLASSES
)
180 expect_policy
= kzalloc(sizeof(struct nf_conntrack_expect_policy
) *
181 class_max
, GFP_KERNEL
);
182 if (expect_policy
== NULL
)
185 for (i
= 0; i
< class_max
; i
++) {
186 if (!tb
[NFCTH_POLICY_SET
+i
])
189 ret
= nfnl_cthelper_expect_policy(&expect_policy
[i
],
190 tb
[NFCTH_POLICY_SET
+i
]);
195 helper
->expect_class_max
= class_max
- 1;
196 helper
->expect_policy
= expect_policy
;
199 kfree(expect_policy
);
204 nfnl_cthelper_create(const struct nlattr
* const tb
[],
205 struct nf_conntrack_tuple
*tuple
)
207 struct nf_conntrack_helper
*helper
;
210 if (!tb
[NFCTH_TUPLE
] || !tb
[NFCTH_POLICY
] || !tb
[NFCTH_PRIV_DATA_LEN
])
213 helper
= kzalloc(sizeof(struct nf_conntrack_helper
), GFP_KERNEL
);
217 ret
= nfnl_cthelper_parse_expect_policy(helper
, tb
[NFCTH_POLICY
]);
221 strncpy(helper
->name
, nla_data(tb
[NFCTH_NAME
]), NF_CT_HELPER_NAME_LEN
);
222 helper
->data_len
= ntohl(nla_get_be32(tb
[NFCTH_PRIV_DATA_LEN
]));
223 helper
->flags
|= NF_CT_HELPER_F_USERSPACE
;
224 memcpy(&helper
->tuple
, tuple
, sizeof(struct nf_conntrack_tuple
));
226 helper
->me
= THIS_MODULE
;
227 helper
->help
= nfnl_userspace_cthelper
;
228 helper
->from_nlattr
= nfnl_cthelper_from_nlattr
;
229 helper
->to_nlattr
= nfnl_cthelper_to_nlattr
;
231 /* Default to queue number zero, this can be updated at any time. */
232 if (tb
[NFCTH_QUEUE_NUM
])
233 helper
->queue_num
= ntohl(nla_get_be32(tb
[NFCTH_QUEUE_NUM
]));
235 if (tb
[NFCTH_STATUS
]) {
236 int status
= ntohl(nla_get_be32(tb
[NFCTH_STATUS
]));
239 case NFCT_HELPER_STATUS_ENABLED
:
240 helper
->flags
|= NF_CT_HELPER_F_CONFIGURED
;
242 case NFCT_HELPER_STATUS_DISABLED
:
243 helper
->flags
&= ~NF_CT_HELPER_F_CONFIGURED
;
248 ret
= nf_conntrack_helper_register(helper
);
254 kfree(helper
->expect_policy
);
261 nfnl_cthelper_update_policy_one(const struct nf_conntrack_expect_policy
*policy
,
262 struct nf_conntrack_expect_policy
*new_policy
,
263 const struct nlattr
*attr
)
265 struct nlattr
*tb
[NFCTH_POLICY_MAX
+ 1];
268 err
= nla_parse_nested(tb
, NFCTH_POLICY_MAX
, attr
,
269 nfnl_cthelper_expect_pol
);
273 if (!tb
[NFCTH_POLICY_NAME
] ||
274 !tb
[NFCTH_POLICY_EXPECT_MAX
] ||
275 !tb
[NFCTH_POLICY_EXPECT_TIMEOUT
])
278 if (nla_strcmp(tb
[NFCTH_POLICY_NAME
], policy
->name
))
281 new_policy
->max_expected
=
282 ntohl(nla_get_be32(tb
[NFCTH_POLICY_EXPECT_MAX
]));
283 new_policy
->timeout
=
284 ntohl(nla_get_be32(tb
[NFCTH_POLICY_EXPECT_TIMEOUT
]));
289 static int nfnl_cthelper_update_policy_all(struct nlattr
*tb
[],
290 struct nf_conntrack_helper
*helper
)
292 struct nf_conntrack_expect_policy new_policy
[helper
->expect_class_max
+ 1];
293 struct nf_conntrack_expect_policy
*policy
;
296 /* Check first that all policy attributes are well-formed, so we don't
297 * leave things in inconsistent state on errors.
299 for (i
= 0; i
< helper
->expect_class_max
+ 1; i
++) {
301 if (!tb
[NFCTH_POLICY_SET
+ i
])
304 err
= nfnl_cthelper_update_policy_one(&helper
->expect_policy
[i
],
306 tb
[NFCTH_POLICY_SET
+ i
]);
310 /* Now we can safely update them. */
311 for (i
= 0; i
< helper
->expect_class_max
+ 1; i
++) {
312 policy
= (struct nf_conntrack_expect_policy
*)
313 &helper
->expect_policy
[i
];
314 policy
->max_expected
= new_policy
->max_expected
;
315 policy
->timeout
= new_policy
->timeout
;
321 static int nfnl_cthelper_update_policy(struct nf_conntrack_helper
*helper
,
322 const struct nlattr
*attr
)
324 struct nlattr
*tb
[NFCTH_POLICY_SET_MAX
+ 1];
325 unsigned int class_max
;
328 err
= nla_parse_nested(tb
, NFCTH_POLICY_SET_MAX
, attr
,
329 nfnl_cthelper_expect_policy_set
);
333 if (!tb
[NFCTH_POLICY_SET_NUM
])
336 class_max
= ntohl(nla_get_be32(tb
[NFCTH_POLICY_SET_NUM
]));
337 if (helper
->expect_class_max
+ 1 != class_max
)
340 return nfnl_cthelper_update_policy_all(tb
, helper
);
344 nfnl_cthelper_update(const struct nlattr
* const tb
[],
345 struct nf_conntrack_helper
*helper
)
349 if (tb
[NFCTH_PRIV_DATA_LEN
])
352 if (tb
[NFCTH_POLICY
]) {
353 ret
= nfnl_cthelper_update_policy(helper
, tb
[NFCTH_POLICY
]);
357 if (tb
[NFCTH_QUEUE_NUM
])
358 helper
->queue_num
= ntohl(nla_get_be32(tb
[NFCTH_QUEUE_NUM
]));
360 if (tb
[NFCTH_STATUS
]) {
361 int status
= ntohl(nla_get_be32(tb
[NFCTH_STATUS
]));
364 case NFCT_HELPER_STATUS_ENABLED
:
365 helper
->flags
|= NF_CT_HELPER_F_CONFIGURED
;
367 case NFCT_HELPER_STATUS_DISABLED
:
368 helper
->flags
&= ~NF_CT_HELPER_F_CONFIGURED
;
375 static int nfnl_cthelper_new(struct net
*net
, struct sock
*nfnl
,
376 struct sk_buff
*skb
, const struct nlmsghdr
*nlh
,
377 const struct nlattr
* const tb
[])
379 const char *helper_name
;
380 struct nf_conntrack_helper
*cur
, *helper
= NULL
;
381 struct nf_conntrack_tuple tuple
;
384 if (!tb
[NFCTH_NAME
] || !tb
[NFCTH_TUPLE
])
387 helper_name
= nla_data(tb
[NFCTH_NAME
]);
389 ret
= nfnl_cthelper_parse_tuple(&tuple
, tb
[NFCTH_TUPLE
]);
394 for (i
= 0; i
< nf_ct_helper_hsize
&& !helper
; i
++) {
395 hlist_for_each_entry_rcu(cur
, &nf_ct_helper_hash
[i
], hnode
) {
397 /* skip non-userspace conntrack helpers. */
398 if (!(cur
->flags
& NF_CT_HELPER_F_USERSPACE
))
401 if (strncmp(cur
->name
, helper_name
,
402 NF_CT_HELPER_NAME_LEN
) != 0)
405 if ((tuple
.src
.l3num
!= cur
->tuple
.src
.l3num
||
406 tuple
.dst
.protonum
!= cur
->tuple
.dst
.protonum
))
409 if (nlh
->nlmsg_flags
& NLM_F_EXCL
) {
420 ret
= nfnl_cthelper_create(tb
, &tuple
);
422 ret
= nfnl_cthelper_update(tb
, helper
);
431 nfnl_cthelper_dump_tuple(struct sk_buff
*skb
,
432 struct nf_conntrack_helper
*helper
)
434 struct nlattr
*nest_parms
;
436 nest_parms
= nla_nest_start(skb
, NFCTH_TUPLE
| NLA_F_NESTED
);
437 if (nest_parms
== NULL
)
438 goto nla_put_failure
;
440 if (nla_put_be16(skb
, NFCTH_TUPLE_L3PROTONUM
,
441 htons(helper
->tuple
.src
.l3num
)))
442 goto nla_put_failure
;
444 if (nla_put_u8(skb
, NFCTH_TUPLE_L4PROTONUM
, helper
->tuple
.dst
.protonum
))
445 goto nla_put_failure
;
447 nla_nest_end(skb
, nest_parms
);
455 nfnl_cthelper_dump_policy(struct sk_buff
*skb
,
456 struct nf_conntrack_helper
*helper
)
459 struct nlattr
*nest_parms1
, *nest_parms2
;
461 nest_parms1
= nla_nest_start(skb
, NFCTH_POLICY
| NLA_F_NESTED
);
462 if (nest_parms1
== NULL
)
463 goto nla_put_failure
;
465 if (nla_put_be32(skb
, NFCTH_POLICY_SET_NUM
,
466 htonl(helper
->expect_class_max
+ 1)))
467 goto nla_put_failure
;
469 for (i
= 0; i
< helper
->expect_class_max
+ 1; i
++) {
470 nest_parms2
= nla_nest_start(skb
,
471 (NFCTH_POLICY_SET
+i
) | NLA_F_NESTED
);
472 if (nest_parms2
== NULL
)
473 goto nla_put_failure
;
475 if (nla_put_string(skb
, NFCTH_POLICY_NAME
,
476 helper
->expect_policy
[i
].name
))
477 goto nla_put_failure
;
479 if (nla_put_be32(skb
, NFCTH_POLICY_EXPECT_MAX
,
480 htonl(helper
->expect_policy
[i
].max_expected
)))
481 goto nla_put_failure
;
483 if (nla_put_be32(skb
, NFCTH_POLICY_EXPECT_TIMEOUT
,
484 htonl(helper
->expect_policy
[i
].timeout
)))
485 goto nla_put_failure
;
487 nla_nest_end(skb
, nest_parms2
);
489 nla_nest_end(skb
, nest_parms1
);
497 nfnl_cthelper_fill_info(struct sk_buff
*skb
, u32 portid
, u32 seq
, u32 type
,
498 int event
, struct nf_conntrack_helper
*helper
)
500 struct nlmsghdr
*nlh
;
501 struct nfgenmsg
*nfmsg
;
502 unsigned int flags
= portid
? NLM_F_MULTI
: 0;
505 event
|= NFNL_SUBSYS_CTHELPER
<< 8;
506 nlh
= nlmsg_put(skb
, portid
, seq
, event
, sizeof(*nfmsg
), flags
);
510 nfmsg
= nlmsg_data(nlh
);
511 nfmsg
->nfgen_family
= AF_UNSPEC
;
512 nfmsg
->version
= NFNETLINK_V0
;
515 if (nla_put_string(skb
, NFCTH_NAME
, helper
->name
))
516 goto nla_put_failure
;
518 if (nla_put_be32(skb
, NFCTH_QUEUE_NUM
, htonl(helper
->queue_num
)))
519 goto nla_put_failure
;
521 if (nfnl_cthelper_dump_tuple(skb
, helper
) < 0)
522 goto nla_put_failure
;
524 if (nfnl_cthelper_dump_policy(skb
, helper
) < 0)
525 goto nla_put_failure
;
527 if (nla_put_be32(skb
, NFCTH_PRIV_DATA_LEN
, htonl(helper
->data_len
)))
528 goto nla_put_failure
;
530 if (helper
->flags
& NF_CT_HELPER_F_CONFIGURED
)
531 status
= NFCT_HELPER_STATUS_ENABLED
;
533 status
= NFCT_HELPER_STATUS_DISABLED
;
535 if (nla_put_be32(skb
, NFCTH_STATUS
, htonl(status
)))
536 goto nla_put_failure
;
543 nlmsg_cancel(skb
, nlh
);
548 nfnl_cthelper_dump_table(struct sk_buff
*skb
, struct netlink_callback
*cb
)
550 struct nf_conntrack_helper
*cur
, *last
;
553 last
= (struct nf_conntrack_helper
*)cb
->args
[1];
554 for (; cb
->args
[0] < nf_ct_helper_hsize
; cb
->args
[0]++) {
556 hlist_for_each_entry_rcu(cur
,
557 &nf_ct_helper_hash
[cb
->args
[0]], hnode
) {
559 /* skip non-userspace conntrack helpers. */
560 if (!(cur
->flags
& NF_CT_HELPER_F_USERSPACE
))
568 if (nfnl_cthelper_fill_info(skb
,
569 NETLINK_CB(cb
->skb
).portid
,
571 NFNL_MSG_TYPE(cb
->nlh
->nlmsg_type
),
572 NFNL_MSG_CTHELPER_NEW
, cur
) < 0) {
573 cb
->args
[1] = (unsigned long)cur
;
587 static int nfnl_cthelper_get(struct net
*net
, struct sock
*nfnl
,
588 struct sk_buff
*skb
, const struct nlmsghdr
*nlh
,
589 const struct nlattr
* const tb
[])
591 int ret
= -ENOENT
, i
;
592 struct nf_conntrack_helper
*cur
;
593 struct sk_buff
*skb2
;
594 char *helper_name
= NULL
;
595 struct nf_conntrack_tuple tuple
;
596 bool tuple_set
= false;
598 if (nlh
->nlmsg_flags
& NLM_F_DUMP
) {
599 struct netlink_dump_control c
= {
600 .dump
= nfnl_cthelper_dump_table
,
602 return netlink_dump_start(nfnl
, skb
, nlh
, &c
);
606 helper_name
= nla_data(tb
[NFCTH_NAME
]);
608 if (tb
[NFCTH_TUPLE
]) {
609 ret
= nfnl_cthelper_parse_tuple(&tuple
, tb
[NFCTH_TUPLE
]);
616 for (i
= 0; i
< nf_ct_helper_hsize
; i
++) {
617 hlist_for_each_entry_rcu(cur
, &nf_ct_helper_hash
[i
], hnode
) {
619 /* skip non-userspace conntrack helpers. */
620 if (!(cur
->flags
& NF_CT_HELPER_F_USERSPACE
))
623 if (helper_name
&& strncmp(cur
->name
, helper_name
,
624 NF_CT_HELPER_NAME_LEN
) != 0) {
628 (tuple
.src
.l3num
!= cur
->tuple
.src
.l3num
||
629 tuple
.dst
.protonum
!= cur
->tuple
.dst
.protonum
))
632 skb2
= nlmsg_new(NLMSG_DEFAULT_SIZE
, GFP_KERNEL
);
638 ret
= nfnl_cthelper_fill_info(skb2
, NETLINK_CB(skb
).portid
,
640 NFNL_MSG_TYPE(nlh
->nlmsg_type
),
641 NFNL_MSG_CTHELPER_NEW
, cur
);
647 ret
= netlink_unicast(nfnl
, skb2
, NETLINK_CB(skb
).portid
,
652 /* this avoids a loop in nfnetlink. */
653 return ret
== -EAGAIN
? -ENOBUFS
: ret
;
659 static int nfnl_cthelper_del(struct net
*net
, struct sock
*nfnl
,
660 struct sk_buff
*skb
, const struct nlmsghdr
*nlh
,
661 const struct nlattr
* const tb
[])
663 char *helper_name
= NULL
;
664 struct nf_conntrack_helper
*cur
;
665 struct hlist_node
*tmp
;
666 struct nf_conntrack_tuple tuple
;
667 bool tuple_set
= false, found
= false;
671 helper_name
= nla_data(tb
[NFCTH_NAME
]);
673 if (tb
[NFCTH_TUPLE
]) {
674 ret
= nfnl_cthelper_parse_tuple(&tuple
, tb
[NFCTH_TUPLE
]);
681 for (i
= 0; i
< nf_ct_helper_hsize
; i
++) {
682 hlist_for_each_entry_safe(cur
, tmp
, &nf_ct_helper_hash
[i
],
684 /* skip non-userspace conntrack helpers. */
685 if (!(cur
->flags
& NF_CT_HELPER_F_USERSPACE
))
690 if (helper_name
&& strncmp(cur
->name
, helper_name
,
691 NF_CT_HELPER_NAME_LEN
) != 0) {
695 (tuple
.src
.l3num
!= cur
->tuple
.src
.l3num
||
696 tuple
.dst
.protonum
!= cur
->tuple
.dst
.protonum
))
700 nf_conntrack_helper_unregister(cur
);
701 kfree(cur
->expect_policy
);
705 /* Make sure we return success if we flush and there is no helpers */
706 return (found
|| j
== 0) ? 0 : -ENOENT
;
709 static const struct nla_policy nfnl_cthelper_policy
[NFCTH_MAX
+1] = {
710 [NFCTH_NAME
] = { .type
= NLA_NUL_STRING
,
711 .len
= NF_CT_HELPER_NAME_LEN
-1 },
712 [NFCTH_QUEUE_NUM
] = { .type
= NLA_U32
, },
715 static const struct nfnl_callback nfnl_cthelper_cb
[NFNL_MSG_CTHELPER_MAX
] = {
716 [NFNL_MSG_CTHELPER_NEW
] = { .call
= nfnl_cthelper_new
,
717 .attr_count
= NFCTH_MAX
,
718 .policy
= nfnl_cthelper_policy
},
719 [NFNL_MSG_CTHELPER_GET
] = { .call
= nfnl_cthelper_get
,
720 .attr_count
= NFCTH_MAX
,
721 .policy
= nfnl_cthelper_policy
},
722 [NFNL_MSG_CTHELPER_DEL
] = { .call
= nfnl_cthelper_del
,
723 .attr_count
= NFCTH_MAX
,
724 .policy
= nfnl_cthelper_policy
},
727 static const struct nfnetlink_subsystem nfnl_cthelper_subsys
= {
729 .subsys_id
= NFNL_SUBSYS_CTHELPER
,
730 .cb_count
= NFNL_MSG_CTHELPER_MAX
,
731 .cb
= nfnl_cthelper_cb
,
734 MODULE_ALIAS_NFNL_SUBSYS(NFNL_SUBSYS_CTHELPER
);
736 static int __init
nfnl_cthelper_init(void)
740 ret
= nfnetlink_subsys_register(&nfnl_cthelper_subsys
);
742 pr_err("nfnl_cthelper: cannot register with nfnetlink.\n");
750 static void __exit
nfnl_cthelper_exit(void)
752 struct nf_conntrack_helper
*cur
;
753 struct hlist_node
*tmp
;
756 nfnetlink_subsys_unregister(&nfnl_cthelper_subsys
);
758 for (i
=0; i
<nf_ct_helper_hsize
; i
++) {
759 hlist_for_each_entry_safe(cur
, tmp
, &nf_ct_helper_hash
[i
],
761 /* skip non-userspace conntrack helpers. */
762 if (!(cur
->flags
& NF_CT_HELPER_F_USERSPACE
))
765 nf_conntrack_helper_unregister(cur
);
766 kfree(cur
->expect_policy
);
772 module_init(nfnl_cthelper_init
);
773 module_exit(nfnl_cthelper_exit
);