Skip to content

Commit efe4160

Browse files
Florian Westphalummakynes
Florian Westphal
authored andcommitted
ipvs: convert to use pernet nf_hook api
nf_(un)register_hooks has to maintain an internal hook list to add/remove those hooks from net namespaces as they are added/deleted. ipvs already uses pernet_ops, so we can switch to the (more recent) pernet hook api instead. Compile tested only. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent 1fefe14 commit efe4160

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

net/netfilter/ipvs/ip_vs_core.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -2200,6 +2200,7 @@ static struct nf_hook_ops ip_vs_ops[] __read_mostly = {
22002200
static int __net_init __ip_vs_init(struct net *net)
22012201
{
22022202
struct netns_ipvs *ipvs;
2203+
int ret;
22032204

22042205
ipvs = net_generic(net, ip_vs_net_id);
22052206
if (ipvs == NULL)
@@ -2231,11 +2232,17 @@ static int __net_init __ip_vs_init(struct net *net)
22312232
if (ip_vs_sync_net_init(ipvs) < 0)
22322233
goto sync_fail;
22332234

2235+
ret = nf_register_net_hooks(net, ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
2236+
if (ret < 0)
2237+
goto hook_fail;
2238+
22342239
return 0;
22352240
/*
22362241
* Error handling
22372242
*/
22382243

2244+
hook_fail:
2245+
ip_vs_sync_net_cleanup(ipvs);
22392246
sync_fail:
22402247
ip_vs_conn_net_cleanup(ipvs);
22412248
conn_fail:
@@ -2255,6 +2262,7 @@ static void __net_exit __ip_vs_cleanup(struct net *net)
22552262
{
22562263
struct netns_ipvs *ipvs = net_ipvs(net);
22572264

2265+
nf_unregister_net_hooks(net, ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
22582266
ip_vs_service_net_cleanup(ipvs); /* ip_vs_flush() with locks */
22592267
ip_vs_conn_net_cleanup(ipvs);
22602268
ip_vs_app_net_cleanup(ipvs);
@@ -2315,24 +2323,16 @@ static int __init ip_vs_init(void)
23152323
if (ret < 0)
23162324
goto cleanup_sub;
23172325

2318-
ret = nf_register_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
2319-
if (ret < 0) {
2320-
pr_err("can't register hooks.\n");
2321-
goto cleanup_dev;
2322-
}
2323-
23242326
ret = ip_vs_register_nl_ioctl();
23252327
if (ret < 0) {
23262328
pr_err("can't register netlink/ioctl.\n");
2327-
goto cleanup_hooks;
2329+
goto cleanup_dev;
23282330
}
23292331

23302332
pr_info("ipvs loaded.\n");
23312333

23322334
return ret;
23332335

2334-
cleanup_hooks:
2335-
nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
23362336
cleanup_dev:
23372337
unregister_pernet_device(&ipvs_core_dev_ops);
23382338
cleanup_sub:
@@ -2349,7 +2349,6 @@ static int __init ip_vs_init(void)
23492349
static void __exit ip_vs_cleanup(void)
23502350
{
23512351
ip_vs_unregister_nl_ioctl();
2352-
nf_unregister_hooks(ip_vs_ops, ARRAY_SIZE(ip_vs_ops));
23532352
unregister_pernet_device(&ipvs_core_dev_ops);
23542353
unregister_pernet_subsys(&ipvs_core_ops); /* free ip_vs struct */
23552354
ip_vs_conn_cleanup();

0 commit comments

Comments
 (0)