Skip to content

Commit 21f42cc

Browse files
committed
xfrm: Move device notifications to a sepatate file
This is needed for the upcomming IPsec device offloading. Signed-off-by: Steffen Klassert <[email protected]>
1 parent 9d389d7 commit 21f42cc

File tree

4 files changed

+46
-17
lines changed

4 files changed

+46
-17
lines changed

include/net/xfrm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,6 +1443,7 @@ struct xfrm6_tunnel {
14431443
void xfrm_init(void);
14441444
void xfrm4_init(void);
14451445
int xfrm_state_init(struct net *net);
1446+
void xfrm_dev_init(void);
14461447
void xfrm_state_fini(struct net *net);
14471448
void xfrm4_state_init(void);
14481449
void xfrm4_protocol_init(void);

net/xfrm/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
obj-$(CONFIG_XFRM) := xfrm_policy.o xfrm_state.o xfrm_hash.o \
66
xfrm_input.o xfrm_output.o \
7-
xfrm_sysctl.o xfrm_replay.o
7+
xfrm_sysctl.o xfrm_replay.o xfrm_device.o
88
obj-$(CONFIG_XFRM_STATISTICS) += xfrm_proc.o
99
obj-$(CONFIG_XFRM_ALGO) += xfrm_algo.o
1010
obj-$(CONFIG_XFRM_USER) += xfrm_user.o

net/xfrm/xfrm_device.c

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* xfrm_device.c - IPsec device offloading code.
3+
*
4+
* Copyright (c) 2015 secunet Security Networks AG
5+
*
6+
* Author:
7+
* Steffen Klassert <[email protected]>
8+
*
9+
* This program is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU General Public License
11+
* as published by the Free Software Foundation; either version
12+
* 2 of the License, or (at your option) any later version.
13+
*/
14+
15+
#include <linux/errno.h>
16+
#include <linux/module.h>
17+
#include <linux/netdevice.h>
18+
#include <linux/skbuff.h>
19+
#include <linux/slab.h>
20+
#include <linux/spinlock.h>
21+
#include <net/dst.h>
22+
#include <net/xfrm.h>
23+
#include <linux/notifier.h>
24+
25+
static int xfrm_dev_event(struct notifier_block *this, unsigned long event, void *ptr)
26+
{
27+
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
28+
29+
switch (event) {
30+
case NETDEV_DOWN:
31+
xfrm_garbage_collect(dev_net(dev));
32+
}
33+
return NOTIFY_DONE;
34+
}
35+
36+
static struct notifier_block xfrm_dev_notifier = {
37+
.notifier_call = xfrm_dev_event,
38+
};
39+
40+
void __net_init xfrm_dev_init(void)
41+
{
42+
register_netdevice_notifier(&xfrm_dev_notifier);
43+
}

net/xfrm/xfrm_policy.c

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2929,21 +2929,6 @@ void xfrm_policy_unregister_afinfo(const struct xfrm_policy_afinfo *afinfo)
29292929
}
29302930
EXPORT_SYMBOL(xfrm_policy_unregister_afinfo);
29312931

2932-
static int xfrm_dev_event(struct notifier_block *this, unsigned long event, void *ptr)
2933-
{
2934-
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
2935-
2936-
switch (event) {
2937-
case NETDEV_DOWN:
2938-
xfrm_garbage_collect(dev_net(dev));
2939-
}
2940-
return NOTIFY_DONE;
2941-
}
2942-
2943-
static struct notifier_block xfrm_dev_notifier = {
2944-
.notifier_call = xfrm_dev_event,
2945-
};
2946-
29472932
#ifdef CONFIG_XFRM_STATISTICS
29482933
static int __net_init xfrm_statistics_init(struct net *net)
29492934
{
@@ -3020,7 +3005,7 @@ static int __net_init xfrm_policy_init(struct net *net)
30203005
INIT_WORK(&net->xfrm.policy_hash_work, xfrm_hash_resize);
30213006
INIT_WORK(&net->xfrm.policy_hthresh.work, xfrm_hash_rebuild);
30223007
if (net_eq(net, &init_net))
3023-
register_netdevice_notifier(&xfrm_dev_notifier);
3008+
xfrm_dev_init();
30243009
return 0;
30253010

30263011
out_bydst:

0 commit comments

Comments
 (0)