Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 1 | /* |
| 2 | * connection tracking helpers. |
| 3 | * |
| 4 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> |
| 5 | * - generalize L3 protocol dependent part. |
| 6 | * |
| 7 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_helper.h |
| 8 | */ |
| 9 | |
| 10 | #ifndef _NF_CONNTRACK_HELPER_H |
| 11 | #define _NF_CONNTRACK_HELPER_H |
| 12 | #include <net/netfilter/nf_conntrack.h> |
Yasuyuki Kozakai | ceceae1 | 2007-07-07 22:23:42 -0700 | [diff] [blame] | 13 | #include <net/netfilter/nf_conntrack_extend.h> |
Pablo Neira Ayuso | 1afc567 | 2012-06-07 12:11:50 +0200 | [diff] [blame] | 14 | #include <net/netfilter/nf_conntrack_expect.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 15 | |
| 16 | struct module; |
| 17 | |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 18 | enum nf_ct_helper_flags { |
| 19 | NF_CT_HELPER_F_USERSPACE = (1 << 0), |
| 20 | NF_CT_HELPER_F_CONFIGURED = (1 << 1), |
| 21 | }; |
| 22 | |
Holger Eitzenberger | af9d32a | 2009-03-25 18:44:01 +0100 | [diff] [blame] | 23 | #define NF_CT_HELPER_NAME_LEN 16 |
| 24 | |
Eric Dumazet | fd2c3ef | 2009-11-03 03:26:03 +0000 | [diff] [blame] | 25 | struct nf_conntrack_helper { |
Patrick McHardy | b8a7fe6 | 2007-07-07 22:36:46 -0700 | [diff] [blame] | 26 | struct hlist_node hnode; /* Internal use. */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 27 | |
Pablo Neira Ayuso | 3a8fc53 | 2012-01-15 16:34:08 +0100 | [diff] [blame] | 28 | char name[NF_CT_HELPER_NAME_LEN]; /* name of the module */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 29 | struct module *me; /* pointer to self */ |
Patrick McHardy | 6002f266 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 30 | const struct nf_conntrack_expect_policy *expect_policy; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 31 | |
Pablo Neira Ayuso | 1afc567 | 2012-06-07 12:11:50 +0200 | [diff] [blame] | 32 | /* length of internal data, ie. sizeof(struct nf_ct_*_master) */ |
| 33 | size_t data_len; |
| 34 | |
Patrick McHardy | d4156e8 | 2007-07-07 22:31:32 -0700 | [diff] [blame] | 35 | /* Tuple of things we will help (compared against server response) */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 36 | struct nf_conntrack_tuple tuple; |
Patrick McHardy | d4156e8 | 2007-07-07 22:31:32 -0700 | [diff] [blame] | 37 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 38 | /* Function to call when data passes; return verdict, or -1 to |
| 39 | invalidate. */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 40 | int (*help)(struct sk_buff *skb, |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 41 | unsigned int protoff, |
| 42 | struct nf_conn *ct, |
| 43 | enum ip_conntrack_info conntrackinfo); |
Pablo Neira Ayuso | c1d10ad | 2006-01-05 12:19:05 -0800 | [diff] [blame] | 44 | |
Patrick McHardy | f09943f | 2006-12-02 22:09:41 -0800 | [diff] [blame] | 45 | void (*destroy)(struct nf_conn *ct); |
| 46 | |
Pablo Neira Ayuso | ae243be | 2012-06-07 14:19:42 +0200 | [diff] [blame] | 47 | int (*from_nlattr)(struct nlattr *attr, struct nf_conn *ct); |
Patrick McHardy | fdf7083 | 2007-09-28 14:37:41 -0700 | [diff] [blame] | 48 | int (*to_nlattr)(struct sk_buff *skb, const struct nf_conn *ct); |
Patrick McHardy | 6002f266 | 2008-03-25 20:09:15 -0700 | [diff] [blame] | 49 | unsigned int expect_class_max; |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 50 | |
| 51 | unsigned int flags; |
| 52 | unsigned int queue_num; /* For user-space helpers. */ |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 53 | }; |
| 54 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 55 | struct nf_conntrack_helper *__nf_conntrack_helper_find(const char *name, |
| 56 | u16 l3num, u8 protonum); |
Martin Josefsson | 7e5d03b | 2006-11-29 02:34:59 +0100 | [diff] [blame] | 57 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 58 | struct nf_conntrack_helper *nf_conntrack_helper_try_module_get(const char *name, |
| 59 | u16 l3num, |
| 60 | u8 protonum); |
Gao Feng | 82de0be | 2016-07-18 11:39:23 +0800 | [diff] [blame] | 61 | void nf_ct_helper_init(struct nf_conntrack_helper *helper, |
| 62 | u16 l3num, u16 protonum, const char *name, |
| 63 | u16 default_port, u16 spec_port, u32 id, |
| 64 | const struct nf_conntrack_expect_policy *exp_pol, |
| 65 | u32 expect_class_max, u32 data_len, |
| 66 | int (*help)(struct sk_buff *skb, unsigned int protoff, |
| 67 | struct nf_conn *ct, |
| 68 | enum ip_conntrack_info ctinfo), |
| 69 | int (*from_nlattr)(struct nlattr *attr, |
| 70 | struct nf_conn *ct), |
| 71 | struct module *module); |
Patrick McHardy | 84f3bb9 | 2010-02-03 17:17:06 +0100 | [diff] [blame] | 72 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 73 | int nf_conntrack_helper_register(struct nf_conntrack_helper *); |
| 74 | void nf_conntrack_helper_unregister(struct nf_conntrack_helper *); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 75 | |
Gao Feng | 82de0be | 2016-07-18 11:39:23 +0800 | [diff] [blame] | 76 | int nf_conntrack_helpers_register(struct nf_conntrack_helper *, unsigned int); |
| 77 | void nf_conntrack_helpers_unregister(struct nf_conntrack_helper *, |
| 78 | unsigned int); |
| 79 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 80 | struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct, |
| 81 | struct nf_conntrack_helper *helper, |
| 82 | gfp_t gfp); |
Patrick McHardy | b560580 | 2007-07-07 22:35:56 -0700 | [diff] [blame] | 83 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 84 | int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl, |
| 85 | gfp_t flags); |
Pablo Neira Ayuso | 226c0c0 | 2008-11-18 11:54:05 +0100 | [diff] [blame] | 86 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 87 | void nf_ct_helper_destroy(struct nf_conn *ct); |
Pablo Neira Ayuso | 9858a3a | 2009-06-13 12:28:22 +0200 | [diff] [blame] | 88 | |
Yasuyuki Kozakai | ceceae1 | 2007-07-07 22:23:42 -0700 | [diff] [blame] | 89 | static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct) |
| 90 | { |
| 91 | return nf_ct_ext_find(ct, NF_CT_EXT_HELPER); |
| 92 | } |
Patrick McHardy | b334aad | 2008-01-14 23:48:57 -0800 | [diff] [blame] | 93 | |
Pablo Neira Ayuso | 1afc567 | 2012-06-07 12:11:50 +0200 | [diff] [blame] | 94 | static inline void *nfct_help_data(const struct nf_conn *ct) |
| 95 | { |
| 96 | struct nf_conn_help *help; |
| 97 | |
| 98 | help = nf_ct_ext_find(ct, NF_CT_EXT_HELPER); |
| 99 | |
| 100 | return (void *)help->data; |
| 101 | } |
| 102 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 103 | int nf_conntrack_helper_pernet_init(struct net *net); |
| 104 | void nf_conntrack_helper_pernet_fini(struct net *net); |
Gao feng | 5e615b2 | 2013-01-21 22:10:30 +0000 | [diff] [blame] | 105 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 106 | int nf_conntrack_helper_init(void); |
| 107 | void nf_conntrack_helper_fini(void); |
Patrick McHardy | b334aad | 2008-01-14 23:48:57 -0800 | [diff] [blame] | 108 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 109 | int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff, |
| 110 | struct nf_conn *ct, |
| 111 | enum ip_conntrack_info ctinfo, |
| 112 | unsigned int timeout); |
Jiri Olsa | 93557f5 | 2011-01-18 18:12:24 +0100 | [diff] [blame] | 113 | |
Pablo Neira Ayuso | 544d5c7 | 2012-02-05 03:44:51 +0100 | [diff] [blame] | 114 | struct nf_ct_helper_expectfn { |
| 115 | struct list_head head; |
| 116 | const char *name; |
| 117 | void (*expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp); |
| 118 | }; |
| 119 | |
Pablo Neira Ayuso | b20ab9cc | 2013-02-10 18:56:56 +0100 | [diff] [blame] | 120 | __printf(3,4) |
| 121 | void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct, |
| 122 | const char *fmt, ...); |
| 123 | |
Pablo Neira Ayuso | 544d5c7 | 2012-02-05 03:44:51 +0100 | [diff] [blame] | 124 | void nf_ct_helper_expectfn_register(struct nf_ct_helper_expectfn *n); |
| 125 | void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n); |
| 126 | struct nf_ct_helper_expectfn * |
| 127 | nf_ct_helper_expectfn_find_by_name(const char *name); |
| 128 | struct nf_ct_helper_expectfn * |
| 129 | nf_ct_helper_expectfn_find_by_symbol(const void *symbol); |
| 130 | |
Pablo Neira Ayuso | 12f7a50 | 2012-05-13 21:44:54 +0200 | [diff] [blame] | 131 | extern struct hlist_head *nf_ct_helper_hash; |
| 132 | extern unsigned int nf_ct_helper_hsize; |
| 133 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 134 | #endif /*_NF_CONNTRACK_HELPER_H*/ |