aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2007-03-14 19:38:48 -0400
committerDavid S. Miller <davem@sunset.davemloft.net>2007-04-26 01:25:41 -0400
commit0661cca9c216322e77dca7f47df107c02ce4e70c (patch)
treeff6ada19305a1a1748f8c56de64840001b3e2bb2
parentac5357ebac43e191003c2cd0722377dccfa01a84 (diff)
[NETFILTER]: nf_conntrack: simplify protocol locking
Now that we don't use nf_conntrack_lock anymore but a single mutex for all protocol handling, no need to release and grab it again for sysctl registration. Signed-off-by: Patrick McHardy <kaber@trash.net> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/netfilter/nf_conntrack_proto.c45
1 files changed, 14 insertions, 31 deletions
diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
index 0ca2f0ba7c76..509725412d3b 100644
--- a/net/netfilter/nf_conntrack_proto.c
+++ b/net/netfilter/nf_conntrack_proto.c
@@ -164,13 +164,11 @@ static int nf_ct_l3proto_register_sysctl(struct nf_conntrack_l3proto *l3proto)
164 int err = 0; 164 int err = 0;
165 165
166#ifdef CONFIG_SYSCTL 166#ifdef CONFIG_SYSCTL
167 mutex_lock(&nf_ct_proto_mutex);
168 if (l3proto->ctl_table != NULL) { 167 if (l3proto->ctl_table != NULL) {
169 err = nf_ct_register_sysctl(&l3proto->ctl_table_header, 168 err = nf_ct_register_sysctl(&l3proto->ctl_table_header,
170 l3proto->ctl_table_path, 169 l3proto->ctl_table_path,
171 l3proto->ctl_table, NULL); 170 l3proto->ctl_table, NULL);
172 } 171 }
173 mutex_unlock(&nf_ct_proto_mutex);
174#endif 172#endif
175 return err; 173 return err;
176} 174}
@@ -178,11 +176,9 @@ static int nf_ct_l3proto_register_sysctl(struct nf_conntrack_l3proto *l3proto)
178static void nf_ct_l3proto_unregister_sysctl(struct nf_conntrack_l3proto *l3proto) 176static void nf_ct_l3proto_unregister_sysctl(struct nf_conntrack_l3proto *l3proto)
179{ 177{
180#ifdef CONFIG_SYSCTL 178#ifdef CONFIG_SYSCTL
181 mutex_lock(&nf_ct_proto_mutex);
182 if (l3proto->ctl_table_header != NULL) 179 if (l3proto->ctl_table_header != NULL)
183 nf_ct_unregister_sysctl(&l3proto->ctl_table_header, 180 nf_ct_unregister_sysctl(&l3proto->ctl_table_header,
184 l3proto->ctl_table, NULL); 181 l3proto->ctl_table, NULL);
185 mutex_unlock(&nf_ct_proto_mutex);
186#endif 182#endif
187} 183}
188 184
@@ -190,27 +186,23 @@ int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto)
190{ 186{
191 int ret = 0; 187 int ret = 0;
192 188
193 if (proto->l3proto >= AF_MAX) { 189 if (proto->l3proto >= AF_MAX)
194 ret = -EBUSY; 190 return -EBUSY;
195 goto out;
196 }
197 191
198 mutex_lock(&nf_ct_proto_mutex); 192 mutex_lock(&nf_ct_proto_mutex);
199 if (nf_ct_l3protos[proto->l3proto] != &nf_conntrack_l3proto_generic) { 193 if (nf_ct_l3protos[proto->l3proto] != &nf_conntrack_l3proto_generic) {
200 ret = -EBUSY; 194 ret = -EBUSY;
201 goto out_unlock; 195 goto out_unlock;
202 } 196 }
203 rcu_assign_pointer(nf_ct_l3protos[proto->l3proto], proto);
204 mutex_unlock(&nf_ct_proto_mutex);
205 197
206 ret = nf_ct_l3proto_register_sysctl(proto); 198 ret = nf_ct_l3proto_register_sysctl(proto);
207 if (ret < 0) 199 if (ret < 0)
208 nf_conntrack_l3proto_unregister(proto); 200 goto out_unlock;
209 return ret; 201
202 rcu_assign_pointer(nf_ct_l3protos[proto->l3proto], proto);
210 203
211out_unlock: 204out_unlock:
212 mutex_unlock(&nf_ct_proto_mutex); 205 mutex_unlock(&nf_ct_proto_mutex);
213out:
214 return ret; 206 return ret;
215} 207}
216EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_register); 208EXPORT_SYMBOL_GPL(nf_conntrack_l3proto_register);
@@ -223,10 +215,10 @@ void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto)
223 BUG_ON(nf_ct_l3protos[proto->l3proto] != proto); 215 BUG_ON(nf_ct_l3protos[proto->l3proto] != proto);
224 rcu_assign_pointer(nf_ct_l3protos[proto->l3proto], 216 rcu_assign_pointer(nf_ct_l3protos[proto->l3proto],
225 &nf_conntrack_l3proto_generic); 217 &nf_conntrack_l3proto_generic);
218 nf_ct_l3proto_unregister_sysctl(proto);
226 mutex_unlock(&nf_ct_proto_mutex); 219 mutex_unlock(&nf_ct_proto_mutex);
227 synchronize_rcu();
228 220
229 nf_ct_l3proto_unregister_sysctl(proto); 221 synchronize_rcu();
230 222
231 /* Remove all contrack entries for this protocol */ 223 /* Remove all contrack entries for this protocol */
232 nf_ct_iterate_cleanup(kill_l3proto, proto); 224 nf_ct_iterate_cleanup(kill_l3proto, proto);
@@ -238,7 +230,6 @@ static int nf_ct_l4proto_register_sysctl(struct nf_conntrack_l4proto *l4proto)
238 int err = 0; 230 int err = 0;
239 231
240#ifdef CONFIG_SYSCTL 232#ifdef CONFIG_SYSCTL
241 mutex_lock(&nf_ct_proto_mutex);
242 if (l4proto->ctl_table != NULL) { 233 if (l4proto->ctl_table != NULL) {
243 err = nf_ct_register_sysctl(l4proto->ctl_table_header, 234 err = nf_ct_register_sysctl(l4proto->ctl_table_header,
244 nf_net_netfilter_sysctl_path, 235 nf_net_netfilter_sysctl_path,
@@ -260,7 +251,6 @@ static int nf_ct_l4proto_register_sysctl(struct nf_conntrack_l4proto *l4proto)
260 } 251 }
261#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 252#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
262out: 253out:
263 mutex_unlock(&nf_ct_proto_mutex);
264#endif /* CONFIG_SYSCTL */ 254#endif /* CONFIG_SYSCTL */
265 return err; 255 return err;
266} 256}
@@ -268,7 +258,6 @@ out:
268static void nf_ct_l4proto_unregister_sysctl(struct nf_conntrack_l4proto *l4proto) 258static void nf_ct_l4proto_unregister_sysctl(struct nf_conntrack_l4proto *l4proto)
269{ 259{
270#ifdef CONFIG_SYSCTL 260#ifdef CONFIG_SYSCTL
271 mutex_lock(&nf_ct_proto_mutex);
272 if (l4proto->ctl_table_header != NULL && 261 if (l4proto->ctl_table_header != NULL &&
273 *l4proto->ctl_table_header != NULL) 262 *l4proto->ctl_table_header != NULL)
274 nf_ct_unregister_sysctl(l4proto->ctl_table_header, 263 nf_ct_unregister_sysctl(l4proto->ctl_table_header,
@@ -279,7 +268,6 @@ static void nf_ct_l4proto_unregister_sysctl(struct nf_conntrack_l4proto *l4proto
279 nf_ct_unregister_sysctl(&l4proto->ctl_compat_table_header, 268 nf_ct_unregister_sysctl(&l4proto->ctl_compat_table_header,
280 l4proto->ctl_compat_table, NULL); 269 l4proto->ctl_compat_table, NULL);
281#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */ 270#endif /* CONFIG_NF_CONNTRACK_PROC_COMPAT */
282 mutex_unlock(&nf_ct_proto_mutex);
283#endif /* CONFIG_SYSCTL */ 271#endif /* CONFIG_SYSCTL */
284} 272}
285 273
@@ -289,10 +277,8 @@ int nf_conntrack_l4proto_register(struct nf_conntrack_l4proto *l4proto)
289{ 277{
290 int ret = 0; 278 int ret = 0;
291 279
292 if (l4proto->l3proto >= PF_MAX) { 280 if (l4proto->l3proto >= PF_MAX)
293 ret = -EBUSY; 281 return -EBUSY;
294 goto out;
295 }
296 282
297 mutex_lock(&nf_ct_proto_mutex); 283 mutex_lock(&nf_ct_proto_mutex);
298retry: 284retry:
@@ -331,17 +317,14 @@ retry:
331 goto retry; 317 goto retry;
332 } 318 }
333 319
334 rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto], l4proto);
335 mutex_unlock(&nf_ct_proto_mutex);
336
337 ret = nf_ct_l4proto_register_sysctl(l4proto); 320 ret = nf_ct_l4proto_register_sysctl(l4proto);
338 if (ret < 0) 321 if (ret < 0)
339 nf_conntrack_l4proto_unregister(l4proto); 322 goto out_unlock;
340 return ret; 323
324 rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto], l4proto);
341 325
342out_unlock: 326out_unlock:
343 mutex_unlock(&nf_ct_proto_mutex); 327 mutex_unlock(&nf_ct_proto_mutex);
344out:
345 return ret; 328 return ret;
346} 329}
347EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_register); 330EXPORT_SYMBOL_GPL(nf_conntrack_l4proto_register);
@@ -354,10 +337,10 @@ void nf_conntrack_l4proto_unregister(struct nf_conntrack_l4proto *l4proto)
354 BUG_ON(nf_ct_protos[l4proto->l3proto][l4proto->l4proto] != l4proto); 337 BUG_ON(nf_ct_protos[l4proto->l3proto][l4proto->l4proto] != l4proto);
355 rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto], 338 rcu_assign_pointer(nf_ct_protos[l4proto->l3proto][l4proto->l4proto],
356 &nf_conntrack_l4proto_generic); 339 &nf_conntrack_l4proto_generic);
340 nf_ct_l4proto_unregister_sysctl(l4proto);
357 mutex_unlock(&nf_ct_proto_mutex); 341 mutex_unlock(&nf_ct_proto_mutex);
358 synchronize_rcu();
359 342
360 nf_ct_l4proto_unregister_sysctl(l4proto); 343 synchronize_rcu();
361 344
362 /* Remove all contrack entries for this protocol */ 345 /* Remove all contrack entries for this protocol */
363 nf_ct_iterate_cleanup(kill_l4proto, l4proto); 346 nf_ct_iterate_cleanup(kill_l4proto, l4proto);