]>
Commit | Line | Data |
---|---|---|
9fb9cbb1 YK |
1 | /* (C) 1999-2001 Paul `Rusty' Russell |
2 | * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org> | |
3 | * | |
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. | |
9fb9cbb1 YK |
7 | */ |
8 | ||
9 | #include <linux/types.h> | |
cd354f1a | 10 | #include <linux/jiffies.h> |
9fb9cbb1 YK |
11 | #include <linux/timer.h> |
12 | #include <linux/netfilter.h> | |
605dcad6 | 13 | #include <net/netfilter/nf_conntrack_l4proto.h> |
9fb9cbb1 | 14 | |
933a41e7 | 15 | static unsigned int nf_ct_generic_timeout __read_mostly = 600*HZ; |
9fb9cbb1 | 16 | |
15f585bd G |
17 | static inline struct nf_generic_net *generic_pernet(struct net *net) |
18 | { | |
19 | return &net->ct.nf_ct_proto.generic; | |
20 | } | |
21 | ||
09f263cd JE |
22 | static bool generic_pkt_to_tuple(const struct sk_buff *skb, |
23 | unsigned int dataoff, | |
24 | struct nf_conntrack_tuple *tuple) | |
9fb9cbb1 YK |
25 | { |
26 | tuple->src.u.all = 0; | |
27 | tuple->dst.u.all = 0; | |
28 | ||
09f263cd | 29 | return true; |
9fb9cbb1 YK |
30 | } |
31 | ||
09f263cd JE |
32 | static bool generic_invert_tuple(struct nf_conntrack_tuple *tuple, |
33 | const struct nf_conntrack_tuple *orig) | |
9fb9cbb1 YK |
34 | { |
35 | tuple->src.u.all = 0; | |
36 | tuple->dst.u.all = 0; | |
37 | ||
09f263cd | 38 | return true; |
9fb9cbb1 YK |
39 | } |
40 | ||
41 | /* Print out the per-protocol part of the tuple. */ | |
42 | static int generic_print_tuple(struct seq_file *s, | |
43 | const struct nf_conntrack_tuple *tuple) | |
44 | { | |
45 | return 0; | |
46 | } | |
47 | ||
2c8503f5 PNA |
48 | static unsigned int *generic_get_timeouts(struct net *net) |
49 | { | |
15f585bd | 50 | return &(generic_pernet(net)->timeout); |
2c8503f5 PNA |
51 | } |
52 | ||
9fb9cbb1 | 53 | /* Returns verdict for packet, or -1 for invalid. */ |
2c8503f5 PNA |
54 | static int generic_packet(struct nf_conn *ct, |
55 | const struct sk_buff *skb, | |
56 | unsigned int dataoff, | |
57 | enum ip_conntrack_info ctinfo, | |
58 | u_int8_t pf, | |
59 | unsigned int hooknum, | |
60 | unsigned int *timeout) | |
9fb9cbb1 | 61 | { |
2c8503f5 | 62 | nf_ct_refresh_acct(ct, ctinfo, skb, *timeout); |
9fb9cbb1 YK |
63 | return NF_ACCEPT; |
64 | } | |
65 | ||
66 | /* Called when a new connection for this protocol found. */ | |
2c8503f5 PNA |
67 | static bool generic_new(struct nf_conn *ct, const struct sk_buff *skb, |
68 | unsigned int dataoff, unsigned int *timeouts) | |
9fb9cbb1 | 69 | { |
09f263cd | 70 | return true; |
9fb9cbb1 YK |
71 | } |
72 | ||
50978462 PNA |
73 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
74 | ||
75 | #include <linux/netfilter/nfnetlink.h> | |
76 | #include <linux/netfilter/nfnetlink_cttimeout.h> | |
77 | ||
78 | static int generic_timeout_nlattr_to_obj(struct nlattr *tb[], void *data) | |
79 | { | |
80 | unsigned int *timeout = data; | |
81 | ||
82 | if (tb[CTA_TIMEOUT_GENERIC_TIMEOUT]) | |
83 | *timeout = | |
84 | ntohl(nla_get_be32(tb[CTA_TIMEOUT_GENERIC_TIMEOUT])) * HZ; | |
85 | else { | |
86 | /* Set default generic timeout. */ | |
87 | *timeout = nf_ct_generic_timeout; | |
88 | } | |
89 | ||
90 | return 0; | |
91 | } | |
92 | ||
93 | static int | |
94 | generic_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data) | |
95 | { | |
96 | const unsigned int *timeout = data; | |
97 | ||
f5776941 DM |
98 | if (nla_put_be32(skb, CTA_TIMEOUT_GENERIC_TIMEOUT, htonl(*timeout / HZ))) |
99 | goto nla_put_failure; | |
50978462 PNA |
100 | |
101 | return 0; | |
102 | ||
103 | nla_put_failure: | |
104 | return -ENOSPC; | |
105 | } | |
106 | ||
107 | static const struct nla_policy | |
108 | generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = { | |
109 | [CTA_TIMEOUT_GENERIC_TIMEOUT] = { .type = NLA_U32 }, | |
110 | }; | |
111 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ | |
112 | ||
933a41e7 | 113 | #ifdef CONFIG_SYSCTL |
933a41e7 PM |
114 | static struct ctl_table generic_sysctl_table[] = { |
115 | { | |
933a41e7 | 116 | .procname = "nf_conntrack_generic_timeout", |
933a41e7 PM |
117 | .maxlen = sizeof(unsigned int), |
118 | .mode = 0644, | |
6d9f239a | 119 | .proc_handler = proc_dointvec_jiffies, |
933a41e7 | 120 | }, |
f8572d8f | 121 | { } |
933a41e7 | 122 | }; |
a999e683 PM |
123 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT |
124 | static struct ctl_table generic_compat_sysctl_table[] = { | |
125 | { | |
a999e683 | 126 | .procname = "ip_conntrack_generic_timeout", |
a999e683 PM |
127 | .maxlen = sizeof(unsigned int), |
128 | .mode = 0644, | |
6d9f239a | 129 | .proc_handler = proc_dointvec_jiffies, |
a999e683 | 130 | }, |
f8572d8f | 131 | { } |
a999e683 PM |
132 | }; |
133 | #endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ | |
933a41e7 PM |
134 | #endif /* CONFIG_SYSCTL */ |
135 | ||
15f585bd G |
136 | static int generic_init_net(struct net *net) |
137 | { | |
138 | struct nf_generic_net *gn = generic_pernet(net); | |
139 | struct nf_proto_net *pn = (struct nf_proto_net *)gn; | |
140 | gn->timeout = nf_ct_generic_timeout; | |
141 | #ifdef CONFIG_SYSCTL | |
142 | pn->ctl_table = kmemdup(generic_sysctl_table, | |
143 | sizeof(generic_sysctl_table), | |
144 | GFP_KERNEL); | |
145 | if (!pn->ctl_table) | |
146 | return -ENOMEM; | |
147 | pn->ctl_table[0].data = &gn->timeout; | |
148 | ||
149 | #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT | |
150 | pn->ctl_compat_table = kmemdup(generic_compat_sysctl_table, | |
151 | sizeof(generic_compat_sysctl_table), | |
152 | GFP_KERNEL); | |
153 | if (!pn->ctl_compat_table) { | |
154 | kfree(pn->ctl_table); | |
155 | pn->ctl_table = NULL; | |
156 | return -ENOMEM; | |
157 | } | |
158 | pn->ctl_compat_table[0].data = &gn->timeout; | |
159 | #endif | |
160 | #endif | |
161 | return 0; | |
162 | } | |
163 | ||
61075af5 | 164 | struct nf_conntrack_l4proto nf_conntrack_l4proto_generic __read_mostly = |
9fb9cbb1 YK |
165 | { |
166 | .l3proto = PF_UNSPEC, | |
fe2a7ce4 | 167 | .l4proto = 255, |
9fb9cbb1 YK |
168 | .name = "unknown", |
169 | .pkt_to_tuple = generic_pkt_to_tuple, | |
170 | .invert_tuple = generic_invert_tuple, | |
171 | .print_tuple = generic_print_tuple, | |
2c8503f5 PNA |
172 | .packet = generic_packet, |
173 | .get_timeouts = generic_get_timeouts, | |
174 | .new = generic_new, | |
50978462 PNA |
175 | #if IS_ENABLED(CONFIG_NF_CT_NETLINK_TIMEOUT) |
176 | .ctnl_timeout = { | |
177 | .nlattr_to_obj = generic_timeout_nlattr_to_obj, | |
178 | .obj_to_nlattr = generic_timeout_obj_to_nlattr, | |
179 | .nlattr_max = CTA_TIMEOUT_GENERIC_MAX, | |
180 | .obj_size = sizeof(unsigned int), | |
181 | .nla_policy = generic_timeout_nla_policy, | |
182 | }, | |
183 | #endif /* CONFIG_NF_CT_NETLINK_TIMEOUT */ | |
15f585bd | 184 | .init_net = generic_init_net, |
9fb9cbb1 | 185 | }; |